public function indexAction() { $id = (int) $this->params()->fromRoute('id', 0); $action = $this->params()->fromQuery('action', ''); if ($action == 'delete' && $id > 0) { $this->roleTable()->deleteRole($id); $this->flashMessenger()->addInfoMessage('Delete successful!'); return $this->redirect()->toRoute("role"); } $parentRole = new Role(); $edit = false; if ($id > 0) { $role = $this->roleTable()->getRole($id); if ($role->getParentId()) { $parentRole = $this->roleTable()->getRole($role->getParentId()); } $edit = true; } else { $role = new Role(); } $roles = $this->roleTable()->getChildren(); $helper = new RoleHelper(); $form = $helper->getForm(); if ($action == 'clone') { $edit = false; $id = 0; $role->setRoleId(0); } $form->bind($role); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $this->roleTable()->saveRole($role); $this->flashMessenger()->addSuccessMessage('Save successful!'); return $this->redirect()->toRoute("role"); } } return new ViewModel(array('id' => $id, 'roles' => $roles, 'form' => $form, 'isEdit' => $edit, 'parent' => $parentRole)); }
/** * {@inheritDoc} */ public function getUpdatedAt() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getUpdatedAt', array()); return parent::getUpdatedAt(); }
/** * {@inheritDoc} */ public function getPermissions() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getPermissions', array()); return parent::getPermissions(); }
/** * {@inheritDoc} */ public function setParent(\Application\Entity\Role $parent) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setParent', array($parent)); return parent::setParent($parent); }
/** * @param Role $role * @return Role */ public function saveRole(Role $role) { $id = $role->getRoleId(); $data = $role->getArrayCopy(); if ($id > 0) { $this->update($data, array('roleId' => $id)); } else { unset($data['roleId']); $this->insert($data); } if (!$role->getRoleId()) { $role->setRoleId($this->getLastInsertValue()); } return $role; }
/** * {@inheritDoc} */ public function getDescription() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getDescription', array()); return parent::getDescription(); }