From 738d4d0b355c66720bb8f32a0937fd5149db1d00 Mon Sep 17 00:00:00 2001 From: Saurabh Batra Date: Fri, 4 Mar 2016 14:03:37 +0530 Subject: [PATCH] Fix date range validation for Events --- CRM/Event/BAO/Query.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/CRM/Event/BAO/Query.php b/CRM/Event/BAO/Query.php index cddba764ad..457652a2ae 100644 --- a/CRM/Event/BAO/Query.php +++ b/CRM/Event/BAO/Query.php @@ -611,6 +611,10 @@ class CRM_Event_BAO_Query { 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(array('CRM_Event_BAO_Query', 'formRule'), $form); + $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '%1'))); $form->addSelect('participant_status_id', @@ -677,4 +681,35 @@ class CRM_Event_BAO_Query { } } + /** + * 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 = array(); + + 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']))) { + return TRUE; + } + $lowDate = strtotime($fields['event_start_date_low']); + $highDate = strtotime($fields['event_end_date_high']); + + if ($lowDate > $highDate) { + $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; + } + } -- 2.25.1