Skip to content

Commit

Permalink
Add search option to view groups as other components
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Nov 17, 2017
1 parent 10519dc commit 653b01e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 38 deletions.
13 changes: 9 additions & 4 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,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();
Expand Down Expand Up @@ -1279,12 +1279,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(
Expand Down
13 changes: 12 additions & 1 deletion CRM/Group/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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])
Expand Down
1 change: 1 addition & 0 deletions CRM/Group/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions CRM/Member/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,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
Expand Down
79 changes: 46 additions & 33 deletions templates/CRM/Group/Form/Search.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,57 @@
+--------------------------------------------------------------------+
*}
<div class="crm-block crm-form-block crm-group-search-form-block">

<h3>{ts}Find Groups{/ts}</h3>
<table class="form-layout">
<tr>
<td>
{$form.title.label}<br />
{$form.title.html}<br />
<span class="description font-italic">
<div class="crm-accordion-wrapper crm-search_builder-accordion {if $rows and !$showSearchForm}collapsed{/if}">
<div class="crm-accordion-header crm-master-accordion-header">
{ts}Find Groups{/ts}
</div>
<div class="crm-accordion-body">
<div id="searchForm">
<table class="form-layout">
<tr>
<td>
{$form.title.label}<br />
{$form.title.html}<br />
<span class="description font-italic">
{ts}Complete OR partial group name.{/ts}
</span>
</td>
<td>
{$form.created_by.label}<br />
{$form.created_by.html}<br />
<span class="description font-italic">
</td>
<td>
{$form.created_by.label}<br />
{$form.created_by.html}<br />
<span class="description font-italic">
{ts}Complete OR partial creator name.{/ts}
</span>
</td>
<td id="group_type-block">
{$form.group_type_search.label}<br />
{$form.group_type_search.html}<br />
<span class="description font-italic">
{ts}Filter search by group type(s).{/ts}
</span>
</td>
<td>
{$form.visibility.label}<br />
{$form.visibility.html}<br />
<span class="description font-italic">
</td>
<td>
{$form.visibility.label}<br />
{$form.visibility.html}<br />
<span class="description font-italic">
{ts}Filter search by visibility.{/ts}
</span>
</td>
<td>
{$form.group_status.label}<br />
{$form.group_status.html}
</td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td id="group_type-block">
{$form.group_type_search.label}<br />
{$form.group_type_search.html}<br />
<span class="description font-italic">
{ts}Filter search by group type(s).{/ts}
</span>
</td>
<td>
{$form.group_status.label}<br />
{$form.group_status.html}
</td>
<td>
{$form.component_mode.label}<br />
{$form.component_mode.html}
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="css_right">
<a class="crm-hover-button action-item" href="{crmURL q="reset=1&update_smart_groups=1"}">{ts}Update Smart Group Counts{/ts}</a> {help id="update_smart_groups"}
</div>
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 653b01e

Please sign in to comment.