/** * Get user model * * @return \Gc\User\Model */ public function getUser() { if ($this->getData('user') === null and $this->getUserId() != null) { $this->setData('user', User\Model::fromId($this->getUserId())); } return $this->getData('user'); }
/** * Test * * @return void */ public function testFromFakeId() { $this->assertFalse(Model::fromId(10000)); }
/** * Retrieve user who trigger the event * * @return boolean|\Gc\User\Model */ public function getUser() { if ($this->hasData('user') === false) { $this->setData('user', UserModel::fromId($this->getUserId())); } return $this->getData('user'); }
/** * Edit user * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $userId = $this->getRouteMatch()->getParam('id'); $userModel = User\Model::fromId($userId); if (empty($userModel)) { $this->flashMessenger()->addErrorMessage("Can't edit this user"); return $this->redirect()->toRoute('config/user'); } $form = new UserForm(); $form->setAttribute('action', $this->url()->fromRoute('config/user/edit', array('id' => $userId))); $form->loadValues($userModel); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost()->toArray(); if (!empty($post['password'])) { $form->passwordRequired(); $form->getInputFilter()->get('password_confirm')->getValidatorChain()->addValidator(new Identical($post['password'])); } $form->setData($post); if ($form->isValid()) { $userModel->addData($post); $userModel->setActive(empty($post['active']) ? false : $post['active']); if (!empty($post['password'])) { $userModel->setPassword($post['password']); } $userModel->save(); $this->flashMessenger()->addSuccessMessage('This user has been saved'); return $this->redirect()->toRoute('config/user/edit', array('id' => $userId)); } $this->flashMessenger()->addErrorMessage('User can not be saved'); } return array('form' => $form); }