1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
namespace Chamilo\CourseBundle\Entity; |
6
|
|
|
|
7
|
|
|
use ApiPlatform\Core\Annotation\ApiFilter; |
8
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
9
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter; |
10
|
|
|
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; |
11
|
|
|
use ApiPlatform\Core\Serializer\Filter\PropertyFilter; |
12
|
|
|
use Chamilo\CoreBundle\Controller\Api\CreateResourceNodeFileAction; |
13
|
|
|
use Chamilo\CoreBundle\Controller\Api\UpdateResourceNodeFileAction; |
14
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
15
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
16
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
17
|
|
|
use Chamilo\CoreBundle\Entity\Session; |
18
|
|
|
use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait; |
19
|
|
|
use Doctrine\ORM\Mapping as ORM; |
20
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
21
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @ApiResource( |
25
|
|
|
* shortName="Documents", |
26
|
|
|
* normalizationContext={"groups"={"document:read", "resource_node:read"}}, |
27
|
|
|
* denormalizationContext={"groups"={"document:write"}}, |
28
|
|
|
* itemOperations={ |
29
|
|
|
* "put" ={ |
30
|
|
|
* "controller"=UpdateResourceNodeFileAction::class, |
31
|
|
|
* "deserialize"=false, |
32
|
|
|
* "security" = "is_granted('EDIT', object.resourceNode)", |
33
|
|
|
* "validation_groups"={"Default", "media_object_create", "document:write"}, |
34
|
|
|
* }, |
35
|
|
|
* "get" = { |
36
|
|
|
* "security" = "is_granted('VIEW', object.resourceNode)", |
37
|
|
|
* }, |
38
|
|
|
* "delete" = { |
39
|
|
|
* "security" = "is_granted('DELETE', object.resourceNode)", |
40
|
|
|
* }, |
41
|
|
|
* }, |
42
|
|
|
* collectionOperations={ |
43
|
|
|
* "post"={ |
44
|
|
|
* "controller"=CreateResourceNodeFileAction::class, |
45
|
|
|
* "deserialize"=false, |
46
|
|
|
* "security"="is_granted('ROLE_CURRENT_COURSE_TEACHER') or is_granted('ROLE_CURRENT_SESSION_COURSE_TEACHER')", |
47
|
|
|
* "validation_groups"={"Default", "media_object_create", "document:write"}, |
48
|
|
|
* "openapi_context"={ |
49
|
|
|
* "requestBody"={ |
50
|
|
|
* "content"={ |
51
|
|
|
* "multipart/form-data"={ |
52
|
|
|
* "schema"={ |
53
|
|
|
* "type"="object", |
54
|
|
|
* "properties"={ |
55
|
|
|
* "title"={ |
56
|
|
|
* "type"="string", |
57
|
|
|
* }, |
58
|
|
|
* "filetype"={ |
59
|
|
|
* "type"="string", |
60
|
|
|
* "enum"={"folder", "file"}, |
61
|
|
|
* }, |
62
|
|
|
* "comment"={ |
63
|
|
|
* "type"="string", |
64
|
|
|
* }, |
65
|
|
|
* "contentFile"={ |
66
|
|
|
* "type"="string", |
67
|
|
|
* }, |
68
|
|
|
* "uploadFile"={ |
69
|
|
|
* "type"="string", |
70
|
|
|
* "format"="binary" |
71
|
|
|
* }, |
72
|
|
|
* "parentResourceNodeId"={ |
73
|
|
|
* "type"="integer", |
74
|
|
|
* }, |
75
|
|
|
* "resourceLinkList"={ |
76
|
|
|
* "type"="array", |
77
|
|
|
* "items": { |
78
|
|
|
* "type": "object", |
79
|
|
|
* "properties"={ |
80
|
|
|
* "visibility"={ |
81
|
|
|
* "type"="integer", |
82
|
|
|
* }, |
83
|
|
|
* "c_id"={ |
84
|
|
|
* "type"="integer", |
85
|
|
|
* }, |
86
|
|
|
* "session_id"={ |
87
|
|
|
* "type"="integer", |
88
|
|
|
* }, |
89
|
|
|
* } |
90
|
|
|
* } |
91
|
|
|
* }, |
92
|
|
|
* } |
93
|
|
|
* } |
94
|
|
|
* } |
95
|
|
|
* } |
96
|
|
|
* } |
97
|
|
|
* } |
98
|
|
|
* }, |
99
|
|
|
* "get" = { |
100
|
|
|
* "security"="is_granted('ROLE_USER')", |
101
|
|
|
* }, |
102
|
|
|
* }, |
103
|
|
|
* ) |
104
|
|
|
* @ApiFilter(SearchFilter::class, properties={"title": "partial", "resourceNode.parent": "exact"}) |
105
|
|
|
* @ApiFilter(PropertyFilter::class) |
106
|
|
|
* @ApiFilter( |
107
|
|
|
* OrderFilter::class, |
108
|
|
|
* properties={ |
109
|
|
|
* "id", |
110
|
|
|
* "filetype", |
111
|
|
|
* "resourceNode.title", |
112
|
|
|
* "resourceNode.createdAt", |
113
|
|
|
* "resourceNode.resourceFile.size", |
114
|
|
|
* "resourceNode.updatedAt" |
115
|
|
|
* } |
116
|
|
|
* ) |
117
|
|
|
* |
118
|
|
|
* @ORM\Table( |
119
|
|
|
* name="c_document", |
120
|
|
|
* indexes={ |
121
|
|
|
* @ORM\Index(name="idx_cdoc_type", columns={"filetype"}), |
122
|
|
|
* } |
123
|
|
|
* ) |
124
|
|
|
* GRID\Source(columns="iid, title, resourceNode.createdAt", filterable=false, groups={"resource"}) |
125
|
|
|
* GRID\Source(columns="iid, title", filterable=false, groups={"editor"}) |
126
|
|
|
* @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\ResourceListener"}) |
127
|
|
|
* @ORM\Entity |
128
|
|
|
*/ |
129
|
|
|
class CDocument extends AbstractResource implements ResourceInterface |
130
|
|
|
{ |
131
|
|
|
use ShowCourseResourcesInSessionTrait; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @var int |
135
|
|
|
* @Groups({"document:read"}) |
136
|
|
|
* @ORM\Column(name="iid", type="integer") |
137
|
|
|
* @ORM\Id |
138
|
|
|
* @ORM\GeneratedValue |
139
|
|
|
*/ |
140
|
|
|
protected $iid; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @var string |
144
|
|
|
* @Groups({"document:read", "document:write"}) |
145
|
|
|
* @ORM\Column(name="title", type="string", length=255, nullable=true) |
146
|
|
|
*/ |
147
|
|
|
protected $title; |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @var string |
151
|
|
|
* @Groups({"document:read", "document:write"}) |
152
|
|
|
* @ORM\Column(name="comment", type="text", nullable=true) |
153
|
|
|
*/ |
154
|
|
|
protected $comment; |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @var string File type, it can be 'folder' or 'file' |
158
|
|
|
* @Groups({"document:read", "document:write"}) |
159
|
|
|
* @Assert\Choice({"folder", "file"}, message="Choose a valid filetype.") |
160
|
|
|
* @ORM\Column(name="filetype", type="string", length=10, nullable=false) |
161
|
|
|
*/ |
162
|
|
|
protected $filetype; |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @var bool |
166
|
|
|
* @ORM\Column(name="readonly", type="boolean", nullable=false) |
167
|
|
|
*/ |
168
|
|
|
protected $readonly; |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @var bool |
172
|
|
|
* @ORM\Column(name="template", type="boolean", nullable=false) |
173
|
|
|
*/ |
174
|
|
|
protected $template; |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* CDocument constructor. |
178
|
|
|
*/ |
179
|
|
|
public function __construct() |
180
|
|
|
{ |
181
|
|
|
$this->filetype = 'folder'; |
182
|
|
|
$this->readonly = false; |
183
|
|
|
$this->template = false; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function __toString(): string |
187
|
|
|
{ |
188
|
|
|
return $this->getTitle(); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
public function isTemplate(): bool |
192
|
|
|
{ |
193
|
|
|
return $this->template; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
public function setTemplate(bool $template): self |
197
|
|
|
{ |
198
|
|
|
$this->template = $template; |
199
|
|
|
|
200
|
|
|
return $this; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Set comment. |
205
|
|
|
* |
206
|
|
|
* @param string $comment |
207
|
|
|
*/ |
208
|
|
|
public function setComment($comment): self |
209
|
|
|
{ |
210
|
|
|
$this->comment = $comment; |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Get comment. |
217
|
|
|
* |
218
|
|
|
* @return string |
219
|
|
|
*/ |
220
|
|
|
public function getComment() |
221
|
|
|
{ |
222
|
|
|
return $this->comment; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function setTitle(string $title): self |
226
|
|
|
{ |
227
|
|
|
$this->title = $title; |
228
|
|
|
|
229
|
|
|
return $this; |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Document title. |
234
|
|
|
*/ |
235
|
|
|
public function getTitle(): string |
236
|
|
|
{ |
237
|
|
|
return (string) $this->title; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Set filetype. |
242
|
|
|
*/ |
243
|
|
|
public function setFiletype(string $filetype): self |
244
|
|
|
{ |
245
|
|
|
$this->filetype = $filetype; |
246
|
|
|
|
247
|
|
|
return $this; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Get filetype. |
252
|
|
|
* |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getFiletype() |
256
|
|
|
{ |
257
|
|
|
return $this->filetype; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Set readonly. |
262
|
|
|
* |
263
|
|
|
* @param bool $readonly |
264
|
|
|
* |
265
|
|
|
* @return CDocument |
266
|
|
|
*/ |
267
|
|
|
public function setReadonly($readonly) |
268
|
|
|
{ |
269
|
|
|
$this->readonly = $readonly; |
270
|
|
|
|
271
|
|
|
return $this; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
/** |
275
|
|
|
* Get readonly. |
276
|
|
|
* |
277
|
|
|
* @return bool |
278
|
|
|
*/ |
279
|
|
|
public function getReadonly() |
280
|
|
|
{ |
281
|
|
|
return $this->readonly; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* @return int |
286
|
|
|
*/ |
287
|
|
|
public function getIid() |
288
|
|
|
{ |
289
|
|
|
return $this->iid; |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
/** |
293
|
|
|
* Resource identifier. |
294
|
|
|
*/ |
295
|
|
|
public function getResourceIdentifier(): int |
296
|
|
|
{ |
297
|
|
|
return $this->getIid(); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function getResourceName(): string |
301
|
|
|
{ |
302
|
|
|
return $this->getTitle(); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public function setResourceName(string $name): self |
306
|
|
|
{ |
307
|
|
|
return $this->setTitle($name); |
308
|
|
|
} |
309
|
|
|
} |
310
|
|
|
|