Skip to content

Commit

Permalink
Rework on the relative and absolute dates
Browse files Browse the repository at this point in the history
  • Loading branch information
VangelisP committed Oct 21, 2019
1 parent f73c243 commit 940b14a
Showing 1 changed file with 45 additions and 36 deletions.
81 changes: 45 additions & 36 deletions CRM/Contact/Form/Search/Custom/ContributionAggregate.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
<?php

/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

/**
Expand Down Expand Up @@ -118,8 +119,7 @@ public function templateFile() {
* @return string
*/
public function all(
$offset = 0, $rowcount = 0, $sort = NULL,
$includeContactIDs = FALSE, $justIDs = FALSE
$offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE
) {

// SELECT clause must include contact_id as an alias for civicrm_contact.id
Expand Down Expand Up @@ -226,20 +226,29 @@ public function where($includeContactIDs = FALSE) {
);
}

foreach (CRM_Contact_BAO_Query::convertFormValues($dateParams) as $values) {
list($name, $op, $value) = $values;
if (strstr($name, '_low')) {
if (strlen($value) == 10) {
$value .= ' 00:00:00';
}
$clauses[] = "contrib.receive_date >= '{$value}'";
if ($dateParams['receive_date_relative']) {
list($relativeFrom, $relativeTo) = CRM_Utils_Date::getFromTo($dateParams['receive_date_relative'], $dateParams['receive_date_low'], $dateParams['receive_date_high']);
}
else {
if (strlen($dateParams['receive_date_low']) == 10) {
$relativeFrom = $dateParams['receive_date_low'] . ' 00:00:00';
}
else {
if (strlen($value) == 10) {
$value .= ' 23:59:59';
}
$clauses[] = "contrib.receive_date <= '{$value}'";
$relativeFrom = $dateParams['receive_date_low'];
}
if (strlen($dateParams['receive_date_high']) == 10) {
$relativeTo = $dateParams['receive_date_high'] . ' 23:59:59';
}
else {
$relativeTo = $dateParams['receive_date_high'];
}
}

if ($relativeFrom) {
$clauses[] = "contrib.receive_date >= '{$relativeFrom}'";
}
if ($relativeTo) {
$clauses[] = "contrib.receive_date <= '{$relativeTo}'";
}

if ($includeContactIDs) {
Expand Down

0 comments on commit 940b14a

Please sign in to comment.