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

CLpItemRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 32
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getItemRoot() 0 5 1
A getTree() 0 12 1
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