|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
|
10
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
11
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
|
12
|
|
|
use Chamilo\CoreBundle\Entity\ResourceLink; |
|
13
|
|
|
use Chamilo\CoreBundle\Entity\ResourceNode; |
|
14
|
|
|
use Chamilo\CoreBundle\Form\Type\ResourceCommentType; |
|
15
|
|
|
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository; |
|
16
|
|
|
use Chamilo\CoreBundle\Repository\ResourceWithLinkInterface; |
|
17
|
|
|
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter; |
|
18
|
|
|
use Chamilo\CoreBundle\Traits\ControllerTrait; |
|
19
|
|
|
use Chamilo\CoreBundle\Traits\CourseControllerTrait; |
|
20
|
|
|
use Chamilo\CoreBundle\Traits\ResourceControllerTrait; |
|
21
|
|
|
use Chamilo\CourseBundle\Controller\CourseControllerInterface; |
|
22
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
23
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
24
|
|
|
use Symfony\Component\Filesystem\Exception\FileNotFoundException; |
|
25
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
26
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
27
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
28
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
29
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
30
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
31
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
|
32
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
33
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
34
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
35
|
|
|
use ZipStream\Option\Archive; |
|
36
|
|
|
use ZipStream\ZipStream; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Class ResourceController. |
|
40
|
|
|
* |
|
41
|
|
|
* @Route("/r") |
|
42
|
|
|
* |
|
43
|
|
|
* @author Julio Montoya <[email protected]>. |
|
44
|
|
|
*/ |
|
45
|
|
|
class ResourceController extends AbstractResourceController implements CourseControllerInterface |
|
46
|
|
|
{ |
|
47
|
|
|
use CourseControllerTrait; |
|
48
|
|
|
use ResourceControllerTrait; |
|
49
|
|
|
use ControllerTrait; |
|
50
|
|
|
|
|
51
|
|
|
private string $fileContentName = 'file_content'; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @deprecated Use Vue |
|
55
|
|
|
* |
|
56
|
|
|
* @Route("/{tool}/{type}", name="chamilo_core_resource_index") |
|
57
|
|
|
* |
|
58
|
|
|
* Example: /document/files (See the 'tool' and the 'resource_type' DB tables.) |
|
59
|
|
|
* For the tool value check the Tool entity. |
|
60
|
|
|
* For the type value check the ResourceType entity. |
|
61
|
|
|
*/ |
|
62
|
|
|
/*public function indexAction(Request $request): Response |
|
63
|
|
|
{ |
|
64
|
|
|
$tool = $request->get('tool'); |
|
65
|
|
|
$type = $request->get('type'); |
|
66
|
|
|
|
|
67
|
|
|
$parentResourceNode = $this->getParentResourceNode($request); |
|
68
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
69
|
|
|
$settings = $repository->getResourceSettings(); |
|
70
|
|
|
|
|
71
|
|
|
// The base resource node is the course. |
|
72
|
|
|
$id = $parentResourceNode->getId(); |
|
73
|
|
|
|
|
74
|
|
|
//return $grid->getGridResponse( |
|
75
|
|
|
return $this->render( |
|
76
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
77
|
|
|
[ |
|
78
|
|
|
'tool' => $tool, |
|
79
|
|
|
'type' => $type, |
|
80
|
|
|
'id' => $id, |
|
81
|
|
|
'parent_resource_node' => $parentResourceNode, |
|
82
|
|
|
'resource_settings' => $settings, |
|
83
|
|
|
] |
|
84
|
|
|
); |
|
85
|
|
|
}*/ |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @deprecated Use Vue |
|
89
|
|
|
* |
|
90
|
|
|
* @Route("/{tool}/{type}/{id}/list", name="chamilo_core_resource_list") |
|
91
|
|
|
* |
|
92
|
|
|
* If node has children show it |
|
93
|
|
|
*/ |
|
94
|
|
|
/*public function listAction(Request $request): void |
|
95
|
|
|
{ |
|
96
|
|
|
$tool = $request->get('tool'); |
|
97
|
|
|
$type = $request->get('type'); |
|
98
|
|
|
$resourceNodeId = $request->get('id'); |
|
99
|
|
|
|
|
100
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
101
|
|
|
$settings = $repository->getResourceSettings();*/ |
|
102
|
|
|
|
|
103
|
|
|
/*$grid = $this->getGrid($request, $repository, $grid, $resourceNodeId, 'chamilo_core_resource_list'); |
|
104
|
|
|
$parentResourceNode = $this->getParentResourceNode($request); |
|
105
|
|
|
$this->setBreadCrumb($request, $parentResourceNode);*/ |
|
106
|
|
|
|
|
107
|
|
|
//return $grid->getGridResponse( |
|
108
|
|
|
/*return $this->render( |
|
109
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
110
|
|
|
[ |
|
111
|
|
|
'parent_id' => $resourceNodeId, |
|
112
|
|
|
'tool' => $tool, |
|
113
|
|
|
'type' => $type, |
|
114
|
|
|
'id' => $resourceNodeId, |
|
115
|
|
|
'parent_resource_node' => $parentResourceNode, |
|
116
|
|
|
'resource_settings' => $settings, |
|
117
|
|
|
] |
|
118
|
|
|
); |
|
119
|
|
|
}*/ |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @deprecated Use Vue |
|
123
|
|
|
* |
|
124
|
|
|
* @Route("/{tool}/{type}/{id}/new_folder", methods={"GET", "POST"}, name="chamilo_core_resource_new_folder") |
|
125
|
|
|
*/ |
|
126
|
|
|
/*public function newFolderAction(Request $request): Response |
|
127
|
|
|
{ |
|
128
|
|
|
return $this->createResource($request, 'folder'); |
|
129
|
|
|
}*/ |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* @deprecated Use Vue |
|
133
|
|
|
* |
|
134
|
|
|
* @Route("/{tool}/{type}/{id}/new", methods={"GET", "POST"}, name="chamilo_core_resource_new") |
|
135
|
|
|
*/ |
|
136
|
|
|
/*public function newAction(Request $request): Response |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->createResource($request, 'file'); |
|
139
|
|
|
}*/ |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @Route("/{tool}/{type}/{id}/disk_space", methods={"GET", "POST"}, name="chamilo_core_resource_disk_space") |
|
143
|
|
|
*/ |
|
144
|
|
|
public function diskSpaceAction(Request $request): Response |
|
145
|
|
|
{ |
|
146
|
|
|
$nodeId = $request->get('id'); |
|
147
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
148
|
|
|
|
|
149
|
|
|
/** @var ResourceNode $resourceNode */ |
|
150
|
|
|
$resourceNode = $repository->getResourceNodeRepository()->find($nodeId); |
|
151
|
|
|
|
|
152
|
|
|
$this->denyAccessUnlessGranted( |
|
153
|
|
|
ResourceNodeVoter::VIEW, |
|
154
|
|
|
$resourceNode, |
|
155
|
|
|
$this->trans('Unauthorised access to resource') |
|
156
|
|
|
); |
|
157
|
|
|
|
|
158
|
|
|
$this->setBreadCrumb($request, $resourceNode); |
|
159
|
|
|
|
|
160
|
|
|
$course = $this->getCourse(); |
|
161
|
|
|
$totalSize = 0; |
|
162
|
|
|
if (null !== $course) { |
|
163
|
|
|
$totalSize = $course->getDiskQuota(); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$size = $repository->getResourceNodeRepository()->getSize( |
|
167
|
|
|
$resourceNode, |
|
168
|
|
|
$repository->getResourceType(), |
|
169
|
|
|
$course |
|
170
|
|
|
); |
|
171
|
|
|
|
|
172
|
|
|
$labels[] = $course->getTitle(); |
|
|
|
|
|
|
173
|
|
|
$data[] = $size; |
|
|
|
|
|
|
174
|
|
|
$sessions = $course->getSessions(); |
|
175
|
|
|
|
|
176
|
|
|
foreach ($sessions as $sessionRelCourse) { |
|
177
|
|
|
$session = $sessionRelCourse->getSession(); |
|
178
|
|
|
|
|
179
|
|
|
$labels[] = $course->getTitle().' - '.$session->getName(); |
|
180
|
|
|
$size = $repository->getResourceNodeRepository()->getSize( |
|
181
|
|
|
$resourceNode, |
|
182
|
|
|
$repository->getResourceType(), |
|
183
|
|
|
$course, |
|
184
|
|
|
$session |
|
185
|
|
|
); |
|
186
|
|
|
$data[] = $size; |
|
187
|
|
|
} |
|
188
|
|
|
|
|
189
|
|
|
/*$groups = $course->getGroups(); |
|
190
|
|
|
foreach ($groups as $group) { |
|
191
|
|
|
$labels[] = $course->getTitle().' - '.$group->getName(); |
|
192
|
|
|
$size = $repository->getResourceNodeRepository()->getSize( |
|
193
|
|
|
$resourceNode, |
|
194
|
|
|
$repository->getResourceType(), |
|
195
|
|
|
$course, |
|
196
|
|
|
null, |
|
197
|
|
|
$group |
|
198
|
|
|
); |
|
199
|
|
|
$data[] = $size; |
|
200
|
|
|
}*/ |
|
201
|
|
|
|
|
202
|
|
|
$used = array_sum($data); |
|
203
|
|
|
$labels[] = $this->trans('Free'); |
|
204
|
|
|
$data[] = $totalSize - $used; |
|
205
|
|
|
|
|
206
|
|
|
return $this->render( |
|
207
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
208
|
|
|
[ |
|
209
|
|
|
'resourceNode' => $resourceNode, |
|
210
|
|
|
'labels' => $labels, |
|
211
|
|
|
'data' => $data, |
|
212
|
|
|
] |
|
213
|
|
|
); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* @deprecated Use Vue |
|
218
|
|
|
* |
|
219
|
|
|
* @Route("/{tool}/{type}/{id}/edit", methods={"GET", "POST"}) |
|
220
|
|
|
*/ |
|
221
|
|
|
public function editAction(Request $request, IllustrationRepository $illustrationRepo): Response |
|
222
|
|
|
{ |
|
223
|
|
|
$resourceNodeId = $request->get('id'); |
|
224
|
|
|
|
|
225
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
226
|
|
|
$resource = $repository->getResourceFromResourceNode($resourceNodeId); |
|
227
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
228
|
|
|
$settings = $repository->getResourceSettings(); |
|
229
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
230
|
|
|
|
|
231
|
|
|
$this->denyAccessUnlessGranted( |
|
232
|
|
|
ResourceNodeVoter::EDIT, |
|
233
|
|
|
$resourceNode, |
|
234
|
|
|
$this->trans('Unauthorised access to resource') |
|
235
|
|
|
); |
|
236
|
|
|
|
|
237
|
|
|
$this->setBreadCrumb($request, $resourceNode); |
|
238
|
|
|
$resourceNodeParentId = $resourceNode->getId(); |
|
239
|
|
|
|
|
240
|
|
|
$routeParams = $this->getResourceParams($request); |
|
241
|
|
|
$routeParams['id'] = $resourceNodeParentId; |
|
242
|
|
|
|
|
243
|
|
|
$form = $repository->getForm($this->container->get('form.factory'), $resource); |
|
244
|
|
|
|
|
245
|
|
|
if ($resourceNode->hasEditableTextContent() && $settings->isAllowToSaveEditorToResourceFile()) { |
|
246
|
|
|
/*$form->add( |
|
247
|
|
|
$this->fileContentName, |
|
248
|
|
|
CKEditorType::class, |
|
249
|
|
|
[ |
|
250
|
|
|
'mapped' => false, |
|
251
|
|
|
'config' => [ |
|
252
|
|
|
'filebrowserImageBrowseRoute' => 'resources_filemanager', |
|
253
|
|
|
'filebrowserImageBrowseRouteParameters' => $routeParams, |
|
254
|
|
|
], |
|
255
|
|
|
] |
|
256
|
|
|
); |
|
257
|
|
|
$content = $repository->getResourceNodeFileContent($resourceNode); |
|
258
|
|
|
$form->get($this->fileContentName)->setData($content);*/ |
|
259
|
|
|
} |
|
260
|
|
|
|
|
261
|
|
|
$form->handleRequest($request); |
|
262
|
|
|
|
|
263
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
264
|
|
|
/** @var AbstractResource|ResourceInterface $newResource */ |
|
265
|
|
|
$newResource = $form->getData(); |
|
266
|
|
|
|
|
267
|
|
|
if ($form->has($this->fileContentName)) { |
|
268
|
|
|
$data = $form->get($this->fileContentName)->getData(); |
|
269
|
|
|
$repository->updateResourceFileContent($newResource, $data); |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
$repository->updateNodeForResource($newResource); |
|
273
|
|
|
|
|
274
|
|
|
if ($form->has('illustration')) { |
|
275
|
|
|
$illustration = $form->get('illustration')->getData(); |
|
276
|
|
|
if ($illustration) { |
|
277
|
|
|
$illustrationRepo->addIllustration($newResource, $this->getUser(), $illustration); |
|
278
|
|
|
} |
|
279
|
|
|
} |
|
280
|
|
|
|
|
281
|
|
|
$this->addFlash('success', $this->trans('Updated')); |
|
282
|
|
|
$resourceNodeParentId = $newResource->getResourceNode()->getParent()->getId(); |
|
283
|
|
|
$routeParams['id'] = $resourceNodeParentId; |
|
284
|
|
|
|
|
285
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
return $this->render( |
|
289
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__), |
|
290
|
|
|
[ |
|
291
|
|
|
'form' => $form->createView(), |
|
292
|
|
|
'parent' => $resourceNodeParentId, |
|
293
|
|
|
] |
|
294
|
|
|
); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* @deprecated use Vue |
|
299
|
|
|
* |
|
300
|
|
|
* Shows a resource information |
|
301
|
|
|
* |
|
302
|
|
|
* @Route("/{tool}/{type}/{id}/info", methods={"GET", "POST"}, name="chamilo_core_resource_info") |
|
303
|
|
|
*/ |
|
304
|
|
|
/*public function infoAction(Request $request): Response |
|
305
|
|
|
{ |
|
306
|
|
|
$nodeId = $request->get('id'); |
|
307
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
308
|
|
|
|
|
309
|
|
|
$resource = $repository->getResourceFromResourceNode($nodeId); |
|
310
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
311
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
312
|
|
|
|
|
313
|
|
|
$this->denyAccessUnlessGranted( |
|
314
|
|
|
ResourceNodeVoter::VIEW, |
|
315
|
|
|
$resourceNode, |
|
316
|
|
|
$this->trans(sprintf('Unauthorised access to resource #%s', $nodeId)) |
|
317
|
|
|
); |
|
318
|
|
|
|
|
319
|
|
|
$this->setBreadCrumb($request, $resourceNode); |
|
320
|
|
|
|
|
321
|
|
|
$tool = $request->get('tool'); |
|
322
|
|
|
$type = $request->get('type'); |
|
323
|
|
|
|
|
324
|
|
|
$form = $this->createForm(ResourceCommentType::class, null); |
|
325
|
|
|
|
|
326
|
|
|
$params = [ |
|
327
|
|
|
'resource' => $resource, |
|
328
|
|
|
'course' => $this->getCourse(), |
|
329
|
|
|
// 'illustration' => $illustration, |
|
330
|
|
|
'tool' => $tool, |
|
331
|
|
|
'type' => $type, |
|
332
|
|
|
'comment_form' => $form->createView(), |
|
333
|
|
|
]; |
|
334
|
|
|
|
|
335
|
|
|
return $this->render( |
|
336
|
|
|
$repository->getTemplates()->getFromAction(__FUNCTION__, $request->isXmlHttpRequest()), |
|
337
|
|
|
$params |
|
338
|
|
|
); |
|
339
|
|
|
}*/ |
|
340
|
|
|
|
|
341
|
|
|
/** |
|
342
|
|
|
* Preview a file. Mostly used when using a modal. |
|
343
|
|
|
* |
|
344
|
|
|
* @Route("/{tool}/{type}/{id}/preview", methods={"GET"}, name="chamilo_core_resource_preview") |
|
345
|
|
|
*/ |
|
346
|
|
|
/*public function previewAction(Request $request): Response |
|
347
|
|
|
{ |
|
348
|
|
|
$nodeId = $request->get('id'); |
|
349
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
350
|
|
|
|
|
351
|
|
|
$resource = $repository->getResourceFromResourceNode($nodeId); |
|
352
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
353
|
|
|
|
|
354
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
355
|
|
|
$this->denyAccessUnlessGranted( |
|
356
|
|
|
ResourceNodeVoter::VIEW, |
|
357
|
|
|
$resourceNode, |
|
358
|
|
|
$this->trans('Unauthorised access to resource') |
|
359
|
|
|
); |
|
360
|
|
|
|
|
361
|
|
|
$this->setBreadCrumb($request, $resourceNode); |
|
362
|
|
|
|
|
363
|
|
|
$tool = $request->get('tool'); |
|
364
|
|
|
$type = $request->get('type'); |
|
365
|
|
|
|
|
366
|
|
|
$params = [ |
|
367
|
|
|
'resource' => $resource, |
|
368
|
|
|
'tool' => $tool, |
|
369
|
|
|
'type' => $type, |
|
370
|
|
|
]; |
|
371
|
|
|
|
|
372
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $params); |
|
373
|
|
|
}*/ |
|
374
|
|
|
|
|
375
|
|
|
/** |
|
376
|
|
|
* @deprecated use vue |
|
377
|
|
|
* |
|
378
|
|
|
* @Route("/{tool}/{type}/{id}/change_visibility", name="chamilo_core_resource_change_visibility") |
|
379
|
|
|
*/ |
|
380
|
|
|
public function changeVisibilityAction(Request $request): Response |
|
381
|
|
|
{ |
|
382
|
|
|
$id = (int) $request->get('id'); |
|
383
|
|
|
|
|
384
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
385
|
|
|
|
|
386
|
|
|
$resource = $repository->getResourceFromResourceNode($id); |
|
387
|
|
|
$this->denyAccessUnlessValidResource($resource); |
|
388
|
|
|
/** @var AbstractResource $resource */ |
|
389
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
390
|
|
|
|
|
391
|
|
|
$this->denyAccessUnlessGranted( |
|
392
|
|
|
ResourceNodeVoter::EDIT, |
|
393
|
|
|
$resourceNode, |
|
394
|
|
|
$this->trans('Unauthorised access to resource') |
|
395
|
|
|
); |
|
396
|
|
|
|
|
397
|
|
|
if ($this->hasCourse()) { |
|
398
|
|
|
$link = $resource->getFirstResourceLinkFromCourseSession($this->getCourse(), $this->getSession()); |
|
399
|
|
|
} else { |
|
400
|
|
|
$link = $resource->getFirstResourceLink(); |
|
401
|
|
|
} |
|
402
|
|
|
|
|
403
|
|
|
// Use repository to change settings easily. |
|
404
|
|
|
if ($link && ResourceLink::VISIBILITY_PUBLISHED === $link->getVisibility()) { |
|
405
|
|
|
$repository->setVisibilityDraft($resource); |
|
406
|
|
|
} else { |
|
407
|
|
|
$repository->setVisibilityPublished($resource); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
$result = [ |
|
411
|
|
|
'visibility' => $link->getVisibility(), |
|
412
|
|
|
'ok' => true, |
|
413
|
|
|
]; |
|
414
|
|
|
|
|
415
|
|
|
return new JsonResponse($result); |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
/** |
|
419
|
|
|
* @deprecated Use Vue + api platform |
|
420
|
|
|
* |
|
421
|
|
|
* @Route("/{tool}/{type}/{id}/delete", name="chamilo_core_resource_delete") |
|
422
|
|
|
*/ |
|
423
|
|
|
public function deleteAction(Request $request): Response |
|
424
|
|
|
{ |
|
425
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
426
|
|
|
|
|
427
|
|
|
$id = $request->get('id'); |
|
428
|
|
|
$resourceNode = $this->getDoctrine()->getRepository(ResourceNode::class)->find($id); |
|
429
|
|
|
$parentId = $resourceNode->getParent()->getId(); |
|
430
|
|
|
|
|
431
|
|
|
$this->denyAccessUnlessGranted( |
|
432
|
|
|
ResourceNodeVoter::DELETE, |
|
433
|
|
|
$resourceNode, |
|
434
|
|
|
$this->trans('Unauthorised access to resource') |
|
435
|
|
|
); |
|
436
|
|
|
|
|
437
|
|
|
$children = $resourceNode->getChildren(); |
|
438
|
|
|
|
|
439
|
|
|
if (!empty($children)) { |
|
440
|
|
|
/** @var ResourceNode $child */ |
|
441
|
|
|
foreach ($children as $child) { |
|
442
|
|
|
$em->remove($child); |
|
443
|
|
|
} |
|
444
|
|
|
} |
|
445
|
|
|
|
|
446
|
|
|
$em->remove($resourceNode); |
|
447
|
|
|
$this->addFlash('success', $this->trans('Deleted').': '.$resourceNode->getSlug()); |
|
448
|
|
|
$em->flush(); |
|
449
|
|
|
|
|
450
|
|
|
$routeParams = $this->getResourceParams($request); |
|
451
|
|
|
$routeParams['id'] = $parentId; |
|
452
|
|
|
|
|
453
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
|
454
|
|
|
} |
|
455
|
|
|
|
|
456
|
|
|
/** |
|
457
|
|
|
* @deprecated Use Vue + api platform |
|
458
|
|
|
* |
|
459
|
|
|
* Route("/{tool}/{type}/{id}/delete_mass", methods={"DELETE"}, name="chamilo_core_resource_delete_mass") |
|
460
|
|
|
*/ |
|
461
|
|
|
/*public function deleteMassAction($primaryKeys, $allPrimaryKeys, Request $request): Response |
|
462
|
|
|
{ |
|
463
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
464
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
465
|
|
|
|
|
466
|
|
|
$parentId = 0; |
|
467
|
|
|
foreach ($primaryKeys as $id) { |
|
468
|
|
|
$resource = $repo->find($id); |
|
469
|
|
|
$resourceNode = $resource->getResourceNode(); |
|
470
|
|
|
|
|
471
|
|
|
if (null === $resourceNode) { |
|
472
|
|
|
continue; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
$this->denyAccessUnlessGranted( |
|
476
|
|
|
ResourceNodeVoter::DELETE, |
|
477
|
|
|
$resourceNode, |
|
478
|
|
|
$this->trans('Unauthorised access to resource') |
|
479
|
|
|
); |
|
480
|
|
|
|
|
481
|
|
|
$parentId = $resourceNode->getParent()->getId(); |
|
482
|
|
|
$em->remove($resource); |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
$this->addFlash('success', $this->trans('Deleted')); |
|
486
|
|
|
$em->flush(); |
|
487
|
|
|
|
|
488
|
|
|
$routeParams = $this->getResourceParams($request); |
|
489
|
|
|
$routeParams['id'] = $parentId; |
|
490
|
|
|
|
|
491
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $routeParams); |
|
492
|
|
|
}*/ |
|
493
|
|
|
|
|
494
|
|
|
/** |
|
495
|
|
|
* Shows the associated resource file. |
|
496
|
|
|
* |
|
497
|
|
|
* @deprecated use vue |
|
498
|
|
|
* |
|
499
|
|
|
* @Route("/{tool}/{type}/{id}/view_resource", methods={"GET"}, name="chamilo_core_resource_view_resource") |
|
500
|
|
|
*/ |
|
501
|
|
|
/*public function viewResourceAction(Request $request, RouterInterface $router): Response |
|
502
|
|
|
{ |
|
503
|
|
|
$id = $request->get('id'); |
|
504
|
|
|
|
|
505
|
|
|
$resourceNode = $this->getResourceNodeRepository()->find($id); |
|
506
|
|
|
|
|
507
|
|
|
if (null === $resourceNode) { |
|
508
|
|
|
throw new FileNotFoundException('Resource not found'); |
|
509
|
|
|
} |
|
510
|
|
|
|
|
511
|
|
|
$this->denyAccessUnlessGranted( |
|
512
|
|
|
ResourceNodeVoter::VIEW, |
|
513
|
|
|
$resourceNode, |
|
514
|
|
|
$this->trans('Unauthorised access to resource') |
|
515
|
|
|
); |
|
516
|
|
|
|
|
517
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
518
|
|
|
|
|
519
|
|
|
$resource = $repository->getResourceFromResourceNode($id); |
|
520
|
|
|
|
|
521
|
|
|
$tool = $request->get('tool'); |
|
522
|
|
|
$type = $request->get('type'); |
|
523
|
|
|
$this->setBreadCrumb($request, $resourceNode); |
|
524
|
|
|
|
|
525
|
|
|
$params = [ |
|
526
|
|
|
'resource' => $resource, |
|
527
|
|
|
'tool' => $tool, |
|
528
|
|
|
'type' => $type, |
|
529
|
|
|
]; |
|
530
|
|
|
|
|
531
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $params); |
|
532
|
|
|
}*/ |
|
533
|
|
|
|
|
534
|
|
|
/** |
|
535
|
|
|
* View file of a resource node. |
|
536
|
|
|
* |
|
537
|
|
|
* @Route("/{tool}/{type}/{id}/view", methods={"GET"}, name="chamilo_core_resource_view") |
|
538
|
|
|
*/ |
|
539
|
|
|
public function viewAction(Request $request): Response |
|
540
|
|
|
{ |
|
541
|
|
|
$id = $request->get('id'); |
|
542
|
|
|
$filter = (string) $request->get('filter'); // See filters definitions in /config/services.yml. |
|
543
|
|
|
$resourceNode = $this->getResourceNodeRepository()->find($id); |
|
544
|
|
|
|
|
545
|
|
|
if (null === $resourceNode) { |
|
546
|
|
|
throw new FileNotFoundException('Resource not found'); |
|
547
|
|
|
} |
|
548
|
|
|
|
|
549
|
|
|
return $this->processFile($request, $resourceNode, 'show', $filter); |
|
550
|
|
|
} |
|
551
|
|
|
|
|
552
|
|
|
/** |
|
553
|
|
|
* Redirect resource to link. |
|
554
|
|
|
* |
|
555
|
|
|
* @Route("/{tool}/{type}/{id}/link", methods={"GET"}, name="chamilo_core_resource_link") |
|
556
|
|
|
* |
|
557
|
|
|
* @return RedirectResponse|void |
|
558
|
|
|
*/ |
|
559
|
|
|
public function linkAction(Request $request, RouterInterface $router) |
|
560
|
|
|
{ |
|
561
|
|
|
$id = $request->get('id'); |
|
562
|
|
|
$resourceNode = $this->getResourceNodeRepository()->find($id); |
|
563
|
|
|
|
|
564
|
|
|
if (null === $resourceNode) { |
|
565
|
|
|
throw new FileNotFoundException('Resource not found'); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
569
|
|
|
if ($repo instanceof ResourceWithLinkInterface) { |
|
570
|
|
|
$resource = $repo->getResourceFromResourceNode($resourceNode->getId()); |
|
571
|
|
|
$url = $repo->getLink($resource, $router, $this->getCourseUrlQueryToArray()); |
|
572
|
|
|
|
|
573
|
|
|
return $this->redirect($url); |
|
574
|
|
|
} |
|
575
|
|
|
|
|
576
|
|
|
$this->abort('No redirect'); |
|
577
|
|
|
} |
|
578
|
|
|
|
|
579
|
|
|
/** |
|
580
|
|
|
* Download file of a resource node. |
|
581
|
|
|
* |
|
582
|
|
|
* @Route("/{tool}/{type}/{id}/download", methods={"GET"}, name="chamilo_core_resource_download") |
|
583
|
|
|
* |
|
584
|
|
|
* @return RedirectResponse|StreamedResponse |
|
585
|
|
|
*/ |
|
586
|
|
|
public function downloadAction(Request $request) |
|
587
|
|
|
{ |
|
588
|
|
|
$id = (int) $request->get('id'); |
|
589
|
|
|
$resourceNode = $this->getResourceNodeRepository()->find($id); |
|
590
|
|
|
|
|
591
|
|
|
if (null === $resourceNode) { |
|
592
|
|
|
throw new FileNotFoundException('Resource not found'); |
|
593
|
|
|
} |
|
594
|
|
|
|
|
595
|
|
|
$repo = $this->getRepositoryFromRequest($request); |
|
596
|
|
|
|
|
597
|
|
|
$this->denyAccessUnlessGranted( |
|
598
|
|
|
ResourceNodeVoter::VIEW, |
|
599
|
|
|
$resourceNode, |
|
600
|
|
|
$this->trans('Unauthorised access to resource') |
|
601
|
|
|
); |
|
602
|
|
|
|
|
603
|
|
|
// If resource node has a file just download it. Don't download the children. |
|
604
|
|
|
if ($resourceNode->hasResourceFile()) { |
|
605
|
|
|
// Redirect to download single file. |
|
606
|
|
|
return $this->processFile($request, $resourceNode, 'download'); |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
$zipName = $resourceNode->getSlug().'.zip'; |
|
610
|
|
|
//$rootNodePath = $resourceNode->getPathForDisplay(); |
|
611
|
|
|
$resourceNodeRepo = $repo->getResourceNodeRepository(); |
|
612
|
|
|
$type = $repo->getResourceType(); |
|
613
|
|
|
|
|
614
|
|
|
$criteria = Criteria::create() |
|
615
|
|
|
->where(Criteria::expr()->neq('resourceFile', null)) // must have a file |
|
616
|
|
|
->andWhere(Criteria::expr()->eq('resourceType', $type)) // only download same type |
|
617
|
|
|
; |
|
618
|
|
|
|
|
619
|
|
|
$qb = $resourceNodeRepo->getChildrenQueryBuilder($resourceNode); |
|
620
|
|
|
$qb->addCriteria($criteria); |
|
621
|
|
|
/** @var ArrayCollection|ResourceNode[] $children */ |
|
622
|
|
|
$children = $qb->getQuery()->getResult(); |
|
623
|
|
|
$count = \count($children); |
|
624
|
|
|
if (0 === $count) { |
|
625
|
|
|
$params = $this->getResourceParams($request); |
|
626
|
|
|
$params['id'] = $id; |
|
627
|
|
|
|
|
628
|
|
|
$this->addFlash('warning', $this->trans('No files')); |
|
629
|
|
|
|
|
630
|
|
|
return $this->redirectToRoute('chamilo_core_resource_list', $params); |
|
631
|
|
|
} |
|
632
|
|
|
|
|
633
|
|
|
$response = new StreamedResponse( |
|
634
|
|
|
function () use ($zipName, $children, $repo): void { |
|
635
|
|
|
// Define suitable options for ZipStream Archive. |
|
636
|
|
|
$options = new Archive(); |
|
637
|
|
|
$options->setContentType('application/octet-stream'); |
|
638
|
|
|
//initialise zipstream with output zip filename and options. |
|
639
|
|
|
$zip = new ZipStream($zipName, $options); |
|
640
|
|
|
|
|
641
|
|
|
/** @var ResourceNode $node */ |
|
642
|
|
|
foreach ($children as $node) { |
|
643
|
|
|
$stream = $repo->getResourceNodeFileStream($node); |
|
644
|
|
|
$fileName = $node->getResourceFile()->getOriginalName(); |
|
645
|
|
|
//$fileToDisplay = basename($node->getPathForDisplay()); |
|
646
|
|
|
//$fileToDisplay = str_replace($rootNodePath, '', $node->getPathForDisplay()); |
|
647
|
|
|
//error_log($fileToDisplay); |
|
648
|
|
|
$zip->addFileFromStream($fileName, $stream); |
|
649
|
|
|
} |
|
650
|
|
|
$zip->finish(); |
|
651
|
|
|
} |
|
652
|
|
|
); |
|
653
|
|
|
|
|
654
|
|
|
$disposition = $response->headers->makeDisposition( |
|
655
|
|
|
ResponseHeaderBag::DISPOSITION_ATTACHMENT, |
|
656
|
|
|
$zipName //Transliterator::transliterate($zipName) |
|
657
|
|
|
); |
|
658
|
|
|
$response->headers->set('Content-Disposition', $disposition); |
|
659
|
|
|
$response->headers->set('Content-Type', 'application/octet-stream'); |
|
660
|
|
|
|
|
661
|
|
|
return $response; |
|
662
|
|
|
} |
|
663
|
|
|
|
|
664
|
|
|
/** |
|
665
|
|
|
* Upload form. |
|
666
|
|
|
* |
|
667
|
|
|
* @deprecated use vue + api platform |
|
668
|
|
|
* |
|
669
|
|
|
* @Route("/{tool}/{type}/{id}/upload", name="chamilo_core_resource_upload", methods={"GET", "POST"}, |
|
670
|
|
|
* options={"expose"=true}) |
|
671
|
|
|
*/ |
|
672
|
|
|
/*public function uploadAction(Request $request, $tool, $type, $id): Response |
|
673
|
|
|
{ |
|
674
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
675
|
|
|
$resourceNode = $repository->getResourceNodeRepository()->find($id); |
|
676
|
|
|
|
|
677
|
|
|
$this->denyAccessUnlessGranted( |
|
678
|
|
|
ResourceNodeVoter::EDIT, |
|
679
|
|
|
$resourceNode, |
|
680
|
|
|
$this->trans('Unauthorised access to resource') |
|
681
|
|
|
); |
|
682
|
|
|
|
|
683
|
|
|
$this->setBreadCrumb($request, $resourceNode); |
|
684
|
|
|
|
|
685
|
|
|
$routeParams = $this->getResourceParams($request); |
|
686
|
|
|
$routeParams['tool'] = $tool; |
|
687
|
|
|
$routeParams['type'] = $type; |
|
688
|
|
|
$routeParams['id'] = $id; |
|
689
|
|
|
|
|
690
|
|
|
return $this->render($repository->getTemplates()->getFromAction(__FUNCTION__), $routeParams); |
|
691
|
|
|
}*/ |
|
692
|
|
|
|
|
693
|
|
|
/** |
|
694
|
|
|
* @return mixed|StreamedResponse |
|
695
|
|
|
*/ |
|
696
|
|
|
private function processFile(Request $request, ResourceNode $resourceNode, string $mode = 'show', string $filter = '') |
|
697
|
|
|
{ |
|
698
|
|
|
$this->denyAccessUnlessGranted( |
|
699
|
|
|
ResourceNodeVoter::VIEW, |
|
700
|
|
|
$resourceNode, |
|
701
|
|
|
$this->trans('Unauthorised view access to resource') |
|
702
|
|
|
); |
|
703
|
|
|
|
|
704
|
|
|
$resourceFile = $resourceNode->getResourceFile(); |
|
705
|
|
|
|
|
706
|
|
|
if (null === $resourceFile) { |
|
707
|
|
|
throw new NotFoundHttpException($this->trans('File not found for resource')); |
|
708
|
|
|
} |
|
709
|
|
|
|
|
710
|
|
|
$fileName = $resourceNode->getResourceFile()->getOriginalName(); |
|
711
|
|
|
$mimeType = $resourceFile->getMimeType(); |
|
712
|
|
|
$resourceNodeRepo = $this->getResourceNodeRepository(); |
|
713
|
|
|
|
|
714
|
|
|
switch ($mode) { |
|
715
|
|
|
case 'download': |
|
716
|
|
|
$forceDownload = true; |
|
717
|
|
|
|
|
718
|
|
|
break; |
|
719
|
|
|
case 'show': |
|
720
|
|
|
default: |
|
721
|
|
|
$forceDownload = false; |
|
722
|
|
|
// If it's an image then send it to Glide. |
|
723
|
|
|
if (str_contains($mimeType, 'image')) { |
|
724
|
|
|
$glide = $this->getGlide(); |
|
725
|
|
|
$server = $glide->getServer(); |
|
726
|
|
|
$params = $request->query->all(); |
|
727
|
|
|
|
|
728
|
|
|
// The filter overwrites the params from GET. |
|
729
|
|
|
if (!empty($filter)) { |
|
730
|
|
|
$params = $glide->getFilters()[$filter] ?? []; |
|
731
|
|
|
} |
|
732
|
|
|
|
|
733
|
|
|
// The image was cropped manually by the user, so we force to render this version, |
|
734
|
|
|
// no matter other crop parameters. |
|
735
|
|
|
$crop = $resourceFile->getCrop(); |
|
736
|
|
|
if (!empty($crop)) { |
|
737
|
|
|
$params['crop'] = $crop; |
|
738
|
|
|
} |
|
739
|
|
|
|
|
740
|
|
|
$fileName = $resourceNodeRepo->getFilename($resourceFile); |
|
741
|
|
|
|
|
742
|
|
|
return $server->getImageResponse($fileName, $params); |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
break; |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
$stream = $resourceNodeRepo->getResourceNodeFileStream($resourceNode); |
|
749
|
|
|
|
|
750
|
|
|
$response = new StreamedResponse( |
|
751
|
|
|
function () use ($stream): void { |
|
752
|
|
|
stream_copy_to_stream($stream, fopen('php://output', 'wb')); |
|
753
|
|
|
} |
|
754
|
|
|
); |
|
755
|
|
|
$disposition = $response->headers->makeDisposition( |
|
756
|
|
|
$forceDownload ? ResponseHeaderBag::DISPOSITION_ATTACHMENT : ResponseHeaderBag::DISPOSITION_INLINE, |
|
757
|
|
|
$fileName |
|
758
|
|
|
//Transliterator::transliterate($fileName) |
|
759
|
|
|
); |
|
760
|
|
|
$response->headers->set('Content-Disposition', $disposition); |
|
761
|
|
|
$response->headers->set('Content-Type', $mimeType ?: 'application/octet-stream'); |
|
762
|
|
|
|
|
763
|
|
|
return $response; |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
/** |
|
767
|
|
|
* @return RedirectResponse|Response |
|
768
|
|
|
*/ |
|
769
|
|
|
private function createResource(Request $request, string $fileType = 'file') |
|
|
|
|
|
|
770
|
|
|
{ |
|
771
|
|
|
$resourceNodeParentId = $request->get('id'); |
|
772
|
|
|
$repository = $this->getRepositoryFromRequest($request); |
|
773
|
|
|
|
|
774
|
|
|
// Default parent node is course. |
|
775
|
|
|
$parentNode = $this->getParentResourceNode($request); |
|
776
|
|
|
|
|
777
|
|
|
$this->setBreadCrumb($request, $parentNode); |
|
778
|
|
|
|
|
779
|
|
|
$this->denyAccessUnlessGranted( |
|
780
|
|
|
ResourceNodeVoter::CREATE, |
|
781
|
|
|
$parentNode, |
|
782
|
|
|
$this->trans('Unauthorised access to resource') |
|
783
|
|
|
); |
|
784
|
|
|
|
|
785
|
|
|
$form = $repository->getForm($this->container->get('form.factory'), null); |
|
786
|
|
|
$settings = $repository->getResourceSettings(); |
|
787
|
|
|
|
|
788
|
|
|
if ('file' === $fileType && $settings->isAllowToSaveEditorToResourceFile()) { |
|
789
|
|
|
/*$resourceParams = $this->getResourceParams($request); |
|
790
|
|
|
$form->add( |
|
791
|
|
|
$this->fileContentName, |
|
792
|
|
|
CKEditorType::class, |
|
793
|
|
|
[ |
|
794
|
|
|
'mapped' => false, |
|
795
|
|
|
'config' => [ |
|
796
|
|
|
'filebrowserImageBrowseRoute' => 'resources_filemanager', |
|
797
|
|
|
'filebrowserImageBrowseRouteParameters' => $resourceParams, |
|
798
|
|
|
'fullPage' => true, |
|
799
|
|
|
], |
|
800
|
|
|
] |
|
801
|
|
|
);*/ |
|
802
|
|
|
} |
|
803
|
|
|
|
|
804
|
|
|
$form->handleRequest($request); |
|
805
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
|
806
|
|
|
$em = $this->getDoctrine()->getManager(); |
|
807
|
|
|
$course = $this->getCourse()->getId(); |
|
808
|
|
|
$course = $this->getDoctrine()->getRepository(Course::class)->find($course); |
|
809
|
|
|
$session = $this->getSession(); |
|
810
|
|
|
|
|
811
|
|
|
// @var AbstractResource $newResource |
|
812
|
|
|
/*$newResource = $repository->setResourceProperties($form, $course, $session, $fileType); |
|
813
|
|
|
|
|
814
|
|
|
$file = null; |
|
815
|
|
|
if ('file' === $fileType && $settings->isAllowToSaveEditorToResourceFile()) { |
|
816
|
|
|
$content = $form->get($this->fileContentName)->getViewData(); |
|
817
|
|
|
$newResource->setTitle($newResource->getTitle().'.html'); |
|
818
|
|
|
$fileName = $newResource->getTitle(); |
|
819
|
|
|
|
|
820
|
|
|
$handle = tmpfile(); |
|
821
|
|
|
fwrite($handle, $content); |
|
822
|
|
|
$meta = stream_get_meta_data($handle); |
|
823
|
|
|
$file = new UploadedFile($meta['uri'], $fileName, 'text/html', null, true); |
|
824
|
|
|
} |
|
825
|
|
|
$newResource->addCourseLink( |
|
826
|
|
|
$course, |
|
827
|
|
|
$session |
|
828
|
|
|
); |
|
829
|
|
|
$em->persist($newResource); |
|
830
|
|
|
$em->flush(); |
|
831
|
|
|
|
|
832
|
|
|
$repository->addFile($newResource, $file); |
|
833
|
|
|
$em->flush();*/ |
|
834
|
|
|
|
|
835
|
|
|
// Loops all sharing options |
|
836
|
|
|
/*foreach ($shareList as $share) { |
|
837
|
|
|
$idList = []; |
|
838
|
|
|
if (isset($share['search'])) { |
|
839
|
|
|
$idList = explode(',', $share['search']); |
|
840
|
|
|
} |
|
841
|
|
|
|
|
842
|
|
|
$resourceRight = null; |
|
843
|
|
|
if (isset($share['mask'])) { |
|
844
|
|
|
$resourceRight = new ResourceRight(); |
|
845
|
|
|
$resourceRight |
|
846
|
|
|
->setMask($share['mask']) |
|
847
|
|
|
->setRole($share['role']) |
|
848
|
|
|
; |
|
849
|
|
|
} |
|
850
|
|
|
|
|
851
|
|
|
// Build links |
|
852
|
|
|
switch ($share['sharing']) { |
|
853
|
|
|
case 'everyone': |
|
854
|
|
|
$repository->addResourceToEveryone( |
|
855
|
|
|
$resourceNode, |
|
856
|
|
|
$resourceRight |
|
857
|
|
|
); |
|
858
|
|
|
break; |
|
859
|
|
|
case 'course': |
|
860
|
|
|
$repository->addResourceToCourse( |
|
861
|
|
|
$resourceNode, |
|
862
|
|
|
$course, |
|
863
|
|
|
$resourceRight |
|
864
|
|
|
); |
|
865
|
|
|
break; |
|
866
|
|
|
case 'session': |
|
867
|
|
|
$repository->addResourceToSession( |
|
868
|
|
|
$resourceNode, |
|
869
|
|
|
$course, |
|
870
|
|
|
$session, |
|
871
|
|
|
$resourceRight |
|
872
|
|
|
); |
|
873
|
|
|
break; |
|
874
|
|
|
case 'user': |
|
875
|
|
|
// Only for me |
|
876
|
|
|
if (isset($share['only_me'])) { |
|
877
|
|
|
$repository->addResourceOnlyToMe($resourceNode); |
|
878
|
|
|
} else { |
|
879
|
|
|
// To other users |
|
880
|
|
|
$repository->addResourceToUserList($resourceNode, $idList); |
|
881
|
|
|
} |
|
882
|
|
|
break; |
|
883
|
|
|
case 'group': |
|
884
|
|
|
// @todo |
|
885
|
|
|
break; |
|
886
|
|
|
}*/ |
|
887
|
|
|
//} |
|
888
|
|
|
$em->flush(); |
|
889
|
|
|
$this->addFlash('success', $this->trans('Saved')); |
|
890
|
|
|
|
|
891
|
|
|
$params = $this->getResourceParams($request); |
|
892
|
|
|
$params['id'] = $resourceNodeParentId; |
|
893
|
|
|
|
|
894
|
|
|
return $this->redirectToRoute( |
|
895
|
|
|
'chamilo_core_resource_list', |
|
896
|
|
|
$params |
|
897
|
|
|
); |
|
898
|
|
|
} |
|
899
|
|
|
|
|
900
|
|
|
$template = null; |
|
901
|
|
|
switch ($fileType) { |
|
902
|
|
|
case 'folder': |
|
903
|
|
|
$template = $repository->getTemplates()->getFromAction('newFolderAction'); |
|
904
|
|
|
|
|
905
|
|
|
break; |
|
906
|
|
|
case 'file': |
|
907
|
|
|
$template = $repository->getTemplates()->getFromAction('newAction'); |
|
908
|
|
|
|
|
909
|
|
|
break; |
|
910
|
|
|
} |
|
911
|
|
|
|
|
912
|
|
|
if ($template) { |
|
913
|
|
|
$routeParams = $this->getResourceParams($request); |
|
914
|
|
|
$routeParams['form'] = $form->createView(); |
|
915
|
|
|
$routeParams['parent'] = $resourceNodeParentId; |
|
916
|
|
|
$routeParams['file_type'] = $fileType; |
|
917
|
|
|
|
|
918
|
|
|
return $this->render($template, $routeParams); |
|
919
|
|
|
} |
|
920
|
|
|
|
|
921
|
|
|
throw $this->createAccessDeniedException(); |
|
922
|
|
|
} |
|
923
|
|
|
} |
|
924
|
|
|
|