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();
$userIDsNamespace = Zend_Session::namespaceGet('userIDs');
$this->membership = new Application_Model_Membership();
$this->membershipMapper->find($userIDsNamespace['membershipID'],$this->membership);
} else {
$this->_helper->redirector('login', 'auth');
return;
}
}
public function indexAction()
{
// ACL show overview
if(!Pbs_Acl::checkRight('gso'))
$this->_redirect('/user');
$this->view->groupList = $this->groupList;
// Search
$search = $this->_request->getParam('search');
$mySearch = new Pbs_Search();
$mySearch->setSearchTerm($search);
$mySearch->setModule('group');
if($search != ''){
$this->view->search = $mySearch->getSearchTerm();
$this->view->groupList = $mySearch->search($this->view->groupList);
}
$this->view->searchform = $mySearch->searchForm();
// Pagination
$pagination = new Pbs_Pagination();
$pagination->setPerPage(5);
$pagination->setElement($this->view->groupList);
$pagination->setRequestPage($this->_request->getParam('page'));
$pagination->setPageUrl('/user/group/index'.((isset($this->view->search))?'/search/'.$this->view->search:''));
$this->view->groupList = $pagination->getElements();
$this->view->pagination = $pagination->pagination($pageurl);
$this->view->page = $pagination->getRequestPage();
$this->view->userIDsNamespace = $this->userIDsNamespace;
}
public function searchAction(){
$this->_redirect('/user/group/index/search/'.($_GET['search']));
}
public function addAction()
{
// ACL create new group
if(!Pbs_Acl::checkRight('gc'))
$this->_redirect('/user');
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;
}
$groupID = $this->groupMapper->getDbTable()->getDefaultAdapter()->lastInsertId();
$membership = $this->membershipMapper->find($this->userIDsNamespace['membershipID']);
$role = $this->rolemapper->find($membership->getRoleID());
$rightrolesMapper = new Application_Model_RightRolesMapper();
$rightroleslist = $rightrolesMapper->findBy(array('roleID' => $membership->getRoleID()));
$role->setGroupID($groupID);
$role->setID();
try {
$this->rolemapper->save($role);
} catch(Zend_Exception $e)
{
echo "Caught exception: " . get_class($e) . "
";
echo "Message: " . $e->getMessage() . "
";
return;
}
$roleID = $this->rolemapper->getDbTable()->getDefaultAdapter()->lastInsertId();
$membership->setID();
$membership->setGroupID($groupID);
$membership->setRoleID($roleID);
try {
$this->membershipMapper->save($membership);
} catch(Zend_Exception $e)
{
echo "Caught exception: " . get_class($e) . "
";
echo "Message: " . $e->getMessage() . "
";
return;
}
foreach($rightroleslist as $rightroles) {
$rightroles->setRoleID($roleID);
try {
$rightrolesMapper->save($rightroles);
} catch(Zend_Exception $e)
{
echo "Caught exception: " . get_class($e) . "
";
echo "Message: " . $e->getMessage() . "
";
return;
}
}
if($_POST['superordinatedGroupID'] != -1) {
$groupgroups = new Application_Model_GroupGroups();
$groupgroups->setParentID($_POST['superordinatedGroupID']);
$groupgroups->setGroupID($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->addForm = $addForm;
}
public function editAction()
{
// ACL edit a group
// TODO: THERE IS NO RIGHT TO EDIT A GROUP
#if(!Pbs_Acl::checkRight(''))
# $this->_redirect('/user');
$groupID = $this->_request->getParam('groupID');
if(!isset($groupID)) {
if(count($this->userIDsNamespace) > 0) {
$groupID = $this->userIDsNamespace['groupID'];
}
}
if(!isset($groupID)) {
$this->_helper->redirector('add', 'group');
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($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()
{
// ACL create new group
if(!Pbs_Acl::checkRight('gsdo') && !Pbs_Acl::checkRight('gsdog'))
$this->_redirect('/user');
$groupID = $this->_request->getParam('groupID');
if($groupID == '' || !Pbs_Acl::checkRight('gsdog')) {
if(count($this->userIDsNamespace) > 0) {
$groupID = $this->userIDsNamespace['groupID'];
}
}
if($groupID == $this->membership->getGroupID() && !Pbs_Acl::checkRight('gsdo'))
$this->_redirect('/user');
$this->view->usergroup = $this->membership->getGroupID();
$this->view->requestgroup = $groupID;
// ACL is he allowed to see the requests of a group ?
// TODO: THERE IS NO RIGHT TO EDIT A GROUP
# if(Pbs_Acl::checkRight('')){
$groupRequests = $this->groupRequestMapper->findBy(array('groupID' => $groupID),true);
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;
}
// TODO: expand with al inherit roles
$this->view->roleList = $this->rolemapper->findBy(array('groupID' => $groupID),true);
}
# }
if(Pbs_Acl::checkRight('gsmg')){
$members = $this->membershipMapper->findBy(array('groupID' => $groupID),true);
if(isset($members)) {
foreach($members as $member) {
$person = $this->personmapper->find($member['personID']);
$membership_tmp = $this->membershipMapper->find($member['membershipID']);
$role = $this->rolemapper->find($membership_tmp->getRoleID());
$membersList[] = array(
'membershipID' => $member['membershipID'],
'person' => $person,
'role' => $role
);
}
if(is_array($membersList)) {
// Member Pagination
$memberPagination = new Pbs_Pagination();
$memberPagination->setPerPage(5);
$memberPagination->setElement($membersList);
$memberPagination->setRequestPage($this->_request->getParam('page'));
if($this->_request->getParam('groupID')) {
$memberPagination->setPageUrl('/user/group/show/groupID/' . $groupID . ((isset($this->view->search))?'/search/'.$this->view->search:''));
} else {
$memberPagination->setPageUrl('/user/group/show'.((isset($this->view->search))?'/search/'.$this->view->search:''));
}
$this->view->membersList = $memberPagination->getElements();
$this->view->memberPagination = $memberPagination->pagination($pageurl);
$this->view->page = $memberPagination->getRequestPage();
}
}
}
$groupgroups = $this->groupGroupsMapper->findBy(array('groupID' => $groupID),true);
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)) {
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) . "
";
echo "Message: " . $e->getMessage() . "
";
return;
}
if($_SERVER['HTTP_REFERER']) {
if(strpos($_SERVER['HTTP_REFERER'], '/user/group/show') !== false && strpos($_SERVER['HTTP_REFERER'], '/groupID/') === false) {
$this->_helper->redirector('changemembership', 'person');
} else {
$this->_helper->redirector('', 'group');
}
} else {
$this->_helper->redirector('', '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) . "
";
echo "Message: " . $e->getMessage() . "
";
return;
}
$membership = new Application_Model_Membership();
$membership->setGroupID($groupRequest->getGroupID());
$membership->setPersonID($groupRequest->getPersonID());
$membership->setRoleID($_POST['roleID']);
try {
$id = $this->membershipMapper->save($membership);
$membership->setID($id);
$newMember = new Pbs_NewMember();
$newMember->createDefaults($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/show/groupID/" . $membership->getGroupID());
}
} }
}