From ccf55347b37b99754ebe63781a04e3115b36ce10 Mon Sep 17 00:00:00 2001 From: axman Date: Thu, 25 Mar 2021 07:02:10 -0700 Subject: [PATCH] done --- Controller/GrouperGroupsController.php | 59 ++++++++++++++++++------- Model/GrouperGroup.php | 26 +++++++++++ View/GrouperGroups/emaillistsmember.ctp | 13 +++--- View/GrouperGroups/emaillistsoptin.ctp | 2 + 4 files changed, 80 insertions(+), 20 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index e28a23b..69fc296 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -497,13 +497,27 @@ function isAuthorized() { public function emaillistsOptin() { $this->set('title', _txt('pl.grouperlite.title.emaillists-join')); - // mock data - $this->set('group', array( - 'member' => true, - 'name' => 'Email List 1', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T' - )); + + //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']), + ]; + + try { + //Add settings for optinEmailLists + $scope['method'] = 'optinEmailGroups'; + + $data = $this->Paginator->paginate('GrouperGroup', $scope); + $this->set('emailgroups', $data); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + $this->Flash->set("An error occurred with the Optin Groups, please try again later.", array('key' => 'error')); + $this->set('emailgroups', array()); + return; + } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); @@ -512,19 +526,34 @@ public function emaillistsOptin() { public function emaillistsMember() { $this->set('title', _txt('pl.grouperlite.title.emaillists-member')); - // mock data - $this->set('group', array( - 'member' => true, - 'name' => 'Email List 1', - 'domain' => 'internet2', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T' - )); + + //Set initial settings for pagination + $scope = [ + 'userId' => $this->userId, + 'page' => ($this->passedArgs['page'] ? $this->passedArgs['page']: $this->paginate['page']), + 'limit' => ($this->passedArgs['limit'] ? $this->passedArgs['limit']: $this->paginate['limit']), + ]; + + try { + //Add setting for Group Membership + $scope['method'] = 'filteredMemberOfEmails'; + + $data = $this->Paginator->paginate('GrouperGroup', $scope); + $this->set('emailgroups', $data); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true)); + + $this->Flash->set("Your Member Group cannot be found, please try again later.", array('key' => 'error')); + $this->set('emailgroups', array()); + return; + } $this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId)); $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } + public function emaillistsManage() { $this->set('title', _txt('pl.grouperlite.title.emaillists-manage')); // mock data diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index e4f5995..89bf151 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -138,6 +138,19 @@ 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 $memberOfEmails; + } + /** * Internal process used by other functions to fetch Groups the User is a member of * @@ -362,6 +375,19 @@ 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 $allGroups; + } + /** * Determine if User can use the Grouper Template to create a suite of Groups including Email lists. * diff --git a/View/GrouperGroups/emaillistsmember.ctp b/View/GrouperGroups/emaillistsmember.ctp index d678648..ed1264a 100644 --- a/View/GrouperGroups/emaillistsmember.ctp +++ b/View/GrouperGroups/emaillistsmember.ctp @@ -13,6 +13,7 @@ + Html->link( isset($group['name']) ? $group['domain'].':'.$group['name'] : "No Name", @@ -23,13 +24,15 @@ ) ) ?> - - + + element('GrouperLite.Components/optAction', array( + 'member' => $group['optedin'], + 'action' => 'leavegroup', + 'group' => $group['name'] + )) : ''; ?> + diff --git a/View/GrouperGroups/emaillistsoptin.ctp b/View/GrouperGroups/emaillistsoptin.ctp index 2554c1d..a980633 100644 --- a/View/GrouperGroups/emaillistsoptin.ctp +++ b/View/GrouperGroups/emaillistsoptin.ctp @@ -13,6 +13,7 @@ + Html->link( isset($group['name']) ? $group['domain'] . ':' . $group['name'] : "No Name", @@ -30,6 +31,7 @@ + \ No newline at end of file