From 7d832c0c541b28a6aa2bd25b30475028ee7159cb Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 26 Oct 2019 11:07:52 +1100 Subject: [PATCH] dev/core#561 Convert Case date fields on search forms from jcalendar to datepicker Swap to using buildDateRangeQuery function Fix notice error and generically handle cases where we have specified to use the LIKE operator for strings --- CRM/Case/BAO/Query.php | 33 ++++------------------ CRM/Case/Form/Search.php | 11 +------- CRM/Contact/BAO/Query.php | 2 ++ CRM/Upgrade/Incremental/SmartGroups.php | 2 ++ CRM/Upgrade/Incremental/php/FiveTwenty.php | 16 +++++++++++ templates/CRM/Case/Form/Search/Common.tpl | 10 ++----- 6 files changed, 28 insertions(+), 46 deletions(-) diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index f6b4373975..082268caa3 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -260,6 +260,11 @@ class CRM_Case_BAO_Query extends CRM_Core_BAO_Query { * @param CRM_Contact_BAO_Query $query */ public static function whereClauseSingle(&$values, &$query) { + if ($query->buildDateRangeQuery($values)) { + // @todo - move this to Contact_Query in or near the call to + // $this->buildRelativeDateQuery($values); + return; + } list($name, $op, $value, $grouping, $wildcard) = $values; $val = $names = []; switch ($name) { @@ -718,12 +723,6 @@ case_relation_type.id = case_relationship.relationship_type_id )"; $form->addSearchFieldMetadata(['Case' => self::getSearchFieldMetadata()]); $form->addFormFieldsFromMetadata(); - CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); - CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); - $form->addElement('hidden', 'case_from_start_date_range_error'); - $form->addElement('hidden', 'case_to_end_date_range_error'); - $form->addFormRule(['CRM_Case_BAO_Query', 'formRule'], $form); - $form->assign('validCiviCase', TRUE); //give options when all cases are accessible. @@ -752,26 +751,4 @@ case_relation_type.id = case_relationship.relationship_type_id )"; $form->setDefaults(['case_owner' => 1]); } - /** - * Custom form rules. - * - * @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['case_from_start_date_low']) || empty($fields['case_from_start_date_high'])) && (empty($fields['case_to_end_date_low']) || empty($fields['case_to_end_date_high']))) { - return TRUE; - } - - CRM_Utils_Rule::validDateRange($fields, 'case_from_start_date', $errors, ts('Case Start Date')); - CRM_Utils_Rule::validDateRange($fields, 'case_to_end_date', $errors, ts('Case End Date')); - - return empty($errors) ? TRUE : $errors; - } - } diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index f65c8d00f8..0ef4b21127 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -100,8 +100,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $this->loadFormValues(); if ($this->_force) { - $this->postProcess(); - $this->set('force', 0); + $this->handleForcedSearch(); } $sortID = NULL; @@ -213,7 +212,6 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { $this->_done = TRUE; $this->setFormValues(); $this->fixFormValues(); - if (isset($this->_ssID) && empty($_POST)) { // if we are editing / running a saved search and the form has not been posted $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); @@ -385,13 +383,6 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search { } } - /** - * @return null - */ - public function getFormValues() { - return NULL; - } - /** * Return a descriptive name for the page, used in wizard header * diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 6f7cc442d6..0fccc113f3 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1595,6 +1595,8 @@ class CRM_Contact_BAO_Query { 'membership_join_date_relative', 'membership_start_date_relative', 'membership_end_date_relative', + 'case_start_date_relative', + 'case_end_date_relative', ]; // Handle relative dates first foreach (array_keys($formValues) as $id) { diff --git a/CRM/Upgrade/Incremental/SmartGroups.php b/CRM/Upgrade/Incremental/SmartGroups.php index 2ff9287b82..936209fbc8 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -68,6 +68,8 @@ class CRM_Upgrade_Incremental_SmartGroups { 'pledge_create_date' => 'pledge_create', 'pledge_end_date' => 'pledge_end', 'pledge_start_date' => 'pledge_start', + 'case_start_date' => 'case_from', + 'case_end_date' => 'case_to', ]; foreach ($fields as $field) { diff --git a/CRM/Upgrade/Incremental/php/FiveTwenty.php b/CRM/Upgrade/Incremental/php/FiveTwenty.php index 1dc223b150..7dfb1026f9 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwenty.php +++ b/CRM/Upgrade/Incremental/php/FiveTwenty.php @@ -95,6 +95,22 @@ class CRM_Upgrade_Incremental_php_FiveTwenty extends CRM_Upgrade_Incremental_Bas } $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); $this->addTask('Add "Template" contribution status', 'templateStatus'); + $this->addTask('Update smart groups to rename filters on case_from and case_to to case_start_date and case_end_date', 'updateSmartGroups', [ + 'renameField' => [ + ['old' => 'case_from_relative', 'new' => 'case_start_date_relative'], + ['old' => 'case_from_start_date_high', 'new' => 'case_start_date_high'], + ['old' => 'case_from_start_date_low', 'new' => 'case_start_date_low'], + ['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'], + ], + ]); + $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [ + 'datepickerConversion' => [ + 'case_start_date', + 'case_end_date', + ], + ]); } public static function templateStatus(CRM_Queue_TaskContext $ctx) { diff --git a/templates/CRM/Case/Form/Search/Common.tpl b/templates/CRM/Case/Form/Search/Common.tpl index 8447d56e05..54128fe420 100644 --- a/templates/CRM/Case/Form/Search/Common.tpl +++ b/templates/CRM/Case/Form/Search/Common.tpl @@ -38,16 +38,10 @@ - - - - {include file="CRM/Core/DateRange.tpl" fieldName="case_from" from='_start_date_low' to='_start_date_high'} + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="case_start_date"} - - - - {include file="CRM/Core/DateRange.tpl" fieldName="case_to" from='_end_date_low' to='_end_date_high'} + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="case_end_date"} -- 2.25.1