1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Odiseo\SyliusBannerPlugin\Repository; |
6
|
|
|
|
7
|
|
|
use Doctrine\ORM\QueryBuilder; |
8
|
|
|
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository; |
9
|
|
|
use Sylius\Component\Channel\Model\ChannelInterface; |
10
|
|
|
use Sylius\Component\Taxonomy\Model\TaxonInterface; |
11
|
|
|
|
12
|
|
|
class BannerRepository extends EntityRepository implements BannerRepositoryInterface |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* {@inheritdoc} |
16
|
|
|
*/ |
17
|
|
|
public function findByEnabledQueryBuilder(?ChannelInterface $channel, ?TaxonInterface $taxon): QueryBuilder |
18
|
|
|
{ |
19
|
|
|
$queryBuilder = $this->createQueryBuilder('b') |
20
|
|
|
->andWhere('b.enabled = :enabled') |
21
|
|
|
->setParameter('enabled', true) |
22
|
|
|
; |
23
|
|
|
|
24
|
|
|
if ($channel instanceof ChannelInterface) { |
25
|
|
|
$queryBuilder->innerJoin('b.channels', 'channel') |
26
|
|
|
->andWhere('channel = :channel') |
27
|
|
|
->setParameter('channel', $channel) |
28
|
|
|
; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
if ($taxon instanceof TaxonInterface) { |
32
|
|
|
$queryBuilder->innerJoin('b.taxons', 'taxon') |
33
|
|
|
->andWhere('taxon = :taxon') |
34
|
|
|
->setParameter('taxon', $taxon) |
35
|
|
|
; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $queryBuilder; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
*/ |
44
|
|
|
public function findByChannel(ChannelInterface $channel): array |
45
|
|
|
{ |
46
|
|
|
return $this->findByEnabledQueryBuilder($channel, null)->getQuery()->getResult(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function findByTaxon(TaxonInterface $taxon): array |
53
|
|
|
{ |
54
|
|
|
return $this->findByEnabledQueryBuilder(null, $taxon)->getQuery()->getResult(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* {@inheritdoc} |
59
|
|
|
*/ |
60
|
|
|
public function findByChannelAndTaxon(ChannelInterface $channel, TaxonInterface $taxon): array |
61
|
|
|
{ |
62
|
|
|
return $this->findByEnabledQueryBuilder($channel, $taxon)->getQuery()->getResult(); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|