|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\BlocksModule\Entity\Repository; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\ORM\EntityRepository; |
|
15
|
|
|
use Zikula\BlocksModule\Entity\BlockEntity; |
|
16
|
|
|
use Zikula\BlocksModule\Entity\RepositoryInterface\BlockRepositoryInterface; |
|
17
|
|
|
|
|
18
|
|
|
class BlockRepository extends EntityRepository implements BlockRepositoryInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function getFilteredBlocks(array $filters) |
|
21
|
|
|
{ |
|
22
|
|
|
$qb = $this->_em->createQueryBuilder(); |
|
23
|
|
|
$query = $qb->select('b') |
|
24
|
|
|
->from($this->_entityName, 'b'); |
|
25
|
|
|
if (isset($filters['position'])) { |
|
26
|
|
|
$subQb = $this->_em->createQueryBuilder(); |
|
27
|
|
|
$query |
|
28
|
|
|
->join('b.placements', 'p') |
|
29
|
|
|
->where($qb->expr()->in('p.position', |
|
30
|
|
|
$subQb->select('bp') |
|
31
|
|
|
->from('ZikulaBlocksModule:BlockPositionEntity', 'bp') |
|
32
|
|
|
->where('bp.pid = ?1') |
|
33
|
|
|
->getDQL() |
|
34
|
|
|
)) |
|
35
|
|
|
->setParameter(1, $filters['position']); |
|
36
|
|
|
unset($filters['position']); |
|
37
|
|
|
} |
|
38
|
|
|
$paramIndex = 2; |
|
39
|
|
|
$sortField = isset($filters['sort-field']) ? $filters['sort-field'] : 'bid'; |
|
40
|
|
|
$sortDirection = isset($filters['sort-direction']) ? $filters['sort-direction'] : 'ASC'; |
|
41
|
|
|
unset($filters['sort-field'], $filters['sort-direction']); |
|
42
|
|
|
foreach ($filters as $key => $value) { |
|
43
|
|
|
if (!isset($value)) { |
|
44
|
|
|
unset($filters[$key]); |
|
45
|
|
|
} else { |
|
46
|
|
|
$query->andWhere($qb->expr()->eq('b.' . $key, '?' . $paramIndex)) |
|
47
|
|
|
->setParameter($paramIndex, $value); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
$query->orderBy('b.' . $sortField, $sortDirection); |
|
51
|
|
|
|
|
52
|
|
|
return $query->getQuery()->getResult(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function persistAndFlush(BlockEntity $entity) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->_em->persist($entity); |
|
58
|
|
|
$this->_em->flush($entity); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|