components->friends->are_friend($userID, $targetID)) //Users are friends return $this::VISIBILITY_FRIENDS; else //Users are not friend return $this::VISIBILITY_PUBLIC; } /** * Get a list of post of a user * * @param int $userID The ID of the user making the request * @param int $targetID The ID of the target user * @param int $visibilityLevel Visibility level required * @param int $startPoint The startpoint for the request (0 stands for none) */ public function getUserPosts(int $userID, int $targetID, int $visibilityLevel, int $startPoint = 0) : array { //Prepare the request on the database $conditions = "WHERE ID_personne = ? AND ("; $dataConds = array($targetID); //Add the visibility level conditions $conditions .= "(niveau_visibilite <= ?)"; $dataConds[] = $visibilityLevel; //If user is signed in, include all the posts that he has created if($userID > 0){ $conditions .= " OR (ID_amis = ?) "; $dataConds[] = $userID; } //Close conditions $conditions .= ")"; //Perform the request return CS::get()->db->select( $this::TABLE_NAME, $conditions, $dataConds ); } } //Register component Components::register("posts", new Posts());