|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CourseBundle\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
8
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceLink; |
|
9
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceNode; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
|
11
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
|
12
|
|
|
use Chamilo\CourseBundle\Entity\CGroupInfo; |
|
13
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
14
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
15
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
16
|
|
|
|
|
17
|
|
|
final class CToolRepository extends ResourceRepository |
|
18
|
|
|
{ |
|
19
|
|
|
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder |
|
20
|
|
|
{ |
|
21
|
|
|
$repo = $this->getRepository(); |
|
22
|
|
|
$className = $repo->getClassName(); |
|
23
|
|
|
$checker = $this->getAuthorizationChecker(); |
|
24
|
|
|
|
|
25
|
|
|
$reflectionClass = $repo->getClassMetadata()->getReflectionClass(); |
|
26
|
|
|
|
|
27
|
|
|
// Check if this resource type requires to load the base course resources when using a session |
|
28
|
|
|
$loadBaseSessionContent = $reflectionClass->hasProperty('loadCourseResourcesInSession'); |
|
29
|
|
|
|
|
30
|
|
|
$type = $this->getResourceType(); |
|
31
|
|
|
|
|
32
|
|
|
$qb = $repo->getEntityManager()->createQueryBuilder() |
|
33
|
|
|
->select('resource') |
|
34
|
|
|
->from($className, 'resource') |
|
35
|
|
|
->innerJoin( |
|
36
|
|
|
ResourceNode::class, |
|
37
|
|
|
'node', |
|
38
|
|
|
Join::WITH, |
|
39
|
|
|
'resource.resourceNode = node.id' |
|
40
|
|
|
) |
|
41
|
|
|
->innerJoin('node.resourceLinks', 'links') |
|
42
|
|
|
->where('node.resourceType = :type') |
|
43
|
|
|
->setParameter('type', $type); |
|
44
|
|
|
$qb |
|
45
|
|
|
->andWhere('links.course = :course') |
|
46
|
|
|
->setParameter('course', $course) |
|
47
|
|
|
; |
|
48
|
|
|
|
|
49
|
|
|
$isAdmin = $checker->isGranted('ROLE_ADMIN') || $checker->isGranted('ROLE_CURRENT_COURSE_TEACHER'); |
|
50
|
|
|
|
|
51
|
|
|
if (false === $isAdmin) { |
|
52
|
|
|
$qb |
|
53
|
|
|
->andWhere('links.visibility = :visibility') |
|
54
|
|
|
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED) |
|
55
|
|
|
; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if (null === $session) { |
|
59
|
|
|
$qb->andWhere('links.session IS NULL'); |
|
60
|
|
|
} else { |
|
61
|
|
|
if ($loadBaseSessionContent) { |
|
62
|
|
|
// Load course base content. |
|
63
|
|
|
$qb->andWhere('links.session = :session OR links.session IS NULL'); |
|
64
|
|
|
$qb->setParameter('session', $session); |
|
65
|
|
|
} else { |
|
66
|
|
|
// Load only session resources. |
|
67
|
|
|
$qb->andWhere('links.session = :session'); |
|
68
|
|
|
$qb->setParameter('session', $session); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$qb->andWhere('node.parent = :parentNode'); |
|
73
|
|
|
$qb->setParameter('parentNode', $parentNode); |
|
74
|
|
|
|
|
75
|
|
|
$qb->andWhere('links.group IS NULL'); |
|
76
|
|
|
|
|
77
|
|
|
///var_dump($qb->getQuery()->getSQL(), $type->getId(), $parentNode->getId());exit; |
|
78
|
|
|
|
|
79
|
|
|
return $qb; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|