From 687e42f65730ad81fe56d421714a3c076352865d Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Mon, 3 Dec 2018 07:53:59 +1100 Subject: [PATCH] dev/core#561 Convert DateAdded and Tagged Contributions custom searches to using datepicker rather than jcalendar --- CRM/Contact/Form/Search/Custom/DateAdded.php | 11 +++++------ .../Form/Search/Custom/TagContributions.php | 14 ++++++-------- templates/CRM/Contact/Form/Search/Custom.tpl | 6 +----- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/CRM/Contact/Form/Search/Custom/DateAdded.php b/CRM/Contact/Form/Search/Custom/DateAdded.php index 34ec772f3c..8db5c77683 100644 --- a/CRM/Contact/Form/Search/Custom/DateAdded.php +++ b/CRM/Contact/Form/Search/Custom/DateAdded.php @@ -61,8 +61,8 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C * @param CRM_Core_Form $form */ public function buildForm(&$form) { - $form->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'custom')); - $form->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'custom')); + $form->add('datepicker', 'start_date', ts('Start Date'), [], FALSE, array('time' => FALSE)); + $form->add('datepicker', 'end_date', ts('End Date'), [], FALSE, array('time' => FALSE)); $groups = CRM_Core_PseudoConstant::nestedGroup(); @@ -192,12 +192,11 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C } CRM_Core_DAO::executeQuery($sql); - $startDate = CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::processDate($this->_formValues['start_date'])); + $startDate = !empty($this->_formValues['start_date']) ? $this->_formValues['start_date'] : date('Y-m-d'); $endDateFix = NULL; if (!empty($this->_formValues['end_date'])) { - $endDate = CRM_Utils_Date::mysqlToIso(CRM_Utils_Date::processDate($this->_formValues['end_date'])); # tack 11:59pm on to make search inclusive of the end date - $endDateFix = "AND date_added <= '" . substr($endDate, 0, 10) . " 23:59:00'"; + $endDateFix = "AND date_added <= '{$this->_formValues['end_date']} 23:59:00'"; } $dateRange = "INSERT INTO {$this->_datesTable} ( id, date_added ) @@ -211,7 +210,7 @@ class CRM_Contact_Form_Search_Custom_DateAdded extends CRM_Contact_Form_Search_C GROUP BY civicrm_contact.id HAVING - date_added >= '$startDate' + date_added >= '$startDate 00:00:00' $endDateFix"; if ($this->_debug > 0) { diff --git a/CRM/Contact/Form/Search/Custom/TagContributions.php b/CRM/Contact/Form/Search/Custom/TagContributions.php index fdeeb49922..9e855130fd 100644 --- a/CRM/Contact/Form/Search/Custom/TagContributions.php +++ b/CRM/Contact/Form/Search/Custom/TagContributions.php @@ -73,8 +73,8 @@ class CRM_Contact_Form_Search_Custom_TagContributions extends CRM_Contact_Form_S * Define the search form fields here */ - $form->addDate('start_date', ts('Contribution Date From'), FALSE, array('formatType' => 'custom')); - $form->addDate('end_date', ts('...through'), FALSE, array('formatType' => 'custom')); + $form->add('datepicker', 'start_date', ts('Contribution Date From'), [], FALSE, array('time' => FALSE)); + $form->add('datepicker', 'end_date', ts('...through'), [], FALSE, array('time' => FALSE)); $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); $form->addElement('select', 'tag', ts('Tagged'), $tag); @@ -180,14 +180,12 @@ WHERE $where $clauses[] = "contact_a.contact_type = 'Individual'"; $clauses[] = "civicrm_contribution.contact_id = contact_a.id"; - $startDate = CRM_Utils_Date::processDate($this->_formValues['start_date']); - if ($startDate) { - $clauses[] = "civicrm_contribution.receive_date >= $startDate"; + if ($this->_formValues['start_date']) { + $clauses[] = "civicrm_contribution.receive_date >= '{$this->_formValues['start_date']} 00:00:00'"; } - $endDate = CRM_Utils_Date::processDate($this->_formValues['end_date']); - if ($endDate) { - $clauses[] = "civicrm_contribution.receive_date <= $endDate"; + if ($this->_formValues['end_date']) { + $clauses[] = "civicrm_contribution.receive_date <= '{$this->_formValues['end_date']} 23:59:59'"; } $tag = CRM_Utils_Array::value('tag', $this->_formValues); diff --git a/templates/CRM/Contact/Form/Search/Custom.tpl b/templates/CRM/Contact/Form/Search/Custom.tpl index 2e01271c56..34449bbce3 100644 --- a/templates/CRM/Contact/Form/Search/Custom.tpl +++ b/templates/CRM/Contact/Form/Search/Custom.tpl @@ -38,11 +38,7 @@ {foreach from=$elements item=element} {$form.$element.label} - {if $element|strstr:'_date'} - {include file="CRM/common/jcalendar.tpl" elementName=$element} - {else} - {$form.$element.html} - {/if} + {$form.$element.html} {/foreach} -- 2.25.1