diff options
Diffstat (limited to 'application/modules/user/controllers/RoleController.php')
| -rw-r--r-- | application/modules/user/controllers/RoleController.php | 241 |
1 files changed, 233 insertions, 8 deletions
diff --git a/application/modules/user/controllers/RoleController.php b/application/modules/user/controllers/RoleController.php index d7abc62..da65507 100644 --- a/application/modules/user/controllers/RoleController.php +++ b/application/modules/user/controllers/RoleController.php @@ -2,17 +2,242 @@ class User_RoleController extends Zend_Controller_Action { + private $userIDsNamespace; - public function init() - { - /* Initialize action controller here */ - } + public function init() + { + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs'); + if($this->userIDsNamespace['groupID'] ==''){ + $pbsNotifier = new Pbs_Notifier(); + echo $pbsNotifier->notify('No groupID set','forbidden'); + } + $this->roleMapper = new Application_Model_RoleMapper(); + $this->rightMapper = new Application_Model_RightMapper(); + $this->rightRolesMapper = new Application_Model_RightRolesMapper(); + } else { + $this->_helper->redirector('login', 'auth'); + } + } - public function indexAction() - { - // action body - } + public function indexAction() + { + if(isset($this->userIDsNamespace['groupID'])) { + $roleList = $this->roleMapper->findBy('groupID', $this->userIDsNamespace['groupID']); + $this->view->groupID = $this->userIDsNamespace['groupID']; + $this->view->roleList = $roleList; + } else { + $this->_helper->redirector('groupselect', 'role'); + return; + } + } + + public function addAction() + { + if(isset($this->userIDsNamespace['groupID'])) { + if (!isset($_POST["add"])){ + $addForm = new user_Form_RoleAdd(array('rightlist' => $rightList)); + } else { + $addForm = new user_Form_RoleAdd(array('rightlist' => $rightList),$_POST); + if ($addForm->isValid($_POST)) { + + $_POST['groupID'] = $this->userIDsNamespace['groupID']; + $role = new Application_Model_Role($_POST); + try { + $this->roleMapper->save($role); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'role'); + return; + } + } + + $this->view->addForm = $addForm; + } else { + $this->_helper->redirector('groupselect', 'role'); + return; + } + } + + public function editAction() + { + $roleID = $this->_request->getParam('roleID'); + if(!isset($roleID)) { + $addForm = new user_Form_RoleAdd(); + $this->view->addForm = $addForm; + return; + } + if (!isset($_POST["save"])){ + $role = $this->roleMapper->find($roleID); + $_POST['title'] = $role->getTitle(); + $_POST['description'] = $role->getDescription(); + $_POST['groupID'] = $role->getGroupID(); + $editForm = new user_Form_RoleEdit(array('roleID' => $roleID)); + } else { + $editForm = new user_Form_RoleEdit(array('roleID' => $roleID), $_POST); + if ($editForm->isValid($_POST)) { + $role = new Application_Model_Role($_POST); + $role->setID($this->_request->getParam('roleID')); + try { + $this->roleMapper->save($role); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'role'); + return; + } + } + $this->view->editForm = $editForm; + } + + public function showAction() + { + $roleID = $this->_request->getParam('roleID'); + if($roleID) { + $rightroles = $this->rightRolesMapper->findBy('roleID', $roleID); + if(count($rightroles) > 0) { + foreach($rightroles as $rightrole) { + $right = $this->rightMapper->find($rightrole['rightID']); + $rightsList[] = $right; + } + if(is_array($rightsList)) { + $this->view->rightsList = $rightsList; + } + } + $this->view->role = $this->roleMapper->find($roleID); + $this->view->roleID = $roleID; + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function deleteAction() + { + $this->_helper->viewRenderer->setNoRender(); + $roleID = $this->_request->getParam('roleID'); + if (isset($roleID)){ + $role = $this->roleMapper->find($roleID); + try { + $this->roleMapper->delete($role); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_helper->redirector('', 'role'); + return; + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function linkrightAction() + { + $roleID = $this->_request->getParam('roleID'); + if(isset($roleID)) { + $rightroles = $this->rightRolesMapper->findBy('roleID', $roleID); + $rights = $this->rightMapper->fetchAll(); + if(count($rightroles) > 0) { + if(count($rights) > 0) { + foreach($rights as $right) { + foreach($rightroles as $rightrole) { + if($right->getID() == $rightrole['rightID']) { + $found = true; + break; + } + } + if(!$found) { + $rightlist[] = $right; + } + $found = false; + } + } + } else { + $rightlist = $rights; + } + if(count($rightlist) > 0) { + if (!isset($_POST["link"])){ + $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID)); + } else { + $linkForm = new user_Form_LinkRight(array('rightlist' => $rightlist, 'roleID' => $roleID), $_POST); + if ($linkForm->isValid($_POST)) { + $rightroles = new Application_Model_RightRoles(); + $rightroles->setRightID($_POST['rightID']); + $rightroles->setRoleID($roleID); + try { + $this->rightRolesMapper->save($rightroles); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_redirect('/user/role/show/roleID/' . $roleID); + return; + } + } + $this->view->linkForm = $linkForm; + } else { + $this->_redirect('/user/role/show/roleID/' . $roleID); + return; + } + } else { + $this->_helper->redirector('', 'role'); + return; + } + } + + public function unlinkrightAction() + { + $this->_helper-> viewRenderer-> setNoRender(); + $rightRolesID = $this->_request->getParam('rightrolesID'); + if(isset($rightRolesID)) { + $rightRolesID = explode('-',$rightRolesID); + $roleID = $rightRolesID[0]; + $rightID = $rightRolesID[1]; + if (isset($roleID) && isset($rightID)){ + $rightroles = new Application_Model_RightRoles(); + $rightroles->setRoleID($roleID); + $rightroles->setRightID($rightID); + try { + $this->rightRolesMapper->delete($rightroles); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "<br/>"; + echo "Message: " . $e->getMessage() . "<br/>"; + return; + } + $this->_redirect('/user/role/show/roleID/' . $roleID); + return; + } + } else { + $this->_helper->redirector('', 'role'); + return; + } + } } + + + + + + + + + + + + |
