PHPDoc and clean-up in user and group models
This commit is contained in:
@@ -8,41 +8,40 @@
|
|||||||
class Group extends CI_Model {
|
class Group extends CI_Model {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Calls the parent constructor.
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get
|
* Gets all groups.
|
||||||
*
|
*
|
||||||
* @return object
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get() {
|
public function get() {
|
||||||
return $this->db->get('groups')->result_array();
|
return $this->db->get('groups')->result_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getGroupByID
|
* Gets a specific group.
|
||||||
*
|
*
|
||||||
* @return object
|
* @param string $id
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getGroupByID($id) {
|
public function getByID($id) {
|
||||||
$this->db->where('id', $id);
|
return $this->db->get_where('groups', array('id' => $id))->row_array();
|
||||||
return $this->db->get('groups')->row_array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getGroupByName
|
* Gets a specific group by it's name.
|
||||||
*
|
*
|
||||||
* @return object
|
* @param string $name
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getGroupByName($name) {
|
public function getByName($name) {
|
||||||
$this->db->where('name', $name);
|
return $this->db->get_where('groups', array('name' => $name))->row_array();
|
||||||
return $this->db->get('groups')->row_array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file group.php */
|
/* End of file group.php */
|
||||||
|
|||||||
@@ -7,6 +7,20 @@
|
|||||||
*/
|
*/
|
||||||
class User extends CI_Model {
|
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.
|
* Contains the forgotten password key.
|
||||||
*
|
*
|
||||||
@@ -104,7 +118,7 @@ class User extends CI_Model {
|
|||||||
$new = $this->hashPassword($new, $result->salt);
|
$new = $this->hashPassword($new, $result->salt);
|
||||||
|
|
||||||
if ($dbPassword === $old) {
|
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' => '');
|
$data = array('password' => $new, 'remember_code' => '');
|
||||||
|
|
||||||
$this->db->update('users', $data, array('username' => $username));
|
$this->db->update('users', $data, array('username' => $username));
|
||||||
@@ -130,6 +144,7 @@ class User extends CI_Model {
|
|||||||
/**
|
/**
|
||||||
* Checks entered emails.
|
* Checks entered emails.
|
||||||
*
|
*
|
||||||
|
* @param string $email
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function checkEmail($email = '') {
|
public function checkEmail($email = '') {
|
||||||
@@ -142,6 +157,7 @@ class User extends CI_Model {
|
|||||||
/**
|
/**
|
||||||
* Inserts a forgotten password key.
|
* Inserts a forgotten password key.
|
||||||
*
|
*
|
||||||
|
* @param string $email
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function forgottenPassword($email = '') {
|
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
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function forgottenPasswordComplete($code, $salt = false) {
|
public function forgottenPasswordComplete($code, $salt = false) {
|
||||||
@@ -175,7 +193,7 @@ class User extends CI_Model {
|
|||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
'password' => $this->hashPassword($password, $salt),
|
'password' => $this->hashPassword($password, $salt),
|
||||||
'forgotten_password_code' => null
|
'forgotten_password_code' => null,
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->db->update('users', $data, array('forgotten_password_code' => $code));
|
$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) {
|
public function profile($username = '', $isCode = false) {
|
||||||
if (empty($username)) {
|
if (empty($username)) {
|
||||||
@$username = $this->session->userdata('username');
|
@$username = $this->session->userdata('username');
|
||||||
if(empty($username))
|
if (empty($username)) {
|
||||||
return FALSE;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->select('users.*, groups.name AS `group`, groups.description AS `group_description`');
|
$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');
|
$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
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function login($username, $password, $remember = false) {
|
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
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function get($group = false, $limit = null, $offset = null) {
|
public function get($group = false, $limit = null, $offset = null) {
|
||||||
@@ -332,6 +359,7 @@ class User extends CI_Model {
|
|||||||
/**
|
/**
|
||||||
* Returns the number of users.
|
* Returns the number of users.
|
||||||
*
|
*
|
||||||
|
* @param mixed $group
|
||||||
* @return integer The number of users
|
* @return integer The number of users
|
||||||
*/
|
*/
|
||||||
public function count($group = false) {
|
public function count($group = false) {
|
||||||
@@ -346,6 +374,7 @@ class User extends CI_Model {
|
|||||||
/**
|
/**
|
||||||
* Gets a user by ID.
|
* Gets a user by ID.
|
||||||
*
|
*
|
||||||
|
* @param string $id
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUserByID($id = false) {
|
public function getUserByID($id = false) {
|
||||||
@@ -353,59 +382,58 @@ class User extends CI_Model {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->db->where('users.id', $id);
|
$this->db->where('users.id', $id)->limit(1);
|
||||||
$this->db->limit(1);
|
|
||||||
|
|
||||||
return $this->get()->row_array();
|
return $this->get()->row_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getUserByEmail
|
* Gets a user by email.
|
||||||
*
|
*
|
||||||
* @return object
|
* @param string $email
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUserByEmail($email) {
|
public function getUserByEmail($email) {
|
||||||
$this->db->where('users.email', $email);
|
$this->db->where('users.email', $email)->limit(1);
|
||||||
$this->db->limit(1);
|
|
||||||
return $this->get()->row_array();
|
return $this->get()->row_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getUserByUsername
|
* Gets a user by username.
|
||||||
*
|
*
|
||||||
* @return object
|
* @param string $username
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUserByUsername($username) {
|
public function getUserByUsername($username) {
|
||||||
$this->db->where('users.username', $username);
|
$this->db->where('users.username', $username)->limit(1);
|
||||||
$this->db->limit(1);
|
return $this->get()->row_array();
|
||||||
return $this->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getNewestUsers
|
* Gets a specified number of new users.
|
||||||
*
|
*
|
||||||
* @return object
|
* @param integer $limit
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getNewestUsers($limit = 10) {
|
public function getNewestUsers($limit = 10) {
|
||||||
$this->db->order_by('users.created_on DESC');
|
$this->db->order_by('users.created_on DESC')->limit($limit);
|
||||||
$this->db->limit($limit);
|
return $this->get()->result_array();
|
||||||
return $this->get();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getUsersGroup
|
* Gets a users group.
|
||||||
*
|
*
|
||||||
* @return object
|
* @param string $id
|
||||||
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getUsersGroup($id = false) {
|
public function getUsersGroup($id = false) {
|
||||||
// if no ID was passed use the current users ID
|
// if no ID was passed use the current users ID
|
||||||
$id || $id = $this->session->userdata('user_id');
|
$id || $id = $this->session->userdata('user_id');
|
||||||
|
|
||||||
$user = $this->db->select('group_id')->where('id', $id)->get('users')
|
$user = $this->db->select('group_id')->where('id', $id)->get('users')->row();
|
||||||
->row();
|
|
||||||
|
|
||||||
return $this->db->select('name, description')
|
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) {
|
public function updateLastLogin($id) {
|
||||||
$this->db->update('users', array('last_login' => now()), array('id' => $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
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@@ -497,8 +526,9 @@ class User extends CI_Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rememberUser
|
* Remembers a user.
|
||||||
*
|
*
|
||||||
|
* @param string $id
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
private function rememberUser($id) {
|
private function rememberUser($id) {
|
||||||
@@ -527,7 +557,6 @@ class User extends CI_Model {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file user.php */
|
/* End of file user.php */
|
||||||
|
|||||||
Reference in New Issue
Block a user