mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
Created an helper to get visibility level
This commit is contained in:
parent
4338d7043d
commit
b7052d11f8
@ -118,19 +118,7 @@ class postsController {
|
|||||||
Rest_fatal_error(400, "Your request has been rejected because it has been considered as unsecure !");
|
Rest_fatal_error(400, "Your request has been rejected because it has been considered as unsecure !");
|
||||||
|
|
||||||
//Get the visibility of the post
|
//Get the visibility of the post
|
||||||
if(!isset($_POST['visibility']))
|
$visibility = $this->getPostVisibilityLevel("visibility");
|
||||||
Rest_fatal_error(400, "Please specify the visibility of the post !");
|
|
||||||
$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
|
//Act differently depending of the post content
|
||||||
//For text post
|
//For text post
|
||||||
@ -339,4 +327,30 @@ class postsController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the visibility level specified in a POST request
|
||||||
|
*
|
||||||
|
* @param string $name The name of the POST parameter
|
||||||
|
* @return int The visibility level
|
||||||
|
*/
|
||||||
|
private function getPostVisibilityLevel(string $name) : int {
|
||||||
|
|
||||||
|
if(!isset($_POST[$name]))
|
||||||
|
Rest_fatal_error(400, "Please specify the visibility of the post !");
|
||||||
|
$api_visibility = $_POST[$name];
|
||||||
|
|
||||||
|
//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 !");
|
||||||
|
|
||||||
|
//Return it
|
||||||
|
return $post_visibility[$api_visibility];
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user