Skip to content

Commit

Permalink
Optimizing code
Browse files Browse the repository at this point in the history
  • Loading branch information
francescbassas committed May 22, 2017
1 parent eea5db8 commit 02633eb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
8 changes: 5 additions & 3 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -4210,22 +4210,24 @@ public function addRelationshipActivePeriodClauses($grouping, &$where) {

$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;
}
}

/**
Expand Down
8 changes: 1 addition & 7 deletions CRM/Report/Form/Contact/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,15 +815,9 @@ public function activeClause(
$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;
}

Expand Down

0 comments on commit 02633eb

Please sign in to comment.