|
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 DateTime; |
|
10
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
11
|
|
|
use Doctrine\Common\Collections\Collection; |
|
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
13
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
14
|
|
|
use Symfony\Component\Uid\Uuid; |
|
15
|
|
|
|
|
16
|
|
|
#[ORM\Entity] |
|
17
|
|
|
#[ORM\Table(name: 'portfolio_comment')] |
|
18
|
|
|
#[Gedmo\Tree(type: 'nested')] |
|
19
|
|
|
class PortfolioComment extends AbstractResource implements ResourceInterface, \Stringable |
|
20
|
|
|
{ |
|
21
|
|
|
public const VISIBILITY_VISIBLE = 1; |
|
22
|
|
|
public const VISIBILITY_PER_USER = 2; |
|
23
|
|
|
|
|
24
|
|
|
#[ORM\Column(type: 'smallint', options: ['default' => self::VISIBILITY_VISIBLE])] |
|
25
|
|
|
protected int $visibility; |
|
26
|
|
|
|
|
27
|
|
|
#[ORM\Id] |
|
28
|
|
|
#[ORM\GeneratedValue] |
|
29
|
|
|
#[ORM\Column(type: 'integer')] |
|
30
|
|
|
private int $id; |
|
31
|
|
|
|
|
32
|
|
|
#[ORM\ManyToOne(targetEntity: User::class)] |
|
33
|
|
|
#[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] |
|
34
|
|
|
private User $author; |
|
35
|
|
|
|
|
36
|
|
|
#[ORM\ManyToOne(targetEntity: Portfolio::class, inversedBy: 'comments')] |
|
37
|
|
|
#[ORM\JoinColumn(name: 'item_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')] |
|
38
|
|
|
private Portfolio $item; |
|
39
|
|
|
|
|
40
|
|
|
#[ORM\Column(type: 'text')] |
|
41
|
|
|
private string $content; |
|
42
|
|
|
|
|
43
|
|
|
#[ORM\Column(type: 'datetime')] |
|
44
|
|
|
private DateTime $date; |
|
45
|
|
|
|
|
46
|
|
|
#[ORM\Column(type: 'boolean', options: ['default' => false])] |
|
47
|
|
|
private bool $isImportant; |
|
48
|
|
|
|
|
49
|
|
|
#[Gedmo\TreeLeft] |
|
50
|
|
|
#[ORM\Column(type: 'integer')] |
|
51
|
|
|
private int $lft; |
|
|
|
|
|
|
52
|
|
|
|
|
53
|
|
|
#[Gedmo\TreeLevel] |
|
54
|
|
|
#[ORM\Column(type: 'integer')] |
|
55
|
|
|
private int $lvl; |
|
56
|
|
|
|
|
57
|
|
|
#[Gedmo\TreeRight] |
|
58
|
|
|
#[ORM\Column(type: 'integer')] |
|
59
|
|
|
private int $rgt; |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
#[Gedmo\TreeRoot] |
|
62
|
|
|
#[ORM\ManyToOne(targetEntity: self::class)] |
|
63
|
|
|
#[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
64
|
|
|
private ?PortfolioComment $root; |
|
65
|
|
|
|
|
66
|
|
|
#[Gedmo\TreeParent] |
|
67
|
|
|
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
|
68
|
|
|
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
|
69
|
|
|
private ?PortfolioComment $commentParent; |
|
70
|
|
|
|
|
71
|
|
|
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] |
|
72
|
|
|
#[ORM\OrderBy(['lft' => 'DESC'])] |
|
73
|
|
|
private Collection $children; |
|
74
|
|
|
|
|
75
|
|
|
#[ORM\Column(type: 'float', nullable: true)] |
|
76
|
|
|
private ?float $score; |
|
77
|
|
|
|
|
78
|
|
|
#[ORM\Column(type: 'boolean', options: ['default' => false])] |
|
79
|
|
|
private bool $isTemplate = false; |
|
80
|
|
|
|
|
81
|
|
|
public function __construct() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->isImportant = false; |
|
84
|
|
|
$this->children = new ArrayCollection(); |
|
85
|
|
|
$this->visibility = self::VISIBILITY_VISIBLE; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function getId(): int |
|
89
|
|
|
{ |
|
90
|
|
|
return $this->id; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function getAuthor(): User |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->author; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function setAuthor(User $author): self |
|
99
|
|
|
{ |
|
100
|
|
|
$this->author = $author; |
|
101
|
|
|
|
|
102
|
|
|
return $this; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
public function getItem(): Portfolio |
|
106
|
|
|
{ |
|
107
|
|
|
return $this->item; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
public function setItem(Portfolio $item): self |
|
111
|
|
|
{ |
|
112
|
|
|
$this->item = $item; |
|
113
|
|
|
|
|
114
|
|
|
return $this; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function getContent(): string |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->content; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function setContent(string $content): self |
|
123
|
|
|
{ |
|
124
|
|
|
$this->content = $content; |
|
125
|
|
|
|
|
126
|
|
|
return $this; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function getDate(): DateTime |
|
130
|
|
|
{ |
|
131
|
|
|
return $this->date; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
public function setDate(DateTime $date): self |
|
135
|
|
|
{ |
|
136
|
|
|
$this->date = $date; |
|
137
|
|
|
|
|
138
|
|
|
return $this; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getCommentParent(): ?PortfolioComment |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->commentParent; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function setCommentParent(PortfolioComment $parent): static |
|
147
|
|
|
{ |
|
148
|
|
|
$this->commentParent = $parent; |
|
149
|
|
|
|
|
150
|
|
|
return $this; |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
public function getChildren(): Collection |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->children; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function setChildren(ArrayCollection $children): self |
|
159
|
|
|
{ |
|
160
|
|
|
$this->children = $children; |
|
161
|
|
|
|
|
162
|
|
|
return $this; |
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
public function isImportant(): bool |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->isImportant; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
public function setIsImportant(bool $isImportant): void |
|
171
|
|
|
{ |
|
172
|
|
|
$this->isImportant = $isImportant; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function getExcerpt(int $count = 190): string |
|
176
|
|
|
{ |
|
177
|
|
|
return api_get_short_text_from_html($this->content, $count); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
public function getScore(): ?float |
|
181
|
|
|
{ |
|
182
|
|
|
return $this->score; |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function setScore(?float $score): void |
|
186
|
|
|
{ |
|
187
|
|
|
$this->score = $score; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
public function getRoot(): self |
|
191
|
|
|
{ |
|
192
|
|
|
return $this->root; |
|
|
|
|
|
|
193
|
|
|
} |
|
194
|
|
|
|
|
195
|
|
|
public function getLvl(): int |
|
196
|
|
|
{ |
|
197
|
|
|
return $this->lvl; |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
public function isTemplate(): bool |
|
201
|
|
|
{ |
|
202
|
|
|
return $this->isTemplate; |
|
203
|
|
|
} |
|
204
|
|
|
|
|
205
|
|
|
public function setIsTemplate(bool $isTemplate): self |
|
206
|
|
|
{ |
|
207
|
|
|
$this->isTemplate = $isTemplate; |
|
208
|
|
|
|
|
209
|
|
|
return $this; |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
public function getVisibility(): int |
|
213
|
|
|
{ |
|
214
|
|
|
return $this->visibility; |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function setVisibility(int $visibility): self |
|
218
|
|
|
{ |
|
219
|
|
|
$this->visibility = $visibility; |
|
220
|
|
|
|
|
221
|
|
|
return $this; |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
public function getResourceName(): string |
|
225
|
|
|
{ |
|
226
|
|
|
return $this->getContent(); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
public function setResourceName(string $name): static |
|
230
|
|
|
{ |
|
231
|
|
|
return $this->setContent($name); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
public function __toString(): string |
|
235
|
|
|
{ |
|
236
|
|
|
return $this->getContent(); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
public function getResourceIdentifier(): int|Uuid |
|
240
|
|
|
{ |
|
241
|
|
|
return $this->getId(); |
|
242
|
|
|
} |
|
243
|
|
|
} |
|
244
|
|
|
|