mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-11-03 19:54:14 +00:00 
			
		
		
		
	Can get a user membership
This commit is contained in:
		@@ -412,6 +412,30 @@ class GroupsController {
 | 
			
		||||
		return array("success" => "The response to the request has been successfully saved!");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get information about a membership
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @url POST /groups/get_membership
 | 
			
		||||
	 */
 | 
			
		||||
	public function getMembership() : array {
 | 
			
		||||
 | 
			
		||||
		//Get the ID of the target group
 | 
			
		||||
		$groupID = getPostGroupIdWithAccess("groupID", GroupInfo::MODERATOR_ACCESS);
 | 
			
		||||
 | 
			
		||||
		//Get user ID
 | 
			
		||||
		$userID = getPostUserID("userID");
 | 
			
		||||
 | 
			
		||||
		//Check if the user has a membership or not
 | 
			
		||||
		if(!components()->groups->hasMembership($userID, $groupID))
 | 
			
		||||
			Rest_fatal_error(404, "Specified user does not have any membership in this group!");
 | 
			
		||||
 | 
			
		||||
		//Get user membership
 | 
			
		||||
		$membership = components()->groups->getMembership($userID, $groupID);
 | 
			
		||||
 | 
			
		||||
		//Parse and return result
 | 
			
		||||
		return self::GroupMemberToAPI($membership);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Parse a GroupInfo object into an array for the API
 | 
			
		||||
	 * 
 | 
			
		||||
 
 | 
			
		||||
@@ -240,7 +240,7 @@ class GroupsComponent {
 | 
			
		||||
	 * @param int $groupID The ID of the target group
 | 
			
		||||
	 * @return bool TRUE if the database includes a membership for the user / FALSE else
 | 
			
		||||
	 */
 | 
			
		||||
	private function hasMembership(int $userID, int $groupID) : bool {
 | 
			
		||||
	public function hasMembership(int $userID, int $groupID) : bool {
 | 
			
		||||
		return db()->count(
 | 
			
		||||
			self::GROUPS_MEMBERS_TABLE,
 | 
			
		||||
			"WHERE groups_id = ? AND user_id = ?", 
 | 
			
		||||
@@ -375,6 +375,28 @@ class GroupsComponent {
 | 
			
		||||
		return $results[0]["level"];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get information the membership of a user over a group
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param int $userID The ID of the target user
 | 
			
		||||
	 * @param int $groupID The ID of the target group
 | 
			
		||||
	 * @param GroupMember User membership
 | 
			
		||||
	 */
 | 
			
		||||
	public function getMembership(int $userID, int $groupID) : GroupMember {
 | 
			
		||||
		//Fetch the database to get membership
 | 
			
		||||
		$results = db()->select(
 | 
			
		||||
			self::GROUPS_MEMBERS_TABLE,
 | 
			
		||||
			"WHERE groups_id = ? AND user_id = ?",
 | 
			
		||||
			array($groupID, $userID)
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		//Check for results
 | 
			
		||||
		if(count($results) < 0)
 | 
			
		||||
			return new GroupMember(); //Invalid object
 | 
			
		||||
		
 | 
			
		||||
		return $this->dbToGroupMember($results[0]);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check whether a user is an administrator of a group
 | 
			
		||||
	 * or not
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user