Skip to content

Commit

Permalink
completed work for member of
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Jan 18, 2021
1 parent a48f8b9 commit afda0d9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 52 deletions.
15 changes: 14 additions & 1 deletion Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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'));
Expand Down
16 changes: 14 additions & 2 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function getGrouperUser($queryData)
}


public function getGrouperUserGroups($queryData)
public function getGrouperMemberOfGroups($queryData)
{
$userId = $queryData['conditions']['userId'];

Expand Down Expand Up @@ -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'];
Expand Down
1 change: 1 addition & 0 deletions Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
89 changes: 40 additions & 49 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand All @@ -209,5 +201,4 @@ public function getSearchedGroups($userId, $searchCriteria, $page) {
return $returnResults;
}


}

0 comments on commit afda0d9

Please sign in to comment.