+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
*/
class CRM_Contact_Form_Search_Custom_TagContributions extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
* @param array $formValues
*/
public function __construct(&$formValues) {
- $this->_formValues = $formValues;
+ $this->_formValues = self::formatSavedSearchFields($formValues);
$this->_permissionedComponent = 'CiviContribute';
/**
* Define the columns for search result rows
*/
- $this->_columns = array(
+ $this->_columns = [
ts('Contact ID') => 'contact_id',
ts('Full Name') => 'sort_name',
ts('First Name') => 'first_name',
ts('Last Name') => 'last_name',
ts('Tag') => 'tag_name',
ts('Totals') => 'amount',
- );
+ ];
}
/**
* 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'));
- $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
+ $form->add('datepicker', 'start_date', ts('Contribution Date From'), [], FALSE, ['time' => FALSE]);
+ $form->add('datepicker', 'end_date', ts('...through'), [], FALSE, ['time' => FALSE]);
+ $tag = ['' => ts('- any tag -')] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', ['onlyActive' => FALSE]);
$form->addElement('select', 'tag', ts('Tagged'), $tag);
/**
* If you are using the sample template, this array tells the template fields to render
* for the search form.
*/
- $form->assign('elements', array('start_date', 'end_date', 'tag'));
+ $form->assign('elements', ['start_date', 'end_date', 'tag']);
}
/**
* WHERE clause is an array built from any required JOINS plus conditional filters based on search criteria field values
*
*/
+
/**
* @param bool $includeContactIDs
*
* @return string
*/
public function where($includeContactIDs = FALSE) {
- $clauses = array();
+ $clauses = [];
$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);
}
if ($includeContactIDs) {
- $contactIDs = array();
+ $contactIDs = [];
foreach ($this->_formValues as $id => $value) {
if ($value &&
substr($id, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX
return implode(' AND ', $clauses);
}
-
/*
* Functions below generally don't need to be modified
*/
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 = [
+ '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;
+ }
+
}