Generate grid

This commit is contained in:
thibaud-leclere
2026-01-31 16:17:24 +01:00
parent 1ebf8b99b3
commit a196fac6c6
10 changed files with 158 additions and 40 deletions

View File

@@ -16,28 +16,26 @@ class ActorRepository extends ServiceEntityRepository
parent::__construct($registry, Actor::class);
}
// /**
// * @return Actor[] Returns an array of Actor objects
// */
// public function findByExampleField($value): array
// {
// return $this->createQueryBuilder('a')
// ->andWhere('a.exampleField = :val')
// ->setParameter('val', $value)
// ->orderBy('a.id', 'ASC')
// ->setMaxResults(10)
// ->getQuery()
// ->getResult()
// ;
// }
public function findOneRandom(?float $popularity = null, ?string $char = null): Actor
{
$qb = $this->createQueryBuilder('o');
$expr = $qb->expr();
// public function findOneBySomeField($value): ?Actor
// {
// return $this->createQueryBuilder('a')
// ->andWhere('a.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
if (!empty($popularity)) {
$qb->andWhere($expr->gte('o.popularity', ':popularity'))
->setParameter('popularity', $popularity);
}
if (!empty($char)) {
$qb->andWhere($expr->like('o.name', ':name'))
->setParameter('name', '%'.$char.'%');
}
return $qb
->orderBy('RANDOM()')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult()
;
}
}