Passed
Push — master ( 48b5f2...d3d7f5 )
by Julito
16:02
created

PersonalFile::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Core\Annotation\ApiFilter;
10
use ApiPlatform\Core\Annotation\ApiResource;
11
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
12
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
13
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
14
use Chamilo\CoreBundle\Controller\Api\CreateResourceNodeFileAction;
15
use Chamilo\CoreBundle\Controller\Api\UpdateResourceNodeFileAction;
16
use Doctrine\ORM\Mapping as ORM;
17
use Gedmo\Timestampable\Traits\TimestampableEntity;
18
use Symfony\Component\Serializer\Annotation\Groups;
19
use Symfony\Component\Validator\Constraints as Assert;
20
21
/**
22
 * @ApiResource(
23
 *     normalizationContext={"groups"={"personal_file:read"}},
24
 *     denormalizationContext={"groups"={"personal_file:write"}},
25
 *     itemOperations={
26
 *         "put"={
27
 *             "controller"=UpdateResourceNodeFileAction::class,
28
 *             "deserialize"=false,
29
 *             "security"="is_granted('EDIT', object.resourceNode)",
30
 *         },
31
 *         "get"={
32
 *             "security"="is_granted('VIEW', object.resourceNode)",
33
 *         },
34
 *         "delete"={
35
 *             "security"="is_granted('DELETE', object.resourceNode)",
36
 *         },
37
 *     },
38
 *     collectionOperations={
39
 *         "post"={
40
 *             "controller"=CreateResourceNodeFileAction::class,
41
 *             "deserialize"=false,
42
 *             "security"="is_granted('ROLE_USER')",
43
 *             "validation_groups"={"Default", "media_object_create", "personal_file:write"},
44
 *             "openapi_context"={
45
 *                 "requestBody"={
46
 *                     "content"={
47
 *                         "multipart/form-data"={
48
 *                             "schema"={
49
 *                                 "type"="object",
50
 *                                 "properties"={
51
 *                                     "title"={
52
 *                                         "type"="string",
53
 *                                     },
54
 *                                     "comment"={
55
 *                                         "type"="string",
56
 *                                     },
57
 *                                     "contentFile"={
58
 *                                         "type"="string",
59
 *                                     },
60
 *                                     "uploadFile"={
61
 *                                         "type"="string",
62
 *                                         "format"="binary"
63
 *                                     },
64
 *                                     "parentResourceNodeId"={
65
 *                                         "type"="integer",
66
 *                                     },
67
 *                                     "resourceLinkList"={
68
 *                                         "type"="array",
69
 *                                         "items"={
70
 *                                             "type"="object",
71
 *                                             "properties"={
72
 *                                                 "visibility"={
73
 *                                                     "type"="integer",
74
 *                                                 },
75
 *                                                 "c_id"={
76
 *                                                     "type"="integer",
77
 *                                                 },
78
 *                                                 "session_id"={
79
 *                                                     "type"="integer",
80
 *                                                 },
81
 *                                             }
82
 *                                         }
83
 *                                     },
84
 *                                 }
85
 *                             }
86
 *                         }
87
 *                     }
88
 *                 }
89
 *             }
90
 *         },
91
 *         "get"={
92
 *             "security"="is_granted('ROLE_USER')",
93
 *         },
94
 *     },
95
 * )
96
 * @ApiFilter(SearchFilter::class, properties={"title":"partial", "resourceNode.parent":"exact"})
97
 * @ApiFilter(PropertyFilter::class)
98
 * @ApiFilter(
99
 *     OrderFilter::class,
100
 *     properties={
101
 *         "id",
102
 *         "resourceNode.title",
103
 *         "resourceNode.createdAt",
104
 *         "resourceNode.resourceFile.size",
105
 *         "resourceNode.updatedAt"
106
 *     }
107
 * )
108
 *
109
 * @ORM\EntityListeners({"Chamilo\CoreBundle\Entity\Listener\ResourceListener"})
110
 * @ORM\Table(name="personal_file")
111
 * @ORM\Entity
112
 */
113
class PersonalFile extends AbstractResource implements ResourceInterface
114
{
115
    use TimestampableEntity;
116
117
    /**
118
     * @ORM\Column(name="id", type="integer")
119
     * @ORM\Id
120
     * @ORM\GeneratedValue(strategy="AUTO")
121
     */
122
    protected int $id;
123
124
    /**
125
     * @Assert\NotBlank()
126
     * @ORM\Column(name="title", type="string", length=255, nullable=false)
127
     */
128
    protected string $title;
129
130
    public function __construct()
131
    {
132
    }
133
134
    public function __toString(): string
135
    {
136
        return $this->getTitle();
137
    }
138
139
    public function getId(): int
140
    {
141
        return $this->id;
142
    }
143
144
    public function getTitle(): string
145
    {
146
        return $this->title;
147
    }
148
149
    public function setTitle(string $title): self
150
    {
151
        $this->title = $title;
152
153
        return $this;
154
    }
155
156
    public function getResourceIdentifier(): int
157
    {
158
        return $this->getId();
159
    }
160
161
    public function getResourceName(): string
162
    {
163
        return $this->getTitle();
164
    }
165
166
    public function setResourceName(string $name): self
167
    {
168
        return $this->setTitle($name);
169
    }
170
}
171