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

dev/core#785 Differentiate smart group from regular group using icon in select2 field #17927

Merged
merged 1 commit into from
Jul 27, 2020
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
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE
}
}

if (array_key_exists('group', $params)) {
if (!empty($params['group'])) {
$contactIds = [$params['contact_id']];
foreach ($params['group'] as $groupId => $flag) {
if ($flag == 1) {
Expand Down
11 changes: 6 additions & 5 deletions CRM/Contact/BAO/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ public static function getGroupsHierarchy(
$groups = [];
$args = [1 => [$groupIdString, 'String']];
$query = "
SELECT id, title, description, visibility, parents
SELECT id, title, description, visibility, parents, saved_search_id
FROM civicrm_group
WHERE id IN $groupIdString
";
Expand All @@ -1081,15 +1081,15 @@ public static function getGroupsHierarchy(
$parent = self::filterActiveGroups($parentArray);
$tree[$parent][] = [
'id' => $dao->id,
'title' => $dao->title,
'title' => empty($dao->saved_search_id) ? $dao->title : '* ' . $dao->title,
'visibility' => $dao->visibility,
'description' => $dao->description,
];
}
else {
$roots[] = [
'id' => $dao->id,
'title' => $dao->title,
'title' => empty($dao->saved_search_id) ? $dao->title : '* ' . $dao->title,
'visibility' => $dao->visibility,
'description' => $dao->description,
];
Expand Down Expand Up @@ -1123,8 +1123,9 @@ private static function buildGroupHierarchy(&$hierarchy, $group, $tree, $titleOn
$hierarchy[$group['id']] = $spaces . $group['title'];
}
else {
$hierarchy[$group['id']] = [
'title' => $spaces . $group['title'],
$hierarchy[] = [
'id' => $group['id'],
Copy link
Contributor

Choose a reason for hiding this comment

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

The array() syntax seems to have come back. While I personally prefer array() the civi standard is now square brackets.

'text' => $spaces . $group['title'],
'description' => $group['description'],
'visibility' => $group['visibility'],
];
Expand Down
6 changes: 4 additions & 2 deletions CRM/Contact/Form/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,10 @@ public function postProcess() {
}

$group = $params['group'] ?? NULL;
if (!empty($group) && is_array($group)) {
unset($params['group']);
$params['group'] = ($params['group'] == '') ? [] : $params['group'];
if (!empty($group)) {
Copy link
Contributor

@demeritcowboy demeritcowboy Jul 24, 2020

Choose a reason for hiding this comment

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

CRM_Utils_Array::value is being mercilessly removed everywhere in civi. So it should be the original line $group = $params['group'] ?? NULL;

$group = is_array($group) ? $group : explode(',', $group);
$params['group'] = [];
foreach ($group as $key => $value) {
$params['group'][$value] = 1;
}
Expand Down
18 changes: 9 additions & 9 deletions CRM/Contact/Form/Edit/TagsAndGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ public static function buildQuickForm(
}

if ($groupElementType == 'select') {
$groupsOptions[$id] = $group['title'];
$groupsOptions[$id] = $group;
Copy link
Contributor

Choose a reason for hiding this comment

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

I just have one more thing: line 109 just below also needs title removed, e.g. if you add Group to a profile.

Copy link
Member Author

@monishdeb monishdeb Jul 27, 2020

Choose a reason for hiding this comment

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

@demeritcowboy actually its fine, because its affecting only the group select widget, which now takes the array of information instead of just group title, as now we are supporting select2. The reason why the entire $group array is set, Whereas for advanced checkbox widget, it still needs only the group title as per old behaivour.

Copy link
Contributor

Choose a reason for hiding this comment

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

Try adding group to a profile though and then using the profile.

Copy link
Member Author

Choose a reason for hiding this comment

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

oops my bad ... updated now

}
else {
$form->_tagGroup[$fName][$id]['description'] = $group['description'];
$elements[] = &$form->addElement('advcheckbox', $id, NULL, $group['title'], $attributes);
$elements[] = &$form->addElement('advcheckbox', $id, NULL, $group['text'], $attributes);
}
}

if ($groupElementType == 'select' && !empty($groupsOptions)) {
$form->add('select', $fName, $groupName, $groupsOptions, FALSE,
['id' => $fName, 'multiple' => 'multiple', 'class' => 'crm-select2 twenty']
$form->add('select2', $fName, $groupName, $groupsOptions, FALSE,
['placeholder' => '- select -', 'multiple' => TRUE, 'class' => 'twenty']
);
$form->assign('groupCount', count($groupsOptions));
}
Expand Down Expand Up @@ -166,11 +166,11 @@ public static function setDefaults($id, &$defaults, $type = self::ALL, $fieldNam

$contactGroup = CRM_Contact_BAO_GroupContact::getContactGroup($id, 'Added', NULL, FALSE, TRUE);
if ($contactGroup) {
foreach ($contactGroup as $group) {
if ($groupElementType == 'select') {
$defaults[$fName][] = $group['group_id'];
}
else {
if ($groupElementType == 'select') {
$defaults[$fName] = implode(',', CRM_Utils_Array::collect('group_id', $contactGroup));
}
else {
foreach ($contactGroup as $group) {
$defaults[$fName . '[' . $group['group_id'] . ']'] = 1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/GroupContact.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function buildQuickForm() {
if ($onlyPublicGroups && $group['visibility'] == 'User and User Admin Only') {
continue;
}
$allGroups[$id] = $group;
$allGroups[$group['id']] = $group;
}
}
else {
Expand Down
3 changes: 2 additions & 1 deletion CRM/Contact/Form/Search/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ public function buildQuickForm() {

// add select for groups
// Get hierarchical listing of groups, respecting ACLs for CRM-16836.
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '  ', TRUE);
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($this->_group, NULL, '  ');
if (!empty($searchOptions['groups'])) {
$this->addField('group', [
'entity' => 'group_contact',
'label' => ts('in'),
'placeholder' => ts('- any group -'),
'options' => $groupHierarchy,
'type' => 'Select2',
]);
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function basic(&$form) {
$groupHierarchy = CRM_Contact_BAO_Group::getGroupsHierarchy($form->_group, NULL, '  ', TRUE);

$form->add('select', 'group', ts('Groups'), $groupHierarchy, FALSE,
['id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2']
['id' => 'group', 'multiple' => 'multiple', 'class' => 'crm-select2']
);
$groupOptions = CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('group_type');
$form->add('select', 'group_type', ts('Group Types'), $groupOptions, FALSE,
Expand Down
13 changes: 9 additions & 4 deletions ang/crmMailing/Recipients.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,12 @@
}
var option = convertValueToObj(item.id);
var icon = (option.entity_type === 'civicrm_mailing') ? 'fa-envelope' : 'fa-users';
var smartGroupMarker = item.is_smart ? '* ' : '';
var spanClass = (option.mode == 'exclude') ? 'crmMailing-exclude' : 'crmMailing-include';
if (option.entity_type != 'civicrm_mailing' && isMandatory(option.entity_id)) {
spanClass = 'crmMailing-mandatory';
}
return '<i class="crm-i '+icon+'" aria-hidden="true"></i> <span class="' + spanClass + '">' + item.text + '</span>';
return '<i class="crm-i '+icon+'"></i> <span class="' + spanClass + '">' + smartGroupMarker + item.text + '</span>';
}

function validate() {
Expand Down Expand Up @@ -154,7 +155,7 @@
mids.push(0);
}

CRM.api3('Group', 'getlist', { params: { id: { IN: gids }, options: { limit: 0 } }, extra: ["is_hidden"] } ).then(
CRM.api3('Group', 'getlist', { params: { id: { IN: gids }, options: { limit: 0 } }, extra: ["is_hidden"] }).then(
function(glist) {
CRM.api3('Mailing', 'getlist', { params: { id: { IN: mids }, options: { limit: 0 } } }).then(
function(mlist) {
Expand All @@ -165,6 +166,7 @@

$(glist.values).each(function (idx, group) {
var key = group.id + ' civicrm_group include';

groupNames.push({id: parseInt(group.id), title: group.label, is_hidden: group.extra.is_hidden});
if (values.indexOf(key) >= 0) {
datamap.push({id: key, text: group.label});
Expand Down Expand Up @@ -232,6 +234,9 @@
if('civicrm_mailing' === rcpAjaxState.entity) {
params["api.MailingRecipients.getcount"] = {};
}
else if ('civicrm_group' === rcpAjaxState.entity) {
params.extra = ["saved_search_id"];
}

return params;
},
Expand All @@ -255,8 +260,8 @@
text: obj.label } : '';
}
else {
return { id: obj.id + ' ' + rcpAjaxState.entity + ' ' + rcpAjaxState.type,
text: obj.label };
return { id: obj.id + ' ' + rcpAjaxState.entity + ' ' + rcpAjaxState.type, text: obj.label,
is_smart: (!_.isEmpty(obj.extra.saved_search_id)) };
}
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testBrowseDisplaysCorrectListOfAVailableGroups() {
$group_id_field_html = $form['group_id']['html'];
$this->assertContains($publicSmartGroupTitle, $group_id_field_html, "Group '$publicSmartGroupTitle' should be in listed available groups, but is not.");
$this->assertContains($publicStdGroupTitle, $group_id_field_html, "Group '$publicStdGroupTitle' should be in listed available groups, but is not.");
$this->assertNotContains($adminSmartGroupTitle, $group_id_field_html, "Group '$adminSmartGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains('* ' . $adminSmartGroupTitle, $group_id_field_html, "Group '$adminSmartGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains($adminStdGroupTitle, $group_id_field_html, "Group '$adminStdGroupTitle' should not be in listed available groups, but is.");

// Add current user to the test groups.
Expand All @@ -199,9 +199,9 @@ public function testBrowseDisplaysCorrectListOfAVailableGroups() {

$form = CRM_Core_Smarty::singleton()->get_template_vars('form');
$group_id_field_html = $form['group_id']['html'];
$this->assertNotContains($publicSmartGroupTitle, $group_id_field_html, "Group '$publicSmartGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains('* ' . $publicSmartGroupTitle, $group_id_field_html, "Group '$publicSmartGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains($publicStdGroupTitle, $group_id_field_html, "Group '$publicStdGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains($adminSmartGroupTitle, $group_id_field_html, "Group '$adminSmartGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains('* ' . $adminSmartGroupTitle, $group_id_field_html, "Group '$adminSmartGroupTitle' should not be in listed available groups, but is.");
$this->assertNotContains($adminStdGroupTitle, $group_id_field_html, "Group '$adminStdGroupTitle' should not be in listed available groups, but is.");
}

Expand Down