mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Get the list of latest posts of a user
This commit is contained in:
		@@ -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
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user