From: Saurabh Batra Date: Fri, 4 Mar 2016 08:43:02 +0000 (+0530) Subject: Fix date range search for Activity X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c55d8350cf771b29cc81f632126dcaf444a44398;p=civicrm-core.git Fix date range search for Activity --- diff --git a/CRM/Activity/BAO/Query.php b/CRM/Activity/BAO/Query.php index 2f241f9a48..52c98c257d 100644 --- a/CRM/Activity/BAO/Query.php +++ b/CRM/Activity/BAO/Query.php @@ -415,6 +415,9 @@ class CRM_Activity_BAO_Query { ); 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'), @@ -555,4 +558,27 @@ class CRM_Activity_BAO_Query { 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; + } }