Passed
Push — master ( c76aa7...6c061b )
by Julito
08:15 queued 11s
created

CLpItemRepository::getTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Repository;
8
9
use Chamilo\CoreBundle\Traits\Repository\ORM\NestedTreeRepositoryTrait;
10
use Chamilo\CourseBundle\Entity\CLpItem;
11
use Chamilo\CourseBundle\Traits\NonResourceRepository;
12
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
13
use Doctrine\Persistence\ManagerRegistry;
14
15
final class CLpItemRepository extends ServiceEntityRepository
16
{
17
    use NestedTreeRepositoryTrait;
18
    use NonResourceRepository;
19
20
    public function __construct(ManagerRegistry $registry)
21
    {
22
        parent::__construct($registry, CLpItem::class);
23
24
        $this->initializeTreeRepository($this->getEntityManager(), $this->getClassMetadata());
25
    }
26
27
    public function getItemRoot($lpId): ?CLpItem
28
    {
29
        return $this->findOneBy([
30
            'path' => 'root',
31
            'lp' => $lpId,
32
        ]);
33
    }
34
35
    public function getTree($lpId)
36
    {
37
        $qb = $this->createQueryBuilder('i');
38
        $qb
39
            ->andWhere('lp = :lp AND path = :path')
40
            ->setParameters([
41
                'lp' => $lpId,
42
                'path' => 'root',
43
            ])
44
        ;
45
46
        return $qb->getQuery()->getResult('tree');
47
    }
48
}
49