summaryrefslogtreecommitdiffstats
path: root/application/modules/user/controllers/GroupController.php
diff options
context:
space:
mode:
Diffstat (limited to 'application/modules/user/controllers/GroupController.php')
-rw-r--r--application/modules/user/controllers/GroupController.php275
1 files changed, 273 insertions, 2 deletions
diff --git a/application/modules/user/controllers/GroupController.php b/application/modules/user/controllers/GroupController.php
index 52136af..7a21aa9 100644
--- a/application/modules/user/controllers/GroupController.php
+++ b/application/modules/user/controllers/GroupController.php
@@ -3,20 +3,291 @@
class User_GroupController extends Zend_Controller_Action
{
+ protected $groupMapper = null;
+
+ protected $groupGroupsMapper = null;
+
+ protected $membershipMapper = null;
+
+ protected $groupRequestMapper = null;
+
+ protected $personmapper = null;
+
+ protected $rolemapper = null;
+
+ protected $groupList = null;
+
+ protected $userIDsNamespace = null;
+
public function init()
{
if (Zend_Auth::getInstance()->hasIdentity()) {
-
+ $this->userIDsNamespace = Zend_Session::namespaceGet('userIDs');
+ $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');
+ return;
}
}
public function indexAction()
{
- // action body
+ $this->_helper->redirector('show', 'group');
}
+ public function addAction()
+ {
+ if (!isset($_POST["add"])){
+ $addForm = new user_Form_GroupAdd(array('grouplist' => $this->groupList));
+ } else {
+ $addForm = new user_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) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ 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) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+
+ }
+ $this->_helper->redirector('', 'group');
+ return;
+ }
+ }
+
+ $this->view->addForm = $addForm;
+ }
+
+ public function editAction()
+ {
+ $groupID = $this->_request->getParam('groupID');
+ if(!isset($groupID)) {
+ if(count($this->userIDsNamespace) > 0) {
+ $groupID = $this->userIDsNamespace['groupID'];
+ }
+ }
+ if(!isset($groupID)) {
+ $addForm = new user_Form_GroupAdd(array('grouplist' => $this->groupList));
+ $this->view->addForm = $addForm;
+ return;
+ }
+ if (!isset($_POST["save"])){
+ $group = $this->groupMapper->find($groupID);
+ $_POST['title'] = $group->getTitle();
+ $_POST['description'] = $group->getDescription();
+ $editForm = new user_Form_GroupEdit(array('groupID' => $groupID));
+ } else {
+ $editForm = new user_Form_GroupEdit(array('groupID' => $groupID), $_POST);
+ if ($editForm->isValid($_POST)) {
+ $group = new Application_Model_Group($_POST);
+ $group->setID($this->_request->getParam('groupID'));
+ try {
+ $this->groupMapper->save($group);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_redirect($_SERVER['HTTP_REFERER']);
+ return;
+ }
+ }
+
+ $this->view->editForm = $editForm;
+ }
+
+ public function showAction()
+ {
+ $groupID = $this->_request->getParam('groupID');
+ if(!isset($groupID)) {
+ if(count($this->userIDsNamespace) > 0) {
+ $groupID = $this->userIDsNamespace['groupID'];
+ }
+ }
+ if($groupID) {
+ $groupRequests = $this->groupRequestMapper->findBy('groupID', $groupID);
+ if(isset($groupRequests)) {
+ foreach($groupRequests as $groupRequest) {
+ $person = $this->personmapper->find($groupRequest['personID']);
+ $groupRequestList[] = array(
+ 'grouprequestID' => $groupRequest['grouprequestID'],
+ 'person' => $person
+ );
+ }
+ if(is_array($groupRequestList)) {
+ $this->view->groupRequestList = $groupRequestList;
+ }
+ $this->view->roleList = $this->rolemapper->findBy('groupID', $groupID);
+ }
+ $members = $this->membershipMapper->findBy('groupID', $groupID);
+ if(isset($members)) {
+ foreach($members as $member) {
+ $person = $this->personmapper->find($member['personID']);
+ $membersList[] = array(
+ 'membershipID' => $member['membershipID'],
+ 'person' => $person
+ );
+ }
+ if(is_array($membersList)) {
+ $this->view->membersList = $membersList;
+ }
+ }
+ $groupgroups = $this->groupGroupsMapper->findBy('groupID', $groupID);
+ if(is_object($groupgroups)) {
+ $parentGroup = $this->groupMapper->find($groupgroups->getParentID());
+ $this->view->$parentGroup = $parentGroup;
+ }
+ $group = $this->groupMapper->find($groupID);
+ $this->view->userIDsNamespace = $this->userIDsNamespace;
+ $this->view->group = $group;
+ $this->view->groupID = $groupID;
+ } else {
+ $this->_redirect('/user/');
+ return;
+ }
+ }
+
+ public function linkAction()
+ {
+ if (!isset($_POST["link"])){
+ $linkForm = new user_Form_GroupLink(array('grouplist' => $this->groupList));
+ } else {
+ $linkForm = new user_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) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_helper->redirector('', 'group');
+ return;
+ }
+ }
+
+ $this->view->linkForm = $linkForm;
+ }
+
+ public function deleteAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+ $groupID = $this->_request->getParam('groupID');
+ if(!isset($groupID)) {
+ if(count($this->userIDsNamespace) > 0) {
+ $groupID = $this->userIDsNamespace['groupID'];
+ }
+ }
+ if (isset($groupID)){
+ $group = $this->groupMapper->find($groupID);
+ try {
+ $this->groupMapper->delete($group);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ if(strpos($_SERVER['HTTP_REFERER'], '/user/group/show')) {
+ if(strpos($_SERVER['HTTP_REFERER'], '/groupID/')) {
+ $this->_redirect('/user/group/showall');
+ } else {
+ $this->_helper->redirector('changemembership', 'person');
+ }
+ } else {
+ $this->_helper->redirector('showall', 'group');
+ }
+ return;
+ } else {
+ $this->_redirect('/user/');
+ return;
+ }
+ }
+
+ public function grantpersonAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+ 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) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ 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) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_redirect("/user/group/show/groupID/" . $groupRequest->getGroupID());
+ }
+ }
+
+ public function revokepersonAction()
+ {
+ $this->_helper->viewRenderer->setNoRender();
+ $membershipID = $this->_request->getParam('membershipID');
+ if(isset($membershipID)) {
+ $membership = $this->membershipMapper->find($membershipID);
+ if(isset($membership)) {
+ try {
+ $this->membershipMapper->delete($membership);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_redirect("/user/group/edit/groupID/" . $membership->getGroupID());
+ }
+
+ } }
+
+ public function showallAction()
+ {
+ $this->view->userIDsNamespace = $this->userIDsNamespace;
+ $this->view->groupList = $this->groupList;
+ }
+
}