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);
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;
+ }
+
}