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
|
|
|
public function findItemsByLearningPathAndType(int $learningPathId, string $itemType): array |
42
|
|
|
{ |
43
|
|
|
$qb = $this->createQueryBuilder('i') |
44
|
|
|
->where('i.lp = :learningPathId') |
45
|
|
|
->andWhere('i.itemType = :itemType') |
46
|
|
|
->setParameter('learningPathId', $learningPathId) |
47
|
|
|
->setParameter('itemType', $itemType) |
48
|
|
|
; |
49
|
|
|
|
50
|
|
|
$query = $qb->getQuery(); |
51
|
|
|
|
52
|
|
|
return $query->getResult(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function findLearningPathsUsingDocument(int $resourceFileId): array |
56
|
|
|
{ |
57
|
|
|
return $this->createQueryBuilder('i') |
58
|
|
|
->select('lp.iid AS lpId, lp.title AS lpTitle') |
59
|
|
|
->join('i.lp', 'lp') |
60
|
|
|
->where('i.itemType = :type') |
61
|
|
|
->andWhere('i.path = :path') |
62
|
|
|
->setParameter('type', 'document') |
63
|
|
|
->setParameter('path', $resourceFileId) |
64
|
|
|
->getQuery() |
65
|
|
|
->getArrayResult(); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|