forked from BitBagCommerce/SyliusCmsPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageRepository.php
More file actions
executable file
·167 lines (150 loc) · 5.55 KB
/
Copy pathPageRepository.php
File metadata and controls
executable file
·167 lines (150 loc) · 5.55 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?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\PageInterface;
use Doctrine\ORM\QueryBuilder;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\ProductInterface;
class PageRepository extends EntityRepository implements PageRepositoryInterface
{
public function createListQueryBuilder(string $localeCode): QueryBuilder
{
return $this->createQueryBuilder('o')
->addSelect('translation')
->leftJoin('o.translations', 'translation', 'WITH', 'translation.locale = :localeCode')
->leftJoin('o.sections', 'sections')
->setParameter('localeCode', $localeCode)
;
}
public function findEnabled(bool $enabled): array
{
return $this->createQueryBuilder('o')
->addSelect('translation')
->innerJoin('o.translations', 'translation')
->andWhere('o.enabled = :enabled')
->setParameter('enabled', $enabled)
->getQuery()
->getResult()
;
}
public function findOneEnabledByCode(string $code, ?string $localeCode): ?PageInterface
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->where('translation.locale = :localeCode')
->andWhere('o.code = :code')
->andWhere('o.enabled = true')
->setParameter('code', $code)
->setParameter('localeCode', $localeCode)
->getQuery()
->getOneOrNullResult()
;
}
public function findOneEnabledBySlugAndChannelCode(
string $slug,
?string $localeCode,
string $channelCode
): ?PageInterface {
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->innerJoin('o.channels', 'channels')
->where('translation.locale = :localeCode')
->andWhere('translation.slug = :slug')
->andWhere('channels.code = :channelCode')
->andWhere('o.enabled = true')
->setParameter('localeCode', $localeCode)
->setParameter('slug', $slug)
->setParameter('channelCode', $channelCode)
->getQuery()
->getOneOrNullResult()
;
}
public function createShopListQueryBuilder(string $sectionCode, string $channelCode): QueryBuilder
{
return $this->createQueryBuilder('o')
->innerJoin('o.sections', 'section')
->innerJoin('o.channels', 'channels')
->where('section.code = :sectionCode')
->andWhere('o.enabled = true')
->andWhere('channels.code = :channelCode')
->setParameter('sectionCode', $sectionCode)
->setParameter('channelCode', $channelCode)
;
}
public function findBySectionCode(string $sectionCode, ?string $localeCode): array
{
return $this->createQueryBuilder('o')
->leftJoin('o.translations', 'translation')
->innerJoin('o.sections', 'section')
->where('translation.locale = :localeCode')
->andWhere('section.code = :sectionCode')
->andWhere('o.enabled = true')
->setParameter('sectionCode', $sectionCode)
->setParameter('localeCode', $localeCode)
->getQuery()
->getResult()
;
}
public function findByProduct(ProductInterface $product, string $channelCode, ?\DateTimeInterface $date = null): array
{
$qb = $this->createQueryBuilder('o')
->innerJoin('o.products', 'product')
->innerJoin('o.channels', 'channel')
->where('o.enabled = true')
->andWhere('product = :product')
->andWhere('channel.code = :channelCode')
->setParameter('product', $product)
->setParameter('channelCode', $channelCode)
;
if (!empty($date)) {
$this->addDateFilter($qb);
}
return $qb
->getQuery()
->getResult()
;
}
public function findByProductAndSectionCode(
ProductInterface $product,
string $sectionCode,
string $channelCode,
?\DateTimeInterface $date = null
): array {
$qb = $this->createQueryBuilder('o')
->innerJoin('o.products', 'product')
->innerJoin('o.sections', 'section')
->innerJoin('o.channels', 'channel')
->where('o.enabled = true')
->andWhere('product = :product')
->andWhere('section.code = :sectionCode')
->andWhere('channel.code = :channelCode')
->setParameter('product', $product)
->setParameter('sectionCode', $sectionCode)
->setParameter('channelCode', $channelCode)
;
if (!empty($date)) {
$this->addDateFilter($qb, $date);
}
return $qb->getQuery()
->getResult()
;
}
private function addDateFilter(QueryBuilder $qb, \DateTimeInterface $date): void
{
$qb
->andWhere(
$qb->expr()->orX(
'o.publishAt is NULL',
'o.publishAt <= :date'
)
)
->setParameter('date', $date);
}
}