feat: add AwardRepository::findOneRandomByActorAndTypes()
This commit is contained in:
@@ -26,4 +26,25 @@ class AwardRepository extends ServiceEntityRepository
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int>|null $awardTypeIds null means all types
|
||||
*/
|
||||
public function findOneRandomByActorAndTypes(int $actorId, ?array $awardTypeIds): ?Award
|
||||
{
|
||||
$qb = $this->createQueryBuilder('a')
|
||||
->andWhere('a.actor = :actorId')
|
||||
->setParameter('actorId', $actorId);
|
||||
|
||||
if ($awardTypeIds !== null) {
|
||||
$qb->andWhere('a.awardType IN (:typeIds)')
|
||||
->setParameter('typeIds', $awardTypeIds);
|
||||
}
|
||||
|
||||
return $qb
|
||||
->orderBy('RANDOM()')
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user