Can invite a user to join a group.

This commit is contained in:
Pierre HUBERT 2018-09-02 14:49:15 +02:00
parent 1ef7f662e5
commit 4e0b5c5fc9
2 changed files with 46 additions and 0 deletions

View File

@ -359,6 +359,36 @@ class GroupsController {
return $members;
}
/**
* Invite a user to join the network
*
* @url POST /groups/invite
*/
public function inviteUser(){
user_login_required();
//Get target group ID
$groupID = getPostGroupIdWithAccess("group_id", GroupInfo::MODERATOR_ACCESS);
//Get target user ID
$userID = getPostUserID("userID");
//Get the current status of the user over the group
if(components()->groups->getMembershipLevel($userID, $groupID) != GroupMember::VISITOR)
Rest_fatal_error(401, "The user is not a visitor for this group!");
//Save the invitation of the user
if(!components()->groups->sendInvitation($userID, $groupID))
Rest_fatal_error(500, "Could not send user invitation!");
//Create notification
create_group_membership_notification($userID, userID, $groupID, Notification::SENT_GROUP_MEMBERSHIP_INVITATION);
//Success
return array("success" => "The user has been successfully invited to join this group!");
}
/**
* Respond to a membership invitation
*

View File

@ -354,6 +354,22 @@ class GroupsComponent {
);
}
/**
* Invite a user to join a group
*
* @param int $userID The ID of the target user
* @param int $groupID The ID of the target group
* @param bool TRUE for a success / FALSE else
*/
public function sendInvitation(int $userID, int $groupID) : bool {
$member = new GroupMember();
$member->set_userID($userID);
$member->set_group_id($groupID);
$member->set_time_sent(time());
$member->set_level(GroupMember::INVITED);
return $this->insertMember($member);
}
/**
* Check whether a user received an invitation or not
*