|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CourseBundle\Entity\CDocument; |
|
8
|
|
|
use Chamilo\CourseBundle\Repository\CDocumentRepository; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
11
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
|
12
|
|
|
|
|
13
|
|
|
class UpdateResourceNodeFileAction |
|
14
|
|
|
{ |
|
15
|
|
|
public function __invoke(Request $request, CDocumentRepository $repo): CDocument |
|
16
|
|
|
{ |
|
17
|
|
|
error_log('__invoke update'); |
|
18
|
|
|
|
|
19
|
|
|
$id = (int) $request->get('id'); |
|
20
|
|
|
error_log($id); |
|
21
|
|
|
if (0 === $id) { |
|
22
|
|
|
throw new \InvalidArgumentException('Not valid id'); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** @var CDocument $document */ |
|
26
|
|
|
$document = $repo->find($id); |
|
27
|
|
|
|
|
28
|
|
|
if (null === $document) { |
|
29
|
|
|
throw new \InvalidArgumentException("Resource $id not found"); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
error_log($request->getMethod()); |
|
33
|
|
|
$fileType = $document->getFileType(); |
|
34
|
|
|
|
|
35
|
|
|
$data = $request->getContent(); |
|
36
|
|
|
$title = $request->get('title'); |
|
37
|
|
|
error_log($title); |
|
38
|
|
|
$title = $request->request->get('title'); |
|
39
|
|
|
|
|
40
|
|
|
error_log($title); |
|
41
|
|
|
|
|
42
|
|
|
$comment = $request->request->get('comment'); |
|
43
|
|
|
|
|
44
|
|
|
error_log($comment); |
|
45
|
|
|
|
|
46
|
|
|
if (empty($data)) { |
|
47
|
|
|
throw new \InvalidArgumentException("No data"); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
|
|
51
|
|
|
error_log(print_r($data, 1)); |
|
52
|
|
|
$data = json_decode($data, true); |
|
53
|
|
|
error_log(print_r($data, 1)); |
|
54
|
|
|
|
|
55
|
|
|
$title = $data['title']; |
|
56
|
|
|
$content = $data['contentFile']; |
|
57
|
|
|
$comment = $data['comment']; |
|
58
|
|
|
//$nodeId = (int) $request->get('parentResourceNodeId'); |
|
59
|
|
|
//$document->setParentResourceNode($nodeId); |
|
60
|
|
|
$document->setTitle($title); |
|
61
|
|
|
|
|
62
|
|
|
if ('file' === $fileType) { |
|
63
|
|
|
$repo->updateResourceFileContent($document, $content); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/*if ($request->request->has('resourceLinkList')) { |
|
67
|
|
|
$links = $request->get('resourceLinkList'); |
|
68
|
|
|
if (false === strpos($links, '[')) { |
|
69
|
|
|
$links = json_decode('['.$links.']', true); |
|
70
|
|
|
} else { |
|
71
|
|
|
$links = json_decode($links, true); |
|
72
|
|
|
} |
|
73
|
|
|
if (empty($links)) { |
|
74
|
|
|
throw new \InvalidArgumentException( |
|
75
|
|
|
'resourceLinkList is not a valid json. Example: [{"c_id":1:"visibility":1}]' |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
$document->setResourceLinkList($links); |
|
79
|
|
|
}*/ |
|
80
|
|
|
|
|
81
|
|
|
$repo->setResourceTitle($document, $title); |
|
82
|
|
|
|
|
83
|
|
|
//$document->setTitle($title); |
|
84
|
|
|
$document->setComment($comment); |
|
85
|
|
|
//$document->getResourceNode()->setTitle($title); |
|
86
|
|
|
|
|
87
|
|
|
return $document; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|