Added group membership notifications

This commit is contained in:
Pierre HUBERT
2018-08-02 08:57:49 +02:00
parent 473c1ac3b1
commit 814ee8949b
5 changed files with 155 additions and 1 deletions

View File

@ -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
*