From ac241c349f02ee6d01f45a0b1476a7dead72a237 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Mon, 25 Feb 2019 18:55:44 -0500 Subject: [PATCH] Upgrade age_asof_date to datepicker in search --- CRM/Contact/Form/Search/Criteria.php | 8 +- CRM/Upgrade/Incremental/Base.php | 8 +- CRM/Upgrade/Incremental/SmartGroups.php | 81 ++----------------- CRM/Upgrade/Incremental/php/FiveEleven.php | 9 ++- CRM/Upgrade/Incremental/php/FiveTwelve.php | 29 +++---- templates/CRM/Core/AgeRange.tpl | 22 ++--- .../CRM/Upgrade/Incremental/BaseTest.php | 11 ++- 7 files changed, 54 insertions(+), 114 deletions(-) diff --git a/CRM/Contact/Form/Search/Criteria.php b/CRM/Contact/Form/Search/Criteria.php index 019ee5f3da..7862472f7f 100644 --- a/CRM/Contact/Form/Search/Criteria.php +++ b/CRM/Contact/Form/Search/Criteria.php @@ -494,7 +494,7 @@ class CRM_Contact_Form_Search_Criteria { } /** - * @param $form + * @param CRM_Core_Form_Search $form */ public static function demographics(&$form) { $form->add('hidden', 'hidden_demographics', 1); @@ -509,11 +509,11 @@ class CRM_Contact_Form_Search_Criteria { } $form->addGroup($genderOptions, 'gender_id', ts('Gender'))->setAttribute('allowClear', TRUE); - $form->add('text', 'age_low', ts('Min Age'), array('size' => 6)); + $form->add('number', 'age_low', ts('Min Age'), ['class' => 'four', 'min' => 0]); $form->addRule('age_low', ts('Please enter a positive integer'), 'positiveInteger'); - $form->add('text', 'age_high', ts('Max Age'), array('size' => 6)); + $form->add('number', 'age_high', ts('Max Age'), ['class' => 'four', 'min' => 0]); $form->addRule('age_high', ts('Please enter a positive integer'), 'positiveInteger'); - $form->addDate('age_asof_date', ts('Age as of Date'), FALSE, array('formatType' => 'searchDate')); + $form->add('datepicker', 'age_asof_date', ts('As of'), NULL, FALSE, ['time' => FALSE]); CRM_Core_Form_Date::buildDateRange($form, 'birth_date', 1, '_low', '_high', ts('From'), FALSE, FALSE, 'birth'); diff --git a/CRM/Upgrade/Incremental/Base.php b/CRM/Upgrade/Incremental/Base.php index 5a7770673b..4d53374bd2 100644 --- a/CRM/Upgrade/Incremental/Base.php +++ b/CRM/Upgrade/Incremental/Base.php @@ -199,13 +199,13 @@ class CRM_Upgrade_Incremental_Base { * Do any relevant smart group updates. * * @param CRM_Queue_TaskContext $ctx - * @param string $version + * @param array $actions * * @return bool */ - public function updateSmartGroups($ctx, $version) { - $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups($version); - $groupUpdateObject->updateGroups(); + public function updateSmartGroups($ctx, $actions) { + $groupUpdateObject = new CRM_Upgrade_Incremental_SmartGroups(); + $groupUpdateObject->updateGroups($actions); return TRUE; } diff --git a/CRM/Upgrade/Incremental/SmartGroups.php b/CRM/Upgrade/Incremental/SmartGroups.php index c22daf3941..c2161f4302 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -35,56 +35,12 @@ class CRM_Upgrade_Incremental_SmartGroups { /** - * Version we are upgrading to. - * - * @var string - */ - protected $upgradeVersion; - - /** - * @return string - */ - public function getUpgradeVersion() { - return $this->upgradeVersion; - } - - /** - * @param string $upgradeVersion - */ - public function setUpgradeVersion($upgradeVersion) { - $this->upgradeVersion = $upgradeVersion; - } - - /** - * CRM_Upgrade_Incremental_MessageTemplates constructor. - * - * @param string $upgradeVersion - */ - public function __construct($upgradeVersion) { - $this->setUpgradeVersion($upgradeVersion); - } - - /** - * Get any conversions required for saved smart groups. - * - * @return array + * Perform updates specified by upgrade function. */ - public function getSmartGroupConversions() { - return [ - [ - 'version' => '5.11.alpha1', - 'upgrade_descriptors' => [ts('Upgrade grant smart groups to datepicker format')], - 'actions' => [ - 'function' => 'datepickerConversion', - 'fields' => [ - 'grant_application_received_date', - 'grant_decision_date', - 'grant_money_transfer_date', - 'grant_due_date' - ] - ] - ] - ]; + public function updateGroups($actions) { + foreach ($actions as $func => $fields) { + $this->{$func}($fields); + } } /** @@ -118,33 +74,6 @@ class CRM_Upgrade_Incremental_SmartGroups { } } - /** - * Update message templates. - */ - public function updateGroups() { - $conversions = $this->getSmartGroupConversionsToApply(); - foreach ($conversions as $conversion) { - $function = $conversion['function']; - $this->{$function}($conversion['fields']); - } - } - - /** - * Get any required template updates. - * - * @return array - */ - public function getSmartGroupConversionsToApply() { - $conversions = $this->getSmartGroupConversions(); - $return = []; - foreach ($conversions as $conversion) { - if ($conversion['version'] === $this->getUpgradeVersion()) { - $return[] = $conversion['actions']; - } - } - return $return; - } - /** * Get converted date value. * diff --git a/CRM/Upgrade/Incremental/php/FiveEleven.php b/CRM/Upgrade/Incremental/php/FiveEleven.php index 1335f4ed35..ed3e296d03 100644 --- a/CRM/Upgrade/Incremental/php/FiveEleven.php +++ b/CRM/Upgrade/Incremental/php/FiveEleven.php @@ -74,7 +74,14 @@ class CRM_Upgrade_Incremental_php_FiveEleven extends CRM_Upgrade_Incremental_Bas */ public function upgrade_5_11_alpha1($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); - $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', $rev); + $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [ + 'datepickerConversion' => [ + 'grant_application_received_date', + 'grant_decision_date', + 'grant_money_transfer_date', + 'grant_due_date' + ] + ]); } } diff --git a/CRM/Upgrade/Incremental/php/FiveTwelve.php b/CRM/Upgrade/Incremental/php/FiveTwelve.php index 6cea3934b1..e514d65329 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwelve.php +++ b/CRM/Upgrade/Incremental/php/FiveTwelve.php @@ -67,21 +67,18 @@ class CRM_Upgrade_Incremental_php_FiveTwelve extends CRM_Upgrade_Incremental_Bas * (change the x in the function name): */ - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } - - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_12_alpha1($rev) { + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); + $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [ + 'datepickerConversion' => [ + 'age_asof_date', + ] + ]); + } } diff --git a/templates/CRM/Core/AgeRange.tpl b/templates/CRM/Core/AgeRange.tpl index a76ad74a97..beddf36277 100644 --- a/templates/CRM/Core/AgeRange.tpl +++ b/templates/CRM/Core/AgeRange.tpl @@ -37,22 +37,22 @@ {$form.$maxName.html} - - - {assign var=dateName value=$fieldName|cat:$date} - {$form.$dateName.label} - {include file="CRM/common/jcalendar.tpl" elementName=$dateName} + {assign var=dateName value=$fieldName|cat:$date} + {$form.$dateName.label} + {$form.$dateName.html} {literal} {/literal} diff --git a/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php b/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php index 7137e61e94..b3a3af7429 100644 --- a/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php +++ b/tests/phpunit/CRM/Upgrade/Incremental/BaseTest.php @@ -90,8 +90,15 @@ class CRM_Upgrade_Incremental_BaseTest extends CiviUnitTestCase { ['grant_due_date_low', '=', '01/22/2019'], ] ]); - $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups('5.11.alpha1'); - $smartGroupConversionObject->updateGroups(); + $smartGroupConversionObject = new CRM_Upgrade_Incremental_SmartGroups(); + $smartGroupConversionObject->updateGroups([ + 'datepickerConversion' => [ + 'grant_application_received_date', + 'grant_decision_date', + 'grant_money_transfer_date', + 'grant_due_date' + ] + ]); $savedSearch = $this->callAPISuccessGetSingle('SavedSearch', []); $this->assertEquals('grant_application_received_date_high', $savedSearch['form_values'][0][0]); $this->assertEquals('2019-01-20 00:00:00', $savedSearch['form_values'][0][2]); -- 2.25.1