From 02633eb09e38eb74dde0e6e0009e727317e76797 Mon Sep 17 00:00:00 2001 From: Francesc Bassas i Bullich Date: Mon, 22 May 2017 17:15:49 +0200 Subject: [PATCH] Optimizing code https://github.com/civicrm/civicrm-core/pull/10333#discussion_r117754757 --- CRM/Contact/BAO/Query.php | 8 +++++--- CRM/Report/Form/Contact/Relationship.php | 8 +------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 9aa3310298..6060fa1c83 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -4210,22 +4210,24 @@ civicrm_relationship.is_permission_a_b = 0 $dateValueLow = $this->getWhereValues('relation_active_period_date_low', $grouping); $dateValueHigh = $this->getWhereValues('relation_active_period_date_high', $grouping); + $dateValueLowFormated = $dateValueHighFormated = NULL; if (!empty($dateValueLow) && !empty($dateValueHigh)) { $dateValueLowFormated = date('Ymd', strtotime($dateValueLow[2])); $dateValueHighFormated = date('Ymd', strtotime($dateValueHigh[2])); - $where[$grouping][] = self::getRelationshipActivePeriodClauses($dateValueLowFormated, $dateValueHighFormated, TRUE); $this->_qill[$grouping][] = (ts('Relationship was active between')) . " " . CRM_Utils_Date::customFormat($dateValueLowFormated) . " and " . CRM_Utils_Date::customFormat($dateValueHighFormated); } elseif (!empty($dateValueLow)) { $dateValueLowFormated = date('Ymd', strtotime($dateValueLow[2])); - $where[$grouping][] = self::getRelationshipActivePeriodClauses($dateValueLowFormated, NULL, TRUE); $this->_qill[$grouping][] = (ts('Relationship was active after')) . " " . CRM_Utils_Date::customFormat($dateValueLowFormated); } elseif (!empty($dateValueHigh)) { $dateValueHighFormated = date('Ymd', strtotime($dateValueHigh[2])); - $where[$grouping][] = self::getRelationshipActivePeriodClauses(NULL, $dateValueHighFormated, TRUE); $this->_qill[$grouping][] = (ts('Relationship was active before')) . " " . CRM_Utils_Date::customFormat($dateValueHighFormated); } + + if ($activePeriodClauses = self::getRelationshipActivePeriodClauses($dateValueLowFormated, $dateValueHighFormated, TRUE)) { + $where[$grouping][] = $activePeriodClauses; + } } /** diff --git a/CRM/Report/Form/Contact/Relationship.php b/CRM/Report/Form/Contact/Relationship.php index 46aa82cd12..64ef965811 100644 --- a/CRM/Report/Form/Contact/Relationship.php +++ b/CRM/Report/Form/Contact/Relationship.php @@ -815,15 +815,9 @@ class CRM_Report_Form_Contact_Relationship extends CRM_Report_Form { $to = ($type == CRM_Utils_Type::T_DATE) ? substr($to, 0, 8) : $to; } - if ($from && $to) { + if ($from || $to) { return CRM_Contact_BAO_Query::getRelationshipActivePeriodClauses($from, $to, FALSE); } - elseif ($from) { - return CRM_Contact_BAO_Query::getRelationshipActivePeriodClauses($from, NULL, FALSE); - } - elseif ($to) { - return CRM_Contact_BAO_Query::getRelationshipActivePeriodClauses(NULL, $to, FALSE); - } return NULL; } -- 2.25.1