Skip to content

Commit

Permalink
Toward CRM-19751: conditionally change On-Hold criteria to select on …
Browse files Browse the repository at this point in the history
…Advanced Search form.
  • Loading branch information
twomice committed Nov 13, 2018
1 parent e2669e8 commit 38056b3
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 7 deletions.
5 changes: 3 additions & 2 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1635,8 +1635,9 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
}
}
elseif ($id == 'email_on_hold') {
if ($formValues['email_on_hold']['on_hold']) {
$params[] = array('on_hold', '=', $formValues['email_on_hold']['on_hold'], 0, 0);
if ($onHoldValue = CRM_Utils_Array::value('email_on_hold', $formValues)) {
$onHoldValue = (array) $onHoldValue;
$params[] = array('on_hold', 'IN', $onHoldValue, 0, 0);
}
}
elseif (substr($id, 0, 7) == 'custom_'
Expand Down
10 changes: 7 additions & 3 deletions CRM/Contact/Form/Search/Criteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ public static function basic(&$form) {
$form->addRadio('privacy_toggle', ts('Privacy Options'), $options, array('allowClear' => FALSE));

// preferred communication method

$onHold[] = $form->createElement('advcheckbox', 'on_hold', NULL, '');
$form->addGroup($onHold, 'email_on_hold', ts('Email On Hold'));
if (Civi::settings()->get('civimail_multiple_bulk_emails')) {
$form->addSelect('email_on_hold',
array('entity' => 'email', 'multiple' => 'multiple', 'label' => ts('Email On Hold'), 'options' => CRM_Core_PseudoConstant::emailOnHoldOptions()));
}
else {
$form->add('advcheckbox', 'email_on_hold', ts('Email On Hold'));
}

$form->addSelect('preferred_communication_method',
array('entity' => 'contact', 'multiple' => 'multiple', 'label' => ts('Preferred Communication Method'), 'option_url' => NULL, 'placeholder' => ts('- any -')));
Expand Down
8 changes: 8 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveNine.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NU
* an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
*/
public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
if ($rev == '5.9.0') {
$args = array(
1 => ts('Enable multiple bulk email address for a contact'),
2 => ts('Email on Hold'),
);
$postUpgradeMessage .= '<p>' . ts('If the setting "%1" is enabled, you should update any smart groups based on the "%2" field.', $args) . '</p>';
}

// Example: Generate a post-upgrade message.
// if ($rev == '5.12.34') {
// $postUpgradeMessage .= '<br /><br />' . ts("By default, CiviCRM now disables the ability to import directly from SQL. To use this feature, you must explicitly grant permission 'import SQL datasource'.");
Expand Down
1 change: 1 addition & 0 deletions CRM/Upgrade/Incremental/sql/5.9.0.mysql.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{* file to handle db changes in 5.9.0 during upgrade *}
2 changes: 1 addition & 1 deletion settings/Mailing.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
'title' => ts('Enable multiple bulk email address for a contact.'),
'is_domain' => 1,
'is_contact' => 0,
'description' => ts('CiviMail will deliver a copy of the email to each bulk email listed for the contact.'),
'description' => ts('CiviMail will deliver a copy of the email to each bulk email listed for the contact. Enabling this setting will also change the options for the "Email on Hold" field in Advanced Search.'),
'help_text' => NULL,
),
'include_message_id' => array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
{$form.preferred_communication_method.html}
<br/>

{if $form.email_on_hold}
{if $form.email_on_hold.type == 'select'}
<br/>
{$form.email_on_hold.label}
<br/>
{$form.email_on_hold.html}
<br/>
{elseif $form.email_on_hold.type == 'checkbox'}
<div class="spacer"></div>
{$form.email_on_hold.html}
{$form.email_on_hold.label}
Expand Down
62 changes: 62 additions & 0 deletions tests/phpunit/CRM/Contact/Form/Search/CriteriaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2018 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
* Test class for CRM_Contact_Form_Search_Criteria
*
* @package CiviCRM
* @group headless
*/
class CRM_Contact_Form_Search_CriteraTest extends CiviUnitTestCase {

/**
* Test that the 'multiple bulk email' setting correctly affects the type of
* field used for the 'email on hold' criteria in Advanced Search.
*/
public function testAdvancedHSearchObservesMultipleBulkEmailSetting() {

// If setting is enabled, criteria should be a select element.
Civi::settings()->set('civimail_multiple_bulk_emails', 1);
$form = new CRM_Contact_Form_Search_Advanced();
$form->controller = new CRM_Contact_Controller_Search();
$form->preProcess();
$form->buildQuickForm();
$onHoldElemenClass = (get_class($form->_elements[$form->_elementIndex['email_on_hold']]));
$this->assertEquals('HTML_QuickForm_select', $onHoldElemenClass, 'civimail_multiple_bulk_emails setting = 1, so email_on_hold should be a select element.');

// If setting is disabled, criteria should be a checkbox.
Civi::settings()->set('civimail_multiple_bulk_emails', 0);
$form = new CRM_Contact_Form_Search_Advanced();
$form->controller = new CRM_Contact_Controller_Search();
$form->preProcess();
$form->buildQuickForm();
$onHoldElemenClass = (get_class($form->_elements[$form->_elementIndex['email_on_hold']]));
$this->assertEquals('HTML_QuickForm_advcheckbox', $onHoldElemenClass, 'civimail_multiple_bulk_emails setting = 0, so email_on_hold should be a checkbox.');
}

}

0 comments on commit 38056b3

Please sign in to comment.