From a63056fb956623b7bea9ec708de7a7ef5ef8bb07 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 9 May 2018 19:06:35 +0200 Subject: [PATCH] Can delete posts related with a movie --- classes/components/posts.php | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/classes/components/posts.php b/classes/components/posts.php index b4e39ac..ec5343f 100644 --- a/classes/components/posts.php +++ b/classes/components/posts.php @@ -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 * @@ -595,6 +626,30 @@ class Posts { 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 *