public function account()
{
# @user = User.current
# @pref = @user.pref
if ($this->request->data) {
# @user.attributes = params[:user]
$this->request->data['User']['mail_notification'] = $this->request->data['User']['notification_option'] == 'all' ? 1 : 0;
# @user.pref.attributes = params[:pref]
$this->request->data['UserPreference']['pref']['no_self_notified'] = $this->request->data['UserPreference']['pref']['no_self_notified'] == '1';
$this->request->data['User']['id'] = $this->current_user['id'];
if ($this->User->save($this->request->data)) {
$this->request->data['UserPreference']['user_id'] = $this->User->id;
if (isset($this->current_user['UserPreference']['id'])) {
$this->request->data['UserPreference']['id'] = $this->current_user['UserPreference']['id'];
}
$this->User->UserPreference->save($this->request->data);
$notified_project_ids = array();
if ($this->request->data['User']['notification_option'] === 'selected') {
$notified_project_ids = array_filter($this->request->data['User']['notified_project_ids']);
}
$this->User->set_notified_project_ids($notified_project_ids, $this->current_user['id']);
# set_language_if_valid @user.language
$this->Session->setFlash(__('Successful update.'), 'default', array('class' => 'flash flash_notice'));
$this->redirect('account');
# return
}
} else {
$this->request->data = $this->User->find('first', array('conditions' => array('User.id' => $this->current_user['id'])));
}
$notification_options = array();
$notification_options['all'] = __("\"For any event on all my projects\"");
if (!empty($this->current_user['memberships'])) {
$notification_options['selected'] = __("\"For any event on the selected projects only...\"");
}
$notification_options['none'] = __("\"Only for things I watch or I'm involved in\"");
$project_ids = $this->User->notified_projects_ids($this->current_user['id']);
$this->request->data['User']['notified_project_ids'] = $project_ids;
$notification_option = empty($project_ids) ? 'none' : 'selected';
if ($this->current_user['mail_notification']) {
$notification_option = 'all';
}
$this->set('notification_options', $notification_options);
$this->set('notification_option', $notification_option);
}