mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-12-25 04:58:59 +00:00
Implemented Post object
This commit is contained in:
parent
a97577b7e9
commit
c3af9124b6
@ -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
|
||||
*
|
||||
|
@ -155,7 +155,7 @@ class Posts {
|
||||
//Parse posts
|
||||
$posts = array();
|
||||
foreach($list as $post){
|
||||
$posts[] = $this->parse_post($post, $getComments);
|
||||
$posts[] = $this->dbToPost($post, $getComments);
|
||||
}
|
||||
|
||||
return $posts;
|
||||
@ -223,7 +223,7 @@ class Posts {
|
||||
$allow_comments = CS::get()->components->user->allowComments($row["ID_personne"]);
|
||||
|
||||
//Parse post informations
|
||||
$posts[] = $this->parse_post($row, $allow_comments);
|
||||
$posts[] = $this->dbToPost($row, $allow_comments);
|
||||
}
|
||||
|
||||
//Return the list of posts
|
||||
@ -492,10 +492,10 @@ class Posts {
|
||||
public function delete(int $postID) : bool {
|
||||
|
||||
//Get informations about the post
|
||||
$post_infos = $this->get_single($postID);
|
||||
$post_info = $this->get_single($postID);
|
||||
|
||||
//Check if we didn't get informations about the post
|
||||
if(!$post_infos->isValid())
|
||||
if(!$post_info->isValid())
|
||||
return false;
|
||||
|
||||
//Delete the likes associated to the post
|
||||
@ -507,11 +507,11 @@ class Posts {
|
||||
return false;
|
||||
|
||||
//Delete the associated image or PDF (if any)
|
||||
if($post_infos->get_kind() == $this::POST_KIND_IMAGE
|
||||
|| $post_infos->get_kind() == $this::POST_KIND_PDF){
|
||||
if($post_info->get_kind() == $this::POST_KIND_IMAGE
|
||||
|| $post_info->get_kind() == $this::POST_KIND_PDF){
|
||||
|
||||
//Determine file path
|
||||
$file_path = path_user_data($post_infos->get_file_path(), true);
|
||||
$file_path = path_user_data($post_info->get_file_path(), true);
|
||||
|
||||
//Check if the file exists
|
||||
if(file_exists($file_path)){
|
||||
@ -523,7 +523,7 @@ class Posts {
|
||||
}
|
||||
|
||||
//Delete the associated survey (if any)
|
||||
if($post_infos->get_kind() == $this::POST_KIND_SURVEY){
|
||||
if($post_info->get_kind() == $this::POST_KIND_SURVEY){
|
||||
|
||||
//Check the post has an associated survey
|
||||
if(components()->survey->exists($postID)){
|
||||
@ -564,90 +564,6 @@ class Posts {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a user post from the database into
|
||||
* the standardized version of post structure
|
||||
*
|
||||
* @param array $src Informations about the post from the database
|
||||
* @param bool $load_comments Get comments, if required
|
||||
* @return array Parsed informations about the post
|
||||
*/
|
||||
private function parse_post(array $src, bool $load_comments) : array {
|
||||
|
||||
$info = array();
|
||||
|
||||
//Specify post ID
|
||||
$info["ID"] = $src["ID"];
|
||||
|
||||
//Determine user ID
|
||||
$info["userID"] = $src["ID_amis"] == 0 ? $src["ID_personne"] : $src["ID_amis"];
|
||||
|
||||
//Determine user page ID
|
||||
$info["user_page_id"] = $src["ID_personne"];
|
||||
|
||||
//Time when the message was sent
|
||||
$info["post_time"] = strtotime($src["date_envoi"]);
|
||||
|
||||
//Content of the message
|
||||
$info["content"] = $src["texte"];
|
||||
|
||||
//Visibility level
|
||||
$info["visibility_level"] = $src["niveau_visibilite"];
|
||||
|
||||
//Determine the kind of post
|
||||
$info["kind"] = $this::POSTS_DB_TYPES[$src["type"]];
|
||||
|
||||
//Document info
|
||||
$info["file_size"] = $src["size"];
|
||||
$info["file_type"] = $src["file_type"];
|
||||
$info["file_path"] = $src["path"];
|
||||
$info["file_path_url"] = $src["path"] == null ? null : path_user_data($src["path"], false);
|
||||
|
||||
//Video specific
|
||||
$info["video_id"] = $src["idvideo"];
|
||||
|
||||
//Get informations about the video
|
||||
if(!is_null($info['video_id'])){
|
||||
$info['video_info'] = CS::get()->components->movies->get_info($info['video_id']);
|
||||
}
|
||||
else {
|
||||
$info['video_info'] = null;
|
||||
}
|
||||
|
||||
//Countdown timer specific
|
||||
if($src['annee_fin'] != 0)
|
||||
$info["time_end"] = strtotime($src["annee_fin"]."/".$src['mois_fin']."/".$src["jour_fin"]);
|
||||
else
|
||||
$info["time_end"] = null;
|
||||
|
||||
//Weblink specific
|
||||
$info["link_url"] = $src["url_page"];
|
||||
$info["link_title"] = $src["titre_page"];
|
||||
$info["link_description"] = $src["description_page"];
|
||||
$info["link_image"] = $src["image_page"];
|
||||
|
||||
//Survey specific
|
||||
if($info['kind'] == "survey"){
|
||||
$info["data_survey"] = CS::get()->components->survey->get_infos($info['ID']);
|
||||
}
|
||||
else {
|
||||
$info["data_survey"] = null;
|
||||
}
|
||||
|
||||
//Get informations about likes
|
||||
$info["likes"] = CS::get()->components->likes->count($info["ID"], Likes::LIKE_POST);
|
||||
$info["userlike"] = user_signed_in() ? CS::get()->components->likes->is_liking(userID, $info["ID"], Likes::LIKE_POST) : false;
|
||||
|
||||
//Load comments, if required
|
||||
if($load_comments)
|
||||
$info["comments"] = CS::get()->components->comments->get($info["ID"]);
|
||||
else
|
||||
$info["comments"] = null;
|
||||
|
||||
return $info;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a Post object
|
||||
*
|
||||
@ -672,12 +588,12 @@ class Posts {
|
||||
$post->set_file_size($entry["size"] != null ? $entry["size"] : -1);
|
||||
$post->set_file_type($entry["file_type"] != null ? $entry["file_type"] : "");
|
||||
$post->set_file_path($entry["path"] != null ? $entry["path"] : "");
|
||||
$post->set_file_path_url($post->has_file_path() ? path_user_data($post->get_file_path) : "");
|
||||
$post->set_file_path_url($post->has_file_path() ? path_user_data($post->get_file_path()) : "");
|
||||
|
||||
//Movie specific
|
||||
$post->set_movie_id($entry["idvideo"] == null ? -1 : $entry["idvideo"]);
|
||||
if($post->has_movie_id())
|
||||
$post->set_movie(components()->movie->get_info($post->get_movie_id()));
|
||||
$post->set_movie(components()->movies->get_info($post->get_movie_id()));
|
||||
|
||||
|
||||
//Countdown timer - specific
|
||||
|
@ -23,10 +23,11 @@ class Post extends BaseUniqueObjectFromUser {
|
||||
private $link_title;
|
||||
private $link_description;
|
||||
private $link_image;
|
||||
private $data_survey;
|
||||
private $survey;
|
||||
private $likes = -1;
|
||||
private $userLike;
|
||||
private $comments;
|
||||
private $has_comments = false;
|
||||
private $user_access;
|
||||
|
||||
|
||||
@ -277,10 +278,11 @@ class Post extends BaseUniqueObjectFromUser {
|
||||
//Set and get the list of associated comments
|
||||
public function set_comments(array $comments){
|
||||
$this->comments = $comments;
|
||||
$this->has_comments = true;
|
||||
}
|
||||
|
||||
public function has_comments() : bool {
|
||||
return $this->comments != null;
|
||||
return $this->has_comments;
|
||||
}
|
||||
|
||||
public function get_comments() : array {
|
||||
|
@ -105,8 +105,8 @@ function reduce_image(string $fileName, string $targetFile, int $maxWidth, int $
|
||||
$src = imagecreatefromjpeg($fileName);
|
||||
elseif($imageInfos['mime'] === "image/gif")
|
||||
$src = imagecreatefromgif($fileName);
|
||||
elseif($imagesInfos['mime'] === "image/x-ms-bmp")
|
||||
$src = imagecreatefrombmp($fileName);
|
||||
//elseif($imageInfos['mime'] === "image/x-ms-bmp")
|
||||
// $src = imagecreatefrombmp($fileName);
|
||||
else
|
||||
return false; //Unrecognized image type
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user