Passed
Pull Request — master (#5544)
by Angel Fernando Quiroz
07:03
created

MessageAttachment::getComment()   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\Metadata\ApiResource;
10
use ApiPlatform\Metadata\Get;
11
use Chamilo\CoreBundle\Repository\Node\MessageAttachmentRepository;
12
use Doctrine\ORM\Mapping as ORM;
13
use Stringable;
14
use Symfony\Component\Serializer\Annotation\Groups;
15
16
#[ApiResource(
17
    types: ['http://schema.org/MediaObject'],
18
    operations: [
19
        new Get(),
20
    ],
21
    normalizationContext: [
22
        'groups' => ['message:read'],
23
    ],
24
)]
25
#[ORM\Table(name: 'message_attachment')]
26
#[ORM\Entity(repositoryClass: MessageAttachmentRepository::class)]
27
class MessageAttachment extends AbstractResource implements ResourceInterface, Stringable
28
{
29
    #[ORM\Column(name: 'id', type: 'integer')]
30
    #[ORM\Id]
31
    #[ORM\GeneratedValue(strategy: 'IDENTITY')]
32
    protected ?int $id = null;
33
34
    #[ORM\Column(name: 'path', type: 'string', length: 255, nullable: false)]
35
    protected string $path;
36
37
    #[Groups(['message:read', 'message:write'])]
38
    #[ORM\Column(name: 'comment', type: 'text', nullable: true)]
39
    protected ?string $comment = null;
40
41
    #[ORM\Column(name: 'size', type: 'integer', nullable: false)]
42
    protected int $size;
43
44
    #[ORM\ManyToOne(targetEntity: Message::class, inversedBy: 'attachments')]
45
    #[ORM\JoinColumn(name: 'message_id', referencedColumnName: 'id', nullable: false)]
46
    protected Message $message;
47
48
    #[ORM\Column(name: 'filename', type: 'string', length: 255, nullable: false)]
49
    protected string $filename;
50
51
    #[Groups(['message:write'])]
52
    protected ResourceFile $resourceFileToAttach;
53
54
    public function __construct()
55
    {
56
        $this->size = 0;
57
        $this->comment = '';
58
        $this->path = '';
59
    }
60
61
    public function __toString(): string
62
    {
63
        return $this->getFilename();
64
    }
65
66
    public function getFilename(): string
67
    {
68
        return $this->filename;
69
    }
70
71
    public function setFilename(string $filename): self
72
    {
73
        $this->filename = $filename;
74
75
        return $this;
76
    }
77
78
    /**
79
     * Get path.
80
     *
81
     * @return string
82
     */
83
    public function getPath()
84
    {
85
        return $this->path;
86
    }
87
88
    public function setPath(string $path): self
89
    {
90
        $this->path = $path;
91
92
        return $this;
93
    }
94
95
    /**
96
     * Get comment.
97
     *
98
     * @return string
99
     */
100
    public function getComment()
101
    {
102
        return $this->comment;
103
    }
104
105
    public function setComment(string $comment): self
106
    {
107
        $this->comment = $comment;
108
109
        return $this;
110
    }
111
112
    public function getSize(): int
113
    {
114
        return $this->size;
115
    }
116
117
    public function setSize(int $size): self
118
    {
119
        $this->size = $size;
120
121
        return $this;
122
    }
123
124
    public function getMessage(): ?Message
125
    {
126
        return $this->message;
127
    }
128
129
    public function setMessage(?Message $message): static
130
    {
131
        $this->message = $message;
132
133
        return $this;
134
    }
135
136
    public function getResourceIdentifier(): int
137
    {
138
        return $this->getId();
139
    }
140
141
    /**
142
     * Get id.
143
     *
144
     * @return int
145
     */
146
    public function getId()
147
    {
148
        return $this->id;
149
    }
150
151
    public function getResourceName(): string
152
    {
153
        return $this->getFilename();
154
    }
155
156
    public function setResourceName(string $name): self
157
    {
158
        return $this->setFilename($name);
159
    }
160
161
    public function getResourceFileToAttach(): ResourceFile
162
    {
163
        return $this->resourceFileToAttach;
164
    }
165
166
    public function setResourceFileToAttach(ResourceFile $resourceFileToAttach): self
167
    {
168
        $this
169
            ->setFilename($resourceFileToAttach->getOriginalName())
170
            ->setSize($resourceFileToAttach->getSize())
171
            ->setPath($resourceFileToAttach->getTitle())
172
        ;
173
174
        $this->resourceFileToAttach = $resourceFileToAttach;
175
176
        return $this;
177
    }
178
}
179