Skip to content
Permalink
Browse files

feat(groups): member listing now uses elgg_list_relationship

  • Loading branch information
jeabakker committed Sep 24, 2019
1 parent 9b54398 commit 783f22a637d24ca634d3ab7bdebe1f185abaac4b
Showing with 80 additions and 22 deletions.
  1. +14 −15 mod/groups/start.php
  2. +15 −7 mod/groups/views/default/resources/groups/members.php
  3. +51 −0 views/default/relationship/member.php
@@ -27,7 +27,7 @@ function groups_init() {
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');
elgg_register_plugin_hook_handler('register', 'menu:relationship', 'groups_relationship_menu_setup');

// invitation request actions
elgg_register_plugin_hook_handler('register', 'menu:invitationrequest', 'groups_invitationrequest_menu_setup');
@@ -385,43 +385,42 @@ function groups_entity_menu_setup(\Elgg\Hook $hook) {
}

/**
* Add a remove user link to user hover menu when the page owner is a group
* Add a remove user link to relationship menu if it's about a group membership relationship
*
* @param \Elgg\Hook $hook 'register', 'menu:user_hover'
* @param \Elgg\Hook $hook 'register', 'menu:relationship'
*
* @return void|ElggMenuItem[]
*/
function groups_user_entity_menu_setup(\Elgg\Hook $hook) {
$group = elgg_get_page_owner_entity();

if (!$group instanceof \ElggGroup || !$group->canEdit()) {
function groups_relationship_menu_setup(\Elgg\Hook $hook) {

$relationship = $hook->getParam('relationship');
if (!$relationship instanceof ElggRelationship || $relationship->relationship !== 'member') {
return;
}

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

$entity = $hook->getEntityParam();

// Make sure we have a user and that user is a member of the group
if (!$entity instanceof \ElggUser || !$group->isMember($entity)) {
// Make sure we have a user and a group
if (!$user instanceof \ElggUser || !$group instanceof ElggGroup) {
return;
}

// Check if we are looking at the group owner
if ($group->owner_guid === $entity->guid) {
if ($group->owner_guid === $user->guid) {
return;
}

$return = $hook->getValue();
$return[] = ElggMenuItem::factory([
'name' => 'removeuser',
'href' => elgg_generate_action_url('groups/remove', [
'user_guid' => $entity->guid,
'user_guid' => $user->guid,
'group_guid' => $group->guid,
]),
'text' => elgg_echo('groups:removeuser'),
'icon' => 'user-times',
'confirm' => true,
'priority' => 999,
'section' => 'action',
]);

return $return;
@@ -1,6 +1,8 @@
<?php

use Elgg\Database\Clauses\JoinClause;
use Elgg\Database\Clauses\OrderByClause;
use Elgg\Database\QueryBuilder;

$guid = (int) elgg_extract('guid', $vars);

@@ -24,15 +26,21 @@
$sort = elgg_extract('sort', $vars);
switch ($sort) {
case 'newest':
$options['order_by'] = [
new OrderByClause('r.time_created', 'DESC'),
];
break;
default:
$options['order_by_metadata'] = [
'name' => 'name',
'direction' => 'ASC',
$options['joins'] = [
new JoinClause('metadata', 'ens', function(QueryBuilder $qb, $join_alias, $main_alias) {
$compare = [
$qb->compare("{$join_alias}.entity_guid", '=', "{$main_alias}.guid_one"),
$qb->compare("{$join_alias}.name", '=', 'name', ELGG_VALUE_STRING),
];
return $qb->merge($compare);
}),
];
$options['order_by'] = [
new OrderByClause('ens.value', 'ASC'),
];

break;
}

@@ -43,7 +51,7 @@
'class' => 'elgg-tabs'
]);

$content = elgg_list_entities($options);
$content = elgg_list_relationships($options);

$params = [
'content' => $content,
@@ -0,0 +1,51 @@
<?php
/**
* Elgg (group) member relationship view
*
* @note To add or remove from the relationship menu, register handlers for the menu:relationship hook.
*
* @uses $vars['relationship']
*/

$relationship = elgg_extract('relationship', $vars);
if (!$relationship instanceof ElggRelationship) {
return;
}

$entity_one = get_entity($relationship->guid_one);
$entity_two = get_entity($relationship->guid_two);
if (!$entity_one instanceof ElggUser || !$entity_two instanceof ElggGroup) {
return;
}

$user_params = [
'entity' => $entity_one,
'full_view' => false,
];

$user_params['title'] = elgg_format_element('h3', [], elgg_view('output/url', [
'text' => $entity_one->getDisplayName(),
'href' => $entity_one->getURL(),
'is_trusted' => true,
]));

$subtitle = '';
$location = $entity_one->getProfileData('location');
if (is_string($location) && $location !== '') {
$location = elgg_view_icon('map-marker') . ' ' . $location;
$subtitle .= elgg_format_element('div', [], $location);
}

$briefdescription = $entity_one->getProfileData('briefdescription');
if (is_string($briefdescription) && $briefdescription !== '') {
$subtitle .= elgg_format_element('div', [], $briefdescription);
}

$user_params['subtitle'] = $subtitle ?: false;

if (elgg_view_exists('user/status')) {
$user_params['content'] = elgg_view('user/status', ['entity' => $entity_one]);
}

$user_params = $user_params + $vars;
echo elgg_view('relationship/elements/summary', $user_params);

0 comments on commit 783f22a

Please sign in to comment.
You can’t perform that action at this time.