Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     $this->load->helper('inflector');
     $this->pagination_delimiters = isset($this->pagination_delimiters) ? $this->pagination_delimiters : array('<span>', '</span>');
     $this->pagination_arrows = isset($this->pagination_arrows) ? $this->pagination_arrows : array('&lt;', '&gt;');
 }
Exemplo n.º 2
0
 public function find_author_img($id = 0)
 {
     if ((int) $id == 0) {
         return false;
     }
     $name = parent::find($id);
     return gravatar_link($name->email);
 }
Exemplo n.º 3
0
 public function delete($thread_id = false)
 {
     if ($thread_id === false) {
         $this->error = "No thread ID was received.";
         return false;
     }
     $this->db->where('id', $thread_id)->delete('comments_threads');
     return parent::delete($thread_id);
 }
Exemplo n.º 4
0
 /**
  * Returns Name of Author of article.
  *
  * @param int $id  User ID of Author
  *
  * @return mixed   False if no ID is provided, else String of Display Name of User.
  */
 public function find_author($id = 0)
 {
     if ((int) $id == 0) {
         return false;
     }
     $this->select($this->display_name);
     $name = parent::find($id);
     return $name->{$this->display_name};
 }
 public function find_all($sort_field = null)
 {
     $result_array = parent::find_all();
     if (null != $sort_field) {
         $output_array = array();
         if (is_array($result_array) and count($result_array)) {
             foreach ($result_array as $key => $record) {
                 $output_array[$record->{$sort_field}] = $record;
             }
         }
         $result_array = $output_array;
     }
     return $result_array;
 }
Exemplo n.º 6
0
 function delete($id = 0, $purge = false)
 {
     if ($purge === true) {
         // temporarily set the soft_deletes to true.
         $this->soft_deletes = false;
     }
     // delete the ercord
     $deleted = parent::delete($id);
     // if the delete was successful then delete the role_permissions for this permission_id
     if (TRUE === $deleted) {
         // now delete the role_permissions for this permission
         $this->role_permission_model->delete_for_permission($id);
     }
     return $deleted;
 }
 public function find_for_role($role_id = null)
 {
     parent::select('permission_id');
     return parent::find_all_by('role_id', $role_id);
 }
Exemplo n.º 8
0
 /**
  * Logs a new activity.
  *
  * @access public
  *
  * @param int    $user_id  An int id of the user that performed the activity.
  * @param string $activity A string detailing the activity. Max length of 255 chars.
  * @param string $module   The name of the module that set the activity.
  *
  * @return bool An int with the ID of the new object, or FALSE on failure.
  */
 public function log_activity($user_id = null, $activity = '', $module = 'any')
 {
     if (empty($user_id) || !is_integer($user_id) || $user_id == 0) {
         Template::set_message('You must provide a numeric user id to log activity.', 'error');
         return FALSE;
     } else {
         if (empty($activity)) {
             Template::set_message('Not enough information provided to insert activity.', 'error');
             return FALSE;
         }
     }
     $data = array('user_id' => $user_id, 'activity' => $activity, 'module' => $module);
     return parent::insert($data);
 }
Exemplo n.º 9
0
 public function delete($id = 0, $purge = false)
 {
     if ($purge === true) {
         // temporarily set the soft_deletes to true.
         $this->soft_deletes = false;
     }
     return parent::delete($id);
 }
Exemplo n.º 10
0
 /**
  * Find a single user based on a field/value match, including role information.
  *
  * @param string $field The field to match. If 'both', attempt to find a user
  * with the $value field matching either the username or email.
  * @param string $value The value to search for.
  * @param string $type  The type of where clause to create ('and' or 'or').
  *
  * @return boolean|object An object with the user's info, or false on failure.
  */
 public function find_by($field = null, $value = null, $type = 'and')
 {
     return parent::find_by($field, $value, $type);
 }
Exemplo n.º 11
0
 /**
  * Update a particular permission from the database
  * Remove it from role_permissions if set to inactive
  *
  * @access public
  *
  * @param int   $id   The primary_key value of the row to update.
  * @param array $data An array of key/value pairs to update.
  *
  * @return bool TRUE/FALSE
  */
 function update($id, $data)
 {
     $updated = parent::update($id, $data);
     if ($data['status'] == 'inactive' && $updated === TRUE) {
         // now delete the role_permissions for this permission since it is no longer active
         $updated = $this->role_permission_model->delete_for_permission($id);
     }
     return $updated;
 }
Exemplo n.º 12
0
 function delete($id = 0, $purge = false)
 {
     if ($purge === true) {
         // temporarily set the soft_deletes to true.
         $this->soft_deletes = false;
     }
     // We might not be allowed to delete this role.
     if ($this->can_delete_role($id) == false) {
         $this->error = 'This role can not be deleted.';
         return false;
     }
     // get the name for management deletion later
     $role = $this->role_model->find($id);
     // delete the record
     $deleted = parent::delete($id);
     if ($deleted === TRUE && $purge === TRUE) {
         // now delete the role_permissions for this permission
         $this->role_permission_model->delete_for_role($id);
         // now delete the manage permission for this role
         $prefix = $this->db->dbprefix;
         if (!class_exists('Permission_model')) {
             $this->load->model('permissions/permission_model');
         }
         $perm = $this->permission_model->find_by('name', 'Permissions.' . ucwords($role->role_name) . '.Manage');
         if ($perm) {
             $this->db->query("DELETE FROM {$prefix}permissions WHERE (name = 'Permissions." . ucwords($role->role_name) . ".Manage')");
             $this->db->query("DELETE FROM {$prefix}role_permissions WHERE permission_id='" . $perm->permission_id . "';");
         }
     }
     return $deleted;
 }
Exemplo n.º 13
0
 function delete($id = 0, $purge = false)
 {
     if ($purge === true) {
         // temporarily set the soft_deletes to true.
         $this->soft_deletes = false;
     }
     // We might not be allowed to delete this role.
     if ($this->can_delete_role($id) == false) {
         $this->error = 'This role can not be deleted.';
         return false;
     }
     // delete the ercord
     $deleted = parent::delete($id);
     if (TRUE === $deleted) {
         // now delete the role_permissions for this permission
         $this->role_permission_model->delete_for_role($id);
     }
     return $deleted;
 }
Exemplo n.º 14
0
 /**
  * Update a particular permission in the database.
  *
  * Remove it from role_permissions if set to inactive
  *
  * @param int   $id   The primary_key value or an array of key/value pairs
  * for the where clause to determine the row to update.
  * @param array $data An array of key/value pairs to update.
  *
  * @return bool true if the permission was updated, else false
  */
 function update($id, $data)
 {
     $updated = parent::update($id, $data);
     // If the permission is set to inactive, delete its role_permissions
     if ($updated === true && isset($data['status']) && $data['status'] == 'inactive') {
         $id_is_array = is_array($id);
         // If $id is an array and we don't have the key
         if ($id_is_array && !isset($id[$this->key])) {
             // Find the key(s) and perform the delete
             $result = $this->select($this->key)->find_all_by($id);
             if ($result) {
                 foreach ($result as $permission_key) {
                     $deleted = $this->role_permission_model->delete_for_permission($permission_key);
                     if ($deleted === false) {
                         return $deleted;
                     }
                 }
             }
         } else {
             $id_key = $id_is_array ? $id[$this->key] : $id;
             $updated = $this->role_permission_model->delete_for_permission($id_key);
         }
     }
     return $updated;
 }
Exemplo n.º 15
0
 public function log_activity($user_id = null, $activity = '', $module = 'any')
 {
     if (!is_numeric($user_id) || empty($activity)) {
         logit('Not enough information provided to insert activity.');
     }
     $data = array('user_id' => $user_id, 'activity' => $activity, 'module' => $module);
     return parent::insert($data);
 }
Exemplo n.º 16
0
 /**
  * Deletes a role.
  *
  * By default, it will perform a soft_delete and leave the permissions
  * untouched. However, if $purge == true, then all permissions related to
  * this role are also deleted.
  *
  * @param int  $id    An integer with the role_id to delete.
  * @param bool $purge If false, will perform a soft_delete. If true, will
  * remove the role and related permissions from db.
  *
  * @return bool true on successful delete, else false
  */
 function delete($id = 0, $purge = false)
 {
     // Can this role be deleted?
     if ($this->can_delete_role($id) == false) {
         $this->error = 'This role can not be deleted.';
         return false;
     }
     if ($this->default_role_id() == $id) {
         $this->error = 'The default role can not be deleted.';
         return false;
     }
     if ($purge === true) {
         // Temporarily disable soft deletes.
         $tempSoftDeletes = $this->soft_deletes;
         $this->soft_deletes = false;
     }
     // Get the name for permission deletion later
     $role = $this->role_model->find($id);
     // Delete the record
     $deleted = parent::delete($id);
     if ($deleted === true) {
         // Update the users to the default role
         if (!class_exists('user_model')) {
             $this->load->model('users/user_model');
         }
         $this->user_model->set_to_default_role($id);
         // Delete the role_permissions for this role
         if (!class_exists('role_permission_model')) {
             $this->load->model('roles/role_permission_model');
         }
         $this->role_permission_model->delete_for_role($id);
         // Delete the manage permission for this role
         $permission_name = 'Permissions.' . ucwords($role->role_name) . '.Manage';
         if (!class_exists('permission_model')) {
             $this->load->model('permissions/permission_model');
         }
         $perm = $this->permission_model->find_by('name', $permission_name);
         if ($perm) {
             // The permission_model's update/delete will remove the
             // role_permissions for this permission
             if ($purge === true) {
                 $this->permission_model->delete_by_name($permission_name);
             } else {
                 $this->permission_model->update(array('name' => $permission_name), array('status' => 'inactive'));
             }
         }
     }
     // Restore soft_deletes
     if ($purge === true) {
         $this->soft_deletes = $tempSoftDeletes;
     }
     return $deleted;
 }
Exemplo n.º 17
0
 public function __construct()
 {
     parent::__construct();
     $this->lang->load('activities/activities');
 }
Exemplo n.º 18
0
 /**
  * Extracts the model's fields (except the key and those handled by observers)
  * from the $post_data and returns an array of name => value pairs.
  *
  * @param array $post_data The post data, usually $this->input->post() when
  * called from the controller.
  *
  * @return array An array of name => value pairs containing the prepared data
  * for the model's fields.
  */
 public function prep_data($post_data)
 {
     // Take advantage of BF_Model's prep_data() method.
     $data = parent::prep_data($post_data);
     // Special handling of the data specific to the User_model.
     // Only set 'timezone' if one was selected from the 'timezones' select.
     if (!empty($post_data['timezones'])) {
         $data['timezone'] = $post_data['timezones'];
     }
     // Only set 'password' if a value was provided (so the user's profile can
     // be updated without changing the password).
     if (!empty($post_data['password'])) {
         $data['password'] = $post_data['password'];
     }
     if ($data['display_name'] === '') {
         unset($data['display_name']);
     }
     // Convert actions to the proper values.
     if (isset($post_data['restore']) && $post_data['restore']) {
         // 'restore': unset the soft-delete flag.
         $data['deleted'] = 0;
     }
     if (isset($post_data['unban']) && $post_data['unban']) {
         // 'unban': unset the banned flag.
         $data['banned'] = 0;
     }
     if (isset($post_data['activate']) && $post_data['activate']) {
         // 'activate': set the 'active' flag.
         $data['active'] = 1;
     } elseif (isset($post_data['deactivate']) && $post_data['deactivate']) {
         // 'deactivate': unset the 'active' flag.
         $data['active'] = 0;
     }
     return $data;
 }
Exemplo n.º 19
0
 /**
  * Performs a standard delete, but also allows for purging of a record.
  *
  * @access public
  *
  * @param int  $id    An INT with the record ID to delete.
  * @param bool $purge If FALSE, will perform a soft-delete. If TRUE, will permanently delete the record.
  *
  * @return bool TRUE/FALSE
  */
 public function delete($id = 0, $purge = FALSE)
 {
     if ($purge === TRUE) {
         // temporarily set the soft_deletes to TRUE.
         $this->soft_deletes = FALSE;
     }
     return parent::delete($id);
 }
Exemplo n.º 20
0
 /**
  * Deletes a role. By default, it will perform a soft_delete and
  * leave the permissions untouched. However, if $purge == TRUE, then
  * all permissions related to this role are also deleted.
  *
  * @access public
  *
  * @param int  $id    An integer with the role_id to delete.
  * @param bool $purge If FALSE, will perform a soft_delete. If TRUE, will remove the role and related permissions from db.
  *
  * @return bool TRUE/FALSE
  */
 function delete($id = 0, $purge = FALSE)
 {
     if ($purge === TRUE) {
         // temporarily set the soft_deletes to TRUE.
         $this->soft_deletes = FALSE;
     }
     // We might not be allowed to delete this role.
     if ($this->can_delete_role($id) == FALSE) {
         $this->error = 'This role can not be deleted.';
         return FALSE;
     }
     // get the name for management deletion later
     $role = $this->role_model->find($id);
     // delete the record
     $deleted = parent::delete($id);
     if ($deleted === TRUE) {
         // Now update the users to the default role
         if (!class_exists('User_model')) {
             $this->load->model('users/User_model', 'user_model');
         }
         $this->user_model->set_to_default_role($id);
         // now delete the role_permissions for this permission
         $this->role_permission_model->delete_for_role($id);
         // now delete the manage permission for this role
         $prefix = $this->db->dbprefix;
         if (!class_exists('Permission_model')) {
             $this->load->model('permissions/permission_model');
         }
         $perm = $this->permission_model->find_by('name', 'Permissions.' . ucwords($role->role_name) . '.Manage');
         if ($perm) {
             // remove the role_permissions for this permission
             $this->db->query("DELETE FROM {$prefix}role_permissions WHERE permission_id='" . $perm->permission_id . "';");
             if ($deleted === TRUE && $purge === TRUE) {
                 $this->db->query("DELETE FROM {$prefix}permissions WHERE (name = 'Permissions." . ucwords($role->role_name) . ".Manage')");
             } else {
                 $this->db->query("UPDATE {$prefix}permissions SET status = 'inactive' WHERE (name = 'Permissions." . ucwords($role->role_name) . ".Manage')");
             }
         }
     }
     //end if
     return $deleted;
 }
Exemplo n.º 21
0
 /**
  * Deletes a role. By default, it will perform a soft_delete and
  * leave the permissions untouched. However, if $purge == TRUE, then
  * all permissions related to this role are also deleted.
  *
  * @access public
  *
  * @param int  $id    An integer with the role_id to delete.
  * @param bool $purge If FALSE, will perform a soft_delete. If TRUE, will remove the role and related permissions from db.
  *
  * @return bool TRUE/FALSE
  */
 function delete($id = 0, $purge = FALSE)
 {
     // We might not be allowed to delete this role.
     if ($this->can_delete_role($id) == FALSE) {
         $this->error = 'This role can not be deleted.';
         return FALSE;
     }
     if ($this->default_role_id() == $id) {
         $this->error = 'The default role can not be deleted.';
         return FALSE;
     }
     if ($purge === TRUE) {
         // temporarily set the soft_deletes to TRUE.
         $this->soft_deletes = FALSE;
     }
     // get the name for management deletion later
     $role = $this->role_model->find($id);
     // delete the record
     $deleted = parent::delete($id);
     if ($deleted === TRUE) {
         // Now update the users to the default role
         if (!class_exists('User_model')) {
             $this->load->model('users/User_model', 'user_model');
         }
         $this->user_model->set_to_default_role($id);
         // now delete the role_permissions for this role
         $this->role_permission_model->delete_for_role($id);
         // now delete the manage permission for this role
         $permission_name = 'Permissions.' . ucwords($role->role_name) . '.Manage';
         if (!class_exists('Permission_model')) {
             $this->load->model('permissions/permission_model');
         }
         $perm = $this->permission_model->find_by('name', $permission_name);
         if ($perm) {
             // remove the role_permissions for this permission
             $this->db->delete('role_permissions', array('permission_id' => $perm->permission_id));
             if ($purge === TRUE) {
                 $this->db->delete('permissions', array('name' => $permission_name));
             } else {
                 $this->db->update('permissions', array('status' => 'inactive'), array('name' => $permission_name));
             }
         }
     }
     //end if
     return $deleted;
 }
Exemplo n.º 22
0
 /**
  * Update a particular permission in the database.
  *
  * Remove it from role_permissions if set to inactive.
  *
  * @param integer $id   The primary key value or an array of key/value pairs
  * for the where clause to determine the row to update.
  * @param array   $data An array of key/value pairs to update.
  *
  * @return boolean True if the permission was updated, else false.
  */
 public function update($id = null, $data = null)
 {
     $updated = parent::update($id, $data);
     if ($updated !== true || !isset($data['status']) || $data['status'] != 'inactive') {
         return $updated;
     }
     // If the permission is set to inactive, delete its role_permissions.
     if (is_array($id) && !isset($id[$this->key])) {
         // If $id is an array and the key is not set, find the key(s) and perform
         // the delete.
         $result = $this->select($this->key)->find_all_by($id);
         if (!$result) {
             // This permission is not assigned to any roles, but the permission
             // was updated successfully.
             return true;
         }
         $returnVal = true;
         foreach ($result as $permission) {
             if (!$this->role_permission_model->delete_for_permission($permission->{$this->key})) {
                 // Save failed result, but continue attempting to delete permissions
                 // from the roles to ensure that the permission is deleted from
                 // as many roles as possible.
                 $returnVal = false;
             }
         }
         return $returnVal;
     }
     // If $id is an array, the key is in the array, otherwise, $id is the key.
     $id_key = is_array($id) ? $id[$this->key] : $id;
     return $this->role_permission_model->delete_for_permission($id_key);
 }
Exemplo n.º 23
0
 /**
  * Update a particular permission from the database
  * Remove it from role_permissions if set to inactive
  *
  * @access public
  *
  * @param int   $id   The primary_key value of the row to update.
  * @param array $data An array of key/value pairs to update.
  *
  * @return bool TRUE if the permission was updated, else FALSE
  */
 function update($id, $data)
 {
     $updated = parent::update($id, $data);
     if (isset($data['status']) && $data['status'] == 'inactive' && $updated === TRUE) {
         $id_is_array = is_array($id);
         // now delete the role_permissions for this permission since it is no longer active
         // if $id is an array and we don't have the key
         if ($id_is_array && !isset($id[$key])) {
             // find the key(s) and perform the delete
             $result = $this->permission_model->select($key)->find_all_by($id);
             if ($result) {
                 foreach ($result as $permission_key) {
                     $deleted = $this->role_permission_model->delete_for_permission($permission_key);
                     if ($deleted === FALSE) {
                         return $deleted;
                     }
                 }
             }
         } else {
             $id_key = $id_is_array ? $id[$key] : $id;
             $updated = $this->role_permission_model->delete_for_permission($id_key);
         }
     }
     return $updated;
 }
Exemplo n.º 24
0
 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
 }
Exemplo n.º 25
0
 /**
  * Update an existing user. Before saving, it will:
  * - Generate a new password/hash if both password and pass_confirm are provided.
  * - Store the country code.
  *
  * @param integer $id   The user's ID.
  * @param array $data An array of key/value pairs to update for the user.
  *
  * @return boolean True if the update succeeded, null on invalid $id, or false
  * on failure.
  */
 public function update($id = null, $data = array())
 {
     if (empty($id)) {
         return null;
     }
     $result = parent::update($id, $data);
     return $result;
 }