1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\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\ApiResource; |
13
|
|
|
use ApiPlatform\Metadata\Delete; |
14
|
|
|
use ApiPlatform\Metadata\Get; |
15
|
|
|
use ApiPlatform\Metadata\GetCollection; |
16
|
|
|
use ApiPlatform\Metadata\Post; |
17
|
|
|
use ApiPlatform\Metadata\Put; |
18
|
|
|
use ApiPlatform\Serializer\Filter\PropertyFilter; |
19
|
|
|
use Chamilo\CoreBundle\Controller\Api\CreatePersonalFileAction; |
20
|
|
|
use Chamilo\CoreBundle\Controller\Api\UpdatePersonalFileAction; |
21
|
|
|
use Chamilo\CoreBundle\Entity\Listener\ResourceListener; |
22
|
|
|
use Chamilo\CoreBundle\Repository\Node\PersonalFileRepository; |
23
|
|
|
use Doctrine\ORM\Mapping as ORM; |
24
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
25
|
|
|
use Stringable; |
26
|
|
|
use Symfony\Component\Serializer\Annotation\Groups; |
27
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
28
|
|
|
|
29
|
|
|
#[ApiResource( |
30
|
|
|
operations: [ |
31
|
|
|
new Put( |
32
|
|
|
controller: UpdatePersonalFileAction::class, |
33
|
|
|
security: "is_granted('EDIT', object.resourceNode)", |
34
|
|
|
deserialize: false |
35
|
|
|
), |
36
|
|
|
new Get(security: "is_granted('VIEW', object.resourceNode)"), |
37
|
|
|
new Delete(security: "is_granted('DELETE', object.resourceNode)"), |
38
|
|
|
new Post( |
39
|
|
|
controller: CreatePersonalFileAction::class, |
40
|
|
|
openapiContext: [ |
41
|
|
|
'requestBody' => [ |
42
|
|
|
'content' => [ |
43
|
|
|
'multipart/form-data' => [ |
44
|
|
|
'schema' => [ |
45
|
|
|
'type' => 'object', |
46
|
|
|
'properties' => [ |
47
|
|
|
'title' => ['type' => 'string'], |
48
|
|
|
'comment' => ['type' => 'string'], |
49
|
|
|
'contentFile' => ['type' => 'string'], |
50
|
|
|
'uploadFile' => ['type' => 'string', 'format' => 'binary'], |
51
|
|
|
'parentResourceNodeId' => ['type' => 'integer'], |
52
|
|
|
'resourceLinkList' => [ |
53
|
|
|
'type' => 'array', |
54
|
|
|
'items' => [ |
55
|
|
|
'type' => 'object', |
56
|
|
|
'properties' => [ |
57
|
|
|
'visibility' => ['type' => 'integer'], |
58
|
|
|
'c_id' => ['type' => 'integer'], |
59
|
|
|
'session_id' => ['type' => 'integer'], |
60
|
|
|
], |
61
|
|
|
], |
62
|
|
|
], |
63
|
|
|
], |
64
|
|
|
], |
65
|
|
|
], |
66
|
|
|
], |
67
|
|
|
], |
68
|
|
|
], |
69
|
|
|
security: "is_granted('ROLE_USER')", |
70
|
|
|
validationContext: [ |
71
|
|
|
'groups' => ['Default', 'media_object_create', 'personal_file:write'], |
72
|
|
|
], |
73
|
|
|
deserialize: false |
74
|
|
|
), |
75
|
|
|
new GetCollection(security: "is_granted('ROLE_USER')"), |
76
|
|
|
], |
77
|
|
|
normalizationContext: [ |
78
|
|
|
'groups' => ['personal_file:read', 'resource_node:read'], |
79
|
|
|
], |
80
|
|
|
denormalizationContext: [ |
81
|
|
|
'groups' => ['personal_file:write'], |
82
|
|
|
] |
83
|
|
|
)] |
84
|
|
|
#[ORM\Table(name: 'personal_file')] |
85
|
|
|
#[ORM\EntityListeners([ResourceListener::class])] |
86
|
|
|
#[ORM\Entity(repositoryClass: PersonalFileRepository::class)] |
87
|
|
|
#[ApiFilter( |
88
|
|
|
filterClass: SearchFilter::class, |
89
|
|
|
properties: [ |
90
|
|
|
'title' => 'partial', |
91
|
|
|
'resourceNode.parent' => 'exact', |
92
|
|
|
] |
93
|
|
|
)] |
94
|
|
|
#[ApiFilter( |
95
|
|
|
filterClass: PropertyFilter::class |
96
|
|
|
)] |
97
|
|
|
#[ApiFilter( |
98
|
|
|
filterClass: OrderFilter::class, |
99
|
|
|
properties: [ |
100
|
|
|
'id', |
101
|
|
|
'resourceNode.title', |
102
|
|
|
'resourceNode.createdAt', |
103
|
|
|
'resourceNode.resourceFile.size', |
104
|
|
|
'resourceNode.updatedAt', |
105
|
|
|
] |
106
|
|
|
)] |
107
|
|
|
class PersonalFile extends AbstractResource implements ResourceInterface, Stringable |
108
|
|
|
{ |
109
|
|
|
use TimestampableEntity; |
110
|
|
|
|
111
|
|
|
#[Groups(['personal_file:read'])] |
112
|
|
|
#[ORM\Column(name: 'id', type: 'integer')] |
113
|
|
|
#[ORM\Id] |
114
|
|
|
#[ORM\GeneratedValue(strategy: 'AUTO')] |
115
|
|
|
protected ?int $id = null; |
116
|
|
|
|
117
|
|
|
#[Assert\NotBlank] |
118
|
|
|
#[Groups(['personal_file:read'])] |
119
|
|
|
#[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)] |
120
|
|
|
protected string $title; |
121
|
|
|
|
122
|
|
|
public function __toString(): string |
123
|
|
|
{ |
124
|
|
|
return $this->getTitle(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
public function getId(): int |
128
|
|
|
{ |
129
|
|
|
return $this->id; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
public function getTitle(): string |
133
|
|
|
{ |
134
|
|
|
return $this->title; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setTitle(string $title): self |
138
|
|
|
{ |
139
|
|
|
$this->title = $title; |
140
|
|
|
|
141
|
|
|
return $this; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function getResourceIdentifier(): int |
145
|
|
|
{ |
146
|
|
|
return $this->getId(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getResourceName(): string |
150
|
|
|
{ |
151
|
|
|
return $this->getTitle(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setResourceName(string $name): self |
155
|
|
|
{ |
156
|
|
|
return $this->setTitle($name); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
|