feat: add AwardRepository::findOneRandomByActorAndTypes()

This commit is contained in:
thibaud-leclere
2026-04-01 22:58:04 +02:00
parent 468b72b419
commit 5fbac8359f
2 changed files with 84 additions and 0 deletions

View File

@@ -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();
}
}