From 62491db8e4fb5299cef60f61fd63bdf4266a93ea Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 14 Aug 2018 14:39:06 +1200 Subject: [PATCH] Minor function extraction in report class. This mirrors a similar refactor in the extended reports class (which also allows it to be called from more than one place --- CRM/Report/Form.php | 80 ++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 33 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index f3dbf456e8..a5b5e448b4 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -2699,39 +2699,7 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND 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'])) { @@ -5795,4 +5763,50 @@ LEFT JOIN civicrm_contact {$field['alias']} ON {$field['alias']}.id = {$this->_a } } + /** + * 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 ''; + } + } -- 2.25.1