Generate grid
This commit is contained in:
@@ -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()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user