1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CourseBundle\Entity; |
8
|
|
|
|
9
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter; |
10
|
|
|
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter; |
11
|
|
|
use ApiPlatform\Metadata\ApiFilter; |
12
|
|
|
use ApiPlatform\Metadata\ApiProperty; |
13
|
|
|
use ApiPlatform\Metadata\ApiResource; |
14
|
|
|
use ApiPlatform\Metadata\Delete; |
15
|
|
|
use ApiPlatform\Metadata\Get; |
16
|
|
|
use ApiPlatform\Metadata\GetCollection; |
17
|
|
|
use ApiPlatform\Metadata\Post; |
18
|
|
|
use ApiPlatform\Metadata\Put; |
19
|
|
|
use ApiPlatform\Serializer\Filter\PropertyFilter; |
20
|
|
|
use Chamilo\CoreBundle\Controller\Api\CreateDocumentFileAction; |
21
|
|
|
use Chamilo\CoreBundle\Controller\Api\UpdateDocumentFileAction; |
22
|
|
|
use Chamilo\CoreBundle\Controller\Api\UpdateVisibilityDocument; |
23
|
|
|
use Chamilo\CoreBundle\Entity\AbstractResource; |
24
|
|
|
use Chamilo\CoreBundle\Entity\GradebookCategory; |
25
|
|
|
use Chamilo\CoreBundle\Entity\Listener\ResourceListener; |
26
|
|
|
use Chamilo\CoreBundle\Entity\ResourceInterface; |
27
|
|
|
use Chamilo\CoreBundle\Entity\ResourceShowCourseResourcesInSessionInterface; |
28
|
|
|
use Chamilo\CoreBundle\Filter\CidFilter; |
29
|
|
|
use Chamilo\CoreBundle\Filter\SidFilter; |
30
|
|
|
use Chamilo\CourseBundle\Repository\CDocumentRepository; |
31
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
32
|
|
|
use Doctrine\ORM\Mapping as ORM; |
33
|
|
|
use Stringable; |
34
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
35
|
|
|
use Symfony\Component\Uid\Uuid; |
36
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
37
|
|
|
|
38
|
|
|
#[ApiResource( |
39
|
|
|
shortName: 'Documents', |
40
|
|
|
operations: [ |
41
|
|
|
new Put( |
42
|
|
|
controller: UpdateDocumentFileAction::class, |
43
|
|
|
security: "is_granted('EDIT', object.resourceNode)", |
44
|
|
|
validationContext: [ |
45
|
|
|
'groups' => ['media_object_create', 'document:write'], |
46
|
|
|
], |
47
|
|
|
deserialize: false |
48
|
|
|
), |
49
|
|
|
new Put( |
50
|
|
|
uriTemplate: '/documents/{iid}/toggle_visibility', |
51
|
|
|
controller: UpdateVisibilityDocument::class, |
52
|
|
|
security: "is_granted('EDIT', object.resourceNode)", |
53
|
|
|
deserialize: false |
54
|
|
|
), |
55
|
|
|
new Get(security: "is_granted('VIEW', object.resourceNode)"), |
56
|
|
|
new Delete(security: "is_granted('DELETE', object.resourceNode)"), |
57
|
|
|
new Post( |
58
|
|
|
controller: CreateDocumentFileAction::class, |
59
|
|
|
openapiContext: [ |
60
|
|
|
'requestBody' => [ |
61
|
|
|
'content' => [ |
62
|
|
|
'multipart/form-data' => [ |
63
|
|
|
'schema' => [ |
64
|
|
|
'type' => 'object', |
65
|
|
|
'properties' => [ |
66
|
|
|
'title' => ['type' => 'string'], |
67
|
|
|
'filetype' => [ |
68
|
|
|
'type' => 'string', |
69
|
|
|
'enum' => ['folder', 'file'], |
70
|
|
|
], |
71
|
|
|
'comment' => ['type' => 'string'], |
72
|
|
|
'contentFile' => ['type' => 'string'], |
73
|
|
|
'uploadFile' => [ |
74
|
|
|
'type' => 'string', |
75
|
|
|
'format' => 'binary', |
76
|
|
|
], |
77
|
|
|
'parentResourceNodeId' => ['type' => 'integer'], |
78
|
|
|
'resourceLinkList' => [ |
79
|
|
|
'type' => 'array', |
80
|
|
|
'items' => [ |
81
|
|
|
'type' => 'object', |
82
|
|
|
'properties' => [ |
83
|
|
|
'visibility' => ['type' => 'integer'], |
84
|
|
|
'cid' => ['type' => 'integer'], |
85
|
|
|
'gid' => ['type' => 'integer'], |
86
|
|
|
'sid' => ['type' => 'integer'], |
87
|
|
|
], |
88
|
|
|
], |
89
|
|
|
], |
90
|
|
|
'isUncompressZipEnabled' => ['type' => 'boolean'], |
91
|
|
|
'fileExistsOption' => [ |
92
|
|
|
'type' => 'string', |
93
|
|
|
'enum' => ['overwrite', 'skip', 'rename'], |
94
|
|
|
], |
95
|
|
|
], |
96
|
|
|
], |
97
|
|
|
], |
98
|
|
|
], |
99
|
|
|
], |
100
|
|
|
], |
101
|
|
|
security: "is_granted('ROLE_CURRENT_COURSE_TEACHER') or is_granted('ROLE_CURRENT_COURSE_SESSION_TEACHER') or is_granted('ROLE_TEACHER')", |
102
|
|
|
validationContext: ['groups' => ['Default', 'media_object_create', 'document:write']], |
103
|
|
|
deserialize: false |
104
|
|
|
), |
105
|
|
|
new GetCollection( |
106
|
|
|
openapiContext: [ |
107
|
|
|
'parameters' => [ |
108
|
|
|
[ |
109
|
|
|
'name' => 'resourceNode.parent', |
110
|
|
|
'in' => 'query', |
111
|
|
|
'required' => true, |
112
|
|
|
'description' => 'Resource node Parent', |
113
|
|
|
'schema' => ['type' => 'integer'], |
114
|
|
|
], |
115
|
|
|
], |
116
|
|
|
] |
117
|
|
|
), |
118
|
|
|
], |
119
|
|
|
normalizationContext: [ |
120
|
|
|
'groups' => ['document:read', 'resource_node:read'], |
121
|
|
|
], |
122
|
|
|
denormalizationContext: [ |
123
|
|
|
'groups' => ['document:write'], |
124
|
|
|
] |
125
|
|
|
)] |
126
|
|
|
#[ORM\Table(name: 'c_document')] |
127
|
|
|
#[ORM\Index(columns: ['filetype'], name: 'idx_cdoc_type')] |
128
|
|
|
#[ORM\Entity(repositoryClass: CDocumentRepository::class)] |
129
|
|
|
#[ORM\EntityListeners([ResourceListener::class])] |
130
|
|
|
#[ApiFilter(filterClass: PropertyFilter::class)] |
131
|
|
|
#[ApiFilter(filterClass: SearchFilter::class, properties: ['title' => 'partial', 'resourceNode.parent' => 'exact', 'filetype' => 'exact'])] |
132
|
|
|
#[ApiFilter( |
133
|
|
|
filterClass: OrderFilter::class, |
134
|
|
|
properties: [ |
135
|
|
|
'iid', |
136
|
|
|
'filetype', |
137
|
|
|
'resourceNode.title', |
138
|
|
|
'resourceNode.createdAt', |
139
|
|
|
'resourceNode.firstResourceFile.size', |
140
|
|
|
'resourceNode.updatedAt', |
141
|
|
|
] |
142
|
|
|
)] |
143
|
|
|
#[ApiFilter(filterClass: CidFilter::class)] |
144
|
|
|
#[ApiFilter(filterClass: SidFilter::class)] |
145
|
|
|
class CDocument extends AbstractResource implements ResourceInterface, ResourceShowCourseResourcesInSessionInterface, Stringable |
146
|
|
|
{ |
147
|
|
|
#[ApiProperty(identifier: true)] |
148
|
|
|
#[Groups(['document:read'])] |
149
|
|
|
#[ORM\Column(name: 'iid', type: 'integer')] |
150
|
|
|
#[ORM\Id] |
151
|
|
|
#[ORM\GeneratedValue] |
152
|
|
|
protected ?int $iid = null; |
153
|
|
|
|
154
|
|
|
#[Groups(['document:read', 'document:write', 'document:browse'])] |
155
|
|
|
#[Assert\NotBlank] |
156
|
|
|
#[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
157
|
|
|
protected string $title; |
158
|
|
|
|
159
|
|
|
#[Groups(['document:read', 'document:write'])] |
160
|
|
|
#[ORM\Column(name: 'comment', type: 'text', nullable: true)] |
161
|
|
|
protected ?string $comment; |
162
|
|
|
|
163
|
|
|
#[Groups(['document:read', 'document:write'])] |
164
|
|
|
#[Assert\Choice(['folder', 'file', 'certificate'], message: 'Choose a valid filetype.')] |
165
|
|
|
#[ORM\Column(name: 'filetype', type: 'string', length: 15, nullable: false)] |
166
|
|
|
protected string $filetype; |
167
|
|
|
|
168
|
|
|
#[ORM\Column(name: 'readonly', type: 'boolean', nullable: false)] |
169
|
|
|
protected bool $readonly; |
170
|
|
|
|
171
|
|
|
#[Groups(['document:read', 'document:write'])] |
172
|
|
|
#[ORM\Column(name: 'template', type: 'boolean', nullable: false)] |
173
|
|
|
protected bool $template; |
174
|
|
|
|
175
|
|
|
#[ORM\OneToMany(mappedBy: 'document', targetEntity: GradebookCategory::class)] |
176
|
|
|
#[Groups(['document:read'])] |
177
|
|
|
protected Collection $gradebookCategories; |
178
|
|
|
|
179
|
|
|
public function __construct() |
180
|
|
|
{ |
181
|
|
|
$this->comment = ''; |
182
|
|
|
$this->filetype = 'folder'; |
183
|
|
|
$this->readonly = false; |
184
|
|
|
$this->template = false; |
185
|
|
|
$this->gradebookCategories = new ArrayCollection(); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function __toString(): string |
189
|
|
|
{ |
190
|
|
|
return $this->getTitle(); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
public function getTitle(): string |
194
|
|
|
{ |
195
|
|
|
return $this->title; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
public function setTitle(string $title): self |
199
|
|
|
{ |
200
|
|
|
$this->title = $title; |
201
|
|
|
|
202
|
|
|
return $this; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function isTemplate(): bool |
206
|
|
|
{ |
207
|
|
|
return $this->template; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
public function setTemplate(bool $template): self |
211
|
|
|
{ |
212
|
|
|
$this->template = $template; |
213
|
|
|
|
214
|
|
|
return $this; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function getComment(): ?string |
218
|
|
|
{ |
219
|
|
|
return $this->comment; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
public function setComment(?string $comment): self |
223
|
|
|
{ |
224
|
|
|
$this->comment = $comment; |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
public function getFiletype(): string |
230
|
|
|
{ |
231
|
|
|
return $this->filetype; |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
public function setFiletype(string $filetype): self |
235
|
|
|
{ |
236
|
|
|
$this->filetype = $filetype; |
237
|
|
|
|
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
public function getReadonly(): bool |
242
|
|
|
{ |
243
|
|
|
return $this->readonly; |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
public function setReadonly(bool $readonly): self |
247
|
|
|
{ |
248
|
|
|
$this->readonly = $readonly; |
249
|
|
|
|
250
|
|
|
return $this; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
public function getResourceIdentifier(): int|Uuid |
254
|
|
|
{ |
255
|
|
|
return $this->getIid(); |
|
|
|
|
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function getIid(): ?int |
259
|
|
|
{ |
260
|
|
|
return $this->iid; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
public function getResourceName(): string |
264
|
|
|
{ |
265
|
|
|
return $this->getTitle(); |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
public function setResourceName(string $name): self |
269
|
|
|
{ |
270
|
|
|
return $this->setTitle($name); |
271
|
|
|
} |
272
|
|
|
|
273
|
|
|
/** |
274
|
|
|
* @return Collection<int, GradebookCategory> |
275
|
|
|
*/ |
276
|
|
|
public function getGradebookCategories(): Collection |
277
|
|
|
{ |
278
|
|
|
return $this->gradebookCategories; |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
|