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/user/controllers/GroupController.php | 263 ++++++++++++++++++++-
1 file changed, 261 insertions(+), 2 deletions(-)
(limited to 'application/modules/user/controllers/GroupController.php')
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;
+ }
+
}
--
cgit v1.2.3-55-g7522
From 49ebfec064bb6d7a732466fa2071778665beb184 Mon Sep 17 00:00:00 2001
From: Björn Geiger
Date: Mon, 28 Mar 2011 14:38:51 +0200
Subject: Einführung von Vererbung von Rollen
---
application/models/RightCategoryMapper.php | 6 ++-
application/models/Role.php | 60 +++++++++++++---------
application/models/RoleMapper.php | 6 +--
.../modules/dev/controllers/RoleController.php | 1 +
application/modules/dev/forms/RoleAdd.php | 4 ++
application/modules/dev/forms/RoleEdit.php | 19 +++++--
.../modules/dev/views/scripts/role/show.phtml | 2 +
.../modules/user/controllers/GroupController.php | 12 ++++-
.../modules/user/controllers/RoleController.php | 8 ++-
application/modules/user/forms/RoleAdd.php | 4 ++
application/modules/user/forms/RoleEdit.php | 11 ++++
.../modules/user/views/scripts/role/show.phtml | 2 +
pbs-newdata.sql | 8 +--
pbs.sql | 5 +-
14 files changed, 106 insertions(+), 42 deletions(-)
(limited to 'application/modules/user/controllers/GroupController.php')
diff --git a/application/models/RightCategoryMapper.php b/application/models/RightCategoryMapper.php
index e0e324d..1a3d093 100644
--- a/application/models/RightCategoryMapper.php
+++ b/application/models/RightCategoryMapper.php
@@ -93,7 +93,11 @@ class Application_Model_RightCategoryMapper
return $entries;
}
-
+ public function compare(Application_Model_RightCategory $v1,Application_Model_RightCategory $v2){
+ $vv1 = $v1->toArray();
+ $vv2 = $v2->toArray();
+ return array_diff($vv1,$vv2);
+ }
}
diff --git a/application/models/Role.php b/application/models/Role.php
index 28f0af1..49ed377 100644
--- a/application/models/Role.php
+++ b/application/models/Role.php
@@ -6,6 +6,7 @@ class Application_Model_Role
protected $_groupID;
protected $_title;
protected $_description;
+ protected $_inheritance;
public function __construct(array $options = null)
{
@@ -81,39 +82,48 @@ class Application_Model_Role
$this->_description = $_description;
return $this;
}
- /**
- * Returns current data as associative array using ReflectionClass
- *
- * @return array Returns associative array containing model data
+ public function getInheritance()
+ {
+ return $this->_inheritance;
+ }
+ public function setInheritance($_inheritance)
+ {
+ $this->_inheritance = $_inheritance;
+ return $this;
+ }
+ /**
+ * Returns current data as associative array using ReflectionClass
+ *
+ * @return array Returns associative array containing model data
* If "get"-method not available (our primary keys) the function getID() is called
- */
- public function toArray()
- {
- $reflectionClass = new ReflectionClass($this);
- $properties = $reflectionClass->getProperties();
- $result = array();
- foreach ($properties as $property) {
- $key = $property->name;
- if (substr($key, 0, 1) != '_' && $this->$key !== null) {
- $method = 'get' . ucfirst($key);
- if ($reflectionClass->hasMethod($method)) {
- $result[$key] = $this->$method();
- } else {
- $result[$key] = $this->$key;
- }
- }
+ */
+ public function toArray()
+ {
+ $reflectionClass = new ReflectionClass($this);
+ $properties = $reflectionClass->getProperties();
+ $result = array();
+ foreach ($properties as $property) {
+ $key = $property->name;
+ if (substr($key, 0, 1) != '_' && $this->$key !== null) {
+ $method = 'get' . ucfirst($key);
+ if ($reflectionClass->hasMethod($method)) {
+ $result[$key] = $this->$method();
+ } else {
+ $result[$key] = $this->$key;
+ }
+ }
elseif(substr($key, 0, 1) == '_' && $this->$key !== null) {
$key = substr($key, 1);
- $method = 'get' . ucfirst($key);
+ $method = 'get' . ucfirst($key);
if ($reflectionClass->hasMethod($method)) {
$result[$key] = $this->$method();
}else{
$result[$key] = $this->getID();
}
-
+
}
- }
- return $result;
- }
+ }
+ return $result;
+ }
}
diff --git a/application/models/RoleMapper.php b/application/models/RoleMapper.php
index 561a7d4..4001e3e 100644
--- a/application/models/RoleMapper.php
+++ b/application/models/RoleMapper.php
@@ -47,7 +47,7 @@ class Application_Model_RoleMapper
public function save(Application_Model_Role $role)
{
- $data = array('roleID'=> $role->getID() ,'groupID'=> $role->getGroupID() ,'title'=> $role->getTitle() ,'description'=> $role->getDescription() );
+ $data = array('roleID'=> $role->getID() ,'groupID'=> $role->getGroupID() ,'title'=> $role->getTitle() ,'description'=> $role->getDescription(), 'inheritance' => $role->getInheritance() );
if (null === ($id = $role->getID()) ) {
unset($data['roleID']);
@@ -75,7 +75,7 @@ class Application_Model_RoleMapper
$row = $result->current();
$role = new Application_Model_Role();
- $role->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description);
+ $role->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description)->setInheritance($row->inheritance);
return $role;
}
@@ -86,7 +86,7 @@ class Application_Model_RoleMapper
foreach ($resultSet as $row) {
$entry = new Application_Model_Role();
- $entry->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description);
+ $entry->setID($row->roleID)->setGroupID($row->groupID)->setTitle($row->title)->setDescription($row->description)->setInheritance($row->inheritance);
$entries[] = $entry;
}
diff --git a/application/modules/dev/controllers/RoleController.php b/application/modules/dev/controllers/RoleController.php
index 709d623..65989b6 100644
--- a/application/modules/dev/controllers/RoleController.php
+++ b/application/modules/dev/controllers/RoleController.php
@@ -75,6 +75,7 @@ class dev_RoleController extends Zend_Controller_Action
$_POST['title'] = $role->getTitle();
$_POST['description'] = $role->getDescription();
$_POST['groupID'] = $role->getGroupID();
+ $_POST['inheritance'] = $role->getInheritance();
$editForm = new dev_Form_RoleEdit();
} else {
$editForm = new dev_Form_RoleEdit($_POST);
diff --git a/application/modules/dev/forms/RoleAdd.php b/application/modules/dev/forms/RoleAdd.php
index d773b17..7aae426 100644
--- a/application/modules/dev/forms/RoleAdd.php
+++ b/application/modules/dev/forms/RoleAdd.php
@@ -31,6 +31,10 @@ class dev_Form_RoleAdd extends Zend_Form
'label' => 'Description:',
));
+ $this->addElement('checkbox', 'inheritance', array(
+ 'label' => 'Inheritance:',
+ ));
+
$this->addElement('submit', 'add', array(
'required' => false,
'ignore' => true,
diff --git a/application/modules/dev/forms/RoleEdit.php b/application/modules/dev/forms/RoleEdit.php
index 2c79050..c0617b7 100644
--- a/application/modules/dev/forms/RoleEdit.php
+++ b/application/modules/dev/forms/RoleEdit.php
@@ -3,9 +3,9 @@
class dev_Form_RoleEdit extends Zend_Form
{
- public function init()
- {
- $this->setName("RoleEdit");
+ public function init()
+ {
+ $this->setName("RoleEdit");
$this->setMethod('post');
$this->addElement('text', 'title', array(
@@ -28,6 +28,17 @@ class dev_Form_RoleEdit extends Zend_Form
'value' => $_POST['description'],
));
+ if($_POST['inheritance'] == 1) {
+ $this->addElement('checkbox', 'inheritance', array(
+ 'label' => 'Inheritance:',
+ 'checked' => 'checked',
+ ));
+ } else {
+ $this->addElement('checkbox', 'inheritance', array(
+ 'label' => 'Inheritance:',
+ ));
+ }
+
$this->addElement('hidden', 'groupID', array(
'value' => $_POST['groupID'],
));
@@ -44,7 +55,7 @@ class dev_Form_RoleEdit extends Zend_Form
'label' => 'Cancel',
'onclick' => 'location.href="/dev/role/"',
));
- }
+ }
}
diff --git a/application/modules/dev/views/scripts/role/show.phtml b/application/modules/dev/views/scripts/role/show.phtml
index 93f2782..38e6023 100644
--- a/application/modules/dev/views/scripts/role/show.phtml
+++ b/application/modules/dev/views/scripts/role/show.phtml
@@ -13,10 +13,12 @@ if($this->roleID) {