From 8a6fde27c69f5e6e51fa91060fa67124d9ca9e18 Mon Sep 17 00:00:00 2001 From: eileen Date: Sat, 25 May 2019 20:00:30 +1200 Subject: [PATCH] [jcalendar] remove jcalendar usage from participant_register_date on event search This removes one more place where legacy jcalendar is used. There is actually still one left on the form (event date) which I left out for now as it involves thinking about the fact event is a different entity & might warrant different representation in the arrays --- CRM/Contact/BAO/Query.php | 25 ++++++++++----------- CRM/Contact/BAO/SavedSearch.php | 2 -- CRM/Core/Form/Search.php | 2 +- CRM/Event/BAO/Query.php | 12 ++-------- CRM/Event/Form/Search.php | 3 ++- CRM/Upgrade/Incremental/php/FiveFifteen.php | 5 +++++ templates/CRM/Event/Form/Search/Common.tpl | 2 +- 7 files changed, 23 insertions(+), 28 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index ddabd4f3135a..e0c0bb867bc7 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -1553,23 +1553,21 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals } self::filterCountryFromValuesIfStateExists($formValues); - + // We shouldn't have to whitelist fields to not hack but here we are, for now. + $nonLegacyDateFields = ['participant_register_date_relative']; // Handle relative dates first foreach (array_keys($formValues) as $id) { - if (preg_match('/_date_relative$/', $id) || + if ( + !in_array($id, $nonLegacyDateFields) && ( + preg_match('/_date_relative$/', $id) || $id == 'event_relative' || $id == 'case_from_relative' || - $id == 'case_to_relative' || - $id == 'participant_relative' + $id == 'case_to_relative') ) { if ($id == 'event_relative') { $fromRange = 'event_start_date_low'; $toRange = 'event_end_date_high'; } - elseif ($id == 'participant_relative') { - $fromRange = 'participant_register_date_low'; - $toRange = 'participant_register_date_high'; - } elseif ($id == 'case_from_relative') { $fromRange = 'case_from_start_date_low'; $toRange = 'case_from_start_date_high'; @@ -1647,11 +1645,12 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals ) { self::convertCustomRelativeFields($formValues, $params, $values, $id); } - elseif (preg_match('/_date_relative$/', $id) || - $id == 'event_relative' || - $id == 'case_from_relative' || - $id == 'case_to_relative' || - $id == 'participant_relative' + elseif ( + !in_array($id, $nonLegacyDateFields) && ( + preg_match('/_date_relative$/', $id) || + $id == 'event_relative' || + $id == 'case_from_relative' || + $id == 'case_to_relative') ) { // Already handled in previous loop continue; diff --git a/CRM/Contact/BAO/SavedSearch.php b/CRM/Contact/BAO/SavedSearch.php index 049dcaf5170b..46886c641360 100644 --- a/CRM/Contact/BAO/SavedSearch.php +++ b/CRM/Contact/BAO/SavedSearch.php @@ -95,8 +95,6 @@ public static function getFormValues($id) { $specialDateFields = [ 'event_start_date_low' => 'event_date_low', 'event_end_date_high' => 'event_date_high', - 'participant_register_date_low' => 'participant_date_low', - 'participant_register_date_high' => 'participant_date_high', 'case_from_start_date_low' => 'case_from_date_low', 'case_from_start_date_high' => 'case_from_date_high', 'case_to_end_date_low' => 'case_to_date_low', diff --git a/CRM/Core/Form/Search.php b/CRM/Core/Form/Search.php index 5071980e4bcc..ffeaf99b4088 100644 --- a/CRM/Core/Form/Search.php +++ b/CRM/Core/Form/Search.php @@ -186,7 +186,7 @@ public static function formRule($fields, $files, $form) { foreach ($form->getSearchFieldMetadata() as $entity => $spec) { foreach ($spec as $fieldName => $fieldSpec) { if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || $fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) { - if (isset($fields[$fieldName . '_high']) && isset($fields[$fieldName . '_low']) && empty($fields[$fieldName . '_relative'])) { + if (!empty($fields[$fieldName . '_high']) && !empty($fields[$fieldName . '_low']) && empty($fields[$fieldName . '_relative'])) { if (strtotime($fields[$fieldName . '_low']) > strtotime($fields[$fieldName . '_high'])) { $errors[$fieldName . '_low'] = ts('%1: Please check that your date range is in correct chronological order.', [1 => $fieldSpec['title']]); } diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index 4d21ac4ea580..77fa886ea1f6 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -582,6 +582,7 @@ public static function defaultReturnProperties( public static function getSearchFieldMetadata() { $fields = [ 'participant_status_id', + 'participant_register_date', ]; $metadata = civicrm_api3('Participant', 'getfields', [])['values']; return array_intersect_key($metadata, array_flip($fields)); @@ -628,10 +629,7 @@ public static function buildSearchForm(&$form) { CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE); - CRM_Core_Form_Date::buildDateRange($form, 'participant', 1, '_register_date_low', '_register_date_high', ts('From'), FALSE); - $form->addElement('hidden', 'event_date_range_error'); - $form->addElement('hidden', 'participant_date_range_error'); $form->addFormRule(['CRM_Event_BAO_Query', 'formRule'], $form); $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', [1 => '%1'])); @@ -686,7 +684,7 @@ public static function tableNames(&$tables) { public static function formRule($fields, $files, $form) { $errors = []; - if ((empty($fields['event_start_date_low']) || empty($fields['event_end_date_high'])) && (empty($fields['participant_register_date_low']) || empty($fields['participant_register_date_high']))) { + if ((empty($fields['event_start_date_low']) || empty($fields['event_end_date_high']))) { return TRUE; } $lowDate = strtotime($fields['event_start_date_low']); @@ -696,12 +694,6 @@ public static function formRule($fields, $files, $form) { $errors['event_date_range_error'] = ts('Please check that your Event Date Range is in correct chronological order.'); } - $lowDate1 = strtotime($fields['participant_register_date_low']); - $highDate1 = strtotime($fields['participant_register_date_high']); - - if ($lowDate1 > $highDate1) { - $errors['participant_date_range_error'] = ts('Please check that your Registration Date Range is in correct chronological order.'); - } return empty($errors) ? TRUE : $errors; } diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index 4282764ef9b5..412590c22a54 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -77,8 +77,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search { */ protected $searchFieldMetadata = []; - /** + * Get the default entity for the form. + * * @return string */ public function getDefaultEntity() { diff --git a/CRM/Upgrade/Incremental/php/FiveFifteen.php b/CRM/Upgrade/Incremental/php/FiveFifteen.php index 95248a1a9f3c..17531c280dc0 100644 --- a/CRM/Upgrade/Incremental/php/FiveFifteen.php +++ b/CRM/Upgrade/Incremental/php/FiveFifteen.php @@ -76,6 +76,11 @@ public function upgrade_5_15_alpha1($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); $this->addTask('Fix errant deferred revenue settings', 'updateContributeSettings'); $this->addTask('Fix cache key column name in prev next cache', 'fixCacheKeyColumnNamePrevNext'); + $this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [ + 'datepickerConversion' => [ + 'participant_register_date', + ], + ]); } public static function fixCacheKeyColumnNamePrevNext() { diff --git a/templates/CRM/Event/Form/Search/Common.tpl b/templates/CRM/Event/Form/Search/Common.tpl index f44e7d5d4660..c4a66740ebaf 100644 --- a/templates/CRM/Event/Form/Search/Common.tpl +++ b/templates/CRM/Event/Form/Search/Common.tpl @@ -36,7 +36,7 @@ {include file="CRM/Core/DateRange.tpl" fieldName="event" from='_start_date_low' to='_end_date_high' label=""} - {include file="CRM/Core/DateRange.tpl" fieldName="participant" from='_register_date_low' to='_register_date_high' label=""} + {include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="participant_register_date" colspan="2"}