mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 07:49:27 +00:00
Can update following status of a group membership.
This commit is contained in:
parent
f054107277
commit
6c100fecce
@ -626,6 +626,28 @@ class GroupsController {
|
||||
return array("success" => "Your membership has been successfully deleted!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether a user is following a group or not
|
||||
*
|
||||
* @url POST groups/set_following
|
||||
*/
|
||||
public function setFollowing(){
|
||||
user_login_required();
|
||||
|
||||
//Get the group
|
||||
$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::MEMBER_ACCESS);
|
||||
|
||||
//Get following status
|
||||
$following = postBool("follow");
|
||||
|
||||
//Save the new value
|
||||
if(!components()->groups->setFollowing($groupID, userID, $following))
|
||||
Rest_fatal_error(500, "Could not update following status!");
|
||||
|
||||
//Success
|
||||
return array("success" => "Follow status has been successfully updated!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a GroupInfo object into an array for the API
|
||||
*
|
||||
|
@ -622,6 +622,22 @@ class GroupsComponent {
|
||||
return $groupID == $currID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set (update) user following status
|
||||
*
|
||||
* @param int $groupID Target group ID
|
||||
* @param int $userID Target user ID
|
||||
* @param bool $following New following status
|
||||
* @return bool TRUE to follow / FALSE else
|
||||
*/
|
||||
public function setFollowing(int $groupID, int $userID, bool $following) : bool {
|
||||
return db()->updateDB(
|
||||
self::GROUPS_MEMBERS_TABLE,
|
||||
"groups_id = ? AND user_id = ?",
|
||||
array("following" => $following ? 1 : 0),
|
||||
array($groupID, $userID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn a database entry into a GroupInfo object
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user