From 7be4355001156faed62c71492234cba2c5bf96b4 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Thu, 10 Mar 2011 22:10:05 +0100 Subject: Benutzervewaltung, Gruppenverwaltung, Membershipverwaltung und noch leerer RoleController --- application/controllers/GroupController.php | 238 ++++++++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100644 application/controllers/GroupController.php (limited to 'application/controllers/GroupController.php') diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php new file mode 100644 index 0000000..1de9207 --- /dev/null +++ b/application/controllers/GroupController.php @@ -0,0 +1,238 @@ +groupMapper = new Application_Model_GroupMapper(); + $this->groupGroupsMapper = new Application_Model_GroupGroupsMapper(); + $this->membershipMapper = new Application_Model_MembershipMapper(); + $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); + $this->personmapper = new Application_Model_PersonMapper(); + $this->rolemapper = new Application_Model_RoleMapper(); + $this->groupList = $this->groupMapper->fetchAll(); + } + + public function indexAction() + { + $this->view->groupList = $this->groupList; + } + + public function addAction() + { + if (!isset($_POST["add"])){ + $addForm = new Application_Form_GroupAdd(array('grouplist' => $this->groupList)); + } else { + $addForm = new Application_Form_GroupAdd(array('grouplist' => $this->groupList),$_POST); + + if ($addForm->isValid($_POST)) { + $group = new Application_Model_Group($_POST); + try { + $this->groupMapper->save($group); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + if($_POST['superordinatedGroupID'] != -1) { + $lastID = $this->groupMapper->getDbTable()->getDefaultAdapter()->lastInsertId(); + $groupgroups = new Application_Model_GroupGroups(); + $groupgroups->setParentID($_POST['superordinatedGroupID']); + $groupgroups->setGroupID($lastID); + try { + $this->groupGroupsMapper->save($groupgroups); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + + } + echo "Group successfully added.
"; + } + } + + $this->view->addForm = $addForm; + } + + public function editAction() + { + if(!isset($_POST['groupID'])) { + $addForm = new Application_Form_GroupAdd(array('grouplist' => $this->groupList)); + $this->view->addForm = $addForm; + return; + } + if (!isset($_POST["save"])){ + $group = $this->groupMapper->find($_POST['groupID']); + $_POST['title'] = $group->getTitle(); + $_POST['description'] = $group->getDescription(); + $editForm = new Application_Form_GroupEdit(); + } else { + $editForm = new Application_Form_GroupEdit($_POST); + if ($editForm->isValid($_POST)) { + $group = new Application_Model_Group($_POST); + try { + $this->groupMapper->save($group); + } catch(Zend_Exception $e) + { + echo "Email Address already existing."; + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + echo "Successfully saved.
"; + } + } + + $this->view->editForm = $editForm; + } + + public function showAction() + { + if($_POST['groupID']) { + $groupRequests = $this->groupRequestMapper->findBy('groupID', $_POST['groupID']); + if(isset($groupRequests)) { + foreach($groupRequests as $groupRequest) { + $person = $this->personmapper->find($groupRequest['personID']); + $groupRequestList[] = array( + 'grouprequestID' => $groupRequest['grouprequestID'], + 'person' => $person + ); + } + $this->view->groupRequestList = $groupRequestList; + $this->view->roleList = $this->rolemapper->findBy('groupID', $_POST['groupID']); + } + $members = $this->membershipMapper->findBy('groupID', $_POST['groupID']); + if(isset($members)) { + foreach($members as $member) { + $person = $this->personmapper->find($member['personID']); + $membersList[] = array( + 'membershipID' => $member['membershipID'], + 'person' => $person + ); + } + $this->view->memberslist = $membersList; + } + $groupgroups = $this->groupGroupsMapper->findBy('groupID', $_POST['groupID']); + if(is_object($groupgroups)) { + $parentGroup = $this->groupMapper->find($groupgroups->getParentID()); + $this->view->$parentGroup = $parentGroup; + } + $group = $this->groupMapper->find($_POST['groupID']); + $this->view->group = $group; + } + } + + public function linkAction() + { + if (!isset($_POST["link"])){ + $linkForm = new Application_Form_GroupLink(array('grouplist' => $this->groupList)); + } else { + $linkForm = new Application_Form_GroupLink(array('grouplist' => $this->groupList),$_POST); + + if ($linkForm->isValid($_POST)) { + $groupgroups = new Application_Model_GroupGroups(); + $groupgroups->setParentID($_POST['superordinatedGroupID']); + $groupgroups->setGroupID($_POST['groupID']); + try { + $this->groupGroupsMapper->save($groupgroups); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + echo "Groups successfully linked.
"; + } + } + + $this->view->linkForm = $linkForm; + } + + public function deleteAction() + { + if (isset($_POST["groupID"])){ + $group = $this->groupMapper->find($_POST["groupID"]); + try { + $this->groupMapper->delete($group); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + echo "Group successfully deleted.
"; + } + } + + public function grantpersonAction() + { + if(isset($_POST['grouprequestID']) && isset($_POST['roleID'])) { + $groupRequest = $this->groupRequestMapper->find($_POST['grouprequestID']); + try { + $this->groupRequestMapper->delete($groupRequest); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + $membership = new Application_Model_Membership(); + $membership->setGroupID($groupRequest->getGroupID()); + $membership->setPersonID($groupRequest->getPersonID()); + $membership->setRoleID($_POST['roleID']); + try { + $this->membershipMapper->save($membership); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + echo "Chosen Person has been successfully added to the chosen group.
"; + } + } + + public function revokepersonAction() + { + if(isset($_POST['membershipID'])) { + $membership = $this->membershipMapper->find($_POST['membershipID']); + if(isset($membership)) { + try { + $this->membershipMapper->delete($membership); + } catch(Zend_Exception $e) + { + echo "Caught exception: " . get_class($e) . "
"; + echo "Message: " . $e->getMessage() . "
"; + return; + } + echo "Chosen Person has been successfully removed from the chosen group.
"; + } + + } + } +} + + + + + + + + + + + + + + -- cgit v1.2.3-55-g7522 From fdd473d1a97f2c54243a84b09bf4245e3e4ba8b2 Mon Sep 17 00:00:00 2001 From: Björn Geiger Date: Thu, 10 Mar 2011 22:15:12 +0100 Subject: so geändert, dass nur im eingeloggten Zustand verfügbar --- application/controllers/GroupController.php | 18 ++++--- application/controllers/RoleController.php | 82 +++++++++++++++-------------- 2 files changed, 54 insertions(+), 46 deletions(-) (limited to 'application/controllers/GroupController.php') diff --git a/application/controllers/GroupController.php b/application/controllers/GroupController.php index 1de9207..fbc7943 100644 --- a/application/controllers/GroupController.php +++ b/application/controllers/GroupController.php @@ -12,13 +12,17 @@ class GroupController extends Zend_Controller_Action public function init() { - $this->groupMapper = new Application_Model_GroupMapper(); - $this->groupGroupsMapper = new Application_Model_GroupGroupsMapper(); - $this->membershipMapper = new Application_Model_MembershipMapper(); - $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); - $this->personmapper = new Application_Model_PersonMapper(); - $this->rolemapper = new Application_Model_RoleMapper(); - $this->groupList = $this->groupMapper->fetchAll(); + if (Zend_Auth::getInstance()->hasIdentity()) { + $this->groupMapper = new Application_Model_GroupMapper(); + $this->groupGroupsMapper = new Application_Model_GroupGroupsMapper(); + $this->membershipMapper = new Application_Model_MembershipMapper(); + $this->groupRequestMapper = new Application_Model_GroupRequestMapper(); + $this->personmapper = new Application_Model_PersonMapper(); + $this->rolemapper = new Application_Model_RoleMapper(); + $this->groupList = $this->groupMapper->fetchAll(); + } else { + $this->_helper->redirector('login', 'auth'); + } } public function indexAction() diff --git a/application/controllers/RoleController.php b/application/controllers/RoleController.php index f5e436b..7a6c304 100644 --- a/application/controllers/RoleController.php +++ b/application/controllers/RoleController.php @@ -3,45 +3,49 @@ class RoleController extends Zend_Controller_Action { - public function init() - { - - } - - public function indexAction() - { - - } - - public function addAction() - { - - } - - public function editAction() - { - - } - - public function showAction() - { - - } - - public function deleteAction() - { - - } - - public function linkrightAction() - { - // action body - } - - public function unlinkrightAction() - { - // action body - } + public function init() + { + if (Zend_Auth::getInstance()->hasIdentity()) { + + } else { + $this->_helper->redirector('login', 'auth'); + } + } + + public function indexAction() + { + + } + + public function addAction() + { + + } + + public function editAction() + { + + } + + public function showAction() + { + + } + + public function deleteAction() + { + + } + + public function linkrightAction() + { + // action body + } + + public function unlinkrightAction() + { + // action body + } } -- cgit v1.2.3-55-g7522