1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file was created by the 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\CmsPlugin\Repository; |
14
|
|
|
|
15
|
|
|
use BitBag\CmsPlugin\Entity\BlockInterface; |
16
|
|
|
use Doctrine\ORM\QueryBuilder; |
17
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Patryk Drapik <[email protected]> |
21
|
|
|
* @author Mikołaj Król <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class BlockRepository extends EntityRepository implements BlockRepositoryInterface |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
|
|
public function createListQueryBuilder(string $localeCode): QueryBuilder |
29
|
|
|
{ |
30
|
|
|
return $this->createQueryBuilder('o') |
31
|
|
|
->innerJoin('o.translations', 'translation') |
32
|
|
|
->where('translation.locale = :localeCode') |
33
|
|
|
->setParameter('localeCode', $localeCode) |
34
|
|
|
; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function findEnabledByCode(string $code): ?BlockInterface |
41
|
|
|
{ |
42
|
|
|
return $this->createQueryBuilder('o') |
43
|
|
|
->where('o.code = :code') |
44
|
|
|
->andWhere('o.enabled = true') |
45
|
|
|
->setParameter('code', $code) |
46
|
|
|
->getQuery() |
47
|
|
|
->getOneOrNullResult() |
48
|
|
|
; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* {@inheritdoc} |
53
|
|
|
*/ |
54
|
|
|
public function findEnabledByCodeAndContent(string $code, string $content): ?BlockInterface |
55
|
|
|
{ |
56
|
|
|
return $this->createQueryBuilder('o') |
57
|
|
|
->leftJoin('o.translations', 'translation') |
58
|
|
|
->where('o.code = :code') |
59
|
|
|
->andWhere('o.enabled = true') |
60
|
|
|
->andWhere('translation.content = :content') |
61
|
|
|
->setParameter('code', $code) |
62
|
|
|
->setParameter('content', $content) |
63
|
|
|
->getQuery() |
64
|
|
|
->getOneOrNullResult() |
65
|
|
|
; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
*/ |
71
|
|
|
public function findOneByTypeAndContent(string $type, string $content): ?BlockInterface |
72
|
|
|
{ |
73
|
|
|
return $this->createQueryBuilder('o') |
74
|
|
|
->leftJoin('o.translations', 'translation') |
75
|
|
|
->where('o.type = :type') |
76
|
|
|
->andWhere('o.enabled = true') |
77
|
|
|
->andWhere('translation.content = :content') |
78
|
|
|
->setParameter('type', $type) |
79
|
|
|
->setParameter('content', $content) |
80
|
|
|
->getQuery() |
81
|
|
|
->getOneOrNullResult() |
82
|
|
|
; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritdoc} |
87
|
|
|
*/ |
88
|
|
|
public function findBySectionCode(string $sectionCode, string $localeCode): ?array |
89
|
|
|
{ |
90
|
|
|
return $this->createQueryBuilder('o') |
91
|
|
|
->leftJoin('o.translations', 'translation') |
92
|
|
|
->innerJoin('o.sections', 'section') |
93
|
|
|
->andWhere('translation.locale = :localeCode') |
94
|
|
|
->andWhere('section.code = :sectionCode') |
95
|
|
|
->andWhere('o.enabled = true') |
96
|
|
|
->setParameter('localeCode', $localeCode) |
97
|
|
|
->setParameter('sectionCode', $sectionCode) |
98
|
|
|
->getQuery() |
99
|
|
|
->getResult() |
100
|
|
|
; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* {@inheritdoc} |
105
|
|
|
*/ |
106
|
|
|
public function findByProductCode(string $productCode, string $localeCode): ?array |
107
|
|
|
{ |
108
|
|
|
return $this->createQueryBuilder('o') |
109
|
|
|
->leftJoin('o.translations', 'translation') |
110
|
|
|
->innerJoin('o.products', 'products') |
111
|
|
|
->andWhere('translation.locale = :localeCode') |
112
|
|
|
->andWhere('product.code = :productCode') |
113
|
|
|
->andWhere('o.enabled = true') |
114
|
|
|
->setParameter('localeCode', $localeCode) |
115
|
|
|
->setParameter('productCode', $productCode) |
116
|
|
|
->getQuery() |
117
|
|
|
->getResult() |
118
|
|
|
; |
119
|
|
|
} |
120
|
|
|
} |