|
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\PageContentInterface; |
|
16
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
17
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
|
18
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
19
|
|
|
|
|
20
|
|
|
class PageRepository extends EntityRepository implements PageRepositoryInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function createListQueryBuilder(string $locale): QueryBuilder |
|
23
|
|
|
{ |
|
24
|
|
|
return $this->createQueryBuilder('o') |
|
25
|
|
|
->innerJoin('o.translations', 'translation') |
|
26
|
|
|
->where('translation.locale = :locale') |
|
27
|
|
|
->setParameter('locale', $locale) |
|
28
|
|
|
; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function findEnabled(bool $enabled): array |
|
32
|
|
|
{ |
|
33
|
|
|
return $this->createQueryBuilder('o') |
|
34
|
|
|
->addSelect('translation') |
|
35
|
|
|
->innerJoin('o.translations', 'translation') |
|
36
|
|
|
->andWhere('o.enabled = :enabled') |
|
37
|
|
|
->setParameter('enabled', $enabled) |
|
38
|
|
|
->getQuery() |
|
39
|
|
|
->getResult() |
|
40
|
|
|
; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageContentInterface |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->createQueryBuilder('o') |
|
46
|
|
|
->leftJoin('o.translations', 'translation') |
|
47
|
|
|
->where('translation.locale = :localeCode') |
|
48
|
|
|
->andWhere('o.code = :code') |
|
49
|
|
|
->andWhere('o.enabled = true') |
|
50
|
|
|
->setParameter('code', $code) |
|
51
|
|
|
->setParameter('localeCode', $localeCode) |
|
52
|
|
|
->getQuery() |
|
53
|
|
|
->getOneOrNullResult() |
|
54
|
|
|
; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function findOneEnabledBySlugAndChannelCode( |
|
58
|
|
|
string $slug, |
|
59
|
|
|
?string $localeCode, |
|
60
|
|
|
string $channelCode |
|
61
|
|
|
): ?PageContentInterface { |
|
62
|
|
|
return $this->createQueryBuilder('o') |
|
63
|
|
|
->leftJoin('o.translations', 'translation') |
|
64
|
|
|
->innerJoin('o.channels', 'channels') |
|
65
|
|
|
->where('translation.locale = :localeCode') |
|
66
|
|
|
->andWhere('translation.slug = :slug') |
|
67
|
|
|
->andWhere('channels.code = :channelCode') |
|
68
|
|
|
->andWhere('o.enabled = true') |
|
69
|
|
|
->setParameter('localeCode', $localeCode) |
|
70
|
|
|
->setParameter('slug', $slug) |
|
71
|
|
|
->setParameter('channelCode', $channelCode) |
|
72
|
|
|
->getQuery() |
|
73
|
|
|
->getOneOrNullResult() |
|
74
|
|
|
; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function createShopListQueryBuilder(string $sectionCode, string $channelCode): QueryBuilder |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->createQueryBuilder('o') |
|
80
|
|
|
->innerJoin('o.sections', 'section') |
|
81
|
|
|
->innerJoin('o.channels', 'channels') |
|
82
|
|
|
->where('section.code = :sectionCode') |
|
83
|
|
|
->andWhere('o.enabled = true') |
|
84
|
|
|
->andWhere('channels.code = :channelCode') |
|
85
|
|
|
->setParameter('sectionCode', $sectionCode) |
|
86
|
|
|
->setParameter('channelCode', $channelCode) |
|
87
|
|
|
; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function findByProduct(ProductInterface $product, string $channelCode): array |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->createQueryBuilder('o') |
|
93
|
|
|
->innerJoin('o.products', 'product') |
|
94
|
|
|
->innerJoin('o.channels', 'channel') |
|
95
|
|
|
->where('o.enabled = true') |
|
96
|
|
|
->andWhere('product = :product') |
|
97
|
|
|
->andWhere('channel.code = :channelCode') |
|
98
|
|
|
->setParameter('product', $product) |
|
99
|
|
|
->setParameter('channelCode', $channelCode) |
|
100
|
|
|
->getQuery() |
|
101
|
|
|
->getResult() |
|
102
|
|
|
; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function findByProductAndSectionCode( |
|
106
|
|
|
ProductInterface $product, |
|
107
|
|
|
string $sectionCode, |
|
108
|
|
|
string $channelCode |
|
109
|
|
|
): array { |
|
110
|
|
|
return $this->createQueryBuilder('o') |
|
111
|
|
|
->innerJoin('o.products', 'product') |
|
112
|
|
|
->innerJoin('o.sections', 'section') |
|
113
|
|
|
->innerJoin('o.channels', 'channel') |
|
114
|
|
|
->where('o.enabled = true') |
|
115
|
|
|
->andWhere('product = :product') |
|
116
|
|
|
->andWhere('section.code = :sectionCode') |
|
117
|
|
|
->andWhere('channel.code = :channelCode') |
|
118
|
|
|
->setParameter('product', $product) |
|
119
|
|
|
->setParameter('sectionCode', $sectionCode) |
|
120
|
|
|
->setParameter('channelCode', $channelCode) |
|
121
|
|
|
->getQuery() |
|
122
|
|
|
->getResult() |
|
123
|
|
|
; |
|
124
|
|
|
} |
|
125
|
|
|
} |
|
126
|
|
|
|