);
CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
+ $form->addElement('hidden', 'activity_date_range_error');
+ $form->addFormRule(array('CRM_Activity_BAO_Query', 'formRule'), $form);
+
$followUpActivity = array(
1 => ts('Yes'),
2 => ts('No'),
return $properties;
}
+ /**
+ * 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['activity_date_low']) || empty($fields['activity_date_high'])) {
+ return TRUE;
+ }
+ $lowDate = strtotime($fields['activity_date_low']);
+ $highDate = strtotime($fields['activity_date_high']);
+
+ if ($lowDate > $highDate) {
+ $errors['activity_date_range_error'] = ts('Please check that your Activity Date Range is in correct chronological order.');
+ }
+ return empty($errors) ? TRUE : $errors;
+ }
}