|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Movies\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use App\Movies\Entity\MovieReview; |
|
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
7
|
|
|
use Doctrine\ORM\Query; |
|
8
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
9
|
|
|
use App\Users\Entity\UserWatchedMovie; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @method MovieReview|null find($id, $lockMode = null, $lockVersion = null) |
|
13
|
|
|
* @method MovieReview|null findOneBy(array $criteria, array $orderBy = null) |
|
14
|
|
|
* @method MovieReview[] findAll() |
|
15
|
|
|
* @method MovieReview[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
16
|
|
|
*/ |
|
17
|
|
|
class MovieReviewRepository extends ServiceEntityRepository |
|
18
|
|
|
{ |
|
19
|
1 |
|
public function __construct(RegistryInterface $registry) |
|
20
|
|
|
{ |
|
21
|
1 |
|
parent::__construct($registry, MovieReview::class); |
|
22
|
1 |
|
} |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* use this method instead of find(), because doctrine dont know how to map uwm correctly |
|
26
|
|
|
*/ |
|
27
|
1 |
|
public function findOne(int $id): ?MovieReview |
|
28
|
|
|
{ |
|
29
|
1 |
|
return $this->createQueryBuilder('review') |
|
30
|
1 |
|
->leftJoin('review.userWatchedMovie', 'uwm') |
|
31
|
1 |
|
->addSelect('uwm') |
|
32
|
1 |
|
->where('review.id = :id') |
|
33
|
1 |
|
->setParameter('id', $id) |
|
34
|
1 |
|
->getQuery() |
|
35
|
1 |
|
->getOneOrNullResult(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
1 |
|
public function findAllByMovie(string $locale, int $movieId): Query |
|
39
|
|
|
{ |
|
40
|
1 |
|
return $this->createQueryBuilder('review') |
|
41
|
1 |
|
->leftJoin('review.userWatchedMovie', 'uwm') |
|
42
|
1 |
|
->addSelect('uwm') |
|
43
|
1 |
|
->where('review.movie = :movieId AND review.locale = :locale') |
|
44
|
1 |
|
->setParameter('movieId', $movieId) |
|
45
|
1 |
|
->setParameter('locale', $locale) |
|
46
|
1 |
|
->getQuery(); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|