Skip to content

Commit

Permalink
fixed: member of group listing popular sorting
Browse files Browse the repository at this point in the history
Now actually sorts on number of members
  • Loading branch information
jeabakker committed Jul 22, 2020
1 parent f640175 commit b3c438f
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions views/default/groups/listing/member.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<?php

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

elgg_gatekeeper();

$options = [
Expand All @@ -15,10 +18,19 @@
$sorting = get_input('sort');
switch ($sorting) {
case 'popular':
$getter = 'elgg_get_entities_from_relationship_count';

$options['relationship'] = 'member';
$options['inverse_relationship'] = false;
$options['select'] = [
function (QueryBuilder $qb, $main_alias) {
$sub = $qb->subquery('entity_relationships');
$sub->select('count(*)')
->where($qb->compare('guid_two', '=', "{$main_alias}.guid"))
->andWhere($qb->compare('relationship', '=', 'member', ELGG_VALUE_STRING));

return "({$sub->getSQL()}) as total";
},
];
$options['order_by'] = [
new OrderByClause('total', 'desc'),
];
break;
case 'alpha':
$order = strtoupper(get_input('order'));
Expand Down

0 comments on commit b3c438f

Please sign in to comment.