From 7db38accf42317661cc68020ea7de1fd87e63866 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 26 Apr 2013 17:56:01 +1200 Subject: [PATCH] CRM-12432 make split out the extracting of where functions from the construction of the where clause --- CRM/Report/Form.php | 59 +++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/CRM/Report/Form.php b/CRM/Report/Form.php index 5fcac3d674..6e69bb9fe4 100644 --- a/CRM/Report/Form.php +++ b/CRM/Report/Form.php @@ -228,6 +228,8 @@ class CRM_Report_Form extends CRM_Core_Form { public $_columnHeaders = array(); public $_orderBy = NULL; public $_groupBy = NULL; + public $_whereClauses = array(); + public $_havingClauses = array(); /** * Variable to hold the currency alias @@ -1804,7 +1806,33 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND } function where() { - $whereClauses = $havingClauses = array(); + $this->storeWhereHavingClauseArray(); + + if (empty($this->_whereClauses)) { + $this->_where = "WHERE ( 1 ) "; + $this->_having = ""; + } + else { + $this->_where = "WHERE " . implode(' AND ', $this->_whereClauses); + } + + if ($this->_aclWhere) { + $this->_where .= " AND {$this->_aclWhere} "; + } + + if (!empty($this->_havingClauses)) { + // use this clause to construct group by clause. + $this->_having = "HAVING " . implode(' AND ', $this->_havingClauses); + } + } + + /** + * Store Where clauses into an array - breaking out this step makes + * over-riding more flexible as the clauses can be used in constructing a + * temp table that may not be part of the final where clause or added + * in other functions + */ + function storeWhereHavingClauseArray(){ foreach ($this->_columns as $tableName => $table) { if (array_key_exists('filters', $table)) { foreach ($table['filters'] as $fieldName => $field) { @@ -1830,44 +1858,27 @@ WHERE cg.extends IN ('" . implode("','", $this->_customGroupExtends) . "') AND $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) + $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) ); } } if (!empty($clause)) { if (CRM_Utils_Array::value('having', $field)) { - $havingClauses[] = $clause; + $this->_havingClauses[] = $clause; } else { - $whereClauses[] = $clause; + $this->_whereClauses[] = $clause; } } } } } - if (empty($whereClauses)) { - $this->_where = "WHERE ( 1 ) "; - $this->_having = ""; - } - else { - $this->_where = "WHERE " . implode(' AND ', $whereClauses); - } - - if ($this->_aclWhere) { - $this->_where .= " AND {$this->_aclWhere} "; - } - - if (!empty($havingClauses)) { - // use this clause to construct group by clause. - $this->_having = "HAVING " . implode(' AND ', $havingClauses); - } } - function processReportMode() { $buttonName = $this->controller->getButtonName(); -- 2.25.1