From bb2af33af8800011ac5cf2b10c2f96393e8bc6b6 Mon Sep 17 00:00:00 2001 From: Eike Foken Date: Thu, 18 Aug 2011 04:53:02 +0200 Subject: [PATCH] PHPDoc and clean-up in user and group models --- application/models/group.php | 27 +++++----- application/models/user.php | 101 ++++++++++++++++++++++------------- 2 files changed, 78 insertions(+), 50 deletions(-) diff --git a/application/models/group.php b/application/models/group.php index ba0d4e5..433bc0e 100644 --- a/application/models/group.php +++ b/application/models/group.php @@ -8,41 +8,40 @@ class Group extends CI_Model { /** - * Constructor. + * Calls the parent constructor. */ public function __construct() { parent::__construct(); } /** - * get + * Gets all groups. * - * @return object + * @return array */ public function get() { return $this->db->get('groups')->result_array(); } /** - * getGroupByID + * Gets a specific group. * - * @return object + * @param string $id + * @return array */ - public function getGroupByID($id) { - $this->db->where('id', $id); - return $this->db->get('groups')->row_array(); + public function getByID($id) { + return $this->db->get_where('groups', array('id' => $id))->row_array(); } /** - * getGroupByName + * Gets a specific group by it's name. * - * @return object + * @param string $name + * @return array */ - public function getGroupByName($name) { - $this->db->where('name', $name); - return $this->db->get('groups')->row_array(); + public function getByName($name) { + return $this->db->get_where('groups', array('name' => $name))->row_array(); } - } /* End of file group.php */ diff --git a/application/models/user.php b/application/models/user.php index 91b50dc..8f75d11 100644 --- a/application/models/user.php +++ b/application/models/user.php @@ -7,6 +7,20 @@ */ class User extends CI_Model { + /** + * Should the salt be stored in the database? + * + * @var boolean + */ + private $storeSalt; + + /** + * Contains the salt length. + * + * @var integer + */ + private $saltLength; + /** * Contains the forgotten password key. * @@ -104,7 +118,7 @@ class User extends CI_Model { $new = $this->hashPassword($new, $result->salt); if ($dbPassword === $old) { - // store the new password and reset the remember code so all remembered instances have to re-login + // reset the remember code so all remembered instances have to re-login $data = array('password' => $new, 'remember_code' => ''); $this->db->update('users', $data, array('username' => $username)); @@ -130,6 +144,7 @@ class User extends CI_Model { /** * Checks entered emails. * + * @param string $email * @return boolean */ public function checkEmail($email = '') { @@ -142,6 +157,7 @@ class User extends CI_Model { /** * Inserts a forgotten password key. * + * @param string $email * @return boolean */ public function forgottenPassword($email = '') { @@ -159,8 +175,10 @@ class User extends CI_Model { } /** - * Forgotten Password Complete + * Completes the forgotten password procedure. * + * @param string $code + * @param boolean $salt * @return string */ public function forgottenPasswordComplete($code, $salt = false) { @@ -175,7 +193,7 @@ class User extends CI_Model { $data = array( 'password' => $this->hashPassword($password, $salt), - 'forgotten_password_code' => null + 'forgotten_password_code' => null, ); $this->db->update('users', $data, array('forgotten_password_code' => $code)); @@ -186,15 +204,18 @@ class User extends CI_Model { } /** - * profile + * Gets a users profile. * - * @return boolean|object + * @param string $username + * @param boolean $isCode + * @return mixed */ public function profile($username = '', $isCode = false) { if (empty($username)) { @$username = $this->session->userdata('username'); - if(empty($username)) - return FALSE; + if (empty($username)) { + return false; + } } $this->db->select('users.*, groups.name AS `group`, groups.description AS `group_description`'); @@ -208,7 +229,7 @@ class User extends CI_Model { $query = $this->db->limit(1)->get('users'); - return $query->num_rows > 0 ? $query->row() : false; + return $query->num_rows() > 0 ? $query->row_array() : false; } /** @@ -259,8 +280,11 @@ class User extends CI_Model { } /** - * login + * Validates the given password against the username. * + * @param string $username + * @param string $password + * @param boolean $remember * @return boolean */ public function login($username, $password, $remember = false) { @@ -300,8 +324,11 @@ class User extends CI_Model { } /** - * get + * Gets users. * + * @param mixed $group + * @param integer $limit + * @param integer $offset * @return object */ public function get($group = false, $limit = null, $offset = null) { @@ -332,6 +359,7 @@ class User extends CI_Model { /** * Returns the number of users. * + * @param mixed $group * @return integer The number of users */ public function count($group = false) { @@ -346,6 +374,7 @@ class User extends CI_Model { /** * Gets a user by ID. * + * @param string $id * @return array */ public function getUserByID($id = false) { @@ -353,59 +382,58 @@ class User extends CI_Model { return false; } - $this->db->where('users.id', $id); - $this->db->limit(1); + $this->db->where('users.id', $id)->limit(1); return $this->get()->row_array(); } /** - * getUserByEmail + * Gets a user by email. * - * @return object + * @param string $email + * @return array */ public function getUserByEmail($email) { - $this->db->where('users.email', $email); - $this->db->limit(1); + $this->db->where('users.email', $email)->limit(1); return $this->get()->row_array(); } /** - * getUserByUsername + * Gets a user by username. * - * @return object + * @param string $username + * @return array */ public function getUserByUsername($username) { - $this->db->where('users.username', $username); - $this->db->limit(1); - return $this->get(); + $this->db->where('users.username', $username)->limit(1); + return $this->get()->row_array(); } /** - * getNewestUsers + * Gets a specified number of new users. * - * @return object + * @param integer $limit + * @return array */ public function getNewestUsers($limit = 10) { - $this->db->order_by('users.created_on DESC'); - $this->db->limit($limit); - return $this->get(); + $this->db->order_by('users.created_on DESC')->limit($limit); + return $this->get()->result_array(); } /** - * getUsersGroup + * Gets a users group. * - * @return object + * @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(); + $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(); + ->where('id', $user->group_id)->get('groups')->row_array(); } /** @@ -446,9 +474,10 @@ class User extends CI_Model { } /** - * updateLastLogin + * Updates a users last login time. * - * @return boolean + * @param string $id + * @return boolean Returns TRUE if the update was successful. */ public function updateLastLogin($id) { $this->db->update('users', array('last_login' => now()), array('id' => $id)); @@ -456,7 +485,7 @@ class User extends CI_Model { } /** - * loginRemembedUser + * Logs a remembed user in. * * @return boolean */ @@ -497,8 +526,9 @@ class User extends CI_Model { } /** - * rememberUser + * Remembers a user. * + * @param string $id * @return boolean */ private function rememberUser($id) { @@ -527,7 +557,6 @@ class User extends CI_Model { } return false; } - } /* End of file user.php */