Can delete posts related with a movie

This commit is contained in:
Pierre 2018-05-09 19:06:35 +02:00
parent 478a0480b7
commit a63056fb95

View File

@ -254,6 +254,37 @@ class Posts {
} }
/**
* Get the entire list of posts that uses a movie
*
* This function does not take care of visibility level, and does not admit
* any kind of limit
*
* @param int $movieID The ID of the target movie
* @return array The list of posts
*/
public function getPostsForMovie(int $movieID) : array {
//Security feature
if($movieID < 1)
return array();
//Prepare database request
$conditions = "WHERE idvideo = ?";
$dataConds = array($movieID);
//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, FALSE);
}
/** /**
* Check whether a post exists or not * Check whether a post exists or not
* *
@ -595,6 +626,30 @@ class Posts {
return TRUE; return TRUE;
} }
/**
* Delete all the posts using a specified movie
*
* @param int $movieID The ID of the target movie
* @return bool TRUE for a success / FALSE else
*/
public function deleteAllWithMovie(int $movieID) : bool {
//Get the list of posts of the user
$posts = $this->getPostsForMovie($movieID);
//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
* *