From: Saurabh Batra Date: Fri, 4 Mar 2016 07:58:36 +0000 (+0530) Subject: Fix search date range for Cases. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=26bf6298e32bc57e52c0d0a75d213da12b1eabd4;p=civicrm-core.git Fix search date range for Cases. --- diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index 503d6f0121..76bad1fc96 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -688,6 +688,10 @@ case_relation_type.id = case_relationship.relationship_type_id )"; 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_date_range_error'); + $form->addElement('hidden', 'case_to_date_range_error'); + $form->addFormRule(array('CRM_Case_BAO_Query', 'formRule'), $form); + $form->assign('validCiviCase', TRUE); @@ -738,4 +742,35 @@ case_relation_type.id = case_relationship.relationship_type_id )"; public static function searchAction(&$row, $id) { } + /** + * 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['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; + } + $lowDate = strtotime($fields['case_from_start_date_low']); + $highDate = strtotime($fields['case_from_start_date_high']); + + if ($lowDate > $highDate) { + $errors['case_from_date_range_error'] = ts('Please check that your Case Start Date Range is in correct chronological order.'); + } + + $lowDate = strtotime($fields['case_to_end_date_low']); + $highDate = strtotime($fields['case_to_end_date_high']); + + if ($lowDate > $highDate) { + $errors['case_to_date_range_error'] = ts('Please check that your Case End Date Range is in correct chronological order.'); + } + return empty($errors) ? TRUE : $errors; + } + }