From 0058ef3f2335ac23d87a910b91c6a59fe7c4781d Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 28 Oct 2019 13:14:46 +1100 Subject: [PATCH] dev/core#561 Convert mailing date search field to using datepicker Some more cleanup and also open tab if specified in the URL --- CRM/Contact/BAO/Query.php | 1 + CRM/Contact/BAO/SavedSearch.php | 1 - CRM/Contact/Form/Search.php | 3 +++ CRM/Core/Form/Search.php | 4 +-- CRM/Mailing/BAO/Query.php | 27 +------------------- CRM/Upgrade/Incremental/SmartGroups.php | 1 + CRM/Upgrade/Incremental/php/FiveTwenty.php | 4 +++ templates/CRM/Mailing/Form/Search/Common.tpl | 2 +- 8 files changed, 13 insertions(+), 30 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index accaf6bc0cf5..8b8506b3c30e 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1597,6 +1597,7 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals 'membership_end_date_relative', 'case_start_date_relative', 'case_end_date_relative', + 'mailing_job_start_date_relative', ]; // Handle relative dates first foreach (array_keys($formValues) as $id) { diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index e53b6bf5fd7b..4215c09b73de 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -402,7 +402,6 @@ public static function saveRelativeDates(&$queryParams, $formValues) { 'log_date_relative', 'birth_date_relative', 'deceased_date_relative', - 'mailing_date_relative', 'relation_date_relative', 'relation_start_date_relative', 'relation_end_date_relative', diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 96fb7810d070..4db0e2ea0efa 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -652,6 +652,9 @@ public function preProcess() { 'mailing_unsubscribe', 'mailing_date_low', 'mailing_date_high', + 'mailing_job_start_date_low', + 'mailing_job_start_date_high', + 'mailing_job_start_date_relative', ] as $mailingFilter) { $type = 'String'; if ($mailingFilter == 'mailing_id' && diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 50499e9a5127..c698c6d78555 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -183,9 +183,9 @@ public function addFormFieldsFromMetadata() { foreach ($this->getSearchFieldMetadata() as $entity => $fields) { foreach ($fields as $fieldName => $fieldSpec) { $fieldType = $fieldSpec['type'] ?? ''; - if ($fieldType === CRM_Utils_Type::T_DATE || $fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) { + if ($fieldType === CRM_Utils_Type::T_DATE || $fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) || $fieldType === CRM_Utils_Type::T_TIMESTAMP) { $title = empty($fieldSpec['unique_title']) ? $fieldSpec['title'] : $fieldSpec['unique_title']; - $this->addDatePickerRange($fieldName, $title, ($fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME))); + $this->addDatePickerRange($fieldName, $title, ($fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) || $fieldType === CRM_Utils_Type::T_TIMESTAMP)); } else { // Not quite sure about moving to a mix of keying by entity vs permitting entity to diff --git a/CRM/Mailing/BAO/Query.php b/CRM/Mailing/BAO/Query.php index 348415c1807d..42bd4f9a3a26 100644 --- a/CRM/Mailing/BAO/Query.php +++ b/CRM/Mailing/BAO/Query.php @@ -136,7 +136,7 @@ public static function select(&$query) { * rather than a static function. */ public static function getSearchFieldMetadata() { - $fields = []; + $fields = ['mailing_job_start_date']; $metadata = civicrm_api3('Mailing', 'getfields', [])['values']; $metadata = array_merge($metadata, civicrm_api3('MailingJob', 'getfields', [])['values']); return array_intersect_key($metadata, array_flip($fields)); @@ -427,10 +427,6 @@ public static function buildSearchForm(&$form) { ); } - CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE); - $form->addElement('hidden', 'mailing_date_range_error'); - $form->addFormRule(['CRM_Mailing_BAO_Query', 'formRule'], $form); - $mailingJobStatuses = [ '' => ts('- select -'), 'Complete' => 'Complete', @@ -517,25 +513,4 @@ public static function mailingEventQueryBuilder(&$query, &$values, $tableName, $ $query->_tables[$tableName] = $query->_whereTables[$tableName] = 1; } - /** - * Check if the values in the date range are in correct chronological order. - * - * @param array $fields - * @param array $files - * @param CRM_Core_Form $form - * - * @return bool|array - */ - public static function formRule($fields, $files, $form) { - $errors = []; - - if (empty($fields['mailing_date_high']) || empty($fields['mailing_date_low'])) { - return TRUE; - } - - CRM_Utils_Rule::validDateRange($fields, 'mailing_date', $errors, ts('Mailing Date')); - - return empty($errors) ? TRUE : $errors; - } - } diff --git a/CRM/Upgrade/Incremental/SmartGroups.php b/CRM/Upgrade/Incremental/SmartGroups.php index 936209fbc889..89b701b66d40 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -70,6 +70,7 @@ public function datePickerConversion($fields) { 'pledge_start_date' => 'pledge_start', 'case_start_date' => 'case_from', 'case_end_date' => 'case_to', + 'mailing_job_start_date' => 'mailing_date', ]; foreach ($fields as $field) { diff --git a/CRM/Upgrade/Incremental/php/FiveTwenty.php b/CRM/Upgrade/Incremental/php/FiveTwenty.php index 7dfb1026f95e..ec31ca91c9c2 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwenty.php +++ b/CRM/Upgrade/Incremental/php/FiveTwenty.php @@ -103,12 +103,16 @@ public function upgrade_5_20_alpha1($rev) { ['old' => 'case_to_relative', 'new' => 'case_end_date_relative'], ['old' => 'case_to_end_date_high', 'new' => 'case_end_date_high'], ['old' => 'case_to_end_date_low', 'new' => 'case_end_date_low'], + ['old' => 'mailing_date_relative', 'new' => 'mailing_job_start_date_relative'], + ['old' => 'mailing_date_high', 'new' => 'mailing_job_start_date_high'], + ['old' => 'mailing_date_low', 'new' => 'mailing_job_start_date_low'], ], ]); $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [ 'datepickerConversion' => [ 'case_start_date', 'case_end_date', + 'mailing_job_start_date', ], ]); } diff --git a/templates/CRM/Mailing/Form/Search/Common.tpl b/templates/CRM/Mailing/Form/Search/Common.tpl index a309a36c1bb8..bbf1ce3904a0 100644 --- a/templates/CRM/Mailing/Form/Search/Common.tpl +++ b/templates/CRM/Mailing/Form/Search/Common.tpl @@ -12,7 +12,7 @@ -{include file="CRM/Core/DateRange.tpl" fieldName="mailing_date" from='_low' to='_high'} +{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="mailing_job_start_date"}