From: Saurabh Batra Date: Fri, 4 Mar 2016 08:08:46 +0000 (+0530) Subject: Fix Date Range search for Mailing search. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e512e4b5da6612f811e333a930ed66a0c21aa9d3;p=civicrm-core.git Fix Date Range search for Mailing search. --- diff --git a/CRM/Contribute/BAO/Query.php b/CRM/Contribute/BAO/Query.php index 71ff84dd98..ab886b8877 100644 --- a/CRM/Contribute/BAO/Query.php +++ b/CRM/Contribute/BAO/Query.php @@ -1220,7 +1220,6 @@ class CRM_Contribute_BAO_Query { $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.'); } return empty($errors) ? TRUE : $errors; diff --git a/CRM/Mailing/BAO/Query.php b/CRM/Mailing/BAO/Query.php index 2cf2f04cd8..a0f4251bbd 100644 --- a/CRM/Mailing/BAO/Query.php +++ b/CRM/Mailing/BAO/Query.php @@ -407,6 +407,8 @@ class CRM_Mailing_BAO_Query { } CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE); + $form->addElement('hidden', 'mailing_date_range_error'); + $form->addFormRule(array('CRM_Mailing_BAO_Query', 'formRule'), $form); $mailingJobStatuses = array( '' => ts('- select -'), @@ -494,4 +496,28 @@ class CRM_Mailing_BAO_Query { $query->_tables[$tableName] = $query->_whereTables[$tableName] = 1; } + /** + * 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['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.'); + } + return empty($errors) ? TRUE : $errors; + } + }