質問

I have this model:

News -> 1:n -> Visit
News -> m:n -> FrontendUserGroup
FrontendUser -> 1:n -> Visit

So Visit shows which FrontendUser accessed which News.

I need to get all news for the currently logged in FrontendUser. All News should be ordered DESC by the "datetime" property, but first should appear the news which are not visited yet by the logged in user.

This is the SQL which gives me the correct results:

SELECT 
    (SELECT COUNT(*) FROM tx_xxnews_domain_model_visit v WHERE v.news = n.uid AND v.fe_user = fu.uid) AS visits, 
    n.*

FROM tx_xxnews_domain_model_news AS n
    JOIN tx_xxnews_news_frontendusergroup_mm nfg ON n.uid = nfg.uid_local
    JOIN fe_users fu ON FIND_IN_SET(nfg.uid_foreign, fu.usergroup)

WHERE fu.uid = 2271 # logged in user id

ORDER BY visits ASC, n.datetime DESC

Is there any way to get this result with Extbase?

I tried in NewsRepository this:

protected $defaultOrderings = array(
    'COUNT(visits)' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING,
    'datetime' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
);

but it doesn't seem to work.

Any ideas?

Thank you.

役に立ちましたか?

解決

This is in fact not possible since $defaultOrderings expects properties, not SQL field names or functions.

As far as I know, the only possibility is to use$query->statement('[YOUR QUERY]');.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top