* Admin: fix some status filter gave empty rows for more then 50 accounts

This commit is contained in:
Ralf Becker 2020-09-10 11:11:54 +02:00
parent 9ed7d0b110
commit 9556488db5

View File

@ -333,19 +333,26 @@ class admin_ui
'order' => $query['order'], 'order' => $query['order'],
'sort' => $query['sort'], 'sort' => $query['sort'],
'active' => !empty($query['active']) ? $query['active'] : false, 'active' => !empty($query['active']) ? $query['active'] : false,
'status' => $query['filter2']
); );
// Make sure active filter give status what it needs // Make sure active filter give status what it needs
switch($query['filter2']) switch($query['filter2'])
{ {
case '':
case 'disabled': case 'disabled':
case 'expired': case 'expired':
case 'not_enabled': case 'not_enabled':
case 'expires':
// this filters are not implemented by backend --> need to do unlimited query, then apply status filter and finally limit the query
$need_status_filter = $query['filter2'];
$params['start'] = false;
unset($params['offset']);
$params['active'] = $query['filter2'] === 'expires';
break;
case '': // all
$params['active'] = false; $params['active'] = false;
break; break;
case 'enabled': case 'enabled':
default:
$params['active'] = true; $params['active'] = true;
break; break;
} }
@ -363,14 +370,15 @@ class admin_ui
$rows = array_values(self::$accounts->search($params)); $rows = array_values(self::$accounts->search($params));
//error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total); //error_log(__METHOD__."() accounts->search(".array2string($params).") total=".self::$accounts->total);
$total = self::$accounts->total;
foreach($rows as $key => &$row) foreach($rows as $key => &$row)
{ {
// Filter by status // Filter by status
if($params['status'] && !static::filter_status($params['status'], $row)) if ($need_status_filter && !static::filter_status($need_status_filter, $row))
{ {
unset($rows[$key]); unset($rows[$key]);
self::$accounts->total--; $total--;
continue; continue;
} }
$row['status'] = self::$accounts->is_expired($row) ? $row['status'] = self::$accounts->is_expired($row) ?
@ -381,8 +389,12 @@ class admin_ui
if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive'; if (!self::$accounts->is_active($row)) $row['status_class'] = 'adminAccountInactive';
} }
// finally limit query, if status filter was used
return self::$accounts->total; if ($need_status_filter)
{
$rows = array_values(array_slice($rows, (int)$query['start'], $query['num_rows'] ?: count($rows)));
}
return $total;
} }