diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index f6b437397584..082268caa391 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -260,6 +260,11 @@ public static function where(&$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 @@ public static function buildSearchForm(&$form) { $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 @@ public static function buildSearchForm(&$form) { $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 f65c8d00f86d..0ef4b211273d 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -100,8 +100,7 @@ public function preProcess() { $this->loadFormValues(); if ($this->_force) { - $this->postProcess(); - $this->set('force', 0); + $this->handleForcedSearch(); } $sortID = NULL; @@ -213,7 +212,6 @@ public function postProcess() { $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 @@ public function fixFormValues() { } } - /** - * @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 6f7cc442d644..0fccc113f3cf 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1595,6 +1595,8 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals '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 2ff9287b8266..936209fbc889 100644 --- a/CRM/Upgrade/Incremental/SmartGroups.php +++ b/CRM/Upgrade/Incremental/SmartGroups.php @@ -68,6 +68,8 @@ public function datePickerConversion($fields) { '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 1dc223b15087..7dfb1026f95e 100644 --- a/CRM/Upgrade/Incremental/php/FiveTwenty.php +++ b/CRM/Upgrade/Incremental/php/FiveTwenty.php @@ -95,6 +95,22 @@ public function upgrade_5_20_alpha1($rev) { } $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 8447d56e05d8..54128fe420a1 100644 --- a/templates/CRM/Case/Form/Search/Common.tpl +++ b/templates/CRM/Case/Form/Search/Common.tpl @@ -38,16 +38,10 @@ </tr> <tr> - <td> - <label>{ts}Case Start Date{/ts}</label> - </td> - {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"} </tr> <tr> - <td> - <label>{ts}Case End Date{/ts}</label> - </td> - {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"} </tr> <tr id='case_search_form'>