ZF-11996: Invalid query is generated by DbAdapter for queries grouped by aliases

Description

{{Zend_Paginator_Adapter_DbSelect}} creates invalid SQL query for rows counting in a case if given query have {{GROUP BY}} clause with use of column alias instead of column itself. For example attempt to count rows for the following query:

select a as some_column, b as other_column
from some_table 
where some_column='value'
group by some_column

will produce SQL query:

select count(distinct some_column)
from some_table 
where some_column='value'

which will fail because there is no {{some_column}} column in table.

Comments

Proposed fix for issue. It scans list of columns of original query for aliases for column from GROUP BY clause and replaces it with original column name if found.