Skip to content

Commit

Permalink
Merge pull request #31 from beck24/admin-membership-notification
Browse files Browse the repository at this point in the history
I'll merge this, but will make a small adjustment. The message body needs to be personal for each admin.

Also there needs to be a check for the plugin setting 'allow group admins'
  • Loading branch information
jeabakker committed Oct 24, 2013
2 parents 8e87b40 + 84cbd97 commit 138521b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
50 changes: 49 additions & 1 deletion lib/events.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,52 @@ function group_tools_multiple_admin_group_leave($event, $type, $params){
}
}
}



function group_tools_membership_request($event, $type, $relationship) {
if (!($relationship instanceof ElggRelationship)) {
return;
}

$group = get_entity($relationship->guid_two);
$user = get_user($relationship->guid_one);

if (!elgg_instanceof($group, 'group') || !elgg_instanceof($user, 'user')) {
return;
}

// Notify group owner
$url = elgg_get_site_url() . "groups/requests/$group->guid";
$subject = elgg_echo('groups:request:subject', array(
$user->name,
$group->name,
));
$body = elgg_echo('groups:request:body', array(
$group->getOwnerEntity()->name,
$user->name,
$group->name,
$user->getURL(),
$url,
));

$options = array(
"relationship" => "group_admin",
"relationship_guid" => $group->getGUID(),
"inverse_relationship" => true,
"type" => "user",
"limit" => false,
"wheres" => array("e.guid <> " . $group->owner_guid),
"callback" => false
);

$admins = elgg_get_entities_from_relationship($options);

$guids = array();
foreach ($admins as $a) {
$guids[] = $a->guid;
}

if ($guids) {
notify_user($guids, $user->getGUID(), $subject, $body);
}
}
3 changes: 3 additions & 0 deletions start.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function group_tools_init(){

// register on group leave
elgg_register_event_handler("leave", "group", "group_tools_multiple_admin_group_leave");

//notify admin on membership request
elgg_register_event_handler('create', 'membership_request', 'group_tools_membership_request');
}

// register group activity widget
Expand Down

0 comments on commit 138521b

Please sign in to comment.