correct count for user listing when a filter is applied

This commit is contained in:
coderkun 2014-06-24 21:53:36 +02:00
commit 82b51e3d5b
3 changed files with 9 additions and 7 deletions

View file

@ -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'];