mirror of
https://github.com/pierre42100/ComunicAPI
synced 2025-06-19 00:25:18 +00:00
Can get and return the number of likes of a group.
This commit is contained in:
@ -169,7 +169,7 @@ class GroupsComponent {
|
||||
return new AdvancedGroupInfo(); //Return invalid object
|
||||
|
||||
//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 AdvancedGroupInfo $info Optionnal, fill an existing object
|
||||
* 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
|
||||
*/
|
||||
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)
|
||||
$info = new AdvancedGroupInfo();
|
||||
@ -659,6 +661,11 @@ class GroupsComponent {
|
||||
$info->set_description($data["description"]);
|
||||
if($data["url"] != null && $data["url"] != "" && $data["url"] != "null")
|
||||
$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;
|
||||
|
||||
|
@ -18,6 +18,7 @@ class Likes {
|
||||
const LIKE_USER = "user";
|
||||
const LIKE_POST = "post";
|
||||
const LIKE_COMMENT = "comment";
|
||||
const LIKE_GROUP = "group";
|
||||
|
||||
/**
|
||||
* Translation of the kinds of like for the database
|
||||
@ -25,7 +26,8 @@ class Likes {
|
||||
const KINDS_DB = array(
|
||||
Likes::LIKE_USER => "page",
|
||||
Likes::LIKE_POST => "texte",
|
||||
Likes::LIKE_COMMENT => "commentaire"
|
||||
Likes::LIKE_COMMENT => "commentaire",
|
||||
Likes::LIKE_GROUP => "group"
|
||||
);
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user