mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
Can get and return the number of likes of a group.
This commit is contained in:
parent
a0c750f5eb
commit
9f52240a5c
@ -116,6 +116,11 @@ class GroupsController {
|
|||||||
if(!$group->isValid())
|
if(!$group->isValid())
|
||||||
Rest_fatal_error(404, "The requested group was not found !");
|
Rest_fatal_error(404, "The requested group was not found !");
|
||||||
|
|
||||||
|
//If the user is signed in, check whether he is liking or not the group
|
||||||
|
if(userID > 0)
|
||||||
|
$group->setLiking(components()->likes->is_liking(
|
||||||
|
userID, $group->get_id(), Likes::LIKE_GROUP));
|
||||||
|
|
||||||
//Parse and return information about the group
|
//Parse and return information about the group
|
||||||
return self::AdvancedGroupInfoToAPI($group);
|
return self::AdvancedGroupInfoToAPI($group);
|
||||||
}
|
}
|
||||||
@ -649,6 +654,8 @@ class GroupsController {
|
|||||||
$data["time_create"] = $info->get_time_create();
|
$data["time_create"] = $info->get_time_create();
|
||||||
$data["description"] = $info->get_description();
|
$data["description"] = $info->get_description();
|
||||||
$data["url"] = $info->get_url();
|
$data["url"] = $info->get_url();
|
||||||
|
$data["number_likes"] = $info->get_number_likes();
|
||||||
|
$data["is_liking"] = $info->isLiking();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ class GroupsComponent {
|
|||||||
return new AdvancedGroupInfo(); //Return invalid object
|
return new AdvancedGroupInfo(); //Return invalid object
|
||||||
|
|
||||||
//Create and fill GroupInfo object with database entry
|
//Create and fill GroupInfo object with database entry
|
||||||
return $this->dbToAdvancedGroupInfo($info[0]);
|
return $this->dbToAdvancedGroupInfo($info[0], null, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -643,9 +643,11 @@ class GroupsComponent {
|
|||||||
* @param array $data Database entry
|
* @param array $data Database entry
|
||||||
* @param AdvancedGroupInfo $info Optionnal, fill an existing object
|
* @param AdvancedGroupInfo $info Optionnal, fill an existing object
|
||||||
* instead of creating a new one
|
* instead of creating a new one
|
||||||
|
* @param bool $load_likes Specified whether the likes of the group should
|
||||||
|
* be loaded or not (default: FALSE)
|
||||||
* @return AdvancedGroupInfo Advanced information about the group
|
* @return AdvancedGroupInfo Advanced information about the group
|
||||||
*/
|
*/
|
||||||
private function dbToAdvancedGroupInfo(array $data, AdvancedGroupInfo $info = null) : AdvancedGroupInfo {
|
private function dbToAdvancedGroupInfo(array $data, AdvancedGroupInfo $info = null, bool $load_likes = FALSE) : AdvancedGroupInfo {
|
||||||
|
|
||||||
if($info == null)
|
if($info == null)
|
||||||
$info = new AdvancedGroupInfo();
|
$info = new AdvancedGroupInfo();
|
||||||
@ -660,6 +662,11 @@ class GroupsComponent {
|
|||||||
if($data["url"] != null && $data["url"] != "" && $data["url"] != "null")
|
if($data["url"] != null && $data["url"] != "" && $data["url"] != "null")
|
||||||
$info->set_url($data["url"]);
|
$info->set_url($data["url"]);
|
||||||
|
|
||||||
|
//Load likes information, if required
|
||||||
|
if($load_likes){
|
||||||
|
$info->set_number_likes(components()->likes->count($info->get_id(), Likes::LIKE_GROUP));
|
||||||
|
}
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ class Likes {
|
|||||||
const LIKE_USER = "user";
|
const LIKE_USER = "user";
|
||||||
const LIKE_POST = "post";
|
const LIKE_POST = "post";
|
||||||
const LIKE_COMMENT = "comment";
|
const LIKE_COMMENT = "comment";
|
||||||
|
const LIKE_GROUP = "group";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translation of the kinds of like for the database
|
* Translation of the kinds of like for the database
|
||||||
@ -25,7 +26,8 @@ class Likes {
|
|||||||
const KINDS_DB = array(
|
const KINDS_DB = array(
|
||||||
Likes::LIKE_USER => "page",
|
Likes::LIKE_USER => "page",
|
||||||
Likes::LIKE_POST => "texte",
|
Likes::LIKE_POST => "texte",
|
||||||
Likes::LIKE_COMMENT => "commentaire"
|
Likes::LIKE_COMMENT => "commentaire",
|
||||||
|
Likes::LIKE_GROUP => "group"
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -14,6 +14,8 @@ class AdvancedGroupInfo extends GroupInfo {
|
|||||||
private $time_create = -1;
|
private $time_create = -1;
|
||||||
private $url;
|
private $url;
|
||||||
private $description;
|
private $description;
|
||||||
|
private $number_likes = -1;
|
||||||
|
private $is_liking = false;
|
||||||
|
|
||||||
//Get and set the creation time of the group
|
//Get and set the creation time of the group
|
||||||
public function set_time_create(int $time_create){
|
public function set_time_create(int $time_create){
|
||||||
@ -53,4 +55,26 @@ class AdvancedGroupInfo extends GroupInfo {
|
|||||||
public function get_description() : string {
|
public function get_description() : string {
|
||||||
return $this->description != null ? $this->description : "null";
|
return $this->description != null ? $this->description : "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set and get the number of likes over the group
|
||||||
|
public function set_number_likes(int $number_likes){
|
||||||
|
$this->number_likes = $number_likes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function has_number_likes() : bool {
|
||||||
|
return $this->number_likes > -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function get_number_likes() : int {
|
||||||
|
return $this->number_likes;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set and get wheter the user is liking the group or not
|
||||||
|
public function setLiking(bool $liking){
|
||||||
|
$this->is_liking = $liking;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isLiking() : bool {
|
||||||
|
return $this->is_liking;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user