From 6547efb9ae89c1477930c69ac2dbe73350673a66 Mon Sep 17 00:00:00 2001 From: Jeff Tilson Date: Mon, 13 Jun 2011 14:38:46 -0400 Subject: Added 'remove from group' link to the user hover menu (only appears when the page owner is a group) --- mod/groups/actions/groups/membership/remove.php | 31 ++++++++++++++++++ mod/groups/languages/en.php | 3 ++ mod/groups/start.php | 42 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 mod/groups/actions/groups/membership/remove.php diff --git a/mod/groups/actions/groups/membership/remove.php b/mod/groups/actions/groups/membership/remove.php new file mode 100644 index 000000000..6f0698371 --- /dev/null +++ b/mod/groups/actions/groups/membership/remove.php @@ -0,0 +1,31 @@ +guid); + +if (($user instanceof ElggUser) && ($group instanceof ElggGroup) && $group->canEdit()) { + // Don't allow removeing group owner + if ($group->getOwnerGUID() != $user->getGUID()) { + if ($group->leave($user)) { + system_message(elgg_echo("groups:removed")); + } else { + register_error(elgg_echo("groups:cantremove")); + } + } else { + register_error(elgg_echo("groups:cantremove")); + } +} else { + register_error(elgg_echo("groups:cantremove")); +} + +forward(REFERER); diff --git a/mod/groups/languages/en.php b/mod/groups/languages/en.php index 63a6df3a9..a4d9863ca 100644 --- a/mod/groups/languages/en.php +++ b/mod/groups/languages/en.php @@ -166,6 +166,9 @@ $english = array( 'groups:notitle' => 'Groups must have a title', 'groups:cantjoin' => 'Can not join group', 'groups:cantleave' => 'Could not leave group', + 'groups:removeuser' => 'Remove from group', + 'groups:cantremove' => 'Cannot remove user from group', + 'groups:removed' => 'User successfully removed from group', 'groups:addedtogroup' => 'Successfully added the user to the group', 'groups:joinrequestnotmade' => 'Could not request to join group', 'groups:joinrequestmade' => 'Requested to join group', diff --git a/mod/groups/start.php b/mod/groups/start.php index 73bdd08a9..9a375e89d 100644 --- a/mod/groups/start.php +++ b/mod/groups/start.php @@ -44,6 +44,7 @@ function groups_init() { elgg_register_action("groups/invite", "$action_base/invite.php"); elgg_register_action("groups/join", "$action_base/join.php"); elgg_register_action("groups/leave", "$action_base/leave.php"); + elgg_register_action("groups/remove", "$action_base/remove.php"); elgg_register_action("groups/killrequest", "$action_base/delete_request.php"); elgg_register_action("groups/killinvitation", "$action_base/delete_invite.php"); elgg_register_action("groups/addtogroup", "$action_base/add.php"); @@ -60,6 +61,9 @@ function groups_init() { // group entity menu elgg_register_plugin_hook_handler('register', 'menu:entity', 'groups_entity_menu_setup'); + + // group user hover menu + elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'groups_user_entity_menu_setup'); //extend some views elgg_extend_view('css/elgg', 'groups/css'); @@ -366,6 +370,44 @@ function groups_entity_menu_setup($hook, $type, $return, $params) { return $return; } +/** + * Add a remove user link to user hover menu when the page owner is a group + */ +function groups_user_entity_menu_setup($hook, $type, $return, $params) { + if (elgg_is_logged_in()) { + $group = elgg_get_page_owner_entity(); + + // Check for valid group + if (!elgg_instanceof($group, 'group')) { + return $return; + } + + $entity = $params['entity']; + + // Make sure we have a user and that user is a member of the group + if (!elgg_instanceof($entity, 'user') || !$group->isMember($entity)) { + return $return; + } + + // Add remove link if we can edit the group, and if we're not trying to remove the group owner + if ($group->canEdit() && $group->getOwnerGUID() != $entity->guid) { + $remove = elgg_view('output/confirmlink', array( + 'href' => "action/groups/remove?user_guid={$entity->guid}&group_guid={$group->guid}", + 'text' => elgg_echo('groups:removeuser'), + )); + + $options = array( + 'name' => 'removeuser', + 'text' => $remove, + 'priority' => 999, + ); + $return[] = ElggMenuItem::factory($options); + } + } + + return $return; +} + /** * Groups created so create an access list for it */ -- cgit v1.2.3