/** * Get User Role * * @param boolean $forceReload Force reload * * @return \Gc\User\Role\Model */ public function getRole($forceReload = false) { $role = $this->getData('role'); if (empty($role) or !empty($forceReload)) { $role = Role\Model::fromId($this->getUserAclRoleId()); $this->setData('role', $role); } return $this->getData('role'); }
/** * Test * * @return void */ public function testFromFakeId() { $this->assertFalse(Model::fromId(42)); }
/** * Edit role * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $roleId = $this->getRouteMatch()->getParam('id'); $roleModel = Role\Model::fromId($roleId); if (empty($roleModel) or $roleModel->getName() === Role\Model::PROTECTED_NAME) { $this->flashMessenger()->addErrorMessage("Can't edit this role"); return $this->redirect()->toRoute('config/user/role'); } $form = new RoleForm(); $form->initPermissions($roleModel->getUserPermissions()); $form->setAttribute('action', $this->url()->fromRoute('config/user/role/edit', array('id' => $roleId))); $form->loadValues($roleModel); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost()->toArray(); $form->setData($post); if ($form->isValid()) { $roleModel->addData($form->getInputFilter()->getValues()); $roleModel->save(); $this->flashMessenger()->addSuccessMessage('Role saved!'); return $this->redirect()->toRoute('config/user/role/edit', array('id' => $roleId)); } $this->flashMessenger()->addErrorMessage('Role can not saved!'); $this->useFlashMessenger(); } return array('form' => $form); }