From fecb40f587b44cc019fa34e46c3b772d6ef0dfbc Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 3 Nov 2017 21:50:09 +0000 Subject: [PATCH] Add search option to view groups as other components --- CRM/Contact/BAO/Group.php | 13 ++-- CRM/Group/Form/Search.php | 13 +++- CRM/Group/Page/AJAX.php | 1 + CRM/Member/Task.php | 10 +++ templates/CRM/Group/Form/Search.tpl | 79 +++++++++++++---------- tests/phpunit/CRM/Group/Page/AjaxTest.php | 8 +-- 6 files changed, 82 insertions(+), 42 deletions(-) diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index c7582d99feae..6c09a8eeba90 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -882,7 +882,7 @@ public static function getGroupList(&$params) { // CRM-9936 $reservedPermission = CRM_Core_Permission::check('administer reserved groups'); - $links = self::actionLinks(); + $links = self::actionLinks($params); $allTypes = CRM_Core_OptionGroup::values('group_type'); $values = array(); @@ -1254,12 +1254,17 @@ public static function whereClause(&$params, $sortBy = TRUE, $excludeHidden = TR * @return array * array of action links */ - public static function actionLinks() { + public static function actionLinks($params) { + // If component_mode is set we change the "View" link to match the requested component type + if (!isset($params['component_mode'])) { + $params['component_mode'] = CRM_Contact_BAO_Query::MODE_CONTACTS; + } + $modeValue = CRM_Contact_Form_Search::getModeValue($params['component_mode']); $links = array( CRM_Core_Action::VIEW => array( - 'name' => ts('Contacts'), + 'name' => $modeValue['selectorLabel'], 'url' => 'civicrm/group/search', - 'qs' => 'reset=1&force=1&context=smog&gid=%%id%%', + 'qs' => 'reset=1&force=1&context=smog&gid=%%id%%&component_mode=' . $params['component_mode'], 'title' => ts('Group Contacts'), ), CRM_Core_Action::UPDATE => array( diff --git a/CRM/Group/Form/Search.php b/CRM/Group/Form/Search.php index 22696f447717..b47cb81055dd 100644 --- a/CRM/Group/Form/Search.php +++ b/CRM/Group/Form/Search.php @@ -81,6 +81,17 @@ public function buildQuickForm() { NULL, NULL, NULL, NULL, '   ' ); + $componentModes = CRM_Contact_Form_Search::getModeSelect(); + if (count($componentModes) > 1) { + $this->add('select', + 'component_mode', + ts('View Results As'), + $componentModes, + FALSE, + array('class' => 'crm-select2') + ); + } + $this->addButtons(array( array( 'type' => 'refresh', @@ -97,7 +108,7 @@ public function postProcess() { $params = $this->controller->exportValues($this->_name); $parent = $this->controller->getParent(); if (!empty($params)) { - $fields = array('title', 'created_by', 'group_type', 'visibility', 'active_status', 'inactive_status'); + $fields = array('title', 'created_by', 'group_type', 'visibility', 'active_status', 'inactive_status', 'component_mode'); foreach ($fields as $field) { if (isset($params[$field]) && !CRM_Utils_System::isNull($params[$field]) diff --git a/CRM/Group/Page/AJAX.php b/CRM/Group/Page/AJAX.php index 69359281d3a8..c302c91aefb7 100644 --- a/CRM/Group/Page/AJAX.php +++ b/CRM/Group/Page/AJAX.php @@ -54,6 +54,7 @@ public static function getGroupList() { 'created_by' => 'String', 'group_type' => 'String', 'visibility' => 'String', + 'component_mode' => 'String', 'status' => 'Integer', 'parentsOnly' => 'Integer', 'showOrgInfo' => 'Boolean', diff --git a/CRM/Member/Task.php b/CRM/Member/Task.php index d93726a3a8b3..8a62fc8cd1d6 100644 --- a/CRM/Member/Task.php +++ b/CRM/Member/Task.php @@ -102,6 +102,16 @@ public static function tasks() { 'class' => 'CRM_Member_Form_Task_PDFLetter', 'result' => FALSE, ), + self::SAVE_SEARCH => array( + 'title' => ts('Group - create smart group'), + 'class' => 'CRM_Contact_Form_Task_SaveSearch', + 'result' => TRUE, + ), + self::SAVE_SEARCH_UPDATE => array( + 'title' => ts('Group - update smart group'), + 'class' => 'CRM_Contact_Form_Task_SaveSearch_Update', + 'result' => TRUE, + ), ); //CRM-4418, check for delete diff --git a/templates/CRM/Group/Form/Search.tpl b/templates/CRM/Group/Form/Search.tpl index 5034d4547400..deec4a7a3d28 100644 --- a/templates/CRM/Group/Form/Search.tpl +++ b/templates/CRM/Group/Form/Search.tpl @@ -24,45 +24,57 @@ +--------------------------------------------------------------------+ *}
- -

{ts}Find Groups{/ts}

- - - + + + + + + +
- {$form.title.label}
- {$form.title.html}
- +
+
+ {ts}Find Groups{/ts} +
+
+
+ + + - + - - + - - -
+ {$form.title.label}
+ {$form.title.html}
+ {ts}Complete OR partial group name.{/ts} -
- {$form.created_by.label}
- {$form.created_by.html}
- +
+ {$form.created_by.label}
+ {$form.created_by.html}
+ {ts}Complete OR partial creator name.{/ts} -
- {$form.group_type_search.label}
- {$form.group_type_search.html}
- - {ts}Filter search by group type(s).{/ts} - -
- {$form.visibility.label}
- {$form.visibility.html}
- +
+ {$form.visibility.label}
+ {$form.visibility.html}
+ {ts}Filter search by visibility.{/ts} -
- {$form.group_status.label}
- {$form.group_status.html} -
-
+
+ {$form.group_type_search.label}
+ {$form.group_type_search.html}
+ + {ts}Filter search by group type(s).{/ts} + +
+ {$form.group_status.label}
+ {$form.group_status.html} +
+ {$form.component_mode.label}
+ {$form.component_mode.html} +
+
+ +
{ts}Update Smart Group Counts{/ts} {help id="update_smart_groups"}
@@ -119,6 +131,7 @@ d.group_type = groupTypes, d.visibility = $(".crm-group-search-form-block select#visibility").val(), d.status = groupStatus, + d.component_mode = $(".crm-group-search-form-block select#component_mode").val(), d.showOrgInfo = {/literal}"{$showOrgInfo}"{literal}, d.parentsOnly = parentsOnly } diff --git a/tests/phpunit/CRM/Group/Page/AjaxTest.php b/tests/phpunit/CRM/Group/Page/AjaxTest.php index 56f39829ced9..42222be567c7 100644 --- a/tests/phpunit/CRM/Group/Page/AjaxTest.php +++ b/tests/phpunit/CRM/Group/Page/AjaxTest.php @@ -125,16 +125,16 @@ public function testGroupEditWithAndWithoutPermission() { $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); - $this->assertEquals('Contacts', $groups['data'][0]['links']); - $this->assertEquals('Contacts', $groups['data'][1]['links']); + $this->assertEquals('Contacts', $groups['data'][0]['links']); + $this->assertEquals('Contacts', $groups['data'][1]['links']); // as per changes made in PR-6822 $this->setPermissionAndRequest(array('view all contacts', 'edit groups')); $params = $this->_params; $groups = CRM_Contact_BAO_Group::getGroupListSelector($params); $this->assertEquals(2, $groups['recordsTotal']); - $this->assertEquals('ContactsSettingsmore', $groups['data'][0]['links']); - $this->assertEquals('ContactsSettingsmore', $groups['data'][1]['links']); + $this->assertEquals('ContactsSettingsmore', $groups['data'][0]['links']); + $this->assertEquals('ContactsSettingsmore', $groups['data'][1]['links']); } /**