mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
Can delete groups.
This commit is contained in:
parent
9df1c93a24
commit
827fec68c7
@ -706,6 +706,25 @@ class GroupsController {
|
|||||||
return array("success" => "Follow status has been successfully updated!");
|
return array("success" => "Follow status has been successfully updated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a group
|
||||||
|
*
|
||||||
|
* @url POST groups/delete
|
||||||
|
*/
|
||||||
|
public function delete(){
|
||||||
|
|
||||||
|
user_login_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
|
* Parse a GroupInfo object into an array for the API
|
||||||
*
|
*
|
||||||
|
@ -486,12 +486,6 @@ class PostsController {
|
|||||||
if(!CS::get()->components->posts->delete($postID))
|
if(!CS::get()->components->posts->delete($postID))
|
||||||
Rest_fatal_error(500, "Couldn't delete post!");
|
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
|
//Success
|
||||||
return array("success" => "The post has been deleted!");
|
return array("success" => "The post has been deleted!");
|
||||||
}
|
}
|
||||||
|
@ -684,6 +684,38 @@ class GroupsComponent {
|
|||||||
array($groupID, $userID));
|
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
|
* Turn a database entry into a GroupInfo object
|
||||||
*
|
*
|
||||||
|
@ -93,7 +93,7 @@ class notificationComponent {
|
|||||||
//Determine the visibility level of the notification
|
//Determine the visibility level of the notification
|
||||||
if($notification->get_on_elem_type() == Notification::POST){
|
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());
|
$info_post = components()->posts->get_single($notification->get_on_elem_id());
|
||||||
|
|
||||||
//Check for error
|
//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
|
* 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
|
* 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
|
* Get the entire list of posts that uses a movie
|
||||||
*
|
*
|
||||||
@ -644,13 +672,17 @@ class Posts {
|
|||||||
*/
|
*/
|
||||||
public function delete(int $postID) : bool {
|
public function delete(int $postID) : bool {
|
||||||
|
|
||||||
//Get informations about the post
|
//Get information about the post
|
||||||
$post_info = $this->get_single($postID);
|
$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())
|
if(!$post_info->isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
//Delete all the notifications related to the post
|
||||||
|
if(!components()->notifications->deleteAllRelatedWithPost($postID))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
//Delete the likes associated to the post
|
//Delete the likes associated to the post
|
||||||
if(!components()->likes->delete_all($postID, Likes::LIKE_POST))
|
if(!components()->likes->delete_all($postID, Likes::LIKE_POST))
|
||||||
return false;
|
return false;
|
||||||
@ -765,6 +797,30 @@ class Posts {
|
|||||||
return TRUE;
|
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
|
* Process processing of multiples posts entries in database
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user