mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-04 04:04:20 +00:00 
			
		
		
		
	Can invite a user to join a group.
This commit is contained in:
		@@ -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
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user