1
|
|
|
<?php |
2
|
|
|
/* For licensing terms, see /license.txt */ |
3
|
|
|
|
4
|
|
|
namespace Chamilo\CoreBundle\Entity; |
5
|
|
|
|
6
|
|
|
use Chamilo\UserBundle\Entity\User; |
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
8
|
|
|
use Doctrine\Common\Collections\Collection; |
9
|
|
|
use Doctrine\Common\Collections\Criteria; |
10
|
|
|
use Doctrine\ORM\Mapping as ORM; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class Portfolio. |
14
|
|
|
* |
15
|
|
|
* @package Chamilo\CoreBundle\Entity |
16
|
|
|
* |
17
|
|
|
* @ORM\Table( |
18
|
|
|
* name="portfolio", |
19
|
|
|
* indexes={ |
20
|
|
|
* @ORM\Index(name="user", columns={"user_id"}), |
21
|
|
|
* @ORM\Index(name="course", columns={"c_id"}), |
22
|
|
|
* @ORM\Index(name="session", columns={"session_id"}), |
23
|
|
|
* @ORM\Index(name="category", columns={"category_id"}) |
24
|
|
|
* } |
25
|
|
|
* ) |
26
|
|
|
* Add @ to the next line if api_get_configuration_value('allow_portfolio_tool') is true |
27
|
|
|
* ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\PortfolioRepository") |
28
|
|
|
*/ |
29
|
|
|
class Portfolio |
30
|
|
|
{ |
31
|
|
|
public const TYPE_ITEM = 1; |
32
|
|
|
public const TYPE_COMMENT = 2; |
33
|
|
|
|
34
|
|
|
public const VISIBILITY_HIDDEN = 0; |
35
|
|
|
public const VISIBILITY_VISIBLE = 1; |
36
|
|
|
public const VISIBILITY_HIDDEN_EXCEPT_TEACHER = 2; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var int |
40
|
|
|
* |
41
|
|
|
* @ORM\Column(name="id", type="integer") |
42
|
|
|
* @ORM\Id |
43
|
|
|
* @ORM\GeneratedValue |
44
|
|
|
*/ |
45
|
|
|
protected $id; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
* |
50
|
|
|
* @ORM\Column(name="title", type="string", length=255) |
51
|
|
|
*/ |
52
|
|
|
protected $title; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
* @ORM\Column(name="content", type="text") |
57
|
|
|
*/ |
58
|
|
|
protected $content; |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @var User |
62
|
|
|
* |
63
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User") |
64
|
|
|
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
65
|
|
|
*/ |
66
|
|
|
protected $user; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var Course |
70
|
|
|
* |
71
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course") |
72
|
|
|
* @ORM\JoinColumn(name="c_id", referencedColumnName="id", onDelete="CASCADE") |
73
|
|
|
*/ |
74
|
|
|
protected $course = null; |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var Session |
78
|
|
|
* |
79
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") |
80
|
|
|
* @ORM\JoinColumn(name="session_id", referencedColumnName="id", onDelete="CASCADE") |
81
|
|
|
*/ |
82
|
|
|
protected $session = null; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @var \DateTime |
86
|
|
|
* |
87
|
|
|
* @ORM\Column(name="creation_date", type="datetime") |
88
|
|
|
*/ |
89
|
|
|
protected $creationDate; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var \DateTime |
93
|
|
|
* |
94
|
|
|
* @ORM\Column(name="update_date", type="datetime") |
95
|
|
|
*/ |
96
|
|
|
protected $updateDate; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @var bool |
100
|
|
|
* |
101
|
|
|
* @ORM\Column(name="visibility", type="smallint", options={"default": 1}) |
102
|
|
|
*/ |
103
|
|
|
protected $visibility = 1; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @var \Chamilo\CoreBundle\Entity\PortfolioCategory |
107
|
|
|
* |
108
|
|
|
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\PortfolioCategory", inversedBy="items") |
109
|
|
|
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="SET NULL") |
110
|
|
|
*/ |
111
|
|
|
protected $category; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @var \Doctrine\Common\Collections\ArrayCollection |
115
|
|
|
* |
116
|
|
|
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\PortfolioComment", mappedBy="item") |
117
|
|
|
*/ |
118
|
|
|
private $comments; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @var int|null |
122
|
|
|
* |
123
|
|
|
* @ORM\Column(name="origin", type="integer", nullable=true) |
124
|
|
|
*/ |
125
|
|
|
private $origin; |
126
|
|
|
/** |
127
|
|
|
* @var int|null |
128
|
|
|
* |
129
|
|
|
* @ORM\Column(name="origin_type", type="integer", nullable=true) |
130
|
|
|
*/ |
131
|
|
|
private $originType; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @var float|null |
135
|
|
|
* |
136
|
|
|
* @ORM\Column(name="score", type="float", nullable=true) |
137
|
|
|
*/ |
138
|
|
|
private $score; |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Portfolio constructor. |
142
|
|
|
*/ |
143
|
|
|
public function __construct() |
144
|
|
|
{ |
145
|
|
|
$this->category = null; |
146
|
|
|
$this->comments = new ArrayCollection(); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Set user. |
151
|
|
|
* |
152
|
|
|
* @return Portfolio |
153
|
|
|
*/ |
154
|
|
|
public function setUser(User $user) |
155
|
|
|
{ |
156
|
|
|
$this->user = $user; |
157
|
|
|
|
158
|
|
|
return $this; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* Get user. |
163
|
|
|
* |
164
|
|
|
* @return User |
165
|
|
|
*/ |
166
|
|
|
public function getUser() |
167
|
|
|
{ |
168
|
|
|
return $this->user; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Set course. |
173
|
|
|
* |
174
|
|
|
* @return Portfolio |
175
|
|
|
*/ |
176
|
|
|
public function setCourse(Course $course = null) |
177
|
|
|
{ |
178
|
|
|
$this->course = $course; |
179
|
|
|
|
180
|
|
|
return $this; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Get course. |
185
|
|
|
* |
186
|
|
|
* @return Course |
187
|
|
|
*/ |
188
|
|
|
public function getCourse() |
189
|
|
|
{ |
190
|
|
|
return $this->course; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* Get session. |
195
|
|
|
* |
196
|
|
|
* @return Session |
197
|
|
|
*/ |
198
|
|
|
public function getSession() |
199
|
|
|
{ |
200
|
|
|
return $this->session; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* Set session. |
205
|
|
|
* |
206
|
|
|
* @return Portfolio |
207
|
|
|
*/ |
208
|
|
|
public function setSession(Session $session = null) |
209
|
|
|
{ |
210
|
|
|
$this->session = $session; |
211
|
|
|
|
212
|
|
|
return $this; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Set title. |
217
|
|
|
* |
218
|
|
|
* @param string $title |
219
|
|
|
* |
220
|
|
|
* @return Portfolio |
221
|
|
|
*/ |
222
|
|
|
public function setTitle($title) |
223
|
|
|
{ |
224
|
|
|
$this->title = $title; |
225
|
|
|
|
226
|
|
|
return $this; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Get title. |
231
|
|
|
*/ |
232
|
|
|
public function getTitle(bool $stripTags = false): string |
233
|
|
|
{ |
234
|
|
|
if ($stripTags) { |
235
|
|
|
return strip_tags($this->title); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
return $this->title; |
239
|
|
|
} |
240
|
|
|
|
241
|
|
|
/** |
242
|
|
|
* Set content. |
243
|
|
|
* |
244
|
|
|
* @param string $content |
245
|
|
|
* |
246
|
|
|
* @return Portfolio |
247
|
|
|
*/ |
248
|
|
|
public function setContent($content) |
249
|
|
|
{ |
250
|
|
|
$this->content = $content; |
251
|
|
|
|
252
|
|
|
return $this; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* Get content. |
257
|
|
|
* |
258
|
|
|
* @return string |
259
|
|
|
*/ |
260
|
|
|
public function getContent() |
261
|
|
|
{ |
262
|
|
|
return $this->content; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* Set creationDate. |
267
|
|
|
* |
268
|
|
|
* @return Portfolio |
269
|
|
|
*/ |
270
|
|
|
public function setCreationDate(\DateTime $creationDate) |
271
|
|
|
{ |
272
|
|
|
$this->creationDate = $creationDate; |
273
|
|
|
|
274
|
|
|
return $this; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Get creationDate. |
279
|
|
|
* |
280
|
|
|
* @return \DateTime |
281
|
|
|
*/ |
282
|
|
|
public function getCreationDate() |
283
|
|
|
{ |
284
|
|
|
return $this->creationDate; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* Set updateDate. |
289
|
|
|
* |
290
|
|
|
* @return Portfolio |
291
|
|
|
*/ |
292
|
|
|
public function setUpdateDate(\DateTime $updateDate) |
293
|
|
|
{ |
294
|
|
|
$this->updateDate = $updateDate; |
295
|
|
|
|
296
|
|
|
return $this; |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
/** |
300
|
|
|
* Get updateDate. |
301
|
|
|
* |
302
|
|
|
* @return \DateTime |
303
|
|
|
*/ |
304
|
|
|
public function getUpdateDate() |
305
|
|
|
{ |
306
|
|
|
return $this->updateDate; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* Get id. |
311
|
|
|
* |
312
|
|
|
* @return int |
313
|
|
|
*/ |
314
|
|
|
public function getId() |
315
|
|
|
{ |
316
|
|
|
return $this->id; |
317
|
|
|
} |
318
|
|
|
|
319
|
|
|
/** |
320
|
|
|
* Set isVisible. |
321
|
|
|
*/ |
322
|
|
|
public function setVisibility(int $visibility): Portfolio |
323
|
|
|
{ |
324
|
|
|
$this->visibility = $visibility; |
|
|
|
|
325
|
|
|
|
326
|
|
|
return $this; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Get isVisible. |
331
|
|
|
*/ |
332
|
|
|
public function getVisibility(): int |
333
|
|
|
{ |
334
|
|
|
return $this->visibility; |
|
|
|
|
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Get category. |
339
|
|
|
* |
340
|
|
|
* @return PortfolioCategory |
341
|
|
|
*/ |
342
|
|
|
public function getCategory() |
343
|
|
|
{ |
344
|
|
|
return $this->category; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* Set category. |
349
|
|
|
* |
350
|
|
|
* @return Portfolio |
351
|
|
|
*/ |
352
|
|
|
public function setCategory(PortfolioCategory $category = null) |
353
|
|
|
{ |
354
|
|
|
$this->category = $category; |
355
|
|
|
|
356
|
|
|
return $this; |
357
|
|
|
} |
358
|
|
|
|
359
|
|
|
public function getComments(): Collection |
360
|
|
|
{ |
361
|
|
|
return $this->comments; |
362
|
|
|
} |
363
|
|
|
|
364
|
|
|
public function getLastComments(int $number = 3): Collection |
365
|
|
|
{ |
366
|
|
|
$criteria = Criteria::create(); |
367
|
|
|
$criteria |
368
|
|
|
->orderBy(['date' => 'DESC']) |
369
|
|
|
->setMaxResults($number); |
370
|
|
|
|
371
|
|
|
return $this->comments->matching($criteria); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
public function getOrigin(): ?int |
375
|
|
|
{ |
376
|
|
|
return $this->origin; |
377
|
|
|
} |
378
|
|
|
|
379
|
|
|
/** |
380
|
|
|
* @return \Chamilo\CoreBundle\Entity\Portfolio |
381
|
|
|
*/ |
382
|
|
|
public function setOrigin(?int $origin): Portfolio |
383
|
|
|
{ |
384
|
|
|
$this->origin = $origin; |
385
|
|
|
|
386
|
|
|
return $this; |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
public function getOriginType(): ?int |
390
|
|
|
{ |
391
|
|
|
return $this->originType; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
/** |
395
|
|
|
* @return \Chamilo\CoreBundle\Entity\Portfolio |
396
|
|
|
*/ |
397
|
|
|
public function setOriginType(?int $originType): Portfolio |
398
|
|
|
{ |
399
|
|
|
$this->originType = $originType; |
400
|
|
|
|
401
|
|
|
return $this; |
402
|
|
|
} |
403
|
|
|
|
404
|
|
|
public function getExcerpt(int $count = 380): string |
405
|
|
|
{ |
406
|
|
|
return api_get_short_text_from_html($this->content, $count); |
407
|
|
|
} |
408
|
|
|
|
409
|
|
|
public function getScore(): ?float |
410
|
|
|
{ |
411
|
|
|
return $this->score; |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
public function setScore(?float $score): void |
415
|
|
|
{ |
416
|
|
|
$this->score = $score; |
417
|
|
|
} |
418
|
|
|
} |
419
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.