Skip to content

Commit

Permalink
Merged feature/ICPCO-90 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Jan 29, 2021
2 parents b284310 + 304442e commit 0a73b09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
27 changes: 19 additions & 8 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
Expand Down
28 changes: 20 additions & 8 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 0a73b09

Please sign in to comment.