/** * Shows a form to create or edit a new user. */ public function treatAction() { $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuUser'), array('action' => 'index'))->add($this->getTranslator()->trans('editUser'), array('action' => 'treat')); $userMapper = new UserMapper(); if ($this->getRequest()->isPost()) { $userData = $this->getRequest()->getPost('user'); if (!empty($userData['password'])) { $userData['password'] = (new PasswordService())->hash($userData['password']); } $user = $userMapper->loadFromArray($userData); if (!empty($userData['groups'])) { foreach ($userData['groups'] as $groupId) { $group = new GroupModel(); $group->setId($groupId); $user->addGroup($group); } } $date = new \Ilch\Date(); $user->setDateCreated($date); $userId = $userMapper->save($user); if (!empty($userId) && empty($userData['id'])) { $this->addMessage('newUserMsg'); } } if (empty($userId)) { $userId = $this->getRequest()->getParam('id'); } if ($userMapper->userWithIdExists($userId)) { $user = $userMapper->getUserById($userId); } else { $user = new UserModel(); } $groupMapper = new GroupMapper(); $this->getView()->set('user', $user); $this->getView()->set('groupList', $groupMapper->getGroupList()); }