Implement user settings
This commit is contained in:
@@ -72,6 +72,16 @@ $config['auth/settings'] = array(
|
|||||||
'label' => _('New password'),
|
'label' => _('New password'),
|
||||||
'rules' => 'min_length[6]|matches[new_password_confirm]',
|
'rules' => 'min_length[6]|matches[new_password_confirm]',
|
||||||
),
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'job_check_interval',
|
||||||
|
'label' => _('Job checking interval'),
|
||||||
|
'rules' => 'greater_than[4]',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'field' => 'projects_sort_recently',
|
||||||
|
'label' => _('Sort projects by last access'),
|
||||||
|
'rules' => 'integer',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -128,8 +128,17 @@ class Auth extends CI_Controller {
|
|||||||
'phone' => $this->input->post('phone')
|
'phone' => $this->input->post('phone')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// update the users settings
|
||||||
|
$settings = array(
|
||||||
|
'projects_sort_recently' => $this->input->post('projects_sort_recently'),
|
||||||
|
'jobs_check_interval' => $this->input->post('jobs_check_interval'),
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->user->updateSettings($settings, $user['id']);
|
||||||
|
$this->session->unset_userdata('settings'); // clear saved settings
|
||||||
|
|
||||||
if ($this->user->update($user['id'], $data)) {
|
if ($this->user->update($user['id'], $data)) {
|
||||||
$this->messages->add(_("Settings saved successfully"), 'success');
|
$this->messages->add(_("Changes saved successfully"), 'success');
|
||||||
redirect('auth/settings', 303);
|
redirect('auth/settings', 303);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -273,6 +273,22 @@ class Access {
|
|||||||
return $this->cache['profile'];
|
return $this->cache['profile'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the settings of the current user.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function settings($key) {
|
||||||
|
if ((boolean) $this->CI->session->userdata('settings')) {
|
||||||
|
$settings = $this->CI->session->userdata('settings');
|
||||||
|
} else {
|
||||||
|
$settings = $this->CI->user->getSettings($this->CI->session->userdata('user_id'));
|
||||||
|
$this->CI->session->set_userdata('settings', $settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
return isset($settings[$key]) ? $settings[$key] : false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* End of file Access.php */
|
/* End of file Access.php */
|
||||||
|
|||||||
@@ -454,6 +454,17 @@ class User extends CI_Model {
|
|||||||
->where('id', $user->group_id)->get('groups')->row_array();
|
->where('id', $user->group_id)->get('groups')->row_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a users settings.
|
||||||
|
*
|
||||||
|
* @param string $userId
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSettings($userId) {
|
||||||
|
$query = $this->db->get_where('users_settings', array('user_id' => $userId));
|
||||||
|
return $query->row_array();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a user.
|
* Updates a user.
|
||||||
*
|
*
|
||||||
@@ -480,6 +491,21 @@ class User extends CI_Model {
|
|||||||
return $this->db->affected_rows() > 0;
|
return $this->db->affected_rows() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function updateSettings($data, $userId) {
|
||||||
|
foreach ($data as $key => $value) {
|
||||||
|
$data[$key] = $this->db->escape($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = $this->db->query("REPLACE INTO `users_settings` (`user_id`, "
|
||||||
|
. implode(", ", array_keys($data)) . ") VALUES ('" . $userId . "', "
|
||||||
|
. implode(", ", array_values($data)) . ")");
|
||||||
|
|
||||||
|
return $this->db->affected_rows() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a specified user.
|
* Deletes a specified user.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -57,10 +57,18 @@
|
|||||||
<div id="settings" class="tab_content">
|
<div id="settings" class="tab_content">
|
||||||
<ul>
|
<ul>
|
||||||
<li>
|
<li>
|
||||||
<input type="checkbox" id="projects_sortrecently" name="projects_sortrecently" value="1" class="checkbox"/>
|
<input type="checkbox" id="projects_sort_recently" name="projects_sort_recently" value="1" class="checkbox" <?=set_checkbox('projects_sort_recently', 1, (boolean) $this->access->settings('projects_sort_recently'));?> />
|
||||||
<label for="projects_sortrecently"><?=_('Sort projects by date of the last access');?></label><br />
|
<?=form_label(_('Sort projects by last access'), 'projects_sort_recently');?><br />
|
||||||
<label class="note"><?=_('If the projects are sorted by the data of the last access, the rarely used projects "slip" to the end of the list.');?></label>
|
<label class="note"><?=_('If the projects are sorted by the data of the last access, the rarely used projects "slip" to the end of the list.');?></label>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<?=form_label(_('Job checking interval'), 'jobs_check_interval');?><br />
|
||||||
|
<label class="note"><?=_('Check for new jobs every x seconds.');?></label>
|
||||||
|
<div>
|
||||||
|
<input type="text" name="jobs_check_interval" id="jobs_check_interval" class="text" value="<?=set_value('jobs_check_interval', $this->access->settings('jobs_check_interval'));?>" />
|
||||||
|
<?=form_error('jobs_check_interval');?>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div id="password" class="tab_content">
|
<div id="password" class="tab_content">
|
||||||
|
|||||||
Reference in New Issue
Block a user