Pagination refactoring
This commit is contained in:
@@ -28,6 +28,30 @@ class User extends Base
|
||||
*/
|
||||
const EVERYBODY_ID = -1;
|
||||
|
||||
/**
|
||||
* Get query to fetch all users
|
||||
*
|
||||
* @access public
|
||||
* @return \PicoDb\Table
|
||||
*/
|
||||
public function getQuery()
|
||||
{
|
||||
return $this->db
|
||||
->table(self::TABLE)
|
||||
->columns(
|
||||
'id',
|
||||
'username',
|
||||
'name',
|
||||
'email',
|
||||
'is_admin',
|
||||
'default_project_id',
|
||||
'is_ldap_user',
|
||||
'notifications_enabled',
|
||||
'google_id',
|
||||
'github_id'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the full name
|
||||
*
|
||||
@@ -112,54 +136,7 @@ class User extends Base
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return $this->db
|
||||
->table(self::TABLE)
|
||||
->asc('username')
|
||||
->columns(
|
||||
'id',
|
||||
'username',
|
||||
'name',
|
||||
'email',
|
||||
'is_admin',
|
||||
'default_project_id',
|
||||
'is_ldap_user',
|
||||
'notifications_enabled',
|
||||
'google_id',
|
||||
'github_id'
|
||||
)
|
||||
->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all users with pagination
|
||||
*
|
||||
* @access public
|
||||
* @param integer $offset Offset
|
||||
* @param integer $limit Limit
|
||||
* @param string $column Sorting column
|
||||
* @param string $direction Sorting direction
|
||||
* @return array
|
||||
*/
|
||||
public function paginate($offset = 0, $limit = 25, $column = 'username', $direction = 'ASC')
|
||||
{
|
||||
return $this->db
|
||||
->table(self::TABLE)
|
||||
->columns(
|
||||
'id',
|
||||
'username',
|
||||
'name',
|
||||
'email',
|
||||
'is_admin',
|
||||
'default_project_id',
|
||||
'is_ldap_user',
|
||||
'notifications_enabled',
|
||||
'google_id',
|
||||
'github_id'
|
||||
)
|
||||
->offset($offset)
|
||||
->limit($limit)
|
||||
->orderBy($column, $direction)
|
||||
->findAll();
|
||||
return $this->getQuery()->asc('username')->findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user