From 82b51e3d5b962d1ff5a18feeb8a2e21b3955b951 Mon Sep 17 00:00:00 2001 From: coderkun Date: Tue, 24 Jun 2014 21:53:36 +0200 Subject: [PATCH] correct count for user listing when a filter is applied --- controllers/UsersController.inc | 3 ++- models/UsersModel.inc | 8 +++++--- views/html/users/index.tpl | 5 ++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/controllers/UsersController.inc b/controllers/UsersController.inc index 8bc0f09f..e067ac76 100644 --- a/controllers/UsersController.inc +++ b/controllers/UsersController.inc @@ -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); diff --git a/models/UsersModel.inc b/models/UsersModel.inc index b6158911..d06a2a2e 100644 --- a/models/UsersModel.inc +++ b/models/UsersModel.inc @@ -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']; diff --git a/views/html/users/index.tpl b/views/html/users/index.tpl index d8d921d5..119e2caa 100644 --- a/views/html/users/index.tpl +++ b/views/html/users/index.tpl @@ -10,15 +10,14 @@
-

Sortierung:

+

:

- : - +