diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 9d9b9f0..c0ad433 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -159,12 +159,10 @@ public function membersInGroup() { try { $details = $this->GrouperGroup->membersInGroup($scope); - // $this->set('membersingroup', $details); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); - // $this->set('membersingroup', array()); $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); } @@ -197,7 +195,7 @@ public function groupOwner() { $data = $this->Paginator->paginate('GrouperGroup', $scope); - $finalData = $this->breakoutGroups($data); + $finalData = $this->breakoutGroups($data, 'admin'); $this->set('groupsowners', $finalData['adHocGroups']); $this->set('wgowners', $finalData['workingGroups']); @@ -215,7 +213,7 @@ public function groupOwner() { $data = $this->Paginator->paginate('GrouperGroup', $scope); - $finalData = $this->breakoutGroups($data); + $finalData = $this->breakoutGroups($data, 'admin'); $this->set('groupsowners', $finalData['adHocGroups']); $this->set('wgowners', $finalData['workingGroups']); @@ -234,78 +232,6 @@ public function groupOwner() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - /** - * Breakout Working Groups from AdHoc Groups for display purposes in UI. - * - * @param array $recordSet - * @param string $type - * @return array[] - * - */ - public function breakoutGroups(array $recordSet, $type='basic') { - //TODO - May move this logic down into the GrouperGroup model file, once all is agreed upon. - $wgData = array(); - $notWGData = array(); - foreach($recordSet as $record) { - if(isset($record['WGName'])) { - $wgData[] = $record; - } else { - $notWGData[] = $record; - } - } - - if ($type == 'basic') { - //Need to surface Optout flag to top level of a Working Group - foreach($wgData as &$wgRec) { - $subCount = 0; - foreach($wgRec['Groups'] as $rec){ - if(isset($rec['optOut'])) { - $wgRec['optOut'] = true; - $wgRec['workingGroupId'] = $rec['name']; - $wgRec['workingDesc'] = $this->hackDescription($rec['description']); - } - //Capturing record for incommon-collab since deleting a few lines below. - if ($rec['WGApp'] == 'incommon-collab') { - $recToDelete = $subCount; - } - $subCount += 1; - } - //Removing record with name of incommon-collab since means nothing to the user. - unset($wgRec['Groups'][$recToDelete]); - } - } elseif ($type == 'optin') { - foreach($wgData as &$wgRec) { - $wgRec['workingGroupId'] = $wgRec['Groups'][0]['name']; - $wgRec['workingDesc'] = $this->hackDescription($wgRec['Groups'][0]['description']); - unset($wgRec['Groups']); - } - } - - - return array( - 'adHocGroups' => $notWGData, - 'workingGroups' => $wgData - ); - } - - /** - * Eliminating canned description added by Grouper on creation of a WG in Grouper - * - * @param $description - * @return string - * - */ - private function hackDescription($description) { - - //Verify description has period in it. - if(strpos($description, ".") === false) { - return $description; - } - - $newString = substr($description, strpos($description, ".") + 1); - return trim($newString); - - } /** * Returns all Groups that the User is a member of in Grouper @@ -419,7 +345,7 @@ public function groupOptin() { $data = $this->Paginator->paginate('GrouperGroup', $scope); //$this->set('groupoptin', $data); - $finalData = $this->breakoutGroups($data,'optin'); + $finalData = $this->breakoutGroups($data, 'optin'); $this->set('groupoptins', $finalData['adHocGroups']); $this->set('wgoptins', $finalData['workingGroups']); @@ -445,8 +371,8 @@ public function groupOptin() { * */ public function groupCreateTemplate() { - if ($this->request->is('post')){ - if(!$this->GrouperGroup->createGroupWithTemplate($this->userId, $this->request->data)){ + if ($this->request->is('post')) { + if (!$this->GrouperGroup->createGroupWithTemplate($this->userId, $this->request->data)) { $this->Flash->set("Error in creating group!", array('key' => 'error')); return $this->redirect(array('action' => 'groupoptin')); } else { @@ -462,18 +388,18 @@ public function groupCreateTemplate() { * */ public function groupDeleteTemplate() { - if(!$this->GrouperGroup->deleteGroupWithTemplate($this->userId, $this->request->data)){ - $this->Flash->set("Error in deleting group!", array('key' => 'error')); - return $this->redirect(array('action' => 'groupoptin')); - } + if (!$this->GrouperGroup->deleteGroupWithTemplate($this->userId, $this->request->data)) { + $this->Flash->set("Error in deleting group!", array('key' => 'error')); + return $this->redirect(array('action' => 'groupoptin')); + } $this->set('title', _txt('pl.grouperlite.title.templatecreate')); } public function groupCreate() { - if ($this->request->is('post')){ - if(!$this->GrouperGroup->createUpdateGroup($this->userId, $this->request->data)){ + if ($this->request->is('post')) { + if (!$this->GrouperGroup->createUpdateGroup($this->userId, $this->request->data)) { $this->Flash->set("Error in creating group!", array('key' => 'error')); return $this->redirect(array('action' => 'groupOwner')); } else { @@ -488,13 +414,13 @@ public function groupCreate() { //TODO - Finish this call public function groupDelete() { - if(!$this->GrouperGroup->deleteGroup($this->userId, $this->request->data)){ - $this->Flash->set("Error in deleting group!", array('key' => 'error')); - return $this->redirect(array('action' => 'groupOwner')); - } else { - $this->Flash->set("Your Group has been deleted!", array('key' => 'success')); - return $this->redirect(array('action' => 'groupOwner')); - } + if (!$this->GrouperGroup->deleteGroup($this->userId, $this->request->data)) { + $this->Flash->set("Error in deleting group!", array('key' => 'error')); + return $this->redirect(array('action' => 'groupOwner')); + } else { + $this->Flash->set("Your Group has been deleted!", array('key' => 'success')); + return $this->redirect(array('action' => 'groupOwner')); + } $this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); } @@ -614,30 +540,14 @@ function isAuthorized() { return ($p[$this->action]); } - private function getUserId($id) { - $args = array(); - $args['conditions']['Identifier.co_person_id'] = $id; - $args['conditions']['Identifier.type'] = 'I2CollabPN'; - $args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active; - $args['contain'] = false; - - $Identifier = new Identifier(); - $grouper_identifier = $Identifier->find('first', $args); - - return $grouper_identifier['Identifier']['identifier']; - } - - //############################################################################################################## - //TODO - Need to finish off the email list pages, once we get direction from I2 - //############################################################################################################## public function emaillistsOptin() { $this->set('title', _txt('pl.grouperlite.title.emaillists-join')); //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']), - 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit']: $this->paginate['limit']), + 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page'] : $this->paginate['page']), + 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit'] : $this->paginate['limit']), ]; try { @@ -658,15 +568,18 @@ public function emaillistsOptin() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - public function emaillistsMember() - { + //############################################################################################################## + //TODO - Need to finish off the email list pages, once we get direction from I2 + //############################################################################################################## + + public function emaillistsMember() { $this->set('title', _txt('pl.grouperlite.title.emaillists-member')); //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']), - 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit']: $this->paginate['limit']), + 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page'] : $this->paginate['page']), + 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit'] : $this->paginate['limit']), ]; try { @@ -688,7 +601,6 @@ public function emaillistsMember() $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } - public function emaillistsManage() { $this->set('title', _txt('pl.grouperlite.title.emaillists-manage')); // mock data @@ -723,4 +635,95 @@ public function emaillistInfo() { $this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url')); } + + private function getUserId($id) { + $args = array(); + $args['conditions']['Identifier.co_person_id'] = $id; + $args['conditions']['Identifier.type'] = 'I2CollabPN'; + $args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active; + $args['contain'] = false; + + $Identifier = new Identifier(); + $grouper_identifier = $Identifier->find('first', $args); + + return $grouper_identifier['Identifier']['identifier']; + } + + /** + * Breakout Working Groups from AdHoc Groups for display purposes in UI. + * + * @param array $recordSet + * @param string $type 'basic' = view in Member page, 'admin' = view in Admin page, 'optin' = View in Optin page + * @return array[] + * + */ + private function breakoutGroups(array $recordSet, $type = 'basic') { + //TODO - May move this logic down into the GrouperGroup model file, once all is agreed upon. + $wgData = array(); + $notWGData = array(); + //Parse out the Working Groups from the Ad-hoc groups + foreach ($recordSet as $record) { + if (isset($record['WGName'])) { + $wgData[] = $record; + } else { + $notWGData[] = $record; + } + } + + if ($type == 'basic' || $type == 'admin') { + //Need to surface Optout flag to top level of a Working Group + foreach ($wgData as &$wgRec) { + $subCount = 0; + foreach ($wgRec['Groups'] as $rec) { + if (isset($rec['optOut'])) { + $wgRec['optOut'] = true; + $wgRec['workingGroupId'] = $rec['name']; + $wgRec['workingDesc'] = $this->hackDescription($rec['description']); + } + //Capturing record for incommon-collab since deleting a few lines below. + if ($rec['WGApp'] == 'incommon-collab') { + $recToDelete = $subCount; + if ($type == 'basic') { + //Removing record with stem of 'incommon-collab' since displaying on groups Member page, + // will show on Admin page + unset($wgRec['Groups'][$recToDelete]); + } + } + $subCount += 1; + } + + } + } elseif ($type == 'optin') { + //Working Groups that will show up on the Optin Page + foreach ($wgData as &$wgRec) { + $wgRec['workingGroupId'] = $wgRec['Groups'][0]['name']; + $wgRec['workingDesc'] = $this->hackDescription($wgRec['Groups'][0]['description']); + unset($wgRec['Groups']); + } + } + + return array( + 'adHocGroups' => $notWGData, + 'workingGroups' => $wgData + ); + } + + /** + * Eliminating canned description added by Grouper on creation of a WG in Grouper + * + * @param $description + * @return string + * + */ + private function hackDescription($description) { + + //Verify description has period in it. + if (strpos($description, ".") === false) { + return $description; + } + + $newString = substr($description, strpos($description, ".") + 1); + return trim($newString); + + } } diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 4195374..85dbeb2 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -44,11 +44,16 @@ class GrouperGroup extends GrouperLiteAppModel private $totalRecords = 0; - /** @var string Group whose members can create Groups via Template process*/ + /** @var string Group whose members can create Groups via Template process */ private $templateCreationGroup = 'ref:workinggroupadmins'; + + private $wgStemsTopLevel = array( + 'ref:incommon-collab' + ); + // Current listing of groups that are associated to Working Groups - private $stemsWorkingGroup = array( + private $wgStemsAllGroups = array( 'app:jira', 'app:confluence', 'app:sympa:internet2', @@ -56,6 +61,15 @@ class GrouperGroup extends GrouperLiteAppModel 'ref:incommon-collab' ); + + + // Current listing of stems that are allowed to be viewed in Comanage as AdHoc groups + private $stemsAdHocAllowed = array( + 'app', + 'org', + 'ref' + ); + /** * Verifies if user is an owner/admin of a group and then stores results in Session. * Session variable is reset on Group Creation and Group Deletion @@ -108,6 +122,20 @@ private function initApi() { } } + public function filteredMemberOfEmails(array $conditions) { + + $memberOfEmails = $this->filteredMemberOfGroups($conditions); + + // Strip out all Groups that are not in Sympa Stem/Directory + foreach ($memberOfEmails as $key => $value) { + if (strpos($value['name'], 'sympa') === false) { + unset($memberOfEmails[$key]); + } + } + + return array_values($memberOfEmails); + } + /** * Return all Groups that a User belongs to in Grouper. * Will also add OptOut Groups and flag them as joined so can display Optout option in UI. @@ -148,20 +176,6 @@ public function filteredMemberOfGroups(array $conditions) { } } - public function filteredMemberOfEmails(array $conditions) { - - $memberOfEmails = $this->filteredMemberOfGroups($conditions); - - // Strip out all Groups that are not in Sympa Stem/Directory - foreach($memberOfEmails as $key => $value){ - if(strpos($value['name'], 'sympa') === false) { - unset($memberOfEmails[$key]); - } - } - - return array_values($memberOfEmails); - } - /** * Internal process used by other functions to fetch Groups the User is a member of * @@ -181,141 +195,6 @@ private function memberOfGroups(array $conditions) { } } - /** - * Return array of Working Groups for display on coManage site. - * Logic is for each WG to have one key=>value of main WG name, then array of all associated - * Groups. - * - * NOTE: This is a major hack due to Grouper not giving us the right logic for displaying, so have to run all - * groups through a mapped listing of types of Groups in a WG to see if match and then parse and massage to display - * - * @param array $groups Listing of Groups - * @return array Listing of Groups in WG format for display - * - */ - private function getFriendlyWorkingGroupName(array $groups) { - - $arrayIndex = 0; - - //Loop through groups to see if possibly part of a Working Group - foreach ($groups as &$group) { - foreach($this->stemsWorkingGroup as $stem) { - $len = strlen($stem); - // if match to name of group within WG mapping then start making a WG group array - if (substr(strtolower($group['name']), 0, $len) === $stem){ - $stemSections = explode(':', $group['name']); - //Get second to last stem section - $sectionCount = count($stemSections) - 2; - $group['WGName'] = $stemSections[$sectionCount]; - //Get user type, which is after the WG name - if (isset($stemSections[$sectionCount + 1])){ - $group['WGRole'] = $stemSections[$sectionCount + 1]; - } else { - $group['WGRole'] = ''; - } - $appCount = 0; - $appName = ''; - foreach ($stemSections as $stemSection ) { - //Skip first entry - if ($appCount > 0) { - if ($appCount < $sectionCount) { - if ($appCount == 1) { - $appName = $stemSection; - } else { - $appName = $appName . " - " . $stemSection; - } - } - } - $appCount += 1; - } - //changed the way email list are displayed to actually show lists email address. - if ($appName == 'sympa - internet2' || $appName == 'sympa - incommon'){ - if ($appName == 'sympa - internet2'){ - $appName = $group['WGName'] . '@lists.' . 'internet2.edu'; - } else { - $appName = $group['WGName'] . '@lists.' . 'incommon.org'; - } - - } - $group['WGApp'] = $appName; - //TODO - FOR DEMO PURPOSE THAT LEAVES OUT ADMIN GROUPS TO SHOW WHAT AVERAGE USER SEES - if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') { - $workingGroups[] = $group; - } - //$workingGroups[] = $group; - unset($groups[$arrayIndex]); - } - } - $arrayIndex += 1; - } - - $finalWorkingGroups = array(); - - foreach ($workingGroups as $workingGroup) { - //Need to set first group in final Working Group array - if (count($finalWorkingGroups) == 0) { - $finalWorkingGroups[] = array('WGName' => $workingGroup['WGName'], 'Groups' => array($workingGroup)); - } else { - $foundMatch = false; - foreach ($finalWorkingGroups as &$finalWorkingGroup) { - if($finalWorkingGroup['WGName'] == $workingGroup['WGName']){ - $finalWorkingGroup['Groups'][] = $workingGroup; - $foundMatch = true; - } - } - if (!$foundMatch) { - $finalWorkingGroups[] = array('WGName' => $workingGroup['WGName'], 'Groups' => array($workingGroup)); - } - } - } - - $friendlyGroups = $this->getFriendlyName(array_values($groups)); - - //Now need to add the groups back together for one set - foreach($friendlyGroups as $friendlyGroup) { - $finalWorkingGroups[] = $friendlyGroup; - } - - return $finalWorkingGroups; - } - - - /** - * Determine if result set contains friendly name, if so add as a new attribute in result set - * - * @param array $groups Current result set of Groups - * @return array Same result set with added param for friendly name - * - */ - private function getFriendlyName(array $groups) { - - //NOT fetching attributes now, just using name display name as friendly name, if different from name field -// foreach ($groups as &$group) { -// //$group['friendlyName'] = $group['displayName']; -// $nameSections = explode(':', $group['name']); -// $friendlySections = explode(':', $group['displayName']); -// $numberNameSections = count($nameSections); -// for ($x = 0; $x < $numberNameSections; $x++) { -// if ($nameSections[$x] == $friendlySections[$x]) { -// unset($friendlySections[$x]); -// } else { -// break; -// } -// } -// $group['friendlyName'] = implode(':', $friendlySections); -// if (strlen($group['friendlyName']) == 0) { -// $group['friendlyName'] = $group['name']; -// } -// } - - //TODO - For now just returning Display name as Friendly name, till determined by Bill K. - foreach ($groups as &$group) { - $group['friendlyName'] = $group['displayName']; - } - - return $groups; - } - /** * Gets the Grouper Groups params and values as well as its associated attributes. * @@ -418,6 +297,8 @@ public function ownerGroups(array $conditions) { /** * Get members associated to a specific Grouper Group + * NOTE: This list only shows members, it does not pull in other groups that may be attached in Grouper as + * members * * @param array $conditions Listing of conditions for display of records * @return array Listing of members in requested Grouper Group @@ -428,7 +309,16 @@ public function membersInGroup(array $conditions) { $this->initApi(); try { - return $this->grouperAPI->getMembersInGroup($conditions); + $groupMembers = $this->grouperAPI->getMembersInGroup($conditions); + + $finalMembers = array(); + foreach ($groupMembers as $member) { + if ($member['sourceId'] !== 'g:gsa') { + $finalMembers[] = $member; + } + + } + return $finalMembers; } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -436,6 +326,19 @@ public function membersInGroup(array $conditions) { } } + public function optinEmailGroups(array $conditions) { + $allGroups = $this->optinGroups($conditions); + + // Strip out all Groups that are not in Sympa Stem/Directory + foreach ($allGroups as $key => $value) { + if (strpos($value['name'], 'sympa') === false) { + unset($allGroups[$key]); + } + } + + return array_values($allGroups); + } + /** * Return all Groups the User can JOIN * Get all Groups with Optin attribute set and display ones User can join. @@ -475,21 +378,8 @@ public function optinGroups(array $conditions) { } } - public function optinEmailGroups(array $conditions) { - $allGroups = $this->optinGroups($conditions); - - // Strip out all Groups that are not in Sympa Stem/Directory - foreach($allGroups as $key => $value){ - if(strpos($value['name'], 'sympa') === false) { - unset($allGroups[$key]); - } - } - - return array_values($allGroups); - } - /** - * Determine if User can use the Grouper Template to create a suite of Groups including Email lists. + * Determine if User can use the Grouper Template to create a Working Group. * * @param string $userId Id of User * @return string T for True and F for False @@ -531,7 +421,6 @@ public function isTemplateUser(string $userId) { } - /** * Create a new Grouper Group using the Template methodology in Grouper * @@ -554,7 +443,7 @@ public function createGroupWithTemplate(string $userId, array $groupData) { 'gsh_input_isJira' ); // Template does not except true/false, so convert to string and send that way - foreach($fields as $field) { + foreach ($fields as $field) { ($groupData[$field] == '0') ? $groupData[$field] = 'false' : $groupData[$field] = 'true'; } @@ -574,6 +463,18 @@ public function createGroupWithTemplate(string $userId, array $groupData) { } + /** + * Private function used to reset the IsUserOwner Session variable, + * that maintains the status of a user being an owner/admin of a group + * + * @see GrouperGroup::isUserOwner() + */ + private function resetUserOwner() { + if (CakeSession::check('Plugin.Grouper.isUserOwner')) { + CakeSession::delete('Plugin.Grouper.isUserOwner'); + } + } + /** * Delete a Grouper Group using the Template methodology in Grouper * @@ -630,18 +531,6 @@ public function createUpdateGroup(string $userId, array $data) { } } - /** - * Private function used to reset the IsUserOwner Session variable, - * that maintains the status of a user being an owner/admin of a group - * - * @see GrouperGroup::isUserOwner() - */ - private function resetUserOwner() { - if (CakeSession::check('Plugin.Grouper.isUserOwner')) { - CakeSession::delete('Plugin.Grouper.isUserOwner'); - } - } - /** * Get Grouper Stems where User has authority to create a Grouper Group * @@ -720,6 +609,191 @@ public function paginate($conditions) { return $this->paginateRecords($friendlyResults, $conditions); } + /** + * Return array of Working Groups for display on coManage site. + * Logic is for each WG to have one key=>value of main WG name, then array of all associated + * Groups. + * + * NOTE: This is a major hack due to Grouper not giving us the right logic for displaying, so have to run all + * groups through a mapped listing of types of Groups in a WG to see if match and then parse and massage to display + * + * @param array $groups Listing of Groups + * @return array Listing of Groups in WG format for display + * + */ + private function getFriendlyWorkingGroupName(array $groups) { + + $arrayIndex = 0; + + //First need to loop through all groups and pull in all top levels + $topLevelWG = array(); + foreach ($groups as $group) { + foreach ($this->wgStemsTopLevel as $stem) { + $len = strlen($stem); + if (substr(strtolower($group['name']), 0, $len) === $stem) { + $stemSections = explode(':', $group['name']); + //Get second to last stem section + $sectionCount = count($stemSections) - 2; + if (in_array($stemSections[$sectionCount], $topLevelWG) === false){ + $topLevelWG[] = $stemSections[$sectionCount]; + } + } + } + } + + //Loop through groups to see if possibly part of a Working Group + foreach ($groups as &$group) { + foreach ($this->wgStemsAllGroups as $stem) { + $len = strlen($stem); + // if match to name of group within WG mapping then start making a WG group array + if (substr(strtolower($group['name']), 0, $len) === $stem) { + $stemSections = explode(':', $group['name']); + //Get second to last stem section + $sectionCount = count($stemSections) - 2; + //If group not part of a top level WG, then do not show! + if (in_array($stemSections[$sectionCount], $topLevelWG) === false){ + break; + } + $group['WGName'] = $stemSections[$sectionCount]; + //Get user type, which is after the WG name + if (isset($stemSections[$sectionCount + 1])) { + $group['WGRole'] = $stemSections[$sectionCount + 1]; + } else { + $group['WGRole'] = ''; + } + $appCount = 0; + $appName = ''; + foreach ($stemSections as $stemSection) { + //Skip first entry + if ($appCount > 0) { + if ($appCount < $sectionCount) { + if ($appCount == 1) { + $appName = $stemSection; + } else { + $appName = $appName . " - " . $stemSection; + } + } + } + $appCount += 1; + } + //changed the way email list are displayed to actually show lists email address. + if ($appName == 'sympa - internet2' || $appName == 'sympa - incommon') { + if ($appName == 'sympa - internet2') { + $appName = $group['WGName'] . '@lists.' . 'internet2.edu'; + } else { + $appName = $group['WGName'] . '@lists.' . 'incommon.org'; + } + + } + $group['WGApp'] = $appName; + //TODO - FOR DEMO PURPOSE THAT LEAVES OUT ADMIN GROUPS TO SHOW WHAT AVERAGE USER SEES +// if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') { +// $workingGroups[] = $group; +// } + $workingGroups[] = $group; + unset($groups[$arrayIndex]); + } + } + $arrayIndex += 1; + } + + $finalWorkingGroups = array(); + + foreach ($workingGroups as $workingGroup) { + //Need to set first group in final Working Group array + if (count($finalWorkingGroups) == 0) { + $finalWorkingGroups[] = array('WGName' => $workingGroup['WGName'], 'Groups' => array($workingGroup)); + } else { + $foundMatch = false; + foreach ($finalWorkingGroups as &$finalWorkingGroup) { + if ($finalWorkingGroup['WGName'] == $workingGroup['WGName']) { + $finalWorkingGroup['Groups'][] = $workingGroup; + $foundMatch = true; + } + } + if (!$foundMatch) { + $finalWorkingGroups[] = array('WGName' => $workingGroup['WGName'], 'Groups' => array($workingGroup)); + } + } + } + + $filteredGroups = $this->verifyAdHocStem(array_values($groups)); + $friendlyGroups = $this->getFriendlyName($filteredGroups); + + //Now need to add the groups back together for one set + foreach ($friendlyGroups as $friendlyGroup) { + $finalWorkingGroups[] = $friendlyGroup; + } + + return $finalWorkingGroups; + } + + /** + * Verify that the AdHoc groups are only coming from stems listed in $stemsAdHocAllowed + * + * @param array $groups Array of Ad Hoc groups + * @return array Ad Hoc groups that are coming from approved stems + * + */ + private function verifyAdHocStem(array $groups) { + + foreach ($groups as $key => $value) { + $legit = true; + foreach ($this->stemsAdHocAllowed as $legitStem) { + $len = strlen($legitStem); + if (substr(strtolower($value['name']), 0, $len) === $legitStem) { + $legit = true; + break; + } else { + $legit = false; + } + } + if (!$legit) { + unset($groups[$key]); + } + + } + + return $groups; + } + + /** + * Determine if result set contains friendly name, if so add as a new attribute in result set + * NOTE: Used by Ad-Hoc groups only, since WG are listed under a Grouping + * + * @param array $groups Current result set of Groups + * @return array Same result set with added param for friendly name + * + */ + private function getFriendlyName(array $groups) { + + //NOT fetching attributes now, just using name display name as friendly name, if different from name field +// foreach ($groups as &$group) { +// //$group['friendlyName'] = $group['displayName']; +// $nameSections = explode(':', $group['name']); +// $friendlySections = explode(':', $group['displayName']); +// $numberNameSections = count($nameSections); +// for ($x = 0; $x < $numberNameSections; $x++) { +// if ($nameSections[$x] == $friendlySections[$x]) { +// unset($friendlySections[$x]); +// } else { +// break; +// } +// } +// $group['friendlyName'] = implode(':', $friendlySections); +// if (strlen($group['friendlyName']) == 0) { +// $group['friendlyName'] = $group['name']; +// } +// } + + //TODO - For now just returning Display name as Friendly name, till determined by Bill K. + foreach ($groups as &$group) { + $group['friendlyName'] = $group['displayName']; + } + + return $groups; + } + /** * Parses returned records to display only requested records for pagination. * @@ -737,7 +811,7 @@ private function paginateRecords(array $recSet, array $conditions) { if (strtolower($conditions['limit']) == 'all') { return $recSet; } - + //Now slice recordset to return correct set of records. $page = $conditions['page'] - 1; $limit = $conditions['limit']; @@ -760,8 +834,7 @@ private function paginateRecords(array $recSet, array $conditions) { * @return int Total number of Grouper Records returned by Grouper API call * */ - public function paginateCount($conditions = null, $recursive = 0, - $extra = array()) { + public function paginateCount($conditions = null, $recursive = 0, $extra = array()) { return $this->totalRecords; } } diff --git a/View/Elements/Components/navigation-emaillists.ctp b/View/Elements/Components/navigation-emaillists.ctp index 6b478db..c8f3ffa 100644 --- a/View/Elements/Components/navigation-emaillists.ctp +++ b/View/Elements/Components/navigation-emaillists.ctp @@ -37,7 +37,7 @@ ?> - +