AndyB
Well-known member
Hello,
I'm in the process of converting my Most Likes v2.8 add-on located here:
https://xenforo.com/community/resources/most-likes.3352/
The query I would like to convert to a finder is this:
The documentation is here, but I'm not having any luck:
https://xf2demo.xenforo.com/dev-docs/entities-finders-repositories/#the-finder
The following finder works well:
but it only finds the newest users. I'm trying to get users with the most likes.
Thank you.
I'm in the process of converting my Most Likes v2.8 add-on located here:
https://xenforo.com/community/resources/most-likes.3352/
The query I would like to convert to a finder is this:
PHP:
// run query
$users = $db->fetchAll("
SELECT xf_user.user_id,
xf_user.username,
xf_user.avatar_date,
COUNT(xf_post.likes) AS mostLikes
FROM xf_post
LEFT JOIN xf_user ON xf_user.user_id = xf_post.user_id
LEFT JOIN xf_liked_content ON xf_liked_content.content_id = xf_post.post_id
WHERE xf_post.likes > ?
AND xf_liked_content.like_date >= ?
AND xf_user.username IS NOT NULL
GROUP BY xf_post.user_id
ORDER BY mostLikes DESC, xf_user.username ASC
LIMIT ?
", array(0, $timestamp, $limit));
The documentation is here, but I'm not having any luck:
https://xf2demo.xenforo.com/dev-docs/entities-finders-repositories/#the-finder
The following finder works well:
PHP:
$userFinder = $this->finder('XF:User')
->isValidUser()
->order('register_date', 'DESC')
->limit($this->options['limit']);
$viewParams = [
'users' => $userFinder->fetch()
];
but it only finds the newest users. I'm trying to get users with the most likes.
Thank you.
Last edited: