mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 22:09:29 +00:00
Can get and return following state of a user.
This commit is contained in:
parent
46730f2b97
commit
f054107277
@ -116,11 +116,17 @@ 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 the user is signed in, check whether he is liking and following or not the group
|
||||||
if(userID > 0)
|
if(userID > 0) {
|
||||||
$group->setLiking(components()->likes->is_liking(
|
$group->setLiking(components()->likes->is_liking(
|
||||||
userID, $group->get_id(), Likes::LIKE_GROUP));
|
userID, $group->get_id(), Likes::LIKE_GROUP));
|
||||||
|
|
||||||
|
|
||||||
|
$group->set_following(components()->groups->isFollowing(
|
||||||
|
userID, $group->get_id()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
//Parse and return information about the group
|
//Parse and return information about the group
|
||||||
return self::AdvancedGroupInfoToAPI($group);
|
return self::AdvancedGroupInfoToAPI($group);
|
||||||
}
|
}
|
||||||
@ -638,6 +644,7 @@ class GroupsController {
|
|||||||
$data["registration_level"] = self::GROUPS_REGISTRATION_LEVELS[$info->get_registration_level()];
|
$data["registration_level"] = self::GROUPS_REGISTRATION_LEVELS[$info->get_registration_level()];
|
||||||
$data["posts_level"] = self::GROUPS_POSTS_LEVELS[$info->get_posts_level()];
|
$data["posts_level"] = self::GROUPS_POSTS_LEVELS[$info->get_posts_level()];
|
||||||
$data["virtual_directory"] = $info->get_virtual_directory();
|
$data["virtual_directory"] = $info->get_virtual_directory();
|
||||||
|
$data["following"] = $info->isFollowing();
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -431,6 +431,21 @@ class GroupsComponent {
|
|||||||
return $this->dbToGroupMember($results[0]);
|
return $this->dbToGroupMember($results[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether a user is following or not a group
|
||||||
|
*
|
||||||
|
* @param int $userID Target user ID
|
||||||
|
* @param int $groupID The ID of the related group
|
||||||
|
* @return bool TRUE if the user is following the group / FALSE else
|
||||||
|
*/
|
||||||
|
public function isFollowing(int $userID, int $groupID) : bool {
|
||||||
|
return db()->count(
|
||||||
|
self::GROUPS_MEMBERS_TABLE,
|
||||||
|
"WHERE groups_id = ? AND user_ID = ? AND following = 1",
|
||||||
|
array($groupID, $userID)
|
||||||
|
) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a user is an administrator of a group
|
* Check whether a user is an administrator of a group
|
||||||
* or not
|
* or not
|
||||||
@ -751,6 +766,7 @@ class GroupsComponent {
|
|||||||
$member->set_userID($entry["user_id"]);
|
$member->set_userID($entry["user_id"]);
|
||||||
$member->set_time_sent($entry["time_create"]);
|
$member->set_time_sent($entry["time_create"]);
|
||||||
$member->set_level($entry["level"]);
|
$member->set_level($entry["level"]);
|
||||||
|
$member->set_following($entry["following"] == 1);
|
||||||
|
|
||||||
return $member;
|
return $member;
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@ class GroupInfo extends BaseUniqueObject {
|
|||||||
private $registration_level = -1;
|
private $registration_level = -1;
|
||||||
private $posts_level = -1;
|
private $posts_level = -1;
|
||||||
private $virtual_directory;
|
private $virtual_directory;
|
||||||
|
private $following = FALSE;
|
||||||
|
|
||||||
//Get and set the name of group
|
//Get and set the name of group
|
||||||
public function set_name(string $name){
|
public function set_name(string $name){
|
||||||
@ -160,4 +161,13 @@ class GroupInfo extends BaseUniqueObject {
|
|||||||
public function get_virtual_directory() : string {
|
public function get_virtual_directory() : string {
|
||||||
return $this->virtual_directory != null ? $this->virtual_directory : "null";
|
return $this->virtual_directory != null ? $this->virtual_directory : "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set and get following status
|
||||||
|
public function set_following(bool $following){
|
||||||
|
$this->following = $following;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isFollowing() : bool {
|
||||||
|
return $this->following;
|
||||||
|
}
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ class GroupMember extends BaseUniqueObjectFromUser {
|
|||||||
//Private fields
|
//Private fields
|
||||||
private $group_id = 1;
|
private $group_id = 1;
|
||||||
private $level = -1;
|
private $level = -1;
|
||||||
|
private $following;
|
||||||
|
|
||||||
//Set and get group id
|
//Set and get group id
|
||||||
public function set_group_id(int $group_id){
|
public function set_group_id(int $group_id){
|
||||||
@ -46,4 +47,13 @@ class GroupMember extends BaseUniqueObjectFromUser {
|
|||||||
public function get_level() : int {
|
public function get_level() : int {
|
||||||
return $this->level;
|
return $this->level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Set and get following status
|
||||||
|
public function set_following(bool $following){
|
||||||
|
$this->is_following = $following;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isFollowing() : bool {
|
||||||
|
return $this->is_following;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user