From 9a9129f1b59c0ead5cc530cfa367f9d121867b7f Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Thu, 31 Mar 2011 19:40:08 +0200 Subject: Checkboxen für Rechte beim erstellen einer Rolle --- .../modules/user/controllers/RoleController.php | 34 +++++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'application/modules/user/controllers/RoleController.php') diff --git a/application/modules/user/controllers/RoleController.php b/application/modules/user/controllers/RoleController.php index d8ed9e6..6246c9d 100644 --- a/application/modules/user/controllers/RoleController.php +++ b/application/modules/user/controllers/RoleController.php @@ -35,23 +35,49 @@ class User_RoleController extends Zend_Controller_Action public function addAction() { if(isset($this->userIDsNamespace['groupID'])) { + $roleID = $this->userIDsNamespace['roleID']; + $rights = $this->rightMapper->fetchAll(); + if(count($rights) > 0) { + $rightCategoryMapper = new Application_Model_RightCategoryMapper(); + foreach($rights as $right) { + $rightCategory = $rightCategoryMapper->find($right->getRightcategoryID()); + $rightlist[$rightCategory->getTitle()][$right->getID()] = $right->getTitle(); + } + } if (!isset($_POST["add"])){ - $addForm = new user_Form_RoleAdd(array('rightlist' => $rightList)); + $addForm = new user_Form_RoleAdd(array('rightlist' => $rightlist)); } else { - $addForm = new user_Form_RoleAdd(array('rightlist' => $rightList),$_POST); + $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); + $db = Zend_Db_Table::getDefaultAdapter(); + $insertedRoleID = $db->lastInsertId(); } catch(Zend_Exception $e) { echo "Caught exception: " . get_class($e) . "
"; echo "Message: " . $e->getMessage() . "
"; return; } - $this->_helper->redirector('', 'role'); - return; + foreach($_POST['rights'] as $rightID => $bool) { + if($bool == 1) { + $rightrole = new Application_Model_RightRoles(); + $rightrole->setRightID($rightID); + $rightrole->setRoleID($insertedRoleID); + try { + $this->rightRolesMapper->save($rightrole); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + } + } + //$this->_helper->redirector('', 'role'); + //return; } } -- cgit v1.2.3-55-g7522