From 0442f39664e0509529889848ead9d8667bac9538 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Wed, 21 Sep 2011 02:14:29 +0200 Subject: [PATCH] Clean-up user model --- application/libraries/Access.php | 5 +-- application/models/user.php | 59 +++++++++++++++----------------- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/application/libraries/Access.php b/application/libraries/Access.php index 6e3a395..c177eab 100644 --- a/application/libraries/Access.php +++ b/application/libraries/Access.php @@ -25,6 +25,7 @@ * Simple auth system. * * @package ScattPort + * @subpackage Libraries * @author Eike Foken */ class Access { @@ -90,7 +91,7 @@ class Access { public function forgottenPassword($email) { if ($this->CI->user->forgottenPassword($email)) { // get user information - $user = $this->CI->user->getUserByEmail($email); + $user = $this->CI->user->getByEmail($email); $data = array( 'username' => $user['username'], @@ -258,7 +259,7 @@ class Access { * @return object */ public function getCurrentUser() { - return $this->CI->user->getUserByID($this->CI->session->userdata('user_id')); + return $this->CI->user->getById($this->CI->session->userdata('user_id')); } /** diff --git a/application/models/user.php b/application/models/user.php index 2714a15..59c743b 100644 --- a/application/models/user.php +++ b/application/models/user.php @@ -376,13 +376,24 @@ class User extends CI_Model { return $this->get()->result_array(); } + /** + * Gets a specified number of new users. + * + * @param integer $limit + * @return array + */ + public function getNewest($limit = 10) { + $this->db->order_by('users.created_on DESC')->limit($limit); + return $this->get()->result_array(); + } + /** * Gets a user by ID. * * @param string $id * @return array */ - public function getUserByID($id = false) { + public function getById($id = false) { if (empty($id)) { return false; } @@ -392,13 +403,24 @@ class User extends CI_Model { return $this->get()->row_array(); } + /** + * Gets a user by ID. + * + * @deprecated 21-09-2011 + * @param string $id + * @return array + */ + public function getUserByID($id = false) { + return $this->getById($id); + } + /** * Gets a user by email. * * @param string $email * @return array */ - public function getUserByEmail($email) { + public function getByEmail($email) { $this->db->where('users.email', $email)->limit(1); return $this->get()->row_array(); } @@ -409,38 +431,11 @@ class User extends CI_Model { * @param string $username * @return array */ - public function getUserByUsername($username) { + public function getByUsername($username) { $this->db->where('users.username', $username)->limit(1); return $this->get()->row_array(); } - /** - * Gets a specified number of new users. - * - * @param integer $limit - * @return array - */ - public function getNewestUsers($limit = 10) { - $this->db->order_by('users.created_on DESC')->limit($limit); - return $this->get()->result_array(); - } - - /** - * Gets a users group. - * - * @param string $id - * @return array - */ - public function getUsersGroup($id = false) { - // if no ID was passed use the current users ID - $id || $id = $this->session->userdata('user_id'); - - $user = $this->db->select('group_id')->where('id', $id)->get('users')->row(); - - return $this->db->select('name, description') - ->where('id', $user->group_id)->get('groups')->row_array(); - } - /** * Gets a users settings. * @@ -475,7 +470,7 @@ class User extends CI_Model { * @return boolean Returns TRUE if the update was successful. */ public function update($id, $data) { - $user = $this->getUserByID($id); + $user = $this->getById($id); if (array_key_exists('username', $data) && $this->checkUsername($data['username']) && $user['username'] !== $data['username']) { $this->messages->add(_('The entered username is already in use.'), 'error'); @@ -582,7 +577,7 @@ class User extends CI_Model { return false; } - $user = $this->getUserByID($id); + $user = $this->getById($id); $salt = sha1($user['password']);