From 4338d7043dd15061adec8947f01eab3646fe6ad2 Mon Sep 17 00:00:00 2001 From: Pierre Date: Wed, 10 Jan 2018 07:03:21 +0100 Subject: [PATCH] New version of visibility detection in createPost method --- RestControllers/postsController.php | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/RestControllers/postsController.php b/RestControllers/postsController.php index aa07e6a..59ede54 100644 --- a/RestControllers/postsController.php +++ b/RestControllers/postsController.php @@ -120,23 +120,17 @@ class postsController { //Get the visibility of the post if(!isset($_POST['visibility'])) Rest_fatal_error(400, "Please specify the visibility of the post !"); - switch($_POST['visibility']){ - case "private": - $visibility = Posts::VISIBILITY_USER; - break; - - case "friends": - $visibility = Posts::VISIBILITY_FRIENDS; - break; - - case "public": - $visibility = Posts::VISIBILITY_PUBLIC; - break; - - default: - Rest_fatal_error(500, "Unrecognized visibility level for the post !"); - break; - } + $api_visibility = $_POST['visibility']; + + //Get the visibility levels of the API + $post_visibility = array_flip($this::VISIBILITY_LEVELS_API); + + //Check for the existence of the visibility level + if(!isset($post_visibility[$api_visibility])) + Rest_fatal_error(400, "Specified visibility level not recognized !"); + + //Save it + $visibility = $post_visibility[$api_visibility]; //Act differently depending of the post content //For text post