forked from BitBagCommerce/SyliusCmsPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaRepository.php
More file actions
executable file
·81 lines (73 loc) · 3.02 KB
/
Copy pathMediaRepository.php
File metadata and controls
executable file
·81 lines (73 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace BitBag\SyliusCmsPlugin\Repository;
use BitBag\SyliusCmsPlugin\Entity\MediaInterface;
use Doctrine\ORM\QueryBuilder;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
class MediaRepository extends EntityRepository implements MediaRepositoryInterface
{
public function createListQueryBuilder(string $locale): QueryBuilder
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation', 'WITH', 'translation.locale = :locale')
->setParameter('locale', $locale)
;
}
public function findOneEnabledByCode(string $code, string $localeCode, string $channelCode): ?MediaInterface
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->innerJoin('o.channels', 'channels')
->where('translation.locale = :localeCode')
->andWhere('o.code = :code')
->andWhere('o.enabled = true')
->andWhere('channels.code = :channelCode')
->setParameter('code', $code)
->setParameter('localeCode', $localeCode)
->setParameter('channelCode', $channelCode)
->getQuery()
->getOneOrNullResult()
;
}
public function findBySectionCode(string $sectionCode, string $localeCode, string $channelCode): array
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->innerJoin('o.sections', 'section')
->innerJoin('o.channels', 'channels')
->andWhere('translation.locale = :localeCode')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
->andWhere('channels.code = :channelCode')
->setParameter('localeCode', $localeCode)
->setParameter('sectionCode', $sectionCode)
->setParameter('channelCode', $channelCode)
->getQuery()
->getResult()
;
}
public function findByProductCode(string $productCode, string $localeCode, string $channelCode): array
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->innerJoin('o.products', 'product')
->innerJoin('o.channels', 'channels')
->andWhere('translation.locale = :localeCode')
->andWhere('product.code = :productCode')
->andWhere('o.enabled = true')
->andWhere('channels.code = :channelCode')
->setParameter('localeCode', $localeCode)
->setParameter('productCode', $productCode)
->setParameter('channelCode', $channelCode)
->getQuery()
->getResult()
;
}
}