|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Sequence; |
|
8
|
|
|
use Chamilo\CoreBundle\Entity\SequenceResource; |
|
9
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
10
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
11
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* Class SequenceRepository |
|
15
|
|
|
* The functions inside this class should return an instance of QueryBuilder. |
|
16
|
|
|
*/ |
|
17
|
|
|
class SequenceRepository extends ServiceEntityRepository |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* CourseCategoryRepository constructor. |
|
21
|
|
|
*/ |
|
22
|
|
|
public function __construct(ManagerRegistry $registry) |
|
23
|
|
|
{ |
|
24
|
|
|
parent::__construct($registry, Sequence::class); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $type |
|
29
|
|
|
* |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
|
|
public static function getItems($type) |
|
33
|
|
|
{ |
|
34
|
|
|
$list = []; |
|
35
|
|
|
|
|
36
|
|
|
switch ($type) { |
|
37
|
|
|
case SequenceResource::COURSE_TYPE: |
|
38
|
|
|
$courseListFromDatabase = \CourseManager::get_course_list(); |
|
39
|
|
|
|
|
40
|
|
|
if (!empty($courseListFromDatabase)) { |
|
41
|
|
|
foreach ($courseListFromDatabase as $item) { |
|
42
|
|
|
$list[$item['id']] = $item['title'].' ('.$item['id'].')'; |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
break; |
|
47
|
|
|
case SequenceResource::SESSION_TYPE: |
|
48
|
|
|
$sessionList = \SessionManager::get_sessions_list(); |
|
49
|
|
|
if (!empty($sessionList)) { |
|
50
|
|
|
foreach ($sessionList as $sessionItem) { |
|
51
|
|
|
$list[$sessionItem['id']] = $sessionItem['name'].' ('.$sessionItem['id'].')'; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
break; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return $list; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function getItem($itemId, $type) |
|
62
|
|
|
{ |
|
63
|
|
|
$resource = null; |
|
64
|
|
|
switch ($type) { |
|
65
|
|
|
case SequenceResource::COURSE_TYPE: |
|
66
|
|
|
$repo = $this->getEntityManager()->getRepository('ChamiloCoreBundle:Course'); |
|
67
|
|
|
|
|
68
|
|
|
break; |
|
69
|
|
|
case SequenceResource::SESSION_TYPE: |
|
70
|
|
|
$repo = $this->getEntityManager()->getRepository('ChamiloCoreBundle:Session'); |
|
71
|
|
|
|
|
72
|
|
|
break; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if ($repo) { |
|
|
|
|
|
|
76
|
|
|
$resource = $repo->find($itemId); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $resource; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param int $id |
|
84
|
|
|
*/ |
|
85
|
|
|
public function removeSequence($id) |
|
86
|
|
|
{ |
|
87
|
|
|
$sequence = $this->find($id); |
|
88
|
|
|
$em = $this->getEntityManager(); |
|
89
|
|
|
$em |
|
90
|
|
|
->createQuery('DELETE FROM ChamiloCoreBundle:SequenceResource sr WHERE sr.sequence = :seq') |
|
91
|
|
|
->execute(['seq' => $sequence]); |
|
92
|
|
|
|
|
93
|
|
|
$em->remove($sequence); |
|
94
|
|
|
$em->flush(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param string $type |
|
99
|
|
|
* |
|
100
|
|
|
* @return array |
|
101
|
|
|
*/ |
|
102
|
|
|
public function findAllToSelect($type) |
|
103
|
|
|
{ |
|
104
|
|
|
$qb = $this->createQueryBuilder('r'); |
|
105
|
|
|
$qb |
|
106
|
|
|
->leftJoin('ChamiloCoreBundle:SequenceResource', 'sr', Join::WITH, 'sr.sequence = r'); |
|
107
|
|
|
|
|
108
|
|
|
$qb |
|
109
|
|
|
->andWhere( |
|
110
|
|
|
$qb->expr()->orX( |
|
111
|
|
|
$qb->expr()->isNull('r.graph'), |
|
112
|
|
|
$qb->expr()->eq('sr.type', $type) |
|
113
|
|
|
) |
|
114
|
|
|
) |
|
115
|
|
|
->orderBy('r.name'); |
|
116
|
|
|
|
|
117
|
|
|
return $qb->getQuery()->getResult(); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|