Implemented Post object

This commit is contained in:
Pierre
2018-04-22 12:48:20 +02:00
parent a97577b7e9
commit c3af9124b6
4 changed files with 17 additions and 136 deletions

View File

@ -504,50 +504,13 @@ class postsController {
foreach($list as $num => $infos){
//Parse post informations
$list[$num] = $this->parsePostForAPI($infos);
$list[$num] = $this->PostToAPI($infos);
}
return $list;
}
/**
* Parse a post to make it ready to be displayed on the API
*
* @param array $infos Source informations
* @return array Post informations ready to be returned
*/
private function parsePostForAPI(array $infos) : array {
//Get access level to the post
$access_level = CS::get()->components->posts->access_level_with_infos($infos, userID);
//Save level access in the response
$infos["user_access"] = $this::ACCESS_LEVEL_API[$access_level];
//Update visibility level
$infos['visibility_level'] = $this::VISIBILITY_LEVELS_API[$infos['visibility_level']];
//Turn movie into API entry (if any)
if($infos["video_info"] != null)
$infos["video_info"] = MoviesController::MovieToAPI($infos["video_info"]);
//Turn survey into API entry (if any)
if($infos["data_survey"] != null)
$infos["data_survey"] = SurveysController::SurveyToAPI($infos["data_survey"]);
//Parse comments if required
if(isset($infos['comments'])){
if($infos['comments'] != null){
foreach($infos['comments'] as $num=>$src)
$infos['comments'][$num] = CommentsController::commentToAPI($src);
}
}
//Return the post ready to be shown
return $infos;
}
/**
* Turn a POST object into API entry object
*