Completed
Pull Request — development (#495)
by Mirco
08:08
created

PageRepository::getPageBlocksBySlugQueryBuilder()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 14
nc 4
nop 3
dl 0
loc 22
rs 9.2
c 1
b 0
f 0
1
<?php
2
3
namespace AppBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
7
/**
8
 * PageRepository
9
 *
10
 * This class was generated by the Doctrine ORM. Add your own custom
11
 * repository methods below.
12
 */
13
class PageRepository extends EntityRepository
14
{
15
    /**
16
     * Create Query for Static PageBlocks
17
     *
18
     * @param string $slug
19
     * @param null $filter
20
     * @param null $sort
21
     *
22
     * @return \Doctrine\ORM\QueryBuilder
23
     */
24
    public function getPageBlocksBySlugQueryBuilder($slug, $filter = null, $sort = null)
0 ignored issues
show
Coding Style introduced by
Type hint "null" missing for $filter
Loading history...
Coding Style introduced by
Type hint "null" missing for $sort
Loading history...
25
    {
26
        $qb = $this->createQueryBuilder('page_blocks_by_slug');
27
28
        $qb->select(['pageGroup', 'pageBlocks']);
29
        $qb->from('AppBundle:PageGroup', 'pageGroup')
30
            ->leftJoin('pageGroup.pageBlocks', 'pageBlocks')
31
            ->where('pageGroup.slug = :slug')
32
            ->setParameter('slug', $slug);
33
34
        if ($filter) {
35
            $qb->andWhere($filter);
36
        }
37
38
        if ($sort) {
39
            $qb->addOrderBy($sort);
40
        } else {
41
            $qb->addOrderBy('pageBlocks.position', 'ASC');
42
        }
43
44
        return $qb;
45
    }
46
47
    /**
48
     * GetBlocksBySlugQuery
49
     *
50
     * @param string $slug
51
     * @param null $filter
52
     * @param null $sort
53
     *
54
     * @return \Doctrine\ORM\Query
55
     */
56
    public function getPageBlocksBySlugQuery($slug, $filter = null, $sort = null)
0 ignored issues
show
Coding Style introduced by
Type hint "null" missing for $filter
Loading history...
Coding Style introduced by
Type hint "null" missing for $sort
Loading history...
57
    {
58
        return $this->getPageBlocksBySlugQueryBuilder($slug, $filter, $sort)->getQuery();
59
    }
60
}
61