From a10c89cd5d5b802fc6048e6a2e46c3b0c42f0a0f Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 9 Jan 2018 06:44:34 +0100 Subject: [PATCH] Splited access_level function in two --- RestControllers/postsController.php | 8 ++++++++ classes/components/posts.php | 16 +++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/RestControllers/postsController.php b/RestControllers/postsController.php index 50844fe..c71e339 100644 --- a/RestControllers/postsController.php +++ b/RestControllers/postsController.php @@ -33,6 +33,14 @@ class postsController { //Get the post of the user $posts = CS::get()->components->posts->getUserPosts(userID, $userID, $startFrom); + //Process the list of posts + foreach($posts as $num => $infos){ + + //Get access level to the post + $access_level = CS::get()->components->posts->access_level_with_infos($infos, userID); + + } + return $posts; } diff --git a/classes/components/posts.php b/classes/components/posts.php index a5b309f..a22b127 100644 --- a/classes/components/posts.php +++ b/classes/components/posts.php @@ -186,7 +186,21 @@ class Posts { //Get informations about the post $post_infos = $this->get_single($postID); - + + return $this->access_level_with_infos($post_infos, $userID); + } + + /** + * Get the access level of a user about a post + * + * This function requires the informations about the post + * + * @param array $post_infos Informations about the post + * @param int $userID The ID of the user to check + * @return int The access level over the post + */ + public function access_level_with_infos(array $post_infos, int $userID) : int { + //Check if the user is the owner of the post if($post_infos['userID'] == $userID) return $this::FULL_ACCESS;