From 8794d2b8f17e627457bce3ac7013f1690e6caa48 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 3 Dec 2018 08:03:20 +1100 Subject: [PATCH] Convert last 2 Custom searches to be converted --- CRM/Contact/Form/Search/Custom/DateAdded.php | 25 ++++++++++++++++++- .../Form/Search/Custom/TagContributions.php | 25 ++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CRM/Contact/Form/Search/Custom/DateAdded.php b/CRM/Contact/Form/Search/Custom/DateAdded.php index 34ec772f3c..91f414b641 100644 --- a/CRM/Contact/Form/Search/Custom/DateAdded.php +++ b/CRM/Contact/Form/Search/Custom/DateAdded.php @@ -44,7 +44,7 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C * @param array $formValues */ public function __construct(&$formValues) { - parent::__construct($formValues); + $this->_formValues = self::formatSavedSearchFields($formValues); $this->_includeGroups = CRM_Utils_Array::value('includeGroups', $formValues, array()); $this->_excludeGroups = CRM_Utils_Array::value('excludeGroups', $formValues, array()); @@ -458,4 +458,27 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C 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/TagContributions.php b/CRM/Contact/Form/Search/Custom/TagContributions.php index fdeeb49922..03905537cc 100644 --- a/CRM/Contact/Form/Search/Custom/TagContributions.php +++ b/CRM/Contact/Form/Search/Custom/TagContributions.php @@ -43,7 +43,7 @@ class CRM_Contact_Form_Search_Custom_TagContributions extends CRM_Contact_Form_S * @param array $formValues */ public function __construct(&$formValues) { - $this->_formValues = $formValues; + $this->_formValues = self::formatSavedSearchFields($formValues); $this->_permissionedComponent = 'CiviContribute'; /** @@ -282,4 +282,27 @@ WHERE $where 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