Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21392 Allow viewing groups/smartgroups as as other entities (eg. memberships, events) #11241

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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(
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 @@ -102,6 +102,16 @@ public static function tasks() {
'class' => 'CRM_Member_Form_Task_PDFLetter',
'result' => FALSE,
),
self::SAVE_SEARCH => array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattwire this is the part of the change I'm focussed on

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton Yes, I'm pretty sure it does. When I added it to CRM/Member/Task I was being cautious but ideally we'd move this into CRM_Core_Task - not sure I've time to thoroughly test that change though at the moment but the groundwork should all be in place for that to be done in the future.

'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
8 changes: 4 additions & 4 deletions tests/phpunit/CRM/Group/Page/AjaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ public function testGroupEditWithAndWithoutPermission() {
$params = $this->_params;
$groups = CRM_Contact_BAO_Group::getGroupListSelector($params);
$this->assertEquals(2, $groups['recordsTotal']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=4" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a></span>', $groups['data'][0]['links']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=2" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a></span>', $groups['data'][1]['links']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=4&amp;component_mode=1" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a></span>', $groups['data'][0]['links']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=2&amp;component_mode=1" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a></span>', $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('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=4" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=update&amp;id=4" class="action-item crm-hover-button" title=\'Edit Group\' >Settings</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="#" class="action-item crm-hover-button crm-enable-disable" title=\'Disable Group\' >Disable</a></li><li><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=delete&amp;id=4" class="action-item crm-hover-button small-popup" title=\'Delete Group\' >Delete</a></li></ul></span>', $groups['data'][0]['links']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=2" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=update&amp;id=2" class="action-item crm-hover-button" title=\'Edit Group\' >Settings</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="#" class="action-item crm-hover-button crm-enable-disable" title=\'Disable Group\' >Disable</a></li><li><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=delete&amp;id=2" class="action-item crm-hover-button small-popup" title=\'Delete Group\' >Delete</a></li></ul></span>', $groups['data'][1]['links']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=4&amp;component_mode=1" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=update&amp;id=4" class="action-item crm-hover-button" title=\'Edit Group\' >Settings</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="#" class="action-item crm-hover-button crm-enable-disable" title=\'Disable Group\' >Disable</a></li><li><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=delete&amp;id=4" class="action-item crm-hover-button small-popup" title=\'Delete Group\' >Delete</a></li></ul></span>', $groups['data'][0]['links']);
$this->assertEquals('<span><a href="/index.php?q=civicrm/group/search&amp;reset=1&amp;force=1&amp;context=smog&amp;gid=2&amp;component_mode=1" class="action-item crm-hover-button" title=\'Group Contacts\' >Contacts</a><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=update&amp;id=2" class="action-item crm-hover-button" title=\'Edit Group\' >Settings</a></span><span class=\'btn-slide crm-hover-button\'>more<ul class=\'panel\'><li><a href="#" class="action-item crm-hover-button crm-enable-disable" title=\'Disable Group\' >Disable</a></li><li><a href="/index.php?q=civicrm/group&amp;reset=1&amp;action=delete&amp;id=2" class="action-item crm-hover-button small-popup" title=\'Delete Group\' >Delete</a></li></ul></span>', $groups['data'][1]['links']);
}

/**
Expand Down