Permalink
Browse files

feature(groups): group members page can be sorted on newest members

Tabs were added to the groups members page to sort alphabetical or
newest.
  • Loading branch information...
jeabakker committed Jul 2, 2015
1 parent ebfbef0 commit 2eb5e5eaac9fee0f06e04d2f5d09d19433552018
Showing with 76 additions and 11 deletions.
  1. +47 −1 mod/groups/start.php
  2. +29 −10 mod/groups/views/default/resources/groups/members.php
View
@@ -75,6 +75,9 @@ function groups_init() {
// invitation request actions
elgg_register_plugin_hook_handler('register', 'menu:invitationrequest', 'groups_invitationrequest_menu_setup');
+
+ // group members tabs
+ elgg_register_plugin_hook_handler('register', 'menu:groups_members', 'groups_members_menu_setup');
//extend some views
elgg_extend_view('elgg.css', 'groups/css');
@@ -237,6 +240,7 @@ function groups_page_handler($page) {
elgg_push_breadcrumb(elgg_echo('groups'), "groups/all");
+ $vars = [];
switch ($page[0]) {
case 'add':
case 'all':
@@ -249,10 +253,18 @@ function groups_page_handler($page) {
set_input('username', $page[1]);
echo elgg_view_resource("groups/{$page[0]}");
break;
+ case 'members':
+ $vars['sort'] = elgg_extract('2', $page, 'alpha');
+ $vars['guid'] = elgg_extract('1', $page);
+ if (elgg_view_exists("resources/groups/members/{$vars['sort']}")) {
+ echo elgg_view_resource("groups/members/{$vars['sort']}", $vars);
+ } else {
+ echo elgg_view_resource('groups/members', $vars);
+ }
+ break;
case 'activity':
case 'edit':
case 'invite':
- case 'members':
case 'profile':
case 'requests':
set_input('guid', $page[1]);
@@ -761,3 +773,37 @@ function groups_invitationrequest_menu_setup($hook, $type, $menu, $params) {
return $menu;
}
+
+/**
+ * Setup group members tabs
+ *
+ * @param string $hook "register"
+ * @param string $type "menu:groups_members"
+ * @param ElggMenuItem[] $menu Menu items
+ * @param array $params Hook params
+ *
+ * @return void|ElggMenuItem[]
+ */
+function groups_members_menu_setup($hook, $type, $menu, $params) {
+
+ $entity = elgg_extract('entity', $params);
+ if (empty($entity) || !($entity instanceof ElggGroup)) {
+ return;
+ }
+
+ $menu[] = ElggMenuItem::factory([
+ 'name' => 'alpha',
+ 'text' => elgg_echo('sort:alpha'),
+ 'href' => "groups/members/{$entity->getGUID()}",
+ 'priority' => 100
+ ]);
+
+ $menu[] = ElggMenuItem::factory([
+ 'name' => 'newest',
+ 'text' => elgg_echo('sort:newest'),
+ 'href' => "groups/members/{$entity->getGUID()}/newest",
+ 'priority' => 200
+ ]);
+
+ return $menu;
+}
@@ -1,6 +1,7 @@
<?php
-$guid = get_input('guid');
+$guid = (int) elgg_extract('guid', $vars);
+
elgg_entity_gatekeeper($guid, 'group');
$group = get_entity($guid);
@@ -9,26 +10,44 @@
elgg_group_gatekeeper();
-$title = elgg_echo('groups:members:title', array($group->name));
-
elgg_push_breadcrumb($group->name, $group->getURL());
elgg_push_breadcrumb(elgg_echo('groups:members'));
-$db_prefix = elgg_get_config('dbprefix');
-$content = elgg_list_entities_from_relationship(array(
+$options = [
'relationship' => 'member',
'relationship_guid' => $group->guid,
'inverse_relationship' => true,
'type' => 'user',
- 'limit' => (int)get_input('limit', max(20, elgg_get_config('default_limit')), false),
- 'joins' => array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid"),
- 'order_by' => 'u.name ASC',
-));
+ 'limit' => (int) get_input('limit', max(20, elgg_get_config('default_limit')), false),
+];
+
+$sort = elgg_extract('sort', $vars);
+switch ($sort) {
+ case 'newest':
+ $options['order_by'] = 'r.time_created DESC';
+ break;
+ default:
+ $db_prefix = elgg_get_config('dbprefix');
+
+ $options['joins'] = array("JOIN {$db_prefix}users_entity u ON e.guid=u.guid");
+ $options['order_by'] = 'u.name ASC';
+ break;
+}
+
+$title = elgg_echo('groups:members:title', array($group->name));
+
+$tabs = elgg_view_menu('groups_members', [
+ 'entity' => $group,
+ 'sort_by' => 'priority',
+ 'class' => 'elgg-tabs'
+]);
+
+$content = elgg_list_entities_from_relationship($options);
$params = array(
'content' => $content,
'title' => $title,
- 'filter' => '',
+ 'filter' => $tabs,
);
$body = elgg_view_layout('content', $params);

0 comments on commit 2eb5e5e

Please sign in to comment.