mirror of
				https://github.com/pierre42100/ComunicAPI
				synced 2025-10-30 17:54:59 +00:00 
			
		
		
		
	Added group membership notifications
This commit is contained in:
		| @@ -198,6 +198,28 @@ class notificationComponent { | ||||
| 			return $this->push_private($notification); | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		//Handles groups membership notifications | ||||
| 		else if($notification->get_on_elem_type() == Notification::GROUP_MEMBERSHIP){ | ||||
|  | ||||
| 			//Complete the notification | ||||
| 			$notification->set_from_container_id(0); | ||||
| 			$notification->set_from_container_type(""); | ||||
| 			 | ||||
| 			//Check whether the notification has to be pushed to a single user | ||||
| 			//or to all the moderators of the page | ||||
| 			if($notification->has_dest_user_id()) | ||||
|  | ||||
| 				//Push the notification in private way (if it has a destination, | ||||
| 				//generally the target of the membership request) | ||||
| 				return $this->push_private($notification); | ||||
| 			 | ||||
| 			else { | ||||
| 				//Push the notification to all the moderators of the group | ||||
| 				return $this->push_group_moderators($notification, $notification->get_on_elem_id()); | ||||
| 			} | ||||
|  | ||||
| 		} | ||||
| 		 | ||||
| 		//Unsupported element | ||||
| 		else { | ||||
| @@ -206,6 +228,28 @@ class notificationComponent { | ||||
| 		 | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Push a notification to all the moderators of a group | ||||
| 	 *  | ||||
| 	 * @param Notification $notification The notification to push | ||||
| 	 * @param int $groupID The ID of the target group | ||||
| 	 * @return bool TRUE for a success / FALSE else | ||||
| 	 */ | ||||
| 	private function push_group_moderators(Notification $notification, int $groupID) : bool { | ||||
|  | ||||
| 		//Get the list of the moderators of the group | ||||
| 		$members = components()->groups->getListMembers($groupID); | ||||
| 		$moderators = array(); | ||||
|  | ||||
| 		foreach($members as $member){ | ||||
| 			if($member->get_level() <= GroupMember::MODERATOR) | ||||
| 				$moderators[] = $member->get_userID(); | ||||
| 			 | ||||
| 		} | ||||
|  | ||||
| 		return $this->push_public($notification, $moderators); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Push a notification to several users | ||||
| 	 *  | ||||
|   | ||||
| @@ -25,6 +25,7 @@ class Notification { | ||||
| 	const POST_SURVEY = "post_survey"; | ||||
| 	const COMMENT = "comment"; | ||||
| 	const FRIENDSHIP_REQUEST = "friend_request"; | ||||
| 	const GROUP_MEMBERSHIP = "group_membership"; | ||||
|  | ||||
| 	/** | ||||
| 	 * Event type | ||||
| @@ -35,6 +36,12 @@ class Notification { | ||||
| 	const REJECTED_FRIEND_REQUEST = "rejected_friend_request"; | ||||
| 	const ELEM_CREATED = "elem_created"; | ||||
| 	const ELEM_UPDATED = "elem_updated"; | ||||
| 	const SENT_GROUP_MEMBERSHIP_INVITATION = "sent_group_membership_invitation"; | ||||
| 	const ACCEPTED_GROUP_MEMBERSHIP_INVITATION = "accepted_group_membership_invitation"; | ||||
| 	const REJECTED_GROUP_MEMBERSHIP_INVITATION = "rejected_group_membership_invitation"; | ||||
| 	const SENT_GROUP_MEMBERSHIP_REQUEST = "sent_group_membership_request"; | ||||
| 	const ACCEPTED_GROUP_MEMBERSHIP_REQUEST = "accepted_group_membership_request"; | ||||
| 	const REJECTED_GROUP_MEMBERSHIP_REQUEST = "rejected_group_membership_request"; | ||||
|  | ||||
| 	/** | ||||
| 	 * Event visibility | ||||
| @@ -159,6 +166,10 @@ class Notification { | ||||
| 	 */ | ||||
| 	public function set_from_user_id(int $from_user_id){ | ||||
| 		$this->from_user_id = $from_user_id; | ||||
|  | ||||
| 		//Check if we have to reset the value | ||||
| 		if($from_user_id < 0) | ||||
| 			$this->from_user_id = null; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| @@ -186,6 +197,10 @@ class Notification { | ||||
| 	 */ | ||||
| 	public function set_dest_user_id(int $dest_user_id){ | ||||
| 		$this->dest_user_id = $dest_user_id; | ||||
|  | ||||
| 		//Reset the value if required | ||||
| 		if($dest_user_id < 0) | ||||
| 			$this->dest_user_id = null; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Pierre HUBERT
					Pierre HUBERT