correct count for user listing when a filter is applied
This commit is contained in:
parent
dacb967f32
commit
82b51e3d5b
3 changed files with 9 additions and 7 deletions
|
|
@ -68,7 +68,7 @@
|
|||
// Get registered users
|
||||
$limit = ($all != 'all') ? \nre\configs\AppConfig::$misc['lists_limit'] : null;
|
||||
$offset = ($all != 'all') ? max((intval($page) - 1), 0) * $limit : 0;
|
||||
$usersCount = $this->Users->getUsersCount();
|
||||
$usersCount = $this->Users->getUsersCount($username);
|
||||
$users = $this->Users->getUsers($sortorder, $username, $limit, $offset);
|
||||
foreach($users as &$user) {
|
||||
$user['roles'] = array_map(function($r) { return $r['name']; }, $this->Userroles->getUserrolesForUserById($user['id']));
|
||||
|
|
@ -82,6 +82,7 @@
|
|||
$this->set('users', $users);
|
||||
$this->set('usersCount', $usersCount);
|
||||
$this->set('sortorder', $sortorder);
|
||||
$this->set('username', $username);
|
||||
$this->set('all', $all);
|
||||
$this->set('page', $page);
|
||||
$this->set('limit', $limit);
|
||||
|
|
|
|||
|
|
@ -37,13 +37,15 @@
|
|||
/**
|
||||
* Get count of registered users.
|
||||
*
|
||||
* @return int Count of users
|
||||
* @param string $username Only get users with the given username (optional)
|
||||
* @return int Count of users
|
||||
*/
|
||||
public function getUsersCount()
|
||||
public function getUsersCount($username=null)
|
||||
{
|
||||
$data = $this->db->query(
|
||||
'SELECT count(DISTINCT id) AS c '.
|
||||
'FROM users '
|
||||
'FROM users '.
|
||||
(!is_null($username) ? sprintf('WHERE username LIKE \'%%%s%%\'', $username) : null )
|
||||
);
|
||||
if(!empty($data)) {
|
||||
return $data[0]['c'];
|
||||
|
|
|
|||
|
|
@ -10,15 +10,14 @@
|
|||
<form method="get">
|
||||
<fieldset class="filter">
|
||||
<legend><?=_('Filters')?></legend>
|
||||
<p><small>Sortierung:</small></p>
|
||||
<p><small><?=_('Sortorder')?>:</small></p>
|
||||
<select name="sortorder" onchange="this.form.submit();">
|
||||
<option value="username" <?php if($sortorder == 'username') : ?>selected="selected"<?php endif ?>><?=_('Username')?></option>
|
||||
<option value="role" <?php if($sortorder == 'role') : ?>selected="selected"<?php endif ?>><?=_('Role')?></option>
|
||||
<option value="created" <?php if($sortorder == 'created') : ?>selected="selected"<?php endif ?>><?=_('Date of registration')?></option>
|
||||
</select>
|
||||
<noscript><input type="submit" value="<?=_('Sort list')?>" /></noscript>
|
||||
<label for="username"><?=_('Username')?></label>:
|
||||
<input id="username" type="text" name="username" placeholder="<?=_('Username')?>" value="" />
|
||||
<input id="username" type="text" name="username" placeholder="<?=_('Username')?>" value="<?=$username?>" />
|
||||
</fieldset>
|
||||
<input type="submit" value="<?=_('Apply filters')?>" />
|
||||
</form>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue