From: eileen Date: Fri, 14 Feb 2020 04:42:17 +0000 (+1300) Subject: dev/core#1592 fix regression on relation active period X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c47a23654e09efc839dde425d59caa092d1881ef;p=civicrm-core.git dev/core#1592 fix regression on relation active period Per https://lab.civicrm.org/dev/core/issues/1592 the custom query for this field is being ignored now it's using datepicker with relevant format changes. This causes the custom function for the field to be called --- diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 0f0a1644db..570a3735ab 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4215,7 +4215,7 @@ WHERE $smartGroupClause } $this->_qill[$grouping][] = 'Relationship Type(s) ' . $relQill . " $name"; } - else { + elseif ($name) { $this->_qill[$grouping][] = $name; } } @@ -7074,22 +7074,22 @@ AND displayRelType.is_active = 1 $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. @@ -7099,11 +7099,6 @@ AND displayRelType.is_active = 1 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]), - ]) . ')'; } } @@ -7231,4 +7226,27 @@ AND displayRelType.is_active = 1 } } + /** + * 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), + ]) . ')'; + } + }