Skip to content

Commit

Permalink
Merge pull request #16537 from civicrm/5.23
Browse files Browse the repository at this point in the history
5.23
  • Loading branch information
eileenmcnaughton authored Feb 14, 2020
2 parents 6e7a095 + 52f3fe4 commit 83ed307
Showing 1 changed file with 36 additions and 14 deletions.
50 changes: 36 additions & 14 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,10 @@ public function whereClauseSingle(&$values, $isForcePrimaryOnly = FALSE) {
(substr($values[0], 0, 10) === 'financial_') ||
(substr($values[0], 0, 8) === 'payment_') ||
(substr($values[0], 0, 11) === 'membership_')
// temporary fix for regression https://lab.civicrm.org/dev/core/issues/1551
// ideally the metadata would allow this field to be parsed below & the special handling would not
// be needed.
|| $values[0] === 'mailing_id'
) {
return;
}
Expand Down Expand Up @@ -4215,7 +4219,7 @@ public function relationship(&$values) {
}
$this->_qill[$grouping][] = 'Relationship Type(s) ' . $relQill . " $name";
}
else {
elseif ($name) {
$this->_qill[$grouping][] = $name;
}
}
Expand Down Expand Up @@ -7074,22 +7078,22 @@ protected function buildRelativeDateQuery(&$values) {
$secondWhere = str_replace('civicrm_contact.', 'contact_a.', $secondWhere);
}

$this->_qill[$grouping][] = $this->getQillForRelativeDateRange($dates[0], $dates[1], $fieldSpec['title'], $filters[$value]);
if ($fieldName === 'relation_active_period_date') {
// Hack this to fix regression https://lab.civicrm.org/dev/core/issues/1592
// Not sure the 'right' fix.
$this->_where[$grouping] = [self::getRelationshipActivePeriodClauses($dates[0], $dates[1], TRUE)];
return;
}

if (empty($dates[0])) {
// ie. no start date we only have end date
$this->_where[$grouping][] = $secondWhere . " <= '{$dates[1]}'";

$this->_qill[$grouping][] = ts('%1 is ', [$fieldSpec['title']]) . $filters[$value] . ' (' . ts("to %1", [
CRM_Utils_Date::customFormat($dates[1]),
]) . ')';
}
elseif (empty($dates[1])) {

// ie. no end date we only have start date
$this->_where[$grouping][] = $where . " >= '{$dates[0]}'";

$this->_qill[$grouping][] = ts('%1 is ', [$fieldSpec['title']]) . $filters[$value] . ' (' . ts("from %1", [
CRM_Utils_Date::customFormat($dates[0]),
]) . ')';
}
else {
// we have start and end dates.
Expand All @@ -7099,11 +7103,6 @@ protected function buildRelativeDateQuery(&$values) {
else {
$this->_where[$grouping][] = $where . " BETWEEN '{$dates[0]}' AND '{$dates[1]}'";
}

$this->_qill[$grouping][] = ts('%1 is ', [$fieldSpec['title']]) . $filters[$value] . ' (' . ts("between %1 and %2", [
CRM_Utils_Date::customFormat($dates[0]),
CRM_Utils_Date::customFormat($dates[1]),
]) . ')';
}
}

Expand Down Expand Up @@ -7231,4 +7230,27 @@ public function handleWhereFromMetadata($fieldSpec, $name, $value, $op, $groupin
}
}

/**
* Get the qill for the relative date range.
*
* @param string|null $from
* @param string|null $to
* @param string $fieldTitle
* @param string $relativeRange
*
* @return string
*/
protected function getQillForRelativeDateRange($from, $to, string $fieldTitle, string $relativeRange): string {
if (!$from) {
return ts('%1 is ', [$fieldTitle]) . $relativeRange . ' (' . ts('to %1', [CRM_Utils_Date::customFormat($to)]) . ')';
}
if (!$to) {
return ts('%1 is ', [$fieldTitle]) . $relativeRange . ' (' . ts('from %1', [CRM_Utils_Date::customFormat($from)]) . ')';
}
return ts('%1 is ', [$fieldTitle]) . $relativeRange . ' (' . ts('between %1 and %2', [
CRM_Utils_Date::customFormat($from),
CRM_Utils_Date::customFormat($to),
]) . ')';
}

}

0 comments on commit 83ed307

Please sign in to comment.