Passed
Push — master ( 258428...ddae1a )
by Julito
11:33
created

CLpItemRepository::getTree()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 12
rs 10
c 0
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\NonResourceRepository;
10
use Chamilo\CoreBundle\Traits\Repository\ORM\NestedTreeRepositoryTrait;
11
use Chamilo\CourseBundle\Entity\CLpItem;
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 create(CLpItem $item): void
28
    {
29
        $this->getEntityManager()->persist($item);
30
        $this->getEntityManager()->flush();
31
    }
32
33
    public function getRootItem(int $lpId): ?CLpItem
34
    {
35
        return $this->findOneBy([
36
            'path' => 'root',
37
            'lp' => $lpId,
38
        ]);
39
    }
40
}
41