Get the list of latest posts of a user

This commit is contained in:
Pierre
2018-02-03 15:40:55 +01:00
parent 9bc436b2a2
commit b6466c68e4
2 changed files with 114 additions and 9 deletions

View File

@ -52,17 +52,35 @@ 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){
//Parse post informations
$posts[$num] = $this->parsePostForAPI($infos);
}
return $posts;
//Return parsed list of posts
return $this->parsePostsList($posts);
}
/**
* Get the latest posts for the user
*
* @url POST /posts/get_latest
*/
public function get_latest_posts(){
user_login_required();
//Check if there is a startpoint for the posts
if(isset($_POST['startFrom'])){
$startFrom = toInt($_POST['startFrom']);
}
else
$startFrom = 0; //No start point
//Get the post of the user
$posts = CS::get()->components->posts->get_latest(userID, $startFrom, 10);
//Return parsed list of posts
return $this->parsePostsList($posts);
}
/**
* Get informations about a single post
*
@ -457,6 +475,25 @@ class postsController {
return $postID;
}
/**
* Process a list of post for the API
*
* @param array $list The list of posts to process
* @return array The parsed list of posts for API
*/
private function parsePostsList(array $list) : array {
//Process the list of posts
foreach($list as $num => $infos){
//Parse post informations
$list[$num] = $this->parsePostForAPI($infos);
}
return $list;
}
/**
* Parse a post to make it ready to be displayed on the API
*