Can delete groups.

This commit is contained in:
Pierre HUBERT
2018-08-31 09:56:46 +02:00
parent 9df1c93a24
commit 827fec68c7
5 changed files with 145 additions and 9 deletions

View File

@ -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
*