feat: add ActorRepository::findOneRandomInWatchedFilms()
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
namespace App\Repository;
|
||||
|
||||
use App\Entity\Actor;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UserMovie;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
@@ -38,4 +40,29 @@ class ActorRepository extends ServiceEntityRepository
|
||||
->getOneOrNullResult()
|
||||
;
|
||||
}
|
||||
|
||||
public function findOneRandomInWatchedFilms(User $user, ?float $popularity = null, ?string $char = null): ?Actor
|
||||
{
|
||||
$qb = $this->createQueryBuilder('a')
|
||||
->join('a.movieRoles', 'mr')
|
||||
->join('mr.movie', 'm')
|
||||
->join(UserMovie::class, 'um', 'WITH', 'um.movie = m AND um.user = :user')
|
||||
->setParameter('user', $user);
|
||||
|
||||
if (!empty($popularity)) {
|
||||
$qb->andWhere('a.popularity >= :popularity')
|
||||
->setParameter('popularity', $popularity);
|
||||
}
|
||||
|
||||
if (!empty($char)) {
|
||||
$qb->andWhere('LOWER(a.name) LIKE LOWER(:name)')
|
||||
->setParameter('name', '%' . $char . '%');
|
||||
}
|
||||
|
||||
return $qb
|
||||
->orderBy('RANDOM()')
|
||||
->setMaxResults(1)
|
||||
->getQuery()
|
||||
->getOneOrNullResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user