Skip to content

Commit

Permalink
Merge pull request #12658 from eileenmcnaughton/report_function
Browse files Browse the repository at this point in the history
[NFC] Minor function extraction in report class.
  • Loading branch information
eileenmcnaughton authored Aug 14, 2018
2 parents 28a1c87 + 62491db commit 505bff5
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -2699,39 +2699,7 @@ public function storeWhereHavingClauseArray() {
if (!empty($field['pseudofield'])) {
continue;
}
$clause = NULL;
if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
if (CRM_Utils_Array::value('operatorType', $field) ==
CRM_Report_Form::OP_MONTH
) {
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
$value = CRM_Utils_Array::value("{$fieldName}_value", $this->_params);
if (is_array($value) && !empty($value)) {
$clause
= "(month({$field['dbAlias']}) $op (" . implode(', ', $value) .
'))';
}
}
else {
$relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
$from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
$to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
$fromTime = CRM_Utils_Array::value("{$fieldName}_from_time", $this->_params);
$toTime = CRM_Utils_Array::value("{$fieldName}_to_time", $this->_params);
$clause = $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type'], $fromTime, $toTime);
}
}
else {
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
if ($op) {
$clause = $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
);
}
}
$clause = $this->generateFilterClause($field, $fieldName);

if (!empty($clause)) {
if (!empty($field['having'])) {
Expand Down Expand Up @@ -5795,4 +5763,50 @@ protected function getSelectClauseWithGroupConcatIfNotGroupedBy($tableName, &$fi
}
}

/**
* Generate clause for the selected filter.
*
* @param array $field
* Field specification
* @param string $fieldName
* Field name.
*
* @return string
* Relevant where clause.
*/
protected function generateFilterClause($field, $fieldName) {
if (CRM_Utils_Array::value('type', $field) & CRM_Utils_Type::T_DATE) {
if (CRM_Utils_Array::value('operatorType', $field) ==
CRM_Report_Form::OP_MONTH
) {
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
$value = CRM_Utils_Array::value("{$fieldName}_value", $this->_params);
if (is_array($value) && !empty($value)) {
return "(month({$field['dbAlias']}) $op (" . implode(', ', $value) .
'))';
}
}
else {
$relative = CRM_Utils_Array::value("{$fieldName}_relative", $this->_params);
$from = CRM_Utils_Array::value("{$fieldName}_from", $this->_params);
$to = CRM_Utils_Array::value("{$fieldName}_to", $this->_params);
$fromTime = CRM_Utils_Array::value("{$fieldName}_from_time", $this->_params);
$toTime = CRM_Utils_Array::value("{$fieldName}_to_time", $this->_params);
return $this->dateClause($field['dbAlias'], $relative, $from, $to, $field['type'], $fromTime, $toTime);
}
}
else {
$op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params);
if ($op) {
return $this->whereClause($field,
$op,
CRM_Utils_Array::value("{$fieldName}_value", $this->_params),
CRM_Utils_Array::value("{$fieldName}_min", $this->_params),
CRM_Utils_Array::value("{$fieldName}_max", $this->_params)
);
}
}
return '';
}

}

0 comments on commit 505bff5

Please sign in to comment.