[TYPO3-mvc] Really strange behavior with $query->statement.
Braulio J. Solano-Rojas
braulio at solsoft.biz
Sun Aug 8 06:47:20 CEST 2010
Hello.
I am trying to write an extension that adds functionality to another
extension. I would like to show to a logged user what are his most
visited pages (like a top ten). The number of rows is configurable by
typoscript. However I need to have a SQL SUM which is not supported
right now... therefore I am writing directly the SQL.
This is the code inside my repository class:
/**
* Finds most $links visited pages by $feUSer user
* @param int $links
* @param int $feUser
* @return array<Tx_SolsoftMostvisited_Domain_Model_Pagestat>
*/
public function findMostVisited($links, $feUser) {
$query = $this->createQuery();
$query->statement('SELECT tx_loginusertrack_pagestat.page_id,
SUM(tx_loginusertrack_pagestat.hits) as hits
FROM tx_loginusertrack_pagestat
WHERE tx_loginusertrack_pagestat.fe_user = '.intval($feUser).'
GROUP BY page_id
ORDER BY hits DESC
LIMIT '.intval($links));
$pageStats = $query->execute();
return (count($pageStats) == 0) ? NULL : $pageStats;
}
What is really strange is that if I run the SQL directly in phpMyAdmin I
get this:
page_id hits
130 29
4 1
21 1
69 1
123 1
211 1
328 1
331 1
However the $pageStats variable above returns me an array of exactly the
same number of objects (rows) but each one are the same (the first row).
Has someone a clue of why this happens? Should I report this as a bug?
Best regards,
B.
P.S.: The SQL I am running through phpMyAdmin is:
SELECT tx_loginusertrack_pagestat.page_id, SUM(
tx_loginusertrack_pagestat.hits ) AS hits
FROM tx_loginusertrack_pagestat
WHERE tx_loginusertrack_pagestat.fe_user = 2
GROUP BY page_id
ORDER BY hits DESC
LIMIT 10
More information about the TYPO3-project-typo3v4mvc
mailing list