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 findOneEnabledByCode(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 findBySectionCode(string $sectionCode, string $localeCode): ?array |
55
|
|
|
{ |
56
|
|
|
return $this->createQueryBuilder('o') |
57
|
|
|
->leftJoin('o.translations', 'translation') |
58
|
|
|
->innerJoin('o.sections', 'section') |
59
|
|
|
->andWhere('translation.locale = :localeCode') |
60
|
|
|
->andWhere('section.code = :sectionCode') |
61
|
|
|
->andWhere('o.enabled = true') |
62
|
|
|
->setParameter('localeCode', $localeCode) |
63
|
|
|
->setParameter('sectionCode', $sectionCode) |
64
|
|
|
->getQuery() |
65
|
|
|
->getResult() |
66
|
|
|
; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function findByProductCode(string $productCode, string $localeCode): ?array |
73
|
|
|
{ |
74
|
|
|
return $this->createQueryBuilder('o') |
75
|
|
|
->leftJoin('o.translations', 'translation') |
76
|
|
|
->innerJoin('o.products', 'products') |
77
|
|
|
->andWhere('translation.locale = :localeCode') |
78
|
|
|
->andWhere('product.code = :productCode') |
79
|
|
|
->andWhere('o.enabled = true') |
80
|
|
|
->setParameter('localeCode', $localeCode) |
81
|
|
|
->setParameter('productCode', $productCode) |
82
|
|
|
->getQuery() |
83
|
|
|
->getResult() |
84
|
|
|
; |
85
|
|
|
} |
86
|
|
|
} |