/**
  * Profile action method
  *
  * @return void
  */
 public function profile()
 {
     $this->prepareView('profile.phtml');
     $this->view->title = 'My Profile';
     $user = new Model\User();
     $user->getById($this->sess->user->id);
     $this->view->form = new Form\Profile($this->application->config()['forms']['App\\Form\\Profile']);
     $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray());
     if ($this->request->isPost()) {
         $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost());
         if ($this->view->form->isValid()) {
             $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
             $user = new Model\User();
             $user->update($this->view->form->getFields(), $this->sess);
             $this->view->id = $user->id;
             $this->sess->setRequestValue('saved', true);
             $this->redirect('/profile');
         }
     }
     $this->send();
 }
 /**
  * Edit action method
  *
  * @return void
  */
 public function edit($id)
 {
     $user = new Model\User();
     $user->getById($id);
     if (!isset($user->id)) {
         $this->redirect('/users');
     }
     if ($this->services['acl']->isAllowed($this->sess->user->role, 'users-of-role-' . $user->role_id, 'edit')) {
         $this->prepareView('users/edit.phtml');
         $this->view->title = 'Edit User';
         $this->view->username = $user->username;
         $role = new Model\Role();
         $roles = $role->getAll();
         $roleValues = [];
         foreach ($roles as $r) {
             $roleValues[$r->id] = $r->name;
         }
         $fields = $this->application->config()['forms']['App\\Form\\User'];
         $fields[1]['username']['attributes']['onkeyup'] = 'pop.changeTitle(this.value);';
         $fields[1]['password1']['required'] = false;
         $fields[1]['password2']['required'] = false;
         $fields[0]['clear_logins']['value'][1] = $user->total_logins . ' Login' . ($user->total_logins == 1 ? '' : 's');
         $fields[0]['role_id']['type'] = 'select';
         $fields[0]['role_id']['label'] = 'Role';
         $fields[0]['role_id']['value'] = $roleValues;
         $fields[0]['role_id']['marked'] = $user->role_id;
         $this->view->form = new Form\User($fields);
         $this->view->form->addFilter('strip_tags', null, 'textarea')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($user->toArray());
         if ($this->request->isPost()) {
             $this->view->form->addFilter('strip_tags', null, 'textarea')->setFieldValues($this->request->getPost());
             if ($this->view->form->isValid()) {
                 $this->view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8'])->filter();
                 $user = new Model\User();
                 $user->update($this->view->form->getFields(), $this->application->config()['application_title'], $this->sess);
                 $this->view->id = $user->id;
                 $this->sess->setRequestValue('saved', true);
                 $this->redirect('/users/edit/' . $user->id);
             }
         }
         $this->send();
     } else {
         $this->redirect('/users');
     }
 }