|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Repository; |
|
5
|
|
|
|
|
6
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Templates; |
|
8
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
9
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
10
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
11
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* TemplatesRepository class. |
|
15
|
|
|
*/ |
|
16
|
|
|
class TemplatesRepository extends ServiceEntityRepository |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* TemplatesRepository constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @param ManagerRegistry $registry |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct(ManagerRegistry $registry) |
|
24
|
|
|
{ |
|
25
|
|
|
parent::__construct($registry, Templates::class); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get the course template for a user. |
|
30
|
|
|
* |
|
31
|
|
|
* @param Course $course |
|
32
|
|
|
* @param User $user |
|
33
|
|
|
* |
|
34
|
|
|
* @return array |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getCourseTemplates(Course $course, User $user) |
|
37
|
|
|
{ |
|
38
|
|
|
$qb = $this->createQueryBuilder('t'); |
|
39
|
|
|
|
|
40
|
|
|
$qb->select('t', 'd.path') |
|
41
|
|
|
->innerJoin( |
|
42
|
|
|
'ChamiloCoreBundle:Course', |
|
43
|
|
|
'c', |
|
44
|
|
|
Join::WITH, |
|
45
|
|
|
$qb->expr()->eq('t.id', 'c.id') |
|
46
|
|
|
) |
|
47
|
|
|
->innerJoin( |
|
48
|
|
|
'ChamiloCourseBundle:CDocument', |
|
49
|
|
|
'd', |
|
50
|
|
|
Join::WITH, |
|
51
|
|
|
$qb->expr()->eq('c.id', 'd.course') |
|
52
|
|
|
) |
|
53
|
|
|
->where( |
|
54
|
|
|
$qb->expr()->eq('d.iid', 't.refDoc') |
|
55
|
|
|
) |
|
56
|
|
|
->andWhere( |
|
57
|
|
|
$qb->expr()->eq('c.id', $course->getId()) |
|
58
|
|
|
) |
|
59
|
|
|
->andWhere( |
|
60
|
|
|
$qb->expr()->eq('t.userId', $user->getId()) |
|
61
|
|
|
); |
|
62
|
|
|
|
|
63
|
|
|
return $qb->getQuery()->getResult(); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|