mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-07-01 06:13:30 +00:00
Compare commits
5 Commits
30-08-2018
...
22-01-2019
Author | SHA1 | Date | |
---|---|---|---|
2753569015 | |||
4e0b5c5fc9 | |||
1ef7f662e5 | |||
4f5ab6e966 | |||
827fec68c7 |
@ -359,6 +359,36 @@ class GroupsController {
|
||||
return $members;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite a user to join the network
|
||||
*
|
||||
* @url POST /groups/invite
|
||||
*/
|
||||
public function inviteUser(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Get target group ID
|
||||
$groupID = getPostGroupIdWithAccess("group_id", GroupInfo::MODERATOR_ACCESS);
|
||||
|
||||
//Get target user ID
|
||||
$userID = getPostUserID("userID");
|
||||
|
||||
//Get the current status of the user over the group
|
||||
if(components()->groups->getMembershipLevel($userID, $groupID) != GroupMember::VISITOR)
|
||||
Rest_fatal_error(401, "The user is not a visitor for this group!");
|
||||
|
||||
//Save the invitation of the user
|
||||
if(!components()->groups->sendInvitation($userID, $groupID))
|
||||
Rest_fatal_error(500, "Could not send user invitation!");
|
||||
|
||||
//Create notification
|
||||
create_group_membership_notification($userID, userID, $groupID, Notification::SENT_GROUP_MEMBERSHIP_INVITATION);
|
||||
|
||||
//Success
|
||||
return array("success" => "The user has been successfully invited to join this group!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to a membership invitation
|
||||
*
|
||||
@ -642,10 +672,6 @@ class GroupsController {
|
||||
|
||||
//Get the list of groups of the user
|
||||
$list = components()->groups->getListUser(userID);
|
||||
|
||||
//Parse list
|
||||
foreach($list as $num => $info)
|
||||
$list[$num] = self::GroupInfoToAPI($info);
|
||||
|
||||
return $list;
|
||||
|
||||
@ -706,6 +732,29 @@ class GroupsController {
|
||||
return array("success" => "Follow status has been successfully updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a group
|
||||
*
|
||||
* @url POST groups/delete
|
||||
*/
|
||||
public function delete(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Check user password
|
||||
if(!check_post_password(userID, "password"))
|
||||
Rest_fatal_error(401, "Password required!");
|
||||
|
||||
//Get the group
|
||||
$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::ADMIN_ACCESS);
|
||||
|
||||
//Delete the group
|
||||
if(!components()->groups->delete_group($groupID))
|
||||
Rest_fatal_error(500, "Could not delete group!");
|
||||
|
||||
return array("success" => "The group has been successfully deleted!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a GroupInfo object into an array for the API
|
||||
*
|
||||
|
@ -486,12 +486,6 @@ class PostsController {
|
||||
if(!CS::get()->components->posts->delete($postID))
|
||||
Rest_fatal_error(500, "Couldn't delete post!");
|
||||
|
||||
//Delete related notifications
|
||||
$notification = new Notification();
|
||||
$notification->set_on_elem_type(Notification::POST);
|
||||
$notification->set_on_elem_id($postID);
|
||||
components()->notifications->delete($notification);
|
||||
|
||||
//Success
|
||||
return array("success" => "The post has been deleted!");
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class friendsController{
|
||||
}
|
||||
|
||||
//Update the last activity of the user
|
||||
CS::get()->components->user->updateLastActivity(userID);
|
||||
update_last_user_activity_if_allowed();
|
||||
|
||||
//Return list
|
||||
return $api_list;
|
||||
|
@ -129,7 +129,7 @@ class userController
|
||||
user_login_required();
|
||||
|
||||
//Update last user activity
|
||||
CS::get()->components->user->updateLastActivity(userID);
|
||||
update_last_user_activity_if_allowed();
|
||||
|
||||
//Return userID
|
||||
return array("userID" => userID);
|
||||
|
@ -71,7 +71,7 @@ class GroupsComponent {
|
||||
* Get the list of groups of a user
|
||||
*
|
||||
* @param int $userID The ID of the target user
|
||||
* @return array The list of groups of the user
|
||||
* @return array The list of groups of the user (the IDs of the groups)
|
||||
*/
|
||||
public function getListUser(int $userID) : array {
|
||||
|
||||
@ -86,7 +86,7 @@ class GroupsComponent {
|
||||
//Parse results
|
||||
$info = array();
|
||||
foreach($groups as $group)
|
||||
$info[] = $this->get_info($group["groups_id"]);
|
||||
$info[] = $group["groups_id"];
|
||||
|
||||
return $info;
|
||||
}
|
||||
@ -354,6 +354,22 @@ class GroupsComponent {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invite a user to join a group
|
||||
*
|
||||
* @param int $userID The ID of the target user
|
||||
* @param int $groupID The ID of the target group
|
||||
* @param bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function sendInvitation(int $userID, int $groupID) : bool {
|
||||
$member = new GroupMember();
|
||||
$member->set_userID($userID);
|
||||
$member->set_group_id($groupID);
|
||||
$member->set_time_sent(time());
|
||||
$member->set_level(GroupMember::INVITED);
|
||||
return $this->insertMember($member);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a user received an invitation or not
|
||||
*
|
||||
@ -684,6 +700,38 @@ class GroupsComponent {
|
||||
array($groupID, $userID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a group
|
||||
*
|
||||
* @param int $groupID Target group id
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function delete_group(int $groupID) : bool {
|
||||
|
||||
//Delete group image
|
||||
if(!$this->deleteLogo($groupID))
|
||||
return FALSE;
|
||||
|
||||
//Delete all group posts
|
||||
if(!components()->posts->deleteAllGroup($groupID))
|
||||
return FALSE;
|
||||
|
||||
//Delete all group related notifications
|
||||
if(!components()->notifications->deleteAllRelatedWithGroup($groupID))
|
||||
return FALSE;
|
||||
|
||||
//Delete all group members
|
||||
if(!db()->deleteEntry(self::GROUPS_MEMBERS_TABLE, "groups_id = ?", array($groupID)))
|
||||
return FALSE;
|
||||
|
||||
//Delete group information
|
||||
if(!db()->deleteEntry(self::GROUPS_LIST_TABLE, "id = ?", array($groupID)))
|
||||
return FALSE;
|
||||
|
||||
//Success
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a GroupInfo object
|
||||
*
|
||||
|
@ -93,7 +93,7 @@ class notificationComponent {
|
||||
//Determine the visibility level of the notification
|
||||
if($notification->get_on_elem_type() == Notification::POST){
|
||||
|
||||
//Fetch post informations
|
||||
//Fetch post information
|
||||
$info_post = components()->posts->get_single($notification->get_on_elem_id());
|
||||
|
||||
//Check for error
|
||||
@ -402,6 +402,21 @@ class notificationComponent {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete all the notifications related with a post
|
||||
*
|
||||
* @param int $postID The ID of the target post
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function deleteAllRelatedWithPost(int $postID) : bool {
|
||||
|
||||
$notification = new Notification();
|
||||
$notification->set_on_elem_type(Notification::POST);
|
||||
$notification->set_on_elem_id($postID);
|
||||
return $this->delete($notification);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the notifications related with a user
|
||||
*
|
||||
@ -421,6 +436,26 @@ class notificationComponent {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the notifications related with a group
|
||||
*
|
||||
* @param int $groupID The ID of the target group
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function deleteAllRelatedWithGroup(int $groupID) : bool {
|
||||
|
||||
//Groups membership notifications
|
||||
$notification = new Notification();
|
||||
$notification->set_on_elem_type(Notification::GROUP_MEMBERSHIP);
|
||||
$notification->set_on_elem_id($groupID);
|
||||
if(!$this->delete($notification)) return FALSE;
|
||||
|
||||
$notification->set_on_elem_type(Notification::GROUP_PAGE);
|
||||
if(!$this->delete($notification)) return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a notification object into database array
|
||||
*
|
||||
|
@ -327,6 +327,34 @@ class Posts {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire list of posts of a group, ignoring visibility levels
|
||||
*
|
||||
* @param int $groupID The ID of the target group
|
||||
* @param bool $load_comments Specify whether the comments should be loaded or not
|
||||
* @return array The list of posts
|
||||
*/
|
||||
public function getGroupEntirePostsList(int $groupID, bool $load_comments = FALSE) : array {
|
||||
|
||||
//Security
|
||||
if($groupID == 0)
|
||||
return array();
|
||||
|
||||
//Prepare database request
|
||||
$conditions = "WHERE group_id = ?";
|
||||
$dataConds = array($groupID);
|
||||
|
||||
//Perform the request
|
||||
$list = CS::get()->db->select(
|
||||
$this::TABLE_NAME,
|
||||
$conditions,
|
||||
$dataConds
|
||||
);
|
||||
|
||||
//Parse and return posts (do not load comments)
|
||||
return $this->processGetMultiple($list, $load_comments);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entire list of posts that uses a movie
|
||||
*
|
||||
@ -644,13 +672,17 @@ class Posts {
|
||||
*/
|
||||
public function delete(int $postID) : bool {
|
||||
|
||||
//Get informations about the post
|
||||
//Get information about the post
|
||||
$post_info = $this->get_single($postID);
|
||||
|
||||
//Check if we didn't get informations about the post
|
||||
//Check if we didn't get information about the post
|
||||
if(!$post_info->isValid())
|
||||
return false;
|
||||
|
||||
//Delete all the notifications related to the post
|
||||
if(!components()->notifications->deleteAllRelatedWithPost($postID))
|
||||
return FALSE;
|
||||
|
||||
//Delete the likes associated to the post
|
||||
if(!components()->likes->delete_all($postID, Likes::LIKE_POST))
|
||||
return false;
|
||||
@ -765,6 +797,30 @@ class Posts {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all the posts of a group
|
||||
*
|
||||
* @param int $groupID The ID of the target group
|
||||
* @return bool TRUE for a success / FALSE else
|
||||
*/
|
||||
public function deleteAllGroup(int $groupID) : bool {
|
||||
|
||||
//Get the list of posts of the group
|
||||
$posts = $this->getGroupEntirePostsList($groupID);
|
||||
|
||||
//Delete the list of posts
|
||||
foreach($posts as $post){
|
||||
|
||||
//Delete the posts
|
||||
if(!$this->delete($post->get_id()))
|
||||
return FALSE;
|
||||
|
||||
}
|
||||
|
||||
//Success
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process processing of multiples posts entries in database
|
||||
*
|
||||
|
@ -58,4 +58,21 @@ function check_post_password(int $userID, string $name) : bool {
|
||||
|
||||
//Else the password seems to be valid
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update last user activity if the user allows it
|
||||
*
|
||||
* This function do not do anything if the incognito mode
|
||||
* has been enabled by the user
|
||||
*/
|
||||
function update_last_user_activity_if_allowed() {
|
||||
|
||||
//Check if incognito mode is enabled
|
||||
if(isset($_POST["incognito"]))
|
||||
return;
|
||||
|
||||
//Update last activity time of the user
|
||||
CS::get()->components->user->updateLastActivity(userID);
|
||||
|
||||
}
|
Reference in New Issue
Block a user