Passed
Push — master ( 5a0940...f02335 )
by Julito
12:50 queued 02:57
created

CStudentPublicationComment::setComment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
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\CourseBundle\Entity;
8
9
use Chamilo\CoreBundle\Entity\AbstractResource;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\User;
12
use Cocur\Slugify\Slugify;
13
use DateTime;
14
use Doctrine\ORM\Mapping as ORM;
15
16
/**
17
 * CStudentPublicationComment.
18
 *
19
 * @ORM\Table(
20
 *  name="c_student_publication_comment",
21
 *  indexes={
22
 *  }
23
 * )
24
 * @ORM\Entity
25
 */
26
class CStudentPublicationComment extends AbstractResource implements ResourceInterface
27
{
28
    /**
29
     * @ORM\Column(name="iid", type="integer")
30
     * @ORM\Id
31
     * @ORM\GeneratedValue
32
     */
33
    protected int $iid;
34
35
    /**
36
     * @ORM\ManyToOne(targetEntity="CStudentPublication", inversedBy="comments")
37
     * @ORM\JoinColumn(name="work_id", referencedColumnName="iid", onDelete="CASCADE")
38
     */
39
    protected CStudentPublication $publication;
40
41
    /**
42
     * @ORM\Column(name="comment", type="text", nullable=true)
43
     */
44
    protected ?string $comment;
45
46
    /**
47
     * @ORM\Column(name="file", type="string", length=255, nullable=true)
48
     */
49
    protected ?string $file;
50
51
    /**
52
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
53
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")
54
     */
55
    protected User $user;
56
57
    /**
58
     * @ORM\Column(name="sent_at", type="datetime", nullable=false)
59
     */
60
    protected DateTime $sentAt;
61
62
    public function __construct()
63
    {
64
        $this->sentAt = new DateTime();
65
    }
66
67
    public function __toString(): string
68
    {
69
        return (string) $this->getIid();
70
    }
71
72
    public function getIid(): int
73
    {
74
        return $this->iid;
75
    }
76
77
    /**
78
     * Set comment.
79
     *
80
     * @param string $comment
81
     */
82
    public function setComment($comment): self
83
    {
84
        $this->comment = $comment;
85
86
        return $this;
87
    }
88
89
    /**
90
     * Get comment.
91
     *
92
     * @return string
93
     */
94
    public function getComment()
95
    {
96
        return $this->comment;
97
    }
98
99
    /**
100
     * Set file.
101
     *
102
     * @param string $file
103
     */
104
    public function setFile($file): self
105
    {
106
        $this->file = $file;
107
108
        return $this;
109
    }
110
111
    /**
112
     * Get file.
113
     *
114
     * @return string
115
     */
116
    public function getFile()
117
    {
118
        return $this->file;
119
    }
120
121
    public function getUser(): User
122
    {
123
        return $this->user;
124
    }
125
126
    public function setUser(User $user): self
127
    {
128
        $this->user = $user;
129
130
        return $this;
131
    }
132
133
    /**
134
     * Set sentAt.
135
     *
136
     * @param DateTime $sentAt
137
     */
138
    public function setSentAt($sentAt): self
139
    {
140
        $this->sentAt = $sentAt;
141
142
        return $this;
143
    }
144
145
    /**
146
     * Get sentAt.
147
     *
148
     * @return DateTime
149
     */
150
    public function getSentAt()
151
    {
152
        return $this->sentAt;
153
    }
154
155
    public function getPublication(): CStudentPublication
156
    {
157
        return $this->publication;
158
    }
159
160
    public function setPublication(CStudentPublication $publication): self
161
    {
162
        $this->publication = $publication;
163
164
        return $this;
165
    }
166
167
    public function getResourceIdentifier(): int
168
    {
169
        return $this->getIid();
170
    }
171
172
    public function getResourceName(): string
173
    {
174
        $text = strip_tags($this->getComment());
175
        $slugify = new Slugify();
176
        $text = $slugify->slugify($text);
177
178
        return (string) substr($text, 0, 40);
179
    }
180
181
    public function setResourceName(string $name): self
182
    {
183
        return $this->setComment($name);
184
    }
185
}
186