/** * 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); }
public function update($id = null, $data = null) { // If this one is set to default, then we need to // reset all others to NOT be default if (isset($data['default']) && $data['default'] == 1) { $this->db->set('default', 0); $this->db->update($this->table); } return parent::update($id, $data); }
/** * 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; }
public function update($id = null, $data = array()) { if ($id) { $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('before_user_update', $trigger_data); } if (empty($data['username'])) { unset($data['username']); } if (empty($data['pass_confirm']) && isset($data['password'])) { unset($data['pass_confirm'], $data['password']); } else { if (!empty($data['password']) && !empty($data['pass_confirm']) && $data['password'] == $data['pass_confirm']) { list($password, $salt) = $this->hash_password($data['password']); unset($data['password'], $data['pass_confirm']); $data['password_hash'] = $password; $data['salt'] = $salt; } } // Handle the country if (isset($data['iso'])) { $data['country_iso'] = $data['iso']; unset($data['iso']); } $return = parent::update($id, $data); if ($return) { $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('after_user_update', $trigger_data); } return $return; }
/** * 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; }
/** * 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; }
/** * Updates an existing user. Before saving, it will: * * generate a new password/salt combo if both password and pass_confirm are passed in. * * store the country code * * @access public * * @param int $id An INT with the user's ID. * @param array $data An array of key/value pairs to update for the user. * * @return bool TRUE/FALSE */ public function update($id = null, $data = array()) { if (empty($id)) { return NULL; } $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('before_user_update', $trigger_data); if (!empty($data['password'])) { $password = $this->auth->hash_password($data['password']); if (empty($password) || empty($password['hash'])) { return false; } $data['password_hash'] = $password['hash']; $data['password_iterations'] = $password['iterations']; unset($data['password'], $password); } // Handle the country if (isset($data['iso'])) { $data['country_iso'] = $data['iso']; unset($data['iso']); } $return = parent::update($id, $data); if ($return) { $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('after_user_update', $trigger_data); } return $return; }
/** * 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; } $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('before_user_update', $trigger_data); // If the password is provided, hash it. if (!empty($data['password'])) { $password = $this->auth->hash_password($data['password']); if (empty($password) || empty($password['hash'])) { return false; } $data['password_hash'] = $password['hash']; unset($data['password'], $password); } // If the country is passed as 'iso', change it to 'country_iso'. if (isset($data['iso'])) { $data['country_iso'] = $data['iso']; unset($data['iso']); } $result = parent::update($id, $data); if ($result) { $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('after_user_update', $trigger_data); } return $result; }
public function update($id = null, $data = array()) { if ($id) { $trigger_data = array('article_id' => $id, 'data' => $data); Events::trigger('before_news_update', $trigger_data); } $return = parent::update($id, $data); if ($return) { $trigger_data = array('user_id' => $id, 'data' => $data); Events::trigger('after_news_update', $trigger_data); } return $return; }
/** * A simple update of the role. * * Additionally, this cleans things up when setting this role as the default * role for new users. * * @param integer $id The role id. * @param array $data Array of key/value pairs with which to update the db. * * @return boolean True on successful update, else false. */ public function update($id = null, $data = null) { // If this role is set to default, then set all others to NOT be default. if (isset($data['default']) && $data['default'] == 1) { $this->db->set('default', 0)->update($this->table_name); } return parent::update($id, $data); }
/** * 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; }