|
1
|
|
|
<?php |
|
2
|
|
|
/* For licensing terms, see /license.txt */ |
|
3
|
|
|
|
|
4
|
|
|
namespace Chamilo\CourseBundle\Repository; |
|
5
|
|
|
|
|
6
|
|
|
use APY\DataGridBundle\Grid\Column\Column; |
|
7
|
|
|
use APY\DataGridBundle\Grid\Grid; |
|
8
|
|
|
use Chamilo\CoreBundle\Component\Utils\ResourceSettings; |
|
9
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceLink; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceNode; |
|
12
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
|
13
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
|
14
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepositoryInterface; |
|
15
|
|
|
use Chamilo\CourseBundle\Entity\CGroupInfo; |
|
16
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
17
|
|
|
use Doctrine\ORM\Query\Expr\Join; |
|
18
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
19
|
|
|
use Symfony\Component\Form\FormInterface; |
|
20
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
21
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
22
|
|
|
|
|
23
|
|
|
final class CToolRepository extends ResourceRepository implements ResourceRepositoryInterface |
|
24
|
|
|
{ |
|
25
|
|
|
public function getResourceSettings(): ResourceSettings |
|
26
|
|
|
{ |
|
27
|
|
|
$settings = new ResourceSettings(); |
|
28
|
|
|
$settings |
|
29
|
|
|
->setAllowNodeCreation(false) |
|
30
|
|
|
->setAllowResourceCreation(false) |
|
31
|
|
|
->setAllowResourceUpload(false) |
|
32
|
|
|
; |
|
33
|
|
|
|
|
34
|
|
|
return $settings; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null) |
|
38
|
|
|
{ |
|
39
|
|
|
$repo = $this->getRepository(); |
|
40
|
|
|
$className = $repo->getClassName(); |
|
41
|
|
|
$checker = $this->getAuthorizationChecker(); |
|
42
|
|
|
|
|
43
|
|
|
$reflectionClass = $repo->getClassMetadata()->getReflectionClass(); |
|
44
|
|
|
|
|
45
|
|
|
// Check if this resource type requires to load the base course resources when using a session |
|
46
|
|
|
$loadBaseSessionContent = $reflectionClass->hasProperty('loadCourseResourcesInSession'); |
|
47
|
|
|
|
|
48
|
|
|
$type = $this->getResourceType(); |
|
49
|
|
|
|
|
50
|
|
|
$qb = $repo->getEntityManager()->createQueryBuilder() |
|
51
|
|
|
->select('resource') |
|
52
|
|
|
->from($className, 'resource') |
|
53
|
|
|
->innerJoin( |
|
54
|
|
|
ResourceNode::class, |
|
55
|
|
|
'node', |
|
56
|
|
|
Join::WITH, |
|
57
|
|
|
'resource.resourceNode = node.id' |
|
58
|
|
|
) |
|
59
|
|
|
->innerJoin('node.resourceLinks', 'links') |
|
60
|
|
|
->where('node.resourceType = :type') |
|
61
|
|
|
->setParameter('type', $type); |
|
62
|
|
|
$qb |
|
63
|
|
|
->andWhere('links.course = :course') |
|
64
|
|
|
->setParameter('course', $course) |
|
65
|
|
|
; |
|
66
|
|
|
|
|
67
|
|
|
$isAdmin = $checker->isGranted('ROLE_ADMIN') || $checker->isGranted('ROLE_CURRENT_COURSE_TEACHER'); |
|
68
|
|
|
|
|
69
|
|
|
if (false === $isAdmin) { |
|
70
|
|
|
$qb |
|
71
|
|
|
->andWhere('links.visibility = :visibility') |
|
72
|
|
|
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED) |
|
73
|
|
|
; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (null === $session) { |
|
77
|
|
|
$qb->andWhere('links.session IS NULL'); |
|
78
|
|
|
} else { |
|
79
|
|
|
if ($loadBaseSessionContent) { |
|
80
|
|
|
// Load course base content. |
|
81
|
|
|
$qb->andWhere('links.session = :session OR links.session IS NULL'); |
|
82
|
|
|
$qb->setParameter('session', $session); |
|
83
|
|
|
} else { |
|
84
|
|
|
// Load only session resources. |
|
85
|
|
|
$qb->andWhere('links.session = :session'); |
|
86
|
|
|
$qb->setParameter('session', $session); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
$qb->andWhere('node.parent = :parentNode'); |
|
91
|
|
|
$qb->setParameter('parentNode', $parentNode); |
|
92
|
|
|
|
|
93
|
|
|
$qb->andWhere('links.group IS NULL'); |
|
94
|
|
|
|
|
95
|
|
|
///var_dump($qb->getQuery()->getSQL(), $type->getId(), $parentNode->getId());exit; |
|
96
|
|
|
|
|
97
|
|
|
return $qb; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function saveUpload(UploadedFile $file) |
|
101
|
|
|
{ |
|
102
|
|
|
throw new AccessDeniedException(); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function saveResource(FormInterface $form, $course, $session, $fileType) |
|
106
|
|
|
{ |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
public function getTitleColumn(Grid $grid): Column |
|
110
|
|
|
{ |
|
111
|
|
|
return $grid->getColumn('name'); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|