Skip to content

Commit

Permalink
fix(views): listing of entities and river no longer count if not needed
Browse files Browse the repository at this point in the history
fixes #11807
  • Loading branch information
jdalsem committed Mar 27, 2018
1 parent 759873d commit ee6a043
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 22 deletions.
31 changes: 20 additions & 11 deletions engine/lib/entities.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -414,18 +414,27 @@ function elgg_list_entities(array $options = array(), $getter = 'elgg_get_entiti
$options['list_type_toggle'] = $options['view_type_toggle']; $options['list_type_toggle'] = $options['view_type_toggle'];
} }


$options['count'] = true; $options['count'] = false;
$count = call_user_func($getter, $options); $entities = call_user_func($getter, $options);

$options['count'] = is_array($entities) ? count($entities) : 0;
if ($count > 0) {
$options['count'] = false; if (!empty($entities)) {
$entities = call_user_func($getter, $options); $count_needed = true;
} else { if (!$options['pagination']) {
$entities = array(); $count_needed = false;
} elseif (!$options['offset'] && !$options['limit']) {
$count_needed = false;
} elseif (($options['count'] < (int) $options['limit']) && !$options['offset']) {
$count_needed = false;
}

if ($count_needed) {
$options['count'] = true;

$options['count'] = (int) call_user_func($getter, $options);
}
} }


$options['count'] = $count;

return call_user_func($viewer, $entities, $options); return call_user_func($viewer, $entities, $options);
} }


Expand Down
32 changes: 21 additions & 11 deletions engine/lib/river.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -455,18 +455,28 @@ function elgg_list_river(array $options = array()) {
// no need for pagination if listing is unlimited // no need for pagination if listing is unlimited
$options["pagination"] = false; $options["pagination"] = false;
} }


$options['count'] = true; $options['count'] = false;
$count = elgg_get_river($options); $items = elgg_get_river($options);

$options['count'] = is_array($items) ? count($items) : 0;
if ($count > 0) {
$options['count'] = false; if (!empty($items)) {
$items = elgg_get_river($options); $count_needed = true;
} else { if (!$options['pagination']) {
$items = array(); $count_needed = false;
} elseif (!$options['offset'] && !$options['limit']) {
$count_needed = false;
} elseif (($options['count'] < (int) $options['limit']) && !$options['offset']) {
$count_needed = false;
}

if ($count_needed) {
$options['count'] = true;

$options['count'] = (int) elgg_get_river($options);
}
} }


$options['count'] = $count;
$options['items'] = $items; $options['items'] = $items;


return elgg_view('page/components/list', $options); return elgg_view('page/components/list', $options);
Expand Down

0 comments on commit ee6a043

Please sign in to comment.