|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use APY\DataGridBundle\Grid\Action\MassAction; |
|
8
|
|
|
use APY\DataGridBundle\Grid\Action\RowAction; |
|
9
|
|
|
use APY\DataGridBundle\Grid\Column\Column; |
|
10
|
|
|
use APY\DataGridBundle\Grid\Export\CSVExport; |
|
11
|
|
|
use APY\DataGridBundle\Grid\Export\ExcelExport; |
|
12
|
|
|
use APY\DataGridBundle\Grid\Grid; |
|
13
|
|
|
use APY\DataGridBundle\Grid\Row; |
|
14
|
|
|
use APY\DataGridBundle\Grid\Source\Entity; |
|
15
|
|
|
use Chamilo\CoreBundle\Entity\Resource\AbstractResource; |
|
16
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface; |
|
17
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceLink; |
|
18
|
|
|
use Chamilo\CoreBundle\Entity\Resource\ResourceNode; |
|
19
|
|
|
use Chamilo\CoreBundle\Repository\IllustrationRepository; |
|
20
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
|
21
|
|
|
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface; |
|
22
|
|
|
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter; |
|
23
|
|
|
use Chamilo\CourseBundle\Controller\CourseControllerInterface; |
|
24
|
|
|
use Chamilo\CourseBundle\Controller\CourseControllerTrait; |
|
25
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
26
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
27
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
28
|
|
|
use FOS\CKEditorBundle\Form\Type\CKEditorType; |
|
29
|
|
|
use Symfony\Component\Filesystem\Exception\FileNotFoundException; |
|
30
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
31
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
32
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
33
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
34
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
35
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
36
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
37
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
38
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
39
|
|
|
use Symfony\Component\Routing\Router; |
|
40
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
41
|
|
|
use ZipStream\Option\Archive; |
|
42
|
|
|
use ZipStream\ZipStream; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Class ResourceController. |
|
46
|
|
|
* |
|
47
|
|
|
* @todo improve/refactor $this->denyAccessUnlessGranted |
|
48
|
|
|
* @Route("/resources") |
|
49
|
|
|
* |
|
50
|
|
|
* @author Julio Montoya <[email protected]>. |
|
51
|
|
|
*/ |
|
52
|
|
|
class ResourceController extends AbstractResourceController implements CourseControllerInterface |
|
53
|
|
|
{ |
|
54
|
|
|
use CourseControllerTrait; |
|
55
|
|
|
|
|
56
|
|
|
private $fileContentName = 'file_content'; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @Route("/{tool}/{type}", name="chamilo_core_resource_index") |
|
60
|
|
|
* |
|
61
|
|
|
* Example: /document/files (See the 'tool' and the 'resource_type' DB tables.) |
|
62
|
|
|
* For the tool value check the Tool entity. |
|
63
|
|
|
* For the type value check the ResourceType entity. |
|
64
|
|
|
*/ |
|
65
|
|
|
public function indexAction(Request $request, Grid $grid): Response |
|
66
|
|
|
{ |
|
67
|
|
|
$tool = $request->get('tool'); |
|
68
|
|
|
$type = $request->get('type'); |
|
69
|
|
|
|
|
70
|
|
|
$parentResourceNode = $this->getParentResourceNode($request); |
|
71
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
72
|
|
|
$settings = $repository->getResourceSettings(); |
|
73
|
|
|
|
|
74
|
|
|
$grid = $this->getGrid($request, $repository, $grid, $parentResourceNode->getId()); |
|
75
|
|
|
|
|
76
|
|
|
$breadcrumb = $this->getBreadCrumb(); |
|
77
|
|
|
$breadcrumb->addChild( |
|
78
|
|
|
$this->trans($tool), |
|
79
|
|
|
[ |
|
80
|
|
|
'uri' => '#', |
|
81
|
|
|
] |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
// The base resource node is the course. |
|
85
|
|
|
$id = $parentResourceNode->getId(); |
|
86
|
|
|
|
|
87
|
|
|
return $grid->getGridResponse( |
|
88
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
89
|
|
|
[ |
|
90
|
|
|
'tool' => $tool, |
|
91
|
|
|
'type' => $type, |
|
92
|
|
|
'id' => $id, |
|
93
|
|
|
'parent_resource_node' => $parentResourceNode, |
|
94
|
|
|
'resource_settings' => $settings, |
|
95
|
|
|
] |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @Route("/{tool}/{type}/{id}/list", name="chamilo_core_resource_list") |
|
101
|
|
|
* |
|
102
|
|
|
* If node has children show it |
|
103
|
|
|
*/ |
|
104
|
|
|
public function listAction(Request $request, Grid $grid): Response |
|
105
|
|
|
{ |
|
106
|
|
|
$tool = $request->get('tool'); |
|
107
|
|
|
$type = $request->get('type'); |
|
108
|
|
|
$resourceNodeId = $request->get('id'); |
|
109
|
|
|
|
|
110
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
111
|
|
|
$settings = $repository->getResourceSettings(); |
|
112
|
|
|
|
|
113
|
|
|
$grid = $this->getGrid($request, $repository, $grid, $resourceNodeId); |
|
114
|
|
|
|
|
115
|
|
|
$this->setBreadCrumb($request); |
|
116
|
|
|
$parentResourceNode = $this->getParentResourceNode($request); |
|
117
|
|
|
|
|
118
|
|
|
return $grid->getGridResponse( |
|
119
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
120
|
|
|
[ |
|
121
|
|
|
'parent_id' => $resourceNodeId, |
|
122
|
|
|
'tool' => $tool, |
|
123
|
|
|
'type' => $type, |
|
124
|
|
|
'id' => $resourceNodeId, |
|
125
|
|
|
'parent_resource_node' => $parentResourceNode, |
|
126
|
|
|
'resource_settings' => $settings, |
|
127
|
|
|
] |
|
128
|
|
|
); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function getGrid(Request $request, ResourceRepository $repository, Grid $grid, int $resourceNodeId): Grid |
|
132
|
|
|
{ |
|
133
|
|
|
$class = $repository->getRepository()->getClassName(); |
|
134
|
|
|
|
|
135
|
|
|
// The group 'resource' is set in the @GRID\Source annotation in the entity. |
|
136
|
|
|
$source = new Entity($class, 'resource'); |
|
137
|
|
|
/** @var ResourceNode $parentNode */ |
|
138
|
|
|
$parentNode = $repository->getResourceNodeRepository()->find($resourceNodeId); |
|
139
|
|
|
|
|
140
|
|
|
$this->denyAccessUnlessGranted( |
|
141
|
|
|
ResourceNodeVoter::VIEW, |
|
142
|
|
|
$parentNode, |
|
143
|
|
|
$this->trans('Unauthorised access to resource') |
|
144
|
|
|
); |
|
145
|
|
|
|
|
146
|
|
|
$settings = $repository->getResourceSettings(); |
|
147
|
|
|
|
|
148
|
|
|
$course = $this->getCourse(); |
|
149
|
|
|
$session = $this->getSession(); |
|
150
|
|
|
/** @var QueryBuilder $qb */ |
|
151
|
|
|
$qb = $repository->getResources($this->getUser(), $parentNode, $course, $session, null); |
|
152
|
|
|
|
|
153
|
|
|
// 3. Set QueryBuilder to the source. |
|
154
|
|
|
$source->initQueryBuilder($qb); |
|
155
|
|
|
$grid->setSource($source); |
|
156
|
|
|
|
|
157
|
|
|
$resourceParams = $this->getResourceParams($request); |
|
158
|
|
|
|
|
159
|
|
|
if (0 === $resourceParams['id']) { |
|
160
|
|
|
$resourceParams['id'] = $resourceNodeId; |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
$grid->setRouteUrl($this->generateUrl('chamilo_core_resource_list', $resourceParams)); |
|
164
|
|
|
|
|
165
|
|
|
//$grid->hideFilters(); |
|
166
|
|
|
//$grid->setLimits(20); |
|
167
|
|
|
//$grid->isReadyForRedirect(); |
|
168
|
|
|
//$grid->setMaxResults(1); |
|
169
|
|
|
//$grid->setLimits(2); |
|
170
|
|
|
//$grid->setColumns($columns); |
|
171
|
|
|
$routeParams = $resourceParams; |
|
172
|
|
|
$routeParams['id'] = null; |
|
173
|
|
|
|
|
174
|
|
|
/** @var Column $titleColumn */ |
|
175
|
|
|
$titleColumn = $repository->getTitleColumn($grid); |
|
176
|
|
|
|
|
177
|
|
|
$titleColumn->setSafe(false); // allows links in the title |
|
178
|
|
|
|
|
179
|
|
|
// Title link. |
|
180
|
|
|
$titleColumn->setTitle($this->trans('Name')); |
|
181
|
|
|
|
|
182
|
|
|
$titleColumn->manipulateRenderCell( |
|
183
|
|
|
function ($value, Row $row, $router) use ($routeParams, $settings) { |
|
184
|
|
|
/** @var Router $router */ |
|
185
|
|
|
/** @var ResourceInterface $entity */ |
|
186
|
|
|
$entity = $row->getEntity(); |
|
187
|
|
|
$resourceNode = $entity->getResourceNode(); |
|
188
|
|
|
$id = $resourceNode->getId(); |
|
189
|
|
|
|
|
190
|
|
|
$myParams = $routeParams; |
|
191
|
|
|
$myParams['id'] = $id; |
|
192
|
|
|
unset($myParams[0]); |
|
193
|
|
|
|
|
194
|
|
|
$icon = $resourceNode->getIcon().' '; |
|
195
|
|
|
if ($resourceNode->hasResourceFile()) { |
|
196
|
|
|
// Process node that contains a file, process previews. |
|
197
|
|
|
if ($resourceNode->isResourceFileAnImage()) { |
|
198
|
|
|
$url = $router->generate('chamilo_core_resource_view_file', $myParams); |
|
199
|
|
|
|
|
200
|
|
|
return $icon.'<a data-fancybox="gallery" href="'.$url.'">'.$value.'</a>'; |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
if ($resourceNode->isResourceFileAVideo()) { |
|
204
|
|
|
$url = $router->generate('chamilo_core_resource_view_file', $myParams); |
|
205
|
|
|
|
|
206
|
|
|
return ' |
|
207
|
|
|
<video width="640" height="320" controls id="video'.$id.'" controls preload="metadata" style="display:none;"> |
|
208
|
|
|
<source src="'.$url.'" type="video/mp4"> |
|
209
|
|
|
Your browser doesn\'t support HTML5 video tag. |
|
210
|
|
|
</video> |
|
211
|
|
|
'.$icon.' <a data-fancybox="gallery" data-width="640" data-height="360" href="#video'.$id.'">'.$value.'</a>'; |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
$url = $router->generate('chamilo_core_resource_preview', $myParams); |
|
215
|
|
|
|
|
216
|
|
|
return $icon. |
|
217
|
|
|
'<a data-fancybox="gallery" data-type="iframe" data-src="'.$url.'" href="javascript:;" >'. |
|
218
|
|
|
$value.'</a>'; |
|
219
|
|
|
} else { |
|
220
|
|
|
if ($settings->isAllowNodeCreation()) { |
|
221
|
|
|
$url = $router->generate( |
|
222
|
|
|
'chamilo_core_resource_list', |
|
223
|
|
|
$myParams |
|
224
|
|
|
); |
|
225
|
|
|
} else { |
|
226
|
|
|
$url = $router->generate('chamilo_core_resource_view_resource', $myParams); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
return $icon.'<a href="'.$url.'">'.$value.'</a>'; |
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
); |
|
233
|
|
|
|
|
234
|
|
|
if ($grid->hasColumn('filetype')) { |
|
235
|
|
|
$grid->getColumn('filetype')->manipulateRenderCell( |
|
236
|
|
|
function ($value, Row $row, $router) { |
|
|
|
|
|
|
237
|
|
|
/** @var AbstractResource $entity */ |
|
238
|
|
|
$entity = $row->getEntity(); |
|
239
|
|
|
$resourceNode = $entity->getResourceNode(); |
|
240
|
|
|
|
|
241
|
|
|
if ($resourceNode->hasResourceFile()) { |
|
242
|
|
|
$file = $resourceNode->getResourceFile(); |
|
243
|
|
|
|
|
244
|
|
|
return $file->getMimeType(); |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
return $this->trans('Folder'); |
|
248
|
|
|
} |
|
249
|
|
|
); |
|
250
|
|
|
} |
|
251
|
|
|
|
|
252
|
|
|
if ($grid->hasColumn('iid')) { |
|
253
|
|
|
$grid->setHiddenColumns(['iid']); |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
// Delete mass action. |
|
257
|
|
|
if ($this->isGranted(ResourceNodeVoter::DELETE, $parentNode)) { |
|
258
|
|
|
$deleteMassAction = new MassAction( |
|
259
|
|
|
'Delete', |
|
260
|
|
|
'ChamiloCoreBundle:Resource:deleteMass', |
|
261
|
|
|
true, |
|
262
|
|
|
$routeParams |
|
263
|
|
|
); |
|
264
|
|
|
$grid->addMassAction($deleteMassAction); |
|
265
|
|
|
} |
|
266
|
|
|
|
|
267
|
|
|
// Info action. |
|
268
|
|
|
$myRowAction = new RowAction( |
|
269
|
|
|
$this->trans('Info'), |
|
270
|
|
|
'chamilo_core_resource_info', |
|
271
|
|
|
false, |
|
272
|
|
|
'_self', |
|
273
|
|
|
[ |
|
274
|
|
|
'class' => 'btn btn-secondary info_action', |
|
275
|
|
|
'icon' => 'fa-info-circle', |
|
276
|
|
|
'iframe' => false, |
|
277
|
|
|
] |
|
278
|
|
|
); |
|
279
|
|
|
|
|
280
|
|
|
$setNodeParameters = function (RowAction $action, Row $row) use ($routeParams) { |
|
281
|
|
|
$id = $row->getEntity()->getResourceNode()->getId(); |
|
282
|
|
|
$routeParams['id'] = $id; |
|
283
|
|
|
$action->setRouteParameters($routeParams); |
|
284
|
|
|
$attributes = $action->getAttributes(); |
|
285
|
|
|
$attributes['data-action'] = $action->getRoute(); |
|
286
|
|
|
$attributes['data-action-id'] = $action->getRoute().'_'.$id; |
|
287
|
|
|
$attributes['data-node-id'] = $id; |
|
288
|
|
|
$attributes['title'] = $this->trans('Info').' '.$row->getEntity()->getResourceName(); |
|
289
|
|
|
$action->setAttributes($attributes); |
|
290
|
|
|
|
|
291
|
|
|
return $action; |
|
292
|
|
|
}; |
|
293
|
|
|
|
|
294
|
|
|
$myRowAction->addManipulateRender($setNodeParameters); |
|
295
|
|
|
$grid->addRowAction($myRowAction); |
|
296
|
|
|
|
|
297
|
|
|
// Download action |
|
298
|
|
|
$myRowAction = new RowAction( |
|
299
|
|
|
$this->trans('Download'), |
|
300
|
|
|
'chamilo_core_resource_download', |
|
301
|
|
|
false, |
|
302
|
|
|
'_self', |
|
303
|
|
|
[ |
|
304
|
|
|
'class' => 'btn btn-secondary download_action', |
|
305
|
|
|
'icon' => 'fa-download', |
|
306
|
|
|
'title' => $this->trans('Download'), |
|
307
|
|
|
] |
|
308
|
|
|
); |
|
309
|
|
|
|
|
310
|
|
|
$setNodeDownloadParameters = function (RowAction $action, Row $row) use ($routeParams) { |
|
311
|
|
|
/** @var ResourceNode $resourceNode */ |
|
312
|
|
|
$resourceNode = $row->getEntity()->getResourceNode(); |
|
313
|
|
|
if (false === $resourceNode->hasResourceFile()) { |
|
314
|
|
|
return null; |
|
315
|
|
|
} |
|
316
|
|
|
$id = $row->getEntity()->getResourceNode()->getId(); |
|
317
|
|
|
$routeParams['id'] = $id; |
|
318
|
|
|
$action->setRouteParameters($routeParams); |
|
319
|
|
|
$attributes = $action->getAttributes(); |
|
320
|
|
|
$action->setAttributes($attributes); |
|
321
|
|
|
|
|
322
|
|
|
return $action; |
|
323
|
|
|
}; |
|
324
|
|
|
$myRowAction->addManipulateRender($setNodeDownloadParameters); |
|
325
|
|
|
$grid->addRowAction($myRowAction); |
|
326
|
|
|
|
|
327
|
|
|
// Set EDIT/DELETE |
|
328
|
|
|
$setNodeParameters = function (RowAction $action, Row $row) use ($routeParams) { |
|
329
|
|
|
$id = $row->getEntity()->getResourceNode()->getId(); |
|
330
|
|
|
$allowedEdit = $this->isGranted(ResourceNodeVoter::EDIT, $row->getEntity()->getResourceNode()); |
|
331
|
|
|
|
|
332
|
|
|
if (false === $allowedEdit) { |
|
333
|
|
|
return null; |
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
$routeParams['id'] = $id; |
|
337
|
|
|
|
|
338
|
|
|
$action->setRouteParameters($routeParams); |
|
339
|
|
|
$attributes = $action->getAttributes(); |
|
340
|
|
|
//$attributes['data-action'] = $action->getRoute(); |
|
341
|
|
|
//$attributes['data-action-id'] = $action->getRoute().'_'.$id; |
|
342
|
|
|
//$attributes['data-node-id'] = $id; |
|
343
|
|
|
$action->setAttributes($attributes); |
|
344
|
|
|
|
|
345
|
|
|
return $action; |
|
346
|
|
|
}; |
|
347
|
|
|
|
|
348
|
|
|
if ($this->isGranted(ResourceNodeVoter::EDIT, $parentNode)) { |
|
349
|
|
|
// Enable/Disable |
|
350
|
|
|
$myRowAction = new RowAction( |
|
351
|
|
|
'', |
|
352
|
|
|
'chamilo_core_resource_change_visibility', |
|
353
|
|
|
false, |
|
354
|
|
|
'_self' |
|
355
|
|
|
); |
|
356
|
|
|
|
|
357
|
|
|
$setVisibleParameters = function (RowAction $action, Row $row) use ($routeParams) { |
|
358
|
|
|
/** @var AbstractResource $resource */ |
|
359
|
|
|
$resource = $row->getEntity(); |
|
360
|
|
|
$allowedEdit = $this->isGranted(ResourceNodeVoter::EDIT, $resource->getResourceNode()); |
|
361
|
|
|
|
|
362
|
|
|
if (false === $allowedEdit) { |
|
363
|
|
|
return null; |
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
$id = $resource->getResourceNode()->getId(); |
|
367
|
|
|
|
|
368
|
|
|
$icon = 'fa-eye-slash'; |
|
369
|
|
|
if ($this->hasCourse()) { |
|
370
|
|
|
$link = $resource->getCourseSessionResourceLink($this->getCourse(), $this->getSession()); |
|
371
|
|
|
} else { |
|
372
|
|
|
$link = $resource->getFirstResourceLink(); |
|
373
|
|
|
} |
|
374
|
|
|
|
|
375
|
|
|
if (null === $link) { |
|
376
|
|
|
return null; |
|
377
|
|
|
} |
|
378
|
|
|
if (ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility()) { |
|
379
|
|
|
$icon = 'fa-eye'; |
|
380
|
|
|
} |
|
381
|
|
|
$routeParams['id'] = $id; |
|
382
|
|
|
$action->setRouteParameters($routeParams); |
|
383
|
|
|
$attributes = [ |
|
384
|
|
|
'class' => 'btn btn-secondary change_visibility', |
|
385
|
|
|
'data-id' => $id, |
|
386
|
|
|
'icon' => $icon, |
|
387
|
|
|
]; |
|
388
|
|
|
$action->setAttributes($attributes); |
|
389
|
|
|
|
|
390
|
|
|
return $action; |
|
391
|
|
|
}; |
|
392
|
|
|
|
|
393
|
|
|
$myRowAction->addManipulateRender($setVisibleParameters); |
|
394
|
|
|
$grid->addRowAction($myRowAction); |
|
395
|
|
|
|
|
396
|
|
|
if ($settings->isAllowResourceEdit()) { |
|
397
|
|
|
// Edit action. |
|
398
|
|
|
$myRowAction = new RowAction( |
|
399
|
|
|
$this->trans('Edit'), |
|
400
|
|
|
'chamilo_core_resource_edit', |
|
401
|
|
|
false, |
|
402
|
|
|
'_self', |
|
403
|
|
|
['class' => 'btn btn-secondary', 'icon' => 'fa fa-pen'] |
|
404
|
|
|
); |
|
405
|
|
|
$myRowAction->addManipulateRender($setNodeParameters); |
|
406
|
|
|
$grid->addRowAction($myRowAction); |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
// More action. |
|
410
|
|
|
/*$myRowAction = new RowAction( |
|
411
|
|
|
$this->trans('More'), |
|
412
|
|
|
'chamilo_core_resource_preview', |
|
413
|
|
|
false, |
|
414
|
|
|
'_self', |
|
415
|
|
|
['class' => 'btn btn-secondary edit_resource', 'icon' => 'fa fa-ellipsis-h'] |
|
416
|
|
|
); |
|
417
|
|
|
|
|
418
|
|
|
$myRowAction->addManipulateRender($setNodeParameters); |
|
419
|
|
|
$grid->addRowAction($myRowAction);*/ |
|
420
|
|
|
|
|
421
|
|
|
// Delete action. |
|
422
|
|
|
$myRowAction = new RowAction( |
|
423
|
|
|
$this->trans('Delete'), |
|
424
|
|
|
'chamilo_core_resource_delete', |
|
425
|
|
|
true, |
|
426
|
|
|
'_self', |
|
427
|
|
|
[ |
|
428
|
|
|
'class' => 'btn btn-danger', |
|
429
|
|
|
//'data_hidden' => true, |
|
430
|
|
|
] |
|
431
|
|
|
); |
|
432
|
|
|
$myRowAction->addManipulateRender($setNodeParameters); |
|
433
|
|
|
$grid->addRowAction($myRowAction); |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/*$grid->addExport(new CSVExport($this->trans('CSV export'), 'export', ['course' => $courseIdentifier])); |
|
437
|
|
|
$grid->addExport( |
|
438
|
|
|
new ExcelExport( |
|
439
|
|
|
$this->trans('Excel export'), |
|
440
|
|
|
'export', |
|
441
|
|
|
['course' => $courseIdentifier] |
|
442
|
|
|
) |
|
443
|
|
|
);*/ |
|
444
|
|
|
|
|
445
|
|
|
return $grid; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* @Route("/{tool}/{type}/{id}/new_folder", methods={"GET", "POST"}, name="chamilo_core_resource_new_folder") |
|
450
|
|
|
*/ |
|
451
|
|
|
public function newFolderAction(Request $request): Response |
|
452
|
|
|
{ |
|
453
|
|
|
$this->setBreadCrumb($request); |
|
454
|
|
|
|
|
455
|
|
|
return $this->createResource($request, 'folder'); |
|
456
|
|
|
} |
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* @Route("/{tool}/{type}/{id}/new", methods={"GET", "POST"}, name="chamilo_core_resource_new") |
|
460
|
|
|
*/ |
|
461
|
|
|
public function newAction(Request $request): Response |
|
462
|
|
|
{ |
|
463
|
|
|
$this->setBreadCrumb($request); |
|
464
|
|
|
|
|
465
|
|
|
return $this->createResource($request, 'file'); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* @Route("/{tool}/{type}/{id}/disk_space", methods={"GET", "POST"}, name="chamilo_core_resource_disk_space") |
|
470
|
|
|
*/ |
|
471
|
|
|
public function diskSpaceAction(Request $request): Response |
|
472
|
|
|
{ |
|
473
|
|
|
$this->setBreadCrumb($request); |
|
474
|
|
|
$nodeId = $request->get('id'); |
|
475
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
476
|
|
|
|
|
477
|
|
|
/** @var ResourceNode $resourceNode */ |
|
478
|
|
|
$resourceNode = $repository->getResourceNodeRepository()->find($nodeId); |
|
479
|
|
|
|
|
480
|
|
|
$this->denyAccessUnlessGranted( |
|
481
|
|
|
ResourceNodeVoter::VIEW, |
|
482
|
|
|
$resourceNode, |
|
483
|
|
|
$this->trans('Unauthorised access to resource') |
|
484
|
|
|
); |
|
485
|
|
|
|
|
486
|
|
|
$course = $this->getCourse(); |
|
487
|
|
|
$totalSize = 0; |
|
488
|
|
|
if ($course) { |
|
|
|
|
|
|
489
|
|
|
$totalSize = $course->getDiskQuota(); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
$size = $repository->getResourceNodeRepository()->getSize( |
|
493
|
|
|
$resourceNode, |
|
494
|
|
|
$repository->getResourceType(), |
|
495
|
|
|
$course |
|
496
|
|
|
); |
|
497
|
|
|
|
|
498
|
|
|
$labels[] = $course->getTitle(); |
|
|
|
|
|
|
499
|
|
|
$data[] = $size; |
|
|
|
|
|
|
500
|
|
|
$sessions = $course->getSessions(); |
|
501
|
|
|
|
|
502
|
|
|
foreach ($sessions as $sessionRelCourse) { |
|
503
|
|
|
$session = $sessionRelCourse->getSession(); |
|
504
|
|
|
|
|
505
|
|
|
$labels[] = $course->getTitle().' - '.$session->getName(); |
|
506
|
|
|
$size = $repository->getResourceNodeRepository()->getSize( |
|
507
|
|
|
$resourceNode, |
|
508
|
|
|
$repository->getResourceType(), |
|
509
|
|
|
$course, |
|
510
|
|
|
$session |
|
511
|
|
|
); |
|
512
|
|
|
$data[] = $size; |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
$groups = $course->getGroups(); |
|
516
|
|
|
foreach ($groups as $group) { |
|
517
|
|
|
$labels[] = $course->getTitle().' - '.$group->getName(); |
|
518
|
|
|
$size = $repository->getResourceNodeRepository()->getSize( |
|
519
|
|
|
$resourceNode, |
|
520
|
|
|
$repository->getResourceType(), |
|
521
|
|
|
$course, |
|
522
|
|
|
null, |
|
523
|
|
|
$group |
|
524
|
|
|
); |
|
525
|
|
|
$data[] = $size; |
|
526
|
|
|
} |
|
527
|
|
|
|
|
528
|
|
|
$used = array_sum($data); |
|
529
|
|
|
$labels[] = $this->trans('Free'); |
|
530
|
|
|
$data[] = $totalSize - $used; |
|
531
|
|
|
|
|
532
|
|
|
return $this->render( |
|
533
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
534
|
|
|
[ |
|
535
|
|
|
'resourceNode' => $resourceNode, |
|
536
|
|
|
'labels' => $labels, |
|
537
|
|
|
'data' => $data, |
|
538
|
|
|
] |
|
539
|
|
|
); |
|
540
|
|
|
} |
|
541
|
|
|
|
|
542
|
|
|
/** |
|
543
|
|
|
* @Route("/{tool}/{type}/{id}/edit", methods={"GET", "POST"}) |
|
544
|
|
|
*/ |
|
545
|
|
|
public function editAction(Request $request, IllustrationRepository $illustrationRepository): Response |
|
546
|
|
|
{ |
|
547
|
|
|
$resourceNodeId = $request->get('id'); |
|
548
|
|
|
|
|
549
|
|
|
$this->setBreadCrumb($request); |
|
550
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
551
|
|
|
$resource = $repository->getResourceFromResourceNode($resourceNodeId); |
|
552
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
|
|
|
|
|
553
|
|
|
$settings = $repository->getResourceSettings(); |
|
554
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
555
|
|
|
|
|
556
|
|
|
$this->denyAccessUnlessGranted( |
|
557
|
|
|
ResourceNodeVoter::EDIT, |
|
558
|
|
|
$resourceNode, |
|
559
|
|
|
$this->trans('Unauthorised access to resource') |
|
560
|
|
|
); |
|
561
|
|
|
|
|
562
|
|
|
$resourceNodeParentId = $resourceNode->getId(); |
|
563
|
|
|
|
|
564
|
|
|
$routeParams = $this->getResourceParams($request); |
|
565
|
|
|
$routeParams['id'] = $resourceNodeParentId; |
|
566
|
|
|
|
|
567
|
|
|
$form = $repository->getForm($this->container->get('form.factory'), $resource); |
|
568
|
|
|
|
|
569
|
|
|
if ($resourceNode->hasEditableContent() && $settings->isAllowToSaveEditorToResourceFile()) { |
|
570
|
|
|
$form->add( |
|
571
|
|
|
$this->fileContentName, |
|
572
|
|
|
CKEditorType::class, |
|
573
|
|
|
[ |
|
574
|
|
|
'mapped' => false, |
|
575
|
|
|
'config' => [ |
|
576
|
|
|
'filebrowserImageBrowseRoute' => 'resources_filemanager', |
|
577
|
|
|
'filebrowserImageBrowseRouteParameters' => $routeParams, |
|
578
|
|
|
], |
|
579
|
|
|
] |
|
580
|
|
|
); |
|
581
|
|
|
$content = $repository->getResourceNodeFileContent($resourceNode); |
|
582
|
|
|
$form->get($this->fileContentName)->setData($content); |
|
583
|
|
|
} |
|
584
|
|
|
|
|
585
|
|
|
$form->handleRequest($request); |
|
586
|
|
|
|
|
587
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
588
|
|
|
/** @var AbstractResource $newResource */ |
|
589
|
|
|
$newResource = $form->getData(); |
|
590
|
|
|
|
|
591
|
|
|
if ($form->has($this->fileContentName)) { |
|
592
|
|
|
$data = $form->get($this->fileContentName)->getData(); |
|
593
|
|
|
$repository->updateResourceFileContent($newResource, $data); |
|
594
|
|
|
} |
|
595
|
|
|
|
|
596
|
|
|
$repository->updateNodeForResource($newResource); |
|
597
|
|
|
|
|
598
|
|
|
if ($form->has('illustration')) { |
|
599
|
|
|
$illustration = $form->get('illustration')->getData(); |
|
600
|
|
|
if ($illustration) { |
|
601
|
|
|
$file = $illustrationRepository->addIllustration($newResource, $this->getUser(), $illustration); |
|
602
|
|
|
$em = $illustrationRepository->getEntityManager(); |
|
603
|
|
|
$em->persist($file); |
|
604
|
|
|
$em->flush(); |
|
605
|
|
|
} |
|
606
|
|
|
} |
|
607
|
|
|
|
|
608
|
|
|
$this->addFlash('success', $this->trans('Updated')); |
|
609
|
|
|
|
|
610
|
|
|
//if ($newResource->getResourceNode()->hasResourceFile()) { |
|
611
|
|
|
$resourceNodeParentId = $newResource->getResourceNode()->getParent()->getId(); |
|
612
|
|
|
//} |
|
613
|
|
|
$routeParams['id'] = $resourceNodeParentId; |
|
614
|
|
|
|
|
615
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
|
616
|
|
|
} |
|
617
|
|
|
|
|
618
|
|
|
return $this->render( |
|
619
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
620
|
|
|
[ |
|
621
|
|
|
'form' => $form->createView(), |
|
622
|
|
|
'parent' => $resourceNodeParentId, |
|
623
|
|
|
] |
|
624
|
|
|
); |
|
625
|
|
|
} |
|
626
|
|
|
|
|
627
|
|
|
/** |
|
628
|
|
|
* Shows a resource information. |
|
629
|
|
|
* |
|
630
|
|
|
* @Route("/{tool}/{type}/{id}/info", methods={"GET"}, name="chamilo_core_resource_info") |
|
631
|
|
|
*/ |
|
632
|
|
|
public function infoAction(Request $request, IllustrationRepository $illustrationRepository): Response |
|
633
|
|
|
{ |
|
634
|
|
|
$this->setBreadCrumb($request); |
|
635
|
|
|
$nodeId = $request->get('id'); |
|
636
|
|
|
|
|
637
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
638
|
|
|
|
|
639
|
|
|
/** @var AbstractResource $resource */ |
|
640
|
|
|
$resource = $repository->getResourceFromResourceNode($nodeId); |
|
641
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
642
|
|
|
|
|
643
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
644
|
|
|
$this->denyAccessUnlessGranted( |
|
645
|
|
|
ResourceNodeVoter::VIEW, |
|
646
|
|
|
$resourceNode, |
|
647
|
|
|
$this->trans('Unauthorised access to resource') |
|
648
|
|
|
); |
|
649
|
|
|
|
|
650
|
|
|
$tool = $request->get('tool'); |
|
651
|
|
|
$type = $request->get('type'); |
|
652
|
|
|
|
|
653
|
|
|
$illustration = $illustrationRepository->getIllustrationUrlFromNode($resource->getResourceNode()); |
|
654
|
|
|
|
|
655
|
|
|
$params = [ |
|
656
|
|
|
'resource' => $resource, |
|
657
|
|
|
'illustration' => $illustration, |
|
658
|
|
|
'tool' => $tool, |
|
659
|
|
|
'type' => $type, |
|
660
|
|
|
]; |
|
661
|
|
|
|
|
662
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $params); |
|
663
|
|
|
} |
|
664
|
|
|
|
|
665
|
|
|
/** |
|
666
|
|
|
* Preview a file. Mostly used when using a modal. |
|
667
|
|
|
* |
|
668
|
|
|
* @Route("/{tool}/{type}/{id}/preview", methods={"GET"}, name="chamilo_core_resource_preview") |
|
669
|
|
|
*/ |
|
670
|
|
|
public function previewAction(Request $request): Response |
|
671
|
|
|
{ |
|
672
|
|
|
$this->setBreadCrumb($request); |
|
673
|
|
|
$nodeId = $request->get('id'); |
|
674
|
|
|
|
|
675
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
676
|
|
|
|
|
677
|
|
|
/** @var AbstractResource $resource */ |
|
678
|
|
|
$resource = $repository->getResourceFromResourceNode($nodeId); |
|
679
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
680
|
|
|
|
|
681
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
682
|
|
|
|
|
683
|
|
|
$this->denyAccessUnlessGranted( |
|
684
|
|
|
ResourceNodeVoter::VIEW, |
|
685
|
|
|
$resourceNode, |
|
686
|
|
|
$this->trans('Unauthorised access to resource') |
|
687
|
|
|
); |
|
688
|
|
|
|
|
689
|
|
|
$tool = $request->get('tool'); |
|
690
|
|
|
$type = $request->get('type'); |
|
691
|
|
|
|
|
692
|
|
|
$params = [ |
|
693
|
|
|
'resource' => $resource, |
|
694
|
|
|
'tool' => $tool, |
|
695
|
|
|
'type' => $type, |
|
696
|
|
|
]; |
|
697
|
|
|
|
|
698
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $params); |
|
699
|
|
|
} |
|
700
|
|
|
|
|
701
|
|
|
/** |
|
702
|
|
|
* @Route("/{tool}/{type}/{id}/change_visibility", name="chamilo_core_resource_change_visibility") |
|
703
|
|
|
*/ |
|
704
|
|
|
public function changeVisibilityAction(Request $request): Response |
|
705
|
|
|
{ |
|
706
|
|
|
$id = $request->get('id'); |
|
707
|
|
|
|
|
708
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
709
|
|
|
|
|
710
|
|
|
/** @var AbstractResource $resource */ |
|
711
|
|
|
$resource = $repository->getResourceFromResourceNode($id); |
|
712
|
|
|
|
|
713
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
714
|
|
|
|
|
715
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
716
|
|
|
|
|
717
|
|
|
$this->denyAccessUnlessGranted( |
|
718
|
|
|
ResourceNodeVoter::EDIT, |
|
719
|
|
|
$resourceNode, |
|
720
|
|
|
$this->trans('Unauthorised access to resource') |
|
721
|
|
|
); |
|
722
|
|
|
|
|
723
|
|
|
/** @var ResourceLink $link */ |
|
724
|
|
|
if ($this->hasCourse()) { |
|
725
|
|
|
$link = $resource->getCourseSessionResourceLink($this->getCourse(), $this->getSession()); |
|
726
|
|
|
} else { |
|
727
|
|
|
$link = $resource->getFirstResourceLink(); |
|
728
|
|
|
} |
|
729
|
|
|
|
|
730
|
|
|
$icon = 'fa-eye'; |
|
731
|
|
|
// Use repository to change settings easily. |
|
732
|
|
|
if ($link && ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility()) { |
|
733
|
|
|
$repository->setVisibilityDraft($resource); |
|
734
|
|
|
$icon = 'fa-eye-slash'; |
|
735
|
|
|
} else { |
|
736
|
|
|
$repository->setVisibilityPublished($resource); |
|
737
|
|
|
} |
|
738
|
|
|
|
|
739
|
|
|
$result = ['icon' => $icon]; |
|
740
|
|
|
|
|
741
|
|
|
return new JsonResponse($result); |
|
742
|
|
|
} |
|
743
|
|
|
|
|
744
|
|
|
/** |
|
745
|
|
|
* @Route("/{tool}/{type}/{id}", name="chamilo_core_resource_delete") |
|
746
|
|
|
*/ |
|
747
|
|
|
public function deleteAction(Request $request): Response |
|
748
|
|
|
{ |
|
749
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
750
|
|
|
|
|
751
|
|
|
$id = $request->get('id'); |
|
752
|
|
|
$resourceNode = $this->getDoctrine()->getRepository('ChamiloCoreBundle:Resource\ResourceNode')->find($id); |
|
753
|
|
|
$parentId = $resourceNode->getParent()->getId(); |
|
754
|
|
|
|
|
755
|
|
|
$this->denyAccessUnlessGranted( |
|
756
|
|
|
ResourceNodeVoter::DELETE, |
|
757
|
|
|
$resourceNode, |
|
758
|
|
|
$this->trans('Unauthorised access to resource') |
|
759
|
|
|
); |
|
760
|
|
|
|
|
761
|
|
|
$children = $resourceNode->getChildren(); |
|
762
|
|
|
|
|
763
|
|
|
if (!empty($children)) { |
|
764
|
|
|
/** @var ResourceNode $child */ |
|
765
|
|
|
foreach ($children as $child) { |
|
766
|
|
|
$em->remove($child); |
|
767
|
|
|
} |
|
768
|
|
|
} |
|
769
|
|
|
|
|
770
|
|
|
$em->remove($resourceNode); |
|
771
|
|
|
$this->addFlash('success', $this->trans('Deleted')); |
|
772
|
|
|
$em->flush(); |
|
773
|
|
|
|
|
774
|
|
|
$routeParams = $this->getResourceParams($request); |
|
775
|
|
|
$routeParams['id'] = $parentId; |
|
776
|
|
|
|
|
777
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
|
778
|
|
|
} |
|
779
|
|
|
|
|
780
|
|
|
/** |
|
781
|
|
|
* @Route("/{tool}/{type}/{id}", methods={"DELETE"}, name="chamilo_core_resource_delete_mass") |
|
782
|
|
|
*/ |
|
783
|
|
|
public function deleteMassAction($primaryKeys, $allPrimaryKeys, Request $request): Response |
|
784
|
|
|
{ |
|
785
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
786
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
787
|
|
|
|
|
788
|
|
|
$parentId = 0; |
|
789
|
|
|
foreach ($primaryKeys as $id) { |
|
790
|
|
|
$resource = $repo->find($id); |
|
791
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
792
|
|
|
|
|
793
|
|
|
if (null === $resourceNode) { |
|
794
|
|
|
continue; |
|
795
|
|
|
} |
|
796
|
|
|
|
|
797
|
|
|
$this->denyAccessUnlessGranted( |
|
798
|
|
|
ResourceNodeVoter::DELETE, |
|
799
|
|
|
$resourceNode, |
|
800
|
|
|
$this->trans('Unauthorised access to resource') |
|
801
|
|
|
); |
|
802
|
|
|
|
|
803
|
|
|
$parentId = $resourceNode->getParent()->getId(); |
|
804
|
|
|
$em->remove($resource); |
|
805
|
|
|
} |
|
806
|
|
|
|
|
807
|
|
|
$this->addFlash('success', $this->trans('Deleted')); |
|
808
|
|
|
$em->flush(); |
|
809
|
|
|
|
|
810
|
|
|
$routeParams = $this->getResourceParams($request); |
|
811
|
|
|
$routeParams['id'] = $parentId; |
|
812
|
|
|
|
|
813
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
|
814
|
|
|
} |
|
815
|
|
|
|
|
816
|
|
|
/** |
|
817
|
|
|
* Shows the associated resource file. |
|
818
|
|
|
* |
|
819
|
|
|
* @Route("/{tool}/{type}/{id}/view", methods={"GET"}, name="chamilo_core_resource_view_file") |
|
820
|
|
|
*/ |
|
821
|
|
|
public function viewAction(Request $request, RouterInterface $router): Response |
|
822
|
|
|
{ |
|
823
|
|
|
$id = $request->get('id'); |
|
824
|
|
|
$filter = $request->get('filter'); |
|
825
|
|
|
$mode = $request->get('mode'); |
|
826
|
|
|
$em = $this->getDoctrine(); |
|
827
|
|
|
/** @var ResourceNode $resourceNode */ |
|
828
|
|
|
$resourceNode = $em->getRepository('ChamiloCoreBundle:Resource\ResourceNode')->find($id); |
|
829
|
|
|
|
|
830
|
|
|
if (null === $resourceNode) { |
|
831
|
|
|
throw new FileNotFoundException('Resource not found'); |
|
832
|
|
|
} |
|
833
|
|
|
|
|
834
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
835
|
|
|
|
|
836
|
|
|
if ($repo instanceof ResourceWithLinkInterface) { |
|
837
|
|
|
$resource = $repo->getResourceFromResourceNode($resourceNode->getId()); |
|
838
|
|
|
$url = $repo->getLink($resource, $router, $this->getCourseUrlQueryToArray()); |
|
|
|
|
|
|
839
|
|
|
|
|
840
|
|
|
return $this->redirect($url); |
|
841
|
|
|
} |
|
842
|
|
|
|
|
843
|
|
|
return $this->showFile($request, $resourceNode, $mode, $filter); |
|
844
|
|
|
} |
|
845
|
|
|
|
|
846
|
|
|
/** |
|
847
|
|
|
* Shows the associated resource file. |
|
848
|
|
|
* |
|
849
|
|
|
* @Route("/{tool}/{type}/{id}/view_resource", methods={"GET"}, name="chamilo_core_resource_view_resource") |
|
850
|
|
|
*/ |
|
851
|
|
|
public function viewResourceAction(Request $request, RouterInterface $router): Response |
|
852
|
|
|
{ |
|
853
|
|
|
$id = $request->get('id'); |
|
854
|
|
|
$em = $this->getDoctrine(); |
|
855
|
|
|
|
|
856
|
|
|
/** @var ResourceNode $resourceNode */ |
|
857
|
|
|
$resourceNode = $em->getRepository('ChamiloCoreBundle:Resource\ResourceNode')->find($id); |
|
858
|
|
|
|
|
859
|
|
|
$this->denyAccessUnlessGranted( |
|
860
|
|
|
ResourceNodeVoter::VIEW, |
|
861
|
|
|
$resourceNode, |
|
862
|
|
|
$this->trans('Unauthorised access to resource') |
|
863
|
|
|
); |
|
864
|
|
|
|
|
865
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
866
|
|
|
|
|
867
|
|
|
/** @var AbstractResource $resource */ |
|
868
|
|
|
$resource = $repository->getResourceFromResourceNode($id); |
|
869
|
|
|
|
|
870
|
|
|
$tool = $request->get('tool'); |
|
871
|
|
|
$type = $request->get('type'); |
|
872
|
|
|
$this->setBreadCrumb($request); |
|
873
|
|
|
|
|
874
|
|
|
$params = [ |
|
875
|
|
|
'resource' => $resource, |
|
876
|
|
|
'tool' => $tool, |
|
877
|
|
|
'type' => $type, |
|
878
|
|
|
]; |
|
879
|
|
|
|
|
880
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $params); |
|
881
|
|
|
|
|
882
|
|
|
//return $this->showFile($request, $resourceNode, $mode, $filter); |
|
883
|
|
|
} |
|
884
|
|
|
|
|
885
|
|
|
/** |
|
886
|
|
|
* @Route("/{tool}/{type}/{id}/download", methods={"GET"}, name="chamilo_core_resource_download") |
|
887
|
|
|
*/ |
|
888
|
|
|
public function downloadAction(Request $request) |
|
889
|
|
|
{ |
|
890
|
|
|
$resourceNodeId = (int) $request->get('id'); |
|
891
|
|
|
$courseNode = $this->getCourse()->getResourceNode(); |
|
892
|
|
|
|
|
893
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
894
|
|
|
|
|
895
|
|
|
if (empty($resourceNodeId)) { |
|
896
|
|
|
$resourceNode = $courseNode; |
|
897
|
|
|
} else { |
|
898
|
|
|
$resourceNode = $repo->getResourceNodeRepository()->find($resourceNodeId); |
|
899
|
|
|
} |
|
900
|
|
|
|
|
901
|
|
|
$this->denyAccessUnlessGranted( |
|
902
|
|
|
ResourceNodeVoter::VIEW, |
|
903
|
|
|
$resourceNode, |
|
904
|
|
|
$this->trans('Unauthorised access to resource') |
|
905
|
|
|
); |
|
906
|
|
|
|
|
907
|
|
|
// If resource node has a file just download it. Don't download the children. |
|
908
|
|
|
if ($resourceNode->hasResourceFile()) { |
|
909
|
|
|
// Redirect to download single file. |
|
910
|
|
|
return $this->showFile($request, $resourceNode, 'download'); |
|
911
|
|
|
} |
|
912
|
|
|
|
|
913
|
|
|
$zipName = $resourceNode->getSlug().'.zip'; |
|
914
|
|
|
$rootNodePath = $resourceNode->getPathForDisplay(); |
|
915
|
|
|
$resourceNodeRepo = $repo->getResourceNodeRepository(); |
|
916
|
|
|
|
|
917
|
|
|
$criteria = Criteria::create() |
|
918
|
|
|
->where(Criteria::expr()->neq('resourceFile', null)) // must have a file |
|
919
|
|
|
// ->andWhere(Criteria::expr()->eq('resourceType', $type)) |
|
920
|
|
|
; |
|
921
|
|
|
|
|
922
|
|
|
/** @var ArrayCollection|ResourceNode[] $children */ |
|
923
|
|
|
/** @var QueryBuilder $children */ |
|
924
|
|
|
$qb = $resourceNodeRepo->getChildrenQueryBuilder($resourceNode); |
|
925
|
|
|
$qb->addCriteria($criteria); |
|
926
|
|
|
$children = $qb->getQuery()->getResult(); |
|
927
|
|
|
$count = count($children); |
|
928
|
|
|
if (0 === $count) { |
|
929
|
|
|
$params = $this->getResourceParams($request); |
|
930
|
|
|
$params['id'] = $resourceNodeId; |
|
931
|
|
|
|
|
932
|
|
|
$this->addFlash('warning', $this->trans('No files')); |
|
933
|
|
|
|
|
934
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $params); |
|
935
|
|
|
} |
|
936
|
|
|
|
|
937
|
|
|
$response = new StreamedResponse( |
|
938
|
|
|
function () use ($rootNodePath, $zipName, $children, $repo) { |
|
939
|
|
|
// Define suitable options for ZipStream Archive. |
|
940
|
|
|
$options = new Archive(); |
|
941
|
|
|
$options->setContentType('application/octet-stream'); |
|
942
|
|
|
//initialise zipstream with output zip filename and options. |
|
943
|
|
|
$zip = new ZipStream($zipName, $options); |
|
944
|
|
|
|
|
945
|
|
|
/** @var ResourceNode $node */ |
|
946
|
|
|
foreach ($children as $node) { |
|
947
|
|
|
//$resourceFile = $node->getResourceFile(); |
|
948
|
|
|
//$systemName = $resourceFile->getFile()->getPathname(); |
|
949
|
|
|
$stream = $repo->getResourceNodeFileStream($node); |
|
950
|
|
|
//error_log($node->getPathForDisplay()); |
|
951
|
|
|
$fileToDisplay = str_replace($rootNodePath, '', $node->getPathForDisplay()); |
|
952
|
|
|
$zip->addFileFromStream($fileToDisplay, $stream); |
|
953
|
|
|
} |
|
954
|
|
|
$zip->finish(); |
|
955
|
|
|
} |
|
956
|
|
|
); |
|
957
|
|
|
|
|
958
|
|
|
$disposition = $response->headers->makeDisposition( |
|
959
|
|
|
ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
|
960
|
|
|
$zipName //Transliterator::transliterate($zipName) |
|
961
|
|
|
); |
|
962
|
|
|
$response->headers->set('Content-Disposition', $disposition); |
|
963
|
|
|
$response->headers->set('Content-Type', 'application/octet-stream'); |
|
964
|
|
|
|
|
965
|
|
|
return $response; |
|
966
|
|
|
} |
|
967
|
|
|
|
|
968
|
|
|
/** |
|
969
|
|
|
* Upload form. |
|
970
|
|
|
* |
|
971
|
|
|
* @Route("/{tool}/{type}/{id}/upload", name="chamilo_core_resource_upload", methods={"GET", "POST"}, |
|
972
|
|
|
* options={"expose"=true}) |
|
973
|
|
|
*/ |
|
974
|
|
|
public function uploadAction(Request $request, $tool, $type, $id): Response |
|
975
|
|
|
{ |
|
976
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
977
|
|
|
$resourceNode = $repository->getResourceNodeRepository()->find($id); |
|
978
|
|
|
|
|
979
|
|
|
$this->denyAccessUnlessGranted( |
|
980
|
|
|
ResourceNodeVoter::EDIT, |
|
981
|
|
|
$resourceNode, |
|
982
|
|
|
$this->trans('Unauthorised access to resource') |
|
983
|
|
|
); |
|
984
|
|
|
|
|
985
|
|
|
$this->setBreadCrumb($request); |
|
986
|
|
|
|
|
987
|
|
|
$routeParams = $this->getResourceParams($request); |
|
988
|
|
|
$routeParams['tool'] = $tool; |
|
989
|
|
|
$routeParams['type'] = $type; |
|
990
|
|
|
$routeParams['id'] = $id; |
|
991
|
|
|
|
|
992
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $routeParams); |
|
993
|
|
|
} |
|
994
|
|
|
|
|
995
|
|
|
private function setBreadCrumb(Request $request) |
|
996
|
|
|
{ |
|
997
|
|
|
$tool = $request->get('tool'); |
|
998
|
|
|
$type = $request->get('type'); |
|
999
|
|
|
$resourceNodeId = $request->get('id'); |
|
1000
|
|
|
$routeParams = $this->getResourceParams($request); |
|
1001
|
|
|
|
|
1002
|
|
|
if (!empty($resourceNodeId)) { |
|
1003
|
|
|
$breadcrumb = $this->getBreadCrumb(); |
|
1004
|
|
|
$toolParams = $routeParams; |
|
1005
|
|
|
$toolParams['id'] = null; |
|
1006
|
|
|
|
|
1007
|
|
|
// Root tool link |
|
1008
|
|
|
$breadcrumb->addChild( |
|
1009
|
|
|
$this->trans($tool), |
|
1010
|
|
|
[ |
|
1011
|
|
|
'uri' => $this->generateUrl('chamilo_core_resource_index', $toolParams), |
|
1012
|
|
|
] |
|
1013
|
|
|
); |
|
1014
|
|
|
|
|
1015
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
1016
|
|
|
$settings = $repo->getResourceSettings(); |
|
1017
|
|
|
|
|
1018
|
|
|
/** @var ResourceInterface $originalResource */ |
|
1019
|
|
|
$originalResource = $repo->findOneBy(['resourceNode' => $resourceNodeId]); |
|
1020
|
|
|
if (null === $originalResource) { |
|
1021
|
|
|
return; |
|
1022
|
|
|
} |
|
1023
|
|
|
$parent = $originalParent = $originalResource->getResourceNode(); |
|
1024
|
|
|
|
|
1025
|
|
|
$parentList = []; |
|
1026
|
|
|
while (null !== $parent) { |
|
1027
|
|
|
if ($type !== $parent->getResourceType()->getName()) { |
|
1028
|
|
|
break; |
|
1029
|
|
|
} |
|
1030
|
|
|
$parent = $parent->getParent(); |
|
1031
|
|
|
if ($parent) { |
|
1032
|
|
|
$resource = $repo->findOneBy(['resourceNode' => $parent->getId()]); |
|
1033
|
|
|
if ($resource) { |
|
1034
|
|
|
$parentList[] = $resource; |
|
1035
|
|
|
} |
|
1036
|
|
|
} |
|
1037
|
|
|
} |
|
1038
|
|
|
|
|
1039
|
|
|
$parentList = array_reverse($parentList); |
|
1040
|
|
|
/** @var ResourceInterface $item */ |
|
1041
|
|
|
foreach ($parentList as $item) { |
|
1042
|
|
|
$params = $routeParams; |
|
1043
|
|
|
$params['id'] = $item->getResourceNode()->getId(); |
|
1044
|
|
|
$breadcrumb->addChild( |
|
1045
|
|
|
$item->getResourceName(), |
|
1046
|
|
|
[ |
|
1047
|
|
|
'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
|
1048
|
|
|
] |
|
1049
|
|
|
); |
|
1050
|
|
|
} |
|
1051
|
|
|
|
|
1052
|
|
|
$params = $routeParams; |
|
1053
|
|
|
$params['id'] = $originalParent->getId(); |
|
1054
|
|
|
if (false === $settings->isAllowNodeCreation() || $originalResource->getResourceNode()->hasResourceFile()) { |
|
1055
|
|
|
$breadcrumb->addChild($originalResource->getResourceName()); |
|
1056
|
|
|
} else { |
|
1057
|
|
|
$breadcrumb->addChild( |
|
1058
|
|
|
$originalResource->getResourceName(), |
|
1059
|
|
|
[ |
|
1060
|
|
|
'uri' => $this->generateUrl('chamilo_core_resource_list', $params), |
|
1061
|
|
|
] |
|
1062
|
|
|
); |
|
1063
|
|
|
} |
|
1064
|
|
|
} |
|
1065
|
|
|
} |
|
1066
|
|
|
|
|
1067
|
|
|
/** |
|
1068
|
|
|
* @param string $mode |
|
1069
|
|
|
* @param string $filter |
|
1070
|
|
|
* |
|
1071
|
|
|
* @return mixed|StreamedResponse |
|
1072
|
|
|
*/ |
|
1073
|
|
|
private function showFile(Request $request, ResourceNode $resourceNode, $mode = 'show', $filter = '') |
|
1074
|
|
|
{ |
|
1075
|
|
|
$this->denyAccessUnlessGranted( |
|
1076
|
|
|
ResourceNodeVoter::VIEW, |
|
1077
|
|
|
$resourceNode, |
|
1078
|
|
|
$this->trans('Unauthorised access to resource') |
|
1079
|
|
|
); |
|
1080
|
|
|
|
|
1081
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
1082
|
|
|
$resourceFile = $resourceNode->getResourceFile(); |
|
1083
|
|
|
|
|
1084
|
|
|
if (!$resourceFile) { |
|
|
|
|
|
|
1085
|
|
|
throw new NotFoundHttpException($this->trans('File not found for resource')); |
|
1086
|
|
|
} |
|
1087
|
|
|
|
|
1088
|
|
|
$fileName = $resourceNode->getSlug(); |
|
1089
|
|
|
$mimeType = $resourceFile->getMimeType(); |
|
1090
|
|
|
|
|
1091
|
|
|
switch ($mode) { |
|
1092
|
|
|
case 'download': |
|
1093
|
|
|
$forceDownload = true; |
|
1094
|
|
|
|
|
1095
|
|
|
break; |
|
1096
|
|
|
case 'show': |
|
1097
|
|
|
default: |
|
1098
|
|
|
$forceDownload = false; |
|
1099
|
|
|
// If it's an image then send it to Glide. |
|
1100
|
|
|
if (false !== strpos($mimeType, 'image')) { |
|
1101
|
|
|
$glide = $this->getGlide(); |
|
1102
|
|
|
$server = $glide->getServer(); |
|
1103
|
|
|
$params = $request->query->all(); |
|
1104
|
|
|
|
|
1105
|
|
|
// The filter overwrites the params from get |
|
1106
|
|
|
if (!empty($filter)) { |
|
1107
|
|
|
$params = $glide->getFilters()[$filter] ?? []; |
|
1108
|
|
|
} |
|
1109
|
|
|
|
|
1110
|
|
|
// The image was cropped manually by the user, so we force to render this version, |
|
1111
|
|
|
// no matter other crop parameters. |
|
1112
|
|
|
$crop = $resourceFile->getCrop(); |
|
1113
|
|
|
if (!empty($crop)) { |
|
1114
|
|
|
$params['crop'] = $crop; |
|
1115
|
|
|
} |
|
1116
|
|
|
|
|
1117
|
|
|
$fileName = $repo->getResourceNodeRepository()->getFilename($resourceFile); |
|
1118
|
|
|
|
|
1119
|
|
|
return $server->getImageResponse($fileName, $params); |
|
1120
|
|
|
} |
|
1121
|
|
|
|
|
1122
|
|
|
break; |
|
1123
|
|
|
} |
|
1124
|
|
|
|
|
1125
|
|
|
$stream = $repo->getResourceNodeFileStream($resourceNode); |
|
1126
|
|
|
|
|
1127
|
|
|
$response = new StreamedResponse( |
|
1128
|
|
|
function () use ($stream): void { |
|
1129
|
|
|
stream_copy_to_stream($stream, fopen('php://output', 'wb')); |
|
|
|
|
|
|
1130
|
|
|
} |
|
1131
|
|
|
); |
|
1132
|
|
|
$disposition = $response->headers->makeDisposition( |
|
1133
|
|
|
$forceDownload ? ResponseHeaderBag::DISPOSITION_ATTACHMENT : ResponseHeaderBag::DISPOSITION_INLINE, |
|
1134
|
|
|
$fileName |
|
1135
|
|
|
//Transliterator::transliterate($fileName) |
|
1136
|
|
|
); |
|
1137
|
|
|
$response->headers->set('Content-Disposition', $disposition); |
|
1138
|
|
|
$response->headers->set('Content-Type', $mimeType ?: 'application/octet-stream'); |
|
1139
|
|
|
|
|
1140
|
|
|
return $response; |
|
1141
|
|
|
} |
|
1142
|
|
|
|
|
1143
|
|
|
/** |
|
1144
|
|
|
* @param string $fileType |
|
1145
|
|
|
* |
|
1146
|
|
|
* @return RedirectResponse|Response |
|
1147
|
|
|
*/ |
|
1148
|
|
|
private function createResource(Request $request, $fileType = 'file') |
|
1149
|
|
|
{ |
|
1150
|
|
|
$resourceNodeParentId = $request->get('id'); |
|
1151
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
1152
|
|
|
|
|
1153
|
|
|
// Default parent node is course. |
|
1154
|
|
|
$parentNode = $this->getParentResourceNode($request); |
|
1155
|
|
|
|
|
1156
|
|
|
$this->denyAccessUnlessGranted( |
|
1157
|
|
|
ResourceNodeVoter::CREATE, |
|
1158
|
|
|
$parentNode, |
|
1159
|
|
|
$this->trans('Unauthorised access to resource') |
|
1160
|
|
|
); |
|
1161
|
|
|
|
|
1162
|
|
|
$form = $repository->getForm($this->container->get('form.factory'), null); |
|
1163
|
|
|
|
|
1164
|
|
|
$settings = $repository->getResourceSettings(); |
|
1165
|
|
|
|
|
1166
|
|
|
if ('file' === $fileType && $settings->isAllowToSaveEditorToResourceFile()) { |
|
1167
|
|
|
$resourceParams = $this->getResourceParams($request); |
|
1168
|
|
|
$form->add( |
|
1169
|
|
|
$this->fileContentName, |
|
1170
|
|
|
CKEditorType::class, |
|
1171
|
|
|
[ |
|
1172
|
|
|
'mapped' => false, |
|
1173
|
|
|
'config' => [ |
|
1174
|
|
|
'filebrowserImageBrowseRoute' => 'resources_filemanager', |
|
1175
|
|
|
'filebrowserImageBrowseRouteParameters' => $resourceParams, |
|
1176
|
|
|
'fullPage' => true, |
|
1177
|
|
|
], |
|
1178
|
|
|
] |
|
1179
|
|
|
); |
|
1180
|
|
|
} |
|
1181
|
|
|
|
|
1182
|
|
|
$form->handleRequest($request); |
|
1183
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
1184
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
1185
|
|
|
|
|
1186
|
|
|
$course = $this->getCourse(); |
|
1187
|
|
|
$session = $this->getSession(); |
|
1188
|
|
|
|
|
1189
|
|
|
/** @var ResourceInterface $newResource */ |
|
1190
|
|
|
$newResource = $repository->saveResource($form, $course, $session, $fileType); |
|
1191
|
|
|
|
|
1192
|
|
|
$file = null; |
|
1193
|
|
|
if ('file' === $fileType && $settings->isAllowToSaveEditorToResourceFile()) { |
|
1194
|
|
|
$content = $form->get($this->fileContentName)->getViewData(); |
|
1195
|
|
|
$newResource->setTitle($newResource->getTitle().'.html'); |
|
|
|
|
|
|
1196
|
|
|
$fileName = $newResource->getTitle(); |
|
1197
|
|
|
|
|
1198
|
|
|
$handle = tmpfile(); |
|
1199
|
|
|
fwrite($handle, $content); |
|
|
|
|
|
|
1200
|
|
|
$meta = stream_get_meta_data($handle); |
|
|
|
|
|
|
1201
|
|
|
$file = new UploadedFile($meta['uri'], $fileName, 'text/html', null, true); |
|
1202
|
|
|
$em->persist($newResource); |
|
1203
|
|
|
} |
|
1204
|
|
|
|
|
1205
|
|
|
$repository->addResourceToCourseWithParent( |
|
1206
|
|
|
$newResource, |
|
1207
|
|
|
$parentNode, |
|
1208
|
|
|
ResourceLink::VISIBILITY_PUBLISHED, |
|
1209
|
|
|
$this->getUser(), |
|
1210
|
|
|
$course, |
|
1211
|
|
|
$session, |
|
1212
|
|
|
null, |
|
1213
|
|
|
$file |
|
1214
|
|
|
); |
|
1215
|
|
|
|
|
1216
|
|
|
$em->flush(); |
|
1217
|
|
|
|
|
1218
|
|
|
// Loops all sharing options |
|
1219
|
|
|
/*foreach ($shareList as $share) { |
|
1220
|
|
|
$idList = []; |
|
1221
|
|
|
if (isset($share['search'])) { |
|
1222
|
|
|
$idList = explode(',', $share['search']); |
|
1223
|
|
|
} |
|
1224
|
|
|
|
|
1225
|
|
|
$resourceRight = null; |
|
1226
|
|
|
if (isset($share['mask'])) { |
|
1227
|
|
|
$resourceRight = new ResourceRight(); |
|
1228
|
|
|
$resourceRight |
|
1229
|
|
|
->setMask($share['mask']) |
|
1230
|
|
|
->setRole($share['role']) |
|
1231
|
|
|
; |
|
1232
|
|
|
} |
|
1233
|
|
|
|
|
1234
|
|
|
// Build links |
|
1235
|
|
|
switch ($share['sharing']) { |
|
1236
|
|
|
case 'everyone': |
|
1237
|
|
|
$repository->addResourceToEveryone( |
|
1238
|
|
|
$resourceNode, |
|
1239
|
|
|
$resourceRight |
|
1240
|
|
|
); |
|
1241
|
|
|
break; |
|
1242
|
|
|
case 'course': |
|
1243
|
|
|
$repository->addResourceToCourse( |
|
1244
|
|
|
$resourceNode, |
|
1245
|
|
|
$course, |
|
1246
|
|
|
$resourceRight |
|
1247
|
|
|
); |
|
1248
|
|
|
break; |
|
1249
|
|
|
case 'session': |
|
1250
|
|
|
$repository->addResourceToSession( |
|
1251
|
|
|
$resourceNode, |
|
1252
|
|
|
$course, |
|
1253
|
|
|
$session, |
|
1254
|
|
|
$resourceRight |
|
1255
|
|
|
); |
|
1256
|
|
|
break; |
|
1257
|
|
|
case 'user': |
|
1258
|
|
|
// Only for me |
|
1259
|
|
|
if (isset($share['only_me'])) { |
|
1260
|
|
|
$repository->addResourceOnlyToMe($resourceNode); |
|
1261
|
|
|
} else { |
|
1262
|
|
|
// To other users |
|
1263
|
|
|
$repository->addResourceToUserList($resourceNode, $idList); |
|
1264
|
|
|
} |
|
1265
|
|
|
break; |
|
1266
|
|
|
case 'group': |
|
1267
|
|
|
// @todo |
|
1268
|
|
|
break; |
|
1269
|
|
|
}*/ |
|
1270
|
|
|
//} |
|
1271
|
|
|
$em->flush(); |
|
1272
|
|
|
$this->addFlash('success', $this->trans('Saved')); |
|
1273
|
|
|
|
|
1274
|
|
|
$params = $this->getResourceParams($request); |
|
1275
|
|
|
$params['id'] = $resourceNodeParentId; |
|
1276
|
|
|
|
|
1277
|
|
|
return $this->redirectToRoute( |
|
1278
|
|
|
'chamilo_core_resource_list', |
|
1279
|
|
|
$params |
|
1280
|
|
|
); |
|
1281
|
|
|
} |
|
1282
|
|
|
|
|
1283
|
|
|
switch ($fileType) { |
|
1284
|
|
|
case 'folder': |
|
1285
|
|
|
$template = $repository->getTemplates()->getFromAction('newFolderAction'); |
|
1286
|
|
|
|
|
1287
|
|
|
break; |
|
1288
|
|
|
case 'file': |
|
1289
|
|
|
$template = $repository->getTemplates()->getFromAction('newAction'); |
|
1290
|
|
|
|
|
1291
|
|
|
break; |
|
1292
|
|
|
} |
|
1293
|
|
|
|
|
1294
|
|
|
return $this->render( |
|
1295
|
|
|
$template, |
|
|
|
|
|
|
1296
|
|
|
[ |
|
1297
|
|
|
'form' => $form->createView(), |
|
1298
|
|
|
'parent' => $resourceNodeParentId, |
|
1299
|
|
|
'file_type' => $fileType, |
|
1300
|
|
|
] |
|
1301
|
|
|
); |
|
1302
|
|
|
} |
|
1303
|
|
|
} |
|
1304
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.