From afda0d90945c3bf75d4efbe56e29fbd4db546dc7 Mon Sep 17 00:00:00 2001 From: axman Date: Mon, 18 Jan 2021 14:05:58 -0700 Subject: [PATCH] completed work for member of --- Controller/GrouperGroupsController.php | 15 ++++- Lib/GrouperApiAccess.php | 16 ++++- Lib/lang.php | 1 + Model/GrouperGroup.php | 89 ++++++++++++-------------- 4 files changed, 69 insertions(+), 52 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index d5477cd..402f6c6 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -20,7 +20,7 @@ public function index() { public function groupUser() { $this->set('title', _txt('pl.grouperlite.title.root')); - //TODO - Change to get userid somehow + $this->set('groupergroupsmember', $this->GrouperGroup->optinGroups($this->userId)); } @@ -47,6 +47,19 @@ public function groupOwner() } + public function groupMember() + { + $this->set('title', _txt('pl.grouperlite.title.groupmember')); + if (isset($this->request->data['search'])){ + $searchCriteria = urldecode($this->request->data['search']); + $this->set('groupergroupsowner', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupMember')); + $this->set('searchcriteria', $searchCriteria); + } else { + $this->set('groupergroupsmember', $this->GrouperGroup->filteredMemberOfGroups($this->userId)); + } + + } + public function groupOptin() { $this->set('title', _txt('pl.grouperlite.title.groupoptin')); diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index dcd7556..8b39e70 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -58,7 +58,7 @@ public function getGrouperUser($queryData) } - public function getGrouperUserGroups($queryData) + public function getGrouperMemberOfGroups($queryData) { $userId = $queryData['conditions']['userId']; @@ -117,7 +117,19 @@ public function grouperGroupLeaveOrJoin($queryData) return false; } - public function getGrouperGroups($queryData) + public function getOptinGroups($queryData) { + $queryData['conditions']['groupType'] = 'Optins'; + return $this->getGrouperGroups($queryData); + + } + + public function getOwnerGroups($queryData) { + $queryData['conditions']['groupType'] = 'Owner'; + return $this->getGrouperGroups($queryData); + + } + + private function getGrouperGroups($queryData) { $groupType = $queryData['conditions']['groupType']; $subjectID = $queryData['conditions']['userId']; diff --git a/Lib/lang.php b/Lib/lang.php index 4f3f031..b6868ad 100644 --- a/Lib/lang.php +++ b/Lib/lang.php @@ -18,6 +18,7 @@ 'pl.grouperlite.title.root' => 'Grouper Groups:', 'pl.grouperlite.title.groupinfo' => 'Group configuration and attributes', 'pl.grouperlite.title.groupowner' => 'Grouper Groups I Manage', + 'pl.grouperlite.title.groupmember' => 'Grouper Groups I Belong To', 'pl.grouperlite.title.groupoptin' => 'Grouper Groups I Can Join', 'pl.grouperlite.title.emaillists' => 'Email lists', 'pl.grouperlite.title.emaillistsmanaged' => 'Email lists I manage', diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index a69451a..97b7d66 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -5,32 +5,10 @@ class GrouperGroup extends GrouperLiteAppModel { - //TODO - Add input validation + //TODO - Add input validation, possibly??? public $name = "GrouperGroup"; public $grouperAPI; - public $validate = array( - 'userId' => array( - 'rule' => 'alphaNumeric', - 'required' => true, - 'message' => 'No UserId was given, please try again.' - ), - 'groupName' => array( - 'rule' => 'alphaNumeric', - 'required' => true, - 'message' => 'No Group Name was given, please try again.' - ), - 'groupDesc' => array( - 'rule' => 'alphaNumeric', - 'required' => false, - 'message' => 'There is an error with the Group Description, please try again.' - ), - 'stemName' => array( - 'rule' => 'alphaNumeric', - 'required' => false, - 'message' => 'Stem Name is incorrect, please try again.' - ), - ); /** * @var string @@ -39,23 +17,41 @@ class GrouperGroup extends GrouperLiteAppModel private $friendly = 'sandbox:testAttributeName'; - public function __construct() - { + public function __construct() { parent::__construct(); $this->grouperAPI = new GrouperApiAccess(); } - public function userGroups($userId) - { + private function memberOfGroups($userId) { $args = array(); $args['conditions']['userId'] = $userId; - return $this->grouperAPI->getGrouperUserGroups($args); + return $this->grouperAPI->getGrouperMemberOfGroups($args); } - public function groupDescriptions($groupName) - { + + public function filteredMemberOfGroups($userId) { + //Need to filter out the optin joined groups + + $memberOfGroups = $this->memberOfGroups($userId); + + $args = array(); + $args['conditions']['userId'] = $userId; + $optInGroups = $this->grouperAPI->getOptinGroups($args); + + foreach($memberOfGroups as $key => $value) { + foreach($optInGroups as $optInGroup) { + if ($optInGroup['name'] == $value['name']) { + unset($memberOfGroups[$key]); + } + } + } + + return $memberOfGroups; + } + + public function groupDescriptions($groupName) { $args = array(); $args['conditions']['groupName'] = $groupName; @@ -70,8 +66,7 @@ public function groupDescriptions($groupName) return $groupDescription; } - public function leaveGroup($userId, $groupName) - { + public function leaveGroup($userId, $groupName) { $args = array(); $args['conditions']['LeaveJoin'] = 'Leave'; $args['conditions']['userId'] = $userId; @@ -80,8 +75,7 @@ public function leaveGroup($userId, $groupName) return $this->grouperAPI->grouperGroupLeaveOrJoin($args); } - public function joinGroup($userId, $groupName) - { + public function joinGroup($userId, $groupName) { $args = array(); $args['conditions']['LeaveJoin'] = 'Join'; $args['conditions']['userId'] = $userId; @@ -90,13 +84,11 @@ public function joinGroup($userId, $groupName) return $this->grouperAPI->grouperGroupLeaveOrJoin($args); } - public function ownerGroups($userId) - { + public function ownerGroups($userId) { $args = array(); - $args['conditions']['groupType'] = 'Owner'; $args['conditions']['userId'] = $userId; - $ownGroups = $this->grouperAPI->getGrouperGroups($args); + $ownGroups = $this->grouperAPI->getOwnerGroups($args); //Now for each group need to pull in friendly name attribute. foreach ($ownGroups as &$ownGroup) { @@ -111,27 +103,26 @@ public function ownerGroups($userId) } } } - return $ownGroups; } - public function optinGroups($userId) - { + public function optinGroups($userId) { $args = array(); - $args['conditions']['groupType'] = 'Optins'; $args['conditions']['userId'] = $userId; - $joinOrLeave = $this->grouperAPI->getGrouperGroups($args); - $userGroups = $this->userGroups($userId); + $joinOrLeave = $this->grouperAPI->getOptinGroups($args); + $userGroups = $this->memberOfGroups($userId); //See if Optin group match any of the groups belong to already. foreach ($joinOrLeave as &$groupsJoL) { - foreach ($userGroups as $userGroup) { + foreach ($userGroups as $key => $value) { $groupsJoL['member'] = false; - if ($groupsJoL['name'] == $userGroup['name']) { + if ($groupsJoL['name'] == $value['name']) { //Match!! $groupsJoL['member'] = true; + //I am removing entry for faster processing of loop + unset($userGroups[$key]); break; } } @@ -154,8 +145,7 @@ public function optinGroups($userId) return $joinOrLeave; } - public function createGroup($userId, $groupName, $stemName, $groupDesc) - { + public function createGroup($userId, $groupName, $stemName, $groupDesc) { $args = array(); $args['conditions']['groupType'] = 'Optins'; $args['conditions']['userId'] = $userId; @@ -193,6 +183,8 @@ public function getSearchedGroups($userId, $searchCriteria, $page) { $pageResults = $this->optinGroups($userId); } elseif ($page == 'groupOwner') { $pageResults = $this->ownerGroups($userId); + } elseif ($page == 'groupMember') { + $pageResults = $this->filteredMemberOfGroups($userId); } else { $pageResults = array(); } @@ -209,5 +201,4 @@ public function getSearchedGroups($userId, $searchCriteria, $page) { return $returnResults; } - }