Can update following status of a group membership.

This commit is contained in:
Pierre HUBERT 2018-07-19 14:43:29 +02:00
parent f054107277
commit 6c100fecce
2 changed files with 38 additions and 0 deletions

View File

@ -626,6 +626,28 @@ class GroupsController {
return array("success" => "Your membership has been successfully deleted!"); 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 * Parse a GroupInfo object into an array for the API
* *

View File

@ -622,6 +622,22 @@ class GroupsComponent {
return $groupID == $currID; 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 * Turn a database entry into a GroupInfo object
* *