PageRepository::getTreeForSelect()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 0
cts 18
cp 0
rs 8.439
c 0
b 0
f 0
cc 6
eloc 13
nc 8
nop 2
crap 42
1
<?php
2
3
namespace WebCMS\Entity;
4
5
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
6
7
class PageRepository extends NestedTreeRepository
8
{
9
    public function getTreeForSelect($order = null, $where = null)
10
    {
11
        $qb = $this->_em->createQueryBuilder();
12
13
        if ($order) {
14
            foreach ($order as $o) {
15
                $qb->addOrderBy('l.'.$o['by'], $o['dir']);
16
            }
17
        }
18
19
        if ($where) {
20
            foreach ($where as $w) {
21
                $qb->andWhere('l.'.$w);
22
            }
23
        }
24
25
        $tree = $qb->select('l')->from("WebCMS\Entity\Page", 'l')->getQuery()->getResult();
26
27
        $array = array();
28
        foreach ($tree as $node) {
29
            $array[$node->getId()] = str_repeat("-", $node->getLevel()).$node->getTitle();
30
        }
31
32
        return $array;
33
    }
34
}
35