From 84f8c7b61f61ff68e9568e01c23689d591dc4828 Mon Sep 17 00:00:00 2001
From: Björn Geiger
Date: Mon, 28 Mar 2011 12:56:10 +0200
Subject: Groupcontroller User Module
---
.../modules/dev/views/scripts/group/edit.phtml | 2 +-
.../modules/user/controllers/GroupController.php | 263 ++++++++++++++++++++-
application/modules/user/forms/GroupAdd.php | 65 +++++
application/modules/user/forms/GroupEdit.php | 68 ++++++
application/modules/user/forms/GroupLink.php | 55 +++++
.../modules/user/views/scripts/group/add.phtml | 4 +
.../modules/user/views/scripts/group/edit.phtml | 10 +
.../modules/user/views/scripts/group/index.phtml | 1 -
.../modules/user/views/scripts/group/link.phtml | 4 +
.../modules/user/views/scripts/group/show.phtml | 147 ++++++++++++
.../modules/user/views/scripts/group/showall.phtml | 79 +++++++
11 files changed, 694 insertions(+), 4 deletions(-)
create mode 100644 application/modules/user/forms/GroupAdd.php
create mode 100644 application/modules/user/forms/GroupEdit.php
create mode 100644 application/modules/user/forms/GroupLink.php
create mode 100644 application/modules/user/views/scripts/group/add.phtml
create mode 100644 application/modules/user/views/scripts/group/edit.phtml
delete mode 100644 application/modules/user/views/scripts/group/index.phtml
create mode 100644 application/modules/user/views/scripts/group/link.phtml
create mode 100644 application/modules/user/views/scripts/group/show.phtml
create mode 100644 application/modules/user/views/scripts/group/showall.phtml
(limited to 'application/modules')
diff --git a/application/modules/dev/views/scripts/group/edit.phtml b/application/modules/dev/views/scripts/group/edit.phtml
index dd3acbe..a0f9b32 100644
--- a/application/modules/dev/views/scripts/group/edit.phtml
+++ b/application/modules/dev/views/scripts/group/edit.phtml
@@ -1,6 +1,6 @@
addForm)) {
- $this->addForm->setAction('/etc/group/add');
+ $this->addForm->setAction('/dev/group/add');
echo $this->addForm;
}
else {
diff --git a/application/modules/user/controllers/GroupController.php b/application/modules/user/controllers/GroupController.php
index 52136af..3180ebd 100644
--- a/application/modules/user/controllers/GroupController.php
+++ b/application/modules/user/controllers/GroupController.php
@@ -3,20 +3,279 @@
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) . "
";
+ 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;
+ }
+
+ }
+ $this->_helper->redirector('', 'group');
+ return;
+ }
+ }
+
+ $this->view->addForm = $addForm;
+ }
+
+ public function editAction()
+ {
+ $groupID = $this->_request->getParam('groupID');
+ if(!isset($groupID)) {
+ $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) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ return;
+ }
+ $this->_helper->redirector('', 'group');
+ return;
+ }
+ }
+
+ $this->view->editForm = $editForm;
}
+ public function showAction()
+ {
+ $groupID = $this->_request->getParam('groupID');
+ if(!isset($groupID)) {
+ $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;
+ }
+ }
+
+ 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) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ 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)) {
+ $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) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ return;
+ }
+ if(strpos($_SERVER['HTTP_REFERER'], '/user/group/show')) {
+ if(strpos($_SERVER['HTTP_REFERER'], '/groupID/')) {
+ $this->_redirect('/user/group/show/groupID/' . $groupID);
+ } else {
+ $this->_helper->redirector('changemembership', 'person');
+ }
+ } else {
+ $this->_helper->redirector('showall', 'group');
+ }
+ 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) . "
";
+ 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;
+ }
+ $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) . "
";
+ echo "Message: " . $e->getMessage() . "
";
+ return;
+ }
+ $this->_redirect("/user/group/edit/groupID/" . $membership->getGroupID());
+ }
+
+ } }
+
+ public function showallAction()
+ {
+ $this->view->userIDsNamespace = $this->userIDsNamespace;
+ $this->view->groupList = $this->groupList;
+ }
+
}
diff --git a/application/modules/user/forms/GroupAdd.php b/application/modules/user/forms/GroupAdd.php
new file mode 100644
index 0000000..47855de
--- /dev/null
+++ b/application/modules/user/forms/GroupAdd.php
@@ -0,0 +1,65 @@
+grouplist = $grouplist;
+
+ }
+
+
+ public function init()
+ {
+ $this->setName("GroupAdd");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ ));
+
+ $this->addElement('text', 'description', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 140)),
+ ),
+ 'required' => false,
+ 'label' => 'Description:',
+ ));
+
+ $groupfield = $this->createElement('select','superordinatedGroupID');
+ $groupfield ->setLabel('superordinated Group:');
+
+ $groupfield->addMultiOption('-1', '---- none ----');
+
+ if(count($this->grouplist)>0){
+ foreach($this->grouplist as $group => $g){
+ $groupfield->addMultiOption($g->getID(), $g->getTitle());
+ }
+ }
+ $groupfield->setRegisterInArrayValidator(false);
+ $this->addElement($groupfield);
+
+ $this->addElement('submit', 'add', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Add',
+ ));
+
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/dev/group/"',
+ ));
+ }
+
+
+}
+
diff --git a/application/modules/user/forms/GroupEdit.php b/application/modules/user/forms/GroupEdit.php
new file mode 100644
index 0000000..0da0f61
--- /dev/null
+++ b/application/modules/user/forms/GroupEdit.php
@@ -0,0 +1,68 @@
+groupID = $groupID;
+
+ }
+
+ public function init()
+ {
+ $this->setName("GroupEdit");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ 'value' => $_POST['title'],
+ ));
+
+ $this->addElement('text', 'description', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 140)),
+ ),
+ 'required' => false,
+ 'label' => 'Description:',
+ 'value' => $_POST['description'],
+ ));
+
+ $this->addElement('submit', 'save', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Save',
+ ));
+
+ if(strpos($_SERVER['HTTP_REFERER'], '/user/group/show')) {
+ if(strpos($_SERVER['HTTP_REFERER'], '/groupID/')) {
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/group/show/groupID/' . $this->groupID . '"',
+ ));
+ } else {
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/group/show/"',
+ ));
+ }
+ } else {
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/group/showall"',
+ ));
+ }
+ }
+}
\ No newline at end of file
diff --git a/application/modules/user/forms/GroupLink.php b/application/modules/user/forms/GroupLink.php
new file mode 100644
index 0000000..d2aafcc
--- /dev/null
+++ b/application/modules/user/forms/GroupLink.php
@@ -0,0 +1,55 @@
+grouplist = $grouplist;
+
+ }
+
+ public function init()
+ {
+ $this->setName("GroupLink");
+ $this->setMethod('post');
+
+ $groupfield = $this->createElement('select','groupID');
+ $groupfield ->setLabel('Group:');
+
+ if(count($this->grouplist)>0){
+ foreach($this->grouplist as $group => $g){
+ $groupfield->addMultiOption($g->getID(), $g->getTitle());
+ }
+ }
+ $groupfield->setRegisterInArrayValidator(false);
+ $this->addElement($groupfield);
+
+ $groupfield1 = $this->createElement('select','superordinatedGroupID');
+ $groupfield1 ->setLabel('superordinated Group:');
+
+ if(count($this->grouplist)>0){
+ foreach($this->grouplist as $group => $g){
+ $groupfield1->addMultiOption($g->getID(), $g->getTitle());
+ }
+ }
+ $groupfield1->setRegisterInArrayValidator(false);
+ $this->addElement($groupfield1);
+
+ $this->addElement('submit', 'link', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Link',
+ ));
+
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/group/"',
+ ));
+ }
+
+
+}
+
diff --git a/application/modules/user/views/scripts/group/add.phtml b/application/modules/user/views/scripts/group/add.phtml
new file mode 100644
index 0000000..4f96cf0
--- /dev/null
+++ b/application/modules/user/views/scripts/group/add.phtml
@@ -0,0 +1,4 @@
+addForm->setAction($this->url());
+echo $this->addForm;
+?>
\ No newline at end of file
diff --git a/application/modules/user/views/scripts/group/edit.phtml b/application/modules/user/views/scripts/group/edit.phtml
new file mode 100644
index 0000000..d513dea
--- /dev/null
+++ b/application/modules/user/views/scripts/group/edit.phtml
@@ -0,0 +1,10 @@
+addForm)) {
+ $this->addForm->setAction('/user/group/add');
+ echo $this->addForm;
+}
+else {
+ $this->editForm->setAction($this->url());
+ echo $this->editForm;
+}
+?>
diff --git a/application/modules/user/views/scripts/group/index.phtml b/application/modules/user/views/scripts/group/index.phtml
deleted file mode 100644
index a1e5635..0000000
--- a/application/modules/user/views/scripts/group/index.phtml
+++ /dev/null
@@ -1 +0,0 @@
-
Title | +Description | +
---|---|
group->getTitle(); ?> | +group->getDescription(); ?> | +
Superordinated Group: | +parentGroup->getTitle(); ?> | +
Firstname | +Name | +city | +grant | +|
---|---|---|---|---|
getFirstname(); ?> | +getName(); ?> | +getEmail(); ?> | +getCity(); ?> | ++ + | +
Title | +Actions | +||
---|---|---|---|
getTitle(); ?> | + ![]() |
+ ![]() |
+ ![]() |
+