/** * @param Tx_PtExtlist_Domain_QueryObject_Query $groupDataQuery * @param array $excludeFilters * @param Tx_PtExtlist_Domain_Configuration_Filters_FilterConfig $filterConfig * @return string */ protected function buildGroupDataQuery(Tx_PtExtlist_Domain_QueryObject_Query $groupDataQuery, $excludeFilters = array(), Tx_PtExtlist_Domain_Configuration_Filters_FilterConfig $filterConfig = null) { $this->buildQuery(); $selectPart = 'SELECT ' . $this->queryInterpreter->getSelectPart($groupDataQuery); $fromPart = $this->listQueryParts['FROM']; $groupPart = count($groupDataQuery->getGroupBy()) > 0 ? ' GROUP BY ' . $this->queryInterpreter->getGroupBy($groupDataQuery) : ''; $sortingPart = count($groupDataQuery->getSortings()) > 0 ? ' ORDER BY ' . $this->queryInterpreter->getSorting($groupDataQuery) : ''; /** * If this list is grouped. There are two cases * 1. We want to show the rowCount. In this case we have to build the list first and then use this list as * source to calculate the selectable rows and the count. This has the drawback, that options are not displayed, if grouped within the list. * 2. We do not need the rowCount. In this case, we exchange the original grouping fields with the fields needed by the filter. */ if ($this->listQueryParts['GROUPBY'] && $filterConfig->getShowRowCount()) { $selectPart = $this->convertTableFieldToAlias($selectPart); $groupPart = $this->convertTableFieldToAlias($groupPart); $sortingPart = $this->convertTableFieldToAlias($sortingPart); $filterWherePart = $this->buildWherePart($excludeFilters); $filterWherePart = $filterWherePart ? ' WHERE ' . $filterWherePart . " \n" : ''; // if the list has a group by clause itself, we have to use the listQuery as subQuery $fromPart = ' FROM (' . $this->listQueryParts['SELECT'] . $this->listQueryParts['FROM'] . $filterWherePart . $this->listQueryParts['GROUPBY'] . ') AS SUBQUERY '; unset($filterWherePart); // we confined the subquery, so we dont need this in the group query } else { $filterWherePart = $this->buildWherePart($excludeFilters); if ($filterWherePart != '') { $filterWherePart = ' WHERE ' . $filterWherePart . " \n"; } } $query = implode(" \n", array($selectPart, $fromPart, $filterWherePart, $groupPart, $sortingPart)); $query = $this->processQueryWithFluid($query); return $query; }
public function testGroupByClause() { $this->assertTrue(Tx_PtExtlist_Domain_DataBackend_MySqlDataBackend_MySqlInterpreter_MySqlInterpreter::getGroupBy($this->queryObject) == 'name, company'); }