2026-01-15 19:35:39 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Repository;
|
|
|
|
|
|
|
|
|
|
use App\Entity\Actor;
|
|
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
|
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @extends ServiceEntityRepository<Actor>
|
|
|
|
|
*/
|
|
|
|
|
class ActorRepository extends ServiceEntityRepository
|
|
|
|
|
{
|
|
|
|
|
public function __construct(ManagerRegistry $registry)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct($registry, Actor::class);
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 15:17:24 +00:00
|
|
|
public function findOneRandom(?float $popularity = null, ?string $char = null): Actor
|
|
|
|
|
{
|
|
|
|
|
$qb = $this->createQueryBuilder('o');
|
|
|
|
|
$expr = $qb->expr();
|
|
|
|
|
|
|
|
|
|
if (!empty($popularity)) {
|
|
|
|
|
$qb->andWhere($expr->gte('o.popularity', ':popularity'))
|
|
|
|
|
->setParameter('popularity', $popularity);
|
|
|
|
|
}
|
2026-01-15 19:35:39 +00:00
|
|
|
|
2026-01-31 15:17:24 +00:00
|
|
|
if (!empty($char)) {
|
|
|
|
|
$qb->andWhere($expr->like('o.name', ':name'))
|
|
|
|
|
->setParameter('name', '%'.$char.'%');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $qb
|
|
|
|
|
->orderBy('RANDOM()')
|
|
|
|
|
->setMaxResults(1)
|
|
|
|
|
->getQuery()
|
|
|
|
|
->getOneOrNullResult()
|
|
|
|
|
;
|
|
|
|
|
}
|
2026-01-15 19:35:39 +00:00
|
|
|
}
|