}
/**
- * Check if the values in the date range are in correct chronological order.
+ * Custom form rules.
*
* @param array $fields
* @param array $files
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.');
- }
+ CRM_Utils_Rule::validDateRange($fields, 'activity_date', $errors, ts('Activity Date'));
+
return empty($errors) ? TRUE : $errors;
}
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->addElement('hidden', 'case_from_start_date_range_error');
+ $form->addElement('hidden', 'case_to_end_date_range_error');
$form->addFormRule(array('CRM_Case_BAO_Query', 'formRule'), $form);
$form->assign('validCiviCase', TRUE);
}
/**
- * Check if the values in the date range are in correct chronological order.
+ * Custom form rules.
*
* @param array $fields
* @param array $files
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.');
- }
-
- $lowDate1 = strtotime($fields['case_to_end_date_low']);
- $highDate1 = strtotime($fields['case_to_end_date_high']);
+ CRM_Utils_Rule::validDateRange($fields, 'case_from_start_date', $errors, ts('Case Start Date'));
+ CRM_Utils_Rule::validDateRange($fields, 'case_to_end_date', $errors, ts('Case End Date'));
- if ($lowDate1 > $highDate1) {
- $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;
}
}
/**
- * Check if the values in the date range are in correct chronological order.
+ * Custom form rules.
*
* @param array $fields
* @param array $files
if (empty($fields['contribution_date_high']) || empty($fields['contribution_date_low'])) {
return TRUE;
}
- $lowDate = strtotime($fields['contribution_date_low']);
- $highDate = strtotime($fields['contribution_date_high']);
- if ($lowDate > $highDate) {
- $errors['contribution_date_range_error'] = ts('Please check that your Date Range is in correct chronological order.');
- }
+ CRM_Utils_Rule::validDateRange($fields, 'contribution_date', $errors, ts('Date Received'));
+
return empty($errors) ? TRUE : $errors;
}
/**
* Check if the values in the date range are in correct chronological order.
*
+ * @todo Get this to work with CRM_Utils_Rule::validDateRange
+ *
* @param array $fields
* @param array $files
* @param CRM_Core_Form $form
if (empty($fields['mailing_date_high']) || empty($fields['mailing_date_low'])) {
return TRUE;
}
- $lowDate = strtotime($fields['mailing_date_low']);
- $highDate = strtotime($fields['mailing_date_high']);
- if ($lowDate > $highDate) {
- $errors['mailing_date_range_error'] = ts('Please check that your Date Range is in correct chronological order.');
- }
+ CRM_Utils_Rule::validDateRange($fields, 'mailing_date', $errors, ts('Mailing Date'));
+
return empty($errors) ? TRUE : $errors;
}
}
/**
- * Check if the values in the date range are in correct chronological order.
- * @todo Find a better way to implement this validation when multiple date ranges are present.
+ * Custom form rules.
*
* @param array $fields
* @param array $files
if ((empty($fields['member_join_date_low']) || empty($fields['member_join_date_high'])) && (empty($fields['member_start_date_low']) || empty($fields['member_start_date_high'])) && (empty($fields['member_end_date_low']) || empty($fields['member_end_date_high']))) {
return TRUE;
}
- $lowDate = strtotime($fields['member_join_date_low']);
- $highDate = strtotime($fields['member_join_date_high']);
- if ($lowDate > $highDate) {
- $errors['member_join_date_range_error'] = ts('Please check that your Member Since Date Range is in correct chronological order.');
- }
-
- $lowDate1 = strtotime($fields['member_start_date_low']);
- $highDate1 = strtotime($fields['member_start_date_high']);
- if ($lowDate1 > $highDate1) {
- $errors['member_start_date_range_error'] = ts('Please check that your Start Date Range is in correct chronological order.');
- }
-
- $lowDate2 = strtotime($fields['member_end_date_low']);
- $highDate2 = strtotime($fields['member_end_date_high']);
- if ($lowDate2 > $highDate2) {
- $errors['member_end_date_range_error'] = ts('Please check that your End Date Range is in correct chronological order.');
- }
+ CRM_Utils_Rule::validDateRange($fields, 'member_join_date', $errors, ts('Member Since'));
+ CRM_Utils_Rule::validDateRange($fields, 'member_start_date', $errors, ts('Start Date'));
+ CRM_Utils_Rule::validDateRange($fields, 'member_end_date', $errors, ts('End Date'));
return empty($errors) ? TRUE : $errors;
}
return ($key) ? CRM_Core_Key::valid($key) : FALSE;
}
+ /**
+ * Check if the values in the date range are in correct chronological order.
+ *
+ * @param array $fields
+ * Fields of the form.
+ * @param $fieldName
+ * Name of date range field.
+ * @param $errors
+ * The error array.
+ * @param $title
+ * Title of the date range to be displayed in the error message.
+ */
+ public static function validDateRange($fields, $fieldName, &$errors, $title) {
+ $lowDate = strtotime($fields[$fieldName . '_low']);
+ $highDate = strtotime($fields[$fieldName . '_high']);
+
+ if ($lowDate > $highDate) {
+ $errors[$fieldName . '_range_error'] = ts('%1: Please check that your date range is in correct chronological order.', array(1 => $title));
+ }
+ }
+
}