Skip to content

Commit 6c100fe

Browse files
author
Pierre HUBERT
committed
Can update following status of a group membership.
1 parent f054107 commit 6c100fe

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

RestControllers/GroupsController.php

+22
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,28 @@ public function removeMembership() : array {
626626
return array("success" => "Your membership has been successfully deleted!");
627627
}
628628

629+
/**
630+
* Set whether a user is following a group or not
631+
*
632+
* @url POST groups/set_following
633+
*/
634+
public function setFollowing(){
635+
user_login_required();
636+
637+
//Get the group
638+
$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::MEMBER_ACCESS);
639+
640+
//Get following status
641+
$following = postBool("follow");
642+
643+
//Save the new value
644+
if(!components()->groups->setFollowing($groupID, userID, $following))
645+
Rest_fatal_error(500, "Could not update following status!");
646+
647+
//Success
648+
return array("success" => "Follow status has been successfully updated!");
649+
}
650+
629651
/**
630652
* Parse a GroupInfo object into an array for the API
631653
*

classes/components/GroupsComponent.php

+16
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,22 @@ public function checkDirectoryAvailability(string $directory, int $groupID) : in
622622
return $groupID == $currID;
623623
}
624624

625+
/**
626+
* Set (update) user following status
627+
*
628+
* @param int $groupID Target group ID
629+
* @param int $userID Target user ID
630+
* @param bool $following New following status
631+
* @return bool TRUE to follow / FALSE else
632+
*/
633+
public function setFollowing(int $groupID, int $userID, bool $following) : bool {
634+
return db()->updateDB(
635+
self::GROUPS_MEMBERS_TABLE,
636+
"groups_id = ? AND user_id = ?",
637+
array("following" => $following ? 1 : 0),
638+
array($groupID, $userID));
639+
}
640+
625641
/**
626642
* Turn a database entry into a GroupInfo object
627643
*

0 commit comments

Comments
 (0)