diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-10-25 15:44:38 -0400 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-10-25 15:44:38 -0400 |
commit | 45b5e8b879c1135398790cf988434188aa062cd4 (patch) | |
tree | 61b4db2e7bda95141a17b9f86f414a46aed24fde /app/Model | |
parent | 471736bf8c9304606f183cd6b688b1fae64eea70 (diff) |
Add pagination for users page
Diffstat (limited to 'app/Model')
-rw-r--r-- | app/Model/User.php | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/app/Model/User.php b/app/Model/User.php index 9544f3c9..41bad0bb 100644 --- a/app/Model/User.php +++ b/app/Model/User.php @@ -138,11 +138,65 @@ class User extends Base 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') + ->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(); + } + + /** + * Get the number of users + * + * @access public + * @return integer + */ + public function count() + { + return $this->db->table(self::TABLE)->count(); + } + + /** * List all users (key-value pairs with id/username) * * @access public |