abdfahim
Well-known member
I am trying to develop a widget for XF2 Demo Featured Threads Portal to select a random featured thread. I know how to do it using a raw SQL query, but I am wondering if I could use the existing repo to do the same (I am still a bit hazy about XF repos).
Currently, we can fetch all featured threads using the following code
I am in short of an idea if I can somehow modify this to return one random thread instead.
Appreciate if anyone can help.
Currently, we can fetch all featured threads using the following code
PHP:
/** @var \Demo\Portal\Repository\FeaturedThread $repo */
$repo = $this->repository('Demo\Portal:FeaturedThread');
$finder = $repo->findFeaturedThreadsForPortalView();
$featuredThreads = $finder->fetch()
->filter(function(\Demo\Portal\Entity\FeaturedThread $featuredThread)
{
return ($featuredThread->Thread->canView());
});
$viewParams = [
'featuredThreads' => $featuredThreads
];
I am in short of an idea if I can somehow modify this to return one random thread instead.
Appreciate if anyone can help.