1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file has been created by developers from BitBag. |
||
5 | * Feel free to contact us once you face any issues or want to start |
||
6 | * another great project. |
||
7 | * You can find more information about us on https://bitbag.shop and write us |
||
8 | * an email on [email protected]. |
||
9 | */ |
||
10 | |||
11 | declare(strict_types=1); |
||
12 | |||
13 | namespace BitBag\SyliusCmsPlugin\Repository; |
||
14 | |||
15 | use BitBag\SyliusCmsPlugin\Entity\MediaInterface; |
||
16 | use Doctrine\ORM\QueryBuilder; |
||
17 | use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
||
18 | |||
19 | class MediaRepository extends EntityRepository implements MediaRepositoryInterface |
||
20 | { |
||
21 | public function createListQueryBuilder(string $locale): QueryBuilder |
||
22 | { |
||
23 | return $this->createQueryBuilder('o') |
||
24 | ->leftJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale') |
||
25 | ->setParameter('locale', $locale) |
||
26 | ; |
||
27 | } |
||
28 | |||
29 | public function findOneEnabledByCode(string $code, string $localeCode): ?MediaInterface |
||
30 | { |
||
31 | return $this->createQueryBuilder('o') |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
32 | ->leftJoin('o.translations', 'translation') |
||
33 | ->where('translation.locale = :localeCode') |
||
34 | ->andWhere('o.code = :code') |
||
35 | ->andWhere('o.enabled = true') |
||
36 | ->setParameter('code', $code) |
||
37 | ->setParameter('localeCode', $localeCode) |
||
38 | ->getQuery() |
||
39 | ->getOneOrNullResult() |
||
40 | ; |
||
41 | } |
||
42 | |||
43 | public function findBySectionCode(string $sectionCode, ?string $localeCode): array |
||
44 | { |
||
45 | return $this->createQueryBuilder('o') |
||
0 ignored issues
–
show
|
|||
46 | ->innerJoin('o.channels', 'channel') |
||
47 | ->innerJoin('o.sections', 'section') |
||
48 | ->where('translation.locale = :localeCode') |
||
49 | ->andWhere('section.code = :sectionCode') |
||
50 | ->andWhere('o.enabled = true') |
||
51 | ->setParameter('localeCode', $localeCode) |
||
52 | ->setParameter('sectionCode', $sectionCode) |
||
53 | ->getQuery() |
||
54 | ->getResult() |
||
55 | ; |
||
56 | } |
||
57 | |||
58 | public function findByProductCode(string $productCode, string $channelCode, ?string $localeCode): array |
||
59 | { |
||
60 | return $this->createQueryBuilder('o') |
||
0 ignored issues
–
show
|
|||
61 | ->leftJoin('o.translations', 'translation') |
||
62 | ->innerJoin('o.products', 'product') |
||
63 | ->innerJoin('o.channels', 'channels') |
||
64 | ->andWhere('translation.locale = :localeCode') |
||
65 | ->andWhere('product.code = :productCode') |
||
66 | ->andWhere('o.enabled = true') |
||
67 | ->andWhere('channels.code = :channelCode') |
||
68 | ->setParameter('localeCode', $localeCode) |
||
69 | ->setParameter('productCode', $productCode) |
||
70 | ->setParameter('channelCode', $channelCode) |
||
71 | ->getQuery() |
||
72 | ->getResult() |
||
73 | ; |
||
74 | } |
||
75 | } |
||
76 |