From b8c40ec09ae7a303ad9df02d0077a2ac5aedd8c2 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 3 Dec 2018 09:55:11 +1300 Subject: [PATCH] Add custom search handling for jcalendar converstion. I used the methodology from ContribSybunt. I duplicated rather than shared it because I think the future of these searches is to be more separated from each ohter --- .../Form/Search/Custom/ActivitySearch.php | 26 ++++++++++++++++++- .../Form/Search/Custom/ContribSYBNT.php | 6 ++++- .../Form/Search/Custom/EventAggregate.php | 26 ++++++++++++++++++- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/CRM/Contact/Form/Search/Custom/ActivitySearch.php b/CRM/Contact/Form/Search/Custom/ActivitySearch.php index da9f880910..27c3ed98fe 100644 --- a/CRM/Contact/Form/Search/Custom/ActivitySearch.php +++ b/CRM/Contact/Form/Search/Custom/ActivitySearch.php @@ -42,7 +42,7 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea * @param array $formValues */ public function __construct(&$formValues) { - $this->_formValues = $formValues; + $this->_formValues = self::formatSavedSearchFields($formValues); /** * Define the columns for search result rows @@ -419,4 +419,28 @@ ORDER BY contact_a.sort_name'; list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias); } + /** + * Format saved search fields for this custom group. + * + * Note this is a function to facilitate the transition to jcalendar for + * saved search groups. In time it can be stripped out again. + * + * @param array $formValues + * + * @return array + */ + public static function formatSavedSearchFields($formValues) { + $dateFields = array( + 'start_date', + 'end_date', + ); + foreach ($formValues as $element => $value) { + if (in_array($element, $dateFields) && !empty($value)) { + $formValues[$element] = date('Y-m-d', strtotime($value)); + } + } + + return $formValues; + } + } diff --git a/CRM/Contact/Form/Search/Custom/ContribSYBNT.php b/CRM/Contact/Form/Search/Custom/ContribSYBNT.php index 8a8703800d..377d41f3a3 100644 --- a/CRM/Contact/Form/Search/Custom/ContribSYBNT.php +++ b/CRM/Contact/Form/Search/Custom/ContribSYBNT.php @@ -399,10 +399,14 @@ AND c.receive_date < {$this->start_date_1} } /** - * Format saved search fields for this custom group + * Format saved search fields for this custom group. + * + * Note this is a function to facilitate the transition to jcalendar for + * saved search groups. In time it can be stripped out again. * * @param array $formValues * + * @return array */ public static function formatSavedSearchFields($formValues) { $dateFields = array( diff --git a/CRM/Contact/Form/Search/Custom/EventAggregate.php b/CRM/Contact/Form/Search/Custom/EventAggregate.php index dc90e5932a..d3fe3b936a 100644 --- a/CRM/Contact/Form/Search/Custom/EventAggregate.php +++ b/CRM/Contact/Form/Search/Custom/EventAggregate.php @@ -43,7 +43,7 @@ class CRM_Contact_Form_Search_Custom_EventAggregate extends CRM_Contact_Form_Sea * @param array $formValues */ public function __construct(&$formValues) { - $this->_formValues = $formValues; + $this->_formValues = self::formatSavedSearchFields($formValues); $this->_permissionedComponent = array('CiviContribute', 'CiviEvent'); /** @@ -373,4 +373,28 @@ class CRM_Contact_Form_Search_Custom_EventAggregate extends CRM_Contact_Form_Sea list($this->_aclFrom, $this->_aclWhere) = CRM_Contact_BAO_Contact_Permission::cacheClause($tableAlias); } + /** + * Format saved search fields for this custom group. + * + * Note this is a function to facilitate the transition to jcalendar for + * saved search groups. In time it can be stripped out again. + * + * @param array $formValues + * + * @return array + */ + public static function formatSavedSearchFields($formValues) { + $dateFields = array( + 'start_date', + 'end_date', + ); + foreach ($formValues as $element => $value) { + if (in_array($element, $dateFields) && !empty($value)) { + $formValues[$element] = date('Y-m-d', strtotime($value)); + } + } + + return $formValues; + } + } -- 2.25.1