From 304442e24475df352cdac596116f4309686c9109 Mon Sep 17 00:00:00 2001 From: axman Date: Fri, 29 Jan 2021 14:31:36 -0700 Subject: [PATCH] complete --- Controller/GrouperGroupsController.php | 27 +++++++++++++++++-------- Model/GrouperGroup.php | 28 ++++++++++++++++++-------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 6eff67e..a7bf4df 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -79,16 +79,27 @@ public function groupOwner() { } + /** + * Returns all Groups that the User is a member of in Grouper. + * This includes Optin groups that the User joined + * + */ 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('groupergroupmemberships', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupMember')); - $this->set('searchcriteria', $searchCriteria); - } else { - $this->set('groupergroupmemberships', $this->GrouperGroup->filteredMemberOfGroups($this->userId)); + try { + if (isset($this->request->data['search'])){ + $searchCriteria = urldecode($this->request->data['search']); + $this->set('groupergroupmemberships', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupMember')); + $this->set('searchcriteria', $searchCriteria); + } else { + $this->set('groupergroupmemberships', $this->GrouperGroup->filteredMemberOfGroups($this->userId)); + } + } catch (Exception $e) { + CakeLog::write('error', + 'GrouperLite Controller - groupMember: ' . var_export($e->getMessage(), true)); + $this->Flash->error("Your Membership Groups cannot be found currently, please try again later."); + $this->set('groupergroupmemberships', array()); } - } public function groupOptin() { @@ -102,7 +113,7 @@ public function groupOptin() { try { $optin = $this->GrouperGroup->optinGroups($this->userId); if (isset($optin['errorMessage'])){ - $this->Flash->error($optin['errorMessage']); + $this->Flash->error('Some error'); $this->set('groupergroupoptin', array()); } else { $this->set('groupergroupoptin', $optin); diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index bdb7e63..f6c3e54 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -69,26 +69,38 @@ private function memberOfGroups($userId) { return $this->grouperAPI->getGrouperMemberOfGroups($args); } - - public function filteredMemberOfGroups($userId) { + /** + * Return all Groups that a User belongs to in Grouper. + * Will also compare against Optin Groups to determine if User given option to Optout of the Group + * + * @param string $userId Id of User + * @return array Records of Groups in Grouper that the User belongs to + * @throws GrouperLiteException + * + */ + public function filteredMemberOfGroups(string $userId) { $this->initApi(); - //Need to filter out the optin joined groups $memberOfGroups = $this->memberOfGroups($userId); $args = array(); $args['conditions']['userId'] = $userId; + // Determine which groups can be left by user, if want. $optInGroups = $this->grouperAPI->getOptinGroups($args); - foreach($memberOfGroups as $key => $value) { - foreach($optInGroups as $optInGroup) { - if ($optInGroup['name'] == $value['name']) { - unset($memberOfGroups[$key]); + foreach($memberOfGroups as &$memberOfGroup) { + foreach($optInGroups as $key => $value) { + if ($value['name'] == $memberOfGroup['name']) { + //Match! + $memberOfGroup['member'] = true; + //Remove Optin group since already found and now less loops + unset($optInGroups[$key]); + break; } } } - return $memberOfGroups; + return $this->getFriendlyName($memberOfGroups); } public function groupDescriptions($groupName) {