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
|
|
|
* @var bool |
142
|
|
|
* |
143
|
|
|
* @ORM\Column(name="is_highlighted", type="boolean", options={"default": false}) |
144
|
|
|
*/ |
145
|
|
|
private $isHighlighted = false; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Portfolio constructor. |
149
|
|
|
*/ |
150
|
|
|
public function __construct() |
151
|
|
|
{ |
152
|
|
|
$this->category = null; |
153
|
|
|
$this->comments = new ArrayCollection(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Set user. |
158
|
|
|
* |
159
|
|
|
* @return Portfolio |
160
|
|
|
*/ |
161
|
|
|
public function setUser(User $user) |
162
|
|
|
{ |
163
|
|
|
$this->user = $user; |
164
|
|
|
|
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get user. |
170
|
|
|
* |
171
|
|
|
* @return User |
172
|
|
|
*/ |
173
|
|
|
public function getUser() |
174
|
|
|
{ |
175
|
|
|
return $this->user; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Set course. |
180
|
|
|
* |
181
|
|
|
* @return Portfolio |
182
|
|
|
*/ |
183
|
|
|
public function setCourse(Course $course = null) |
184
|
|
|
{ |
185
|
|
|
$this->course = $course; |
186
|
|
|
|
187
|
|
|
return $this; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Get course. |
192
|
|
|
* |
193
|
|
|
* @return Course |
194
|
|
|
*/ |
195
|
|
|
public function getCourse() |
196
|
|
|
{ |
197
|
|
|
return $this->course; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Get session. |
202
|
|
|
* |
203
|
|
|
* @return Session |
204
|
|
|
*/ |
205
|
|
|
public function getSession() |
206
|
|
|
{ |
207
|
|
|
return $this->session; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Set session. |
212
|
|
|
* |
213
|
|
|
* @return Portfolio |
214
|
|
|
*/ |
215
|
|
|
public function setSession(Session $session = null) |
216
|
|
|
{ |
217
|
|
|
$this->session = $session; |
218
|
|
|
|
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Set title. |
224
|
|
|
* |
225
|
|
|
* @param string $title |
226
|
|
|
* |
227
|
|
|
* @return Portfolio |
228
|
|
|
*/ |
229
|
|
|
public function setTitle($title) |
230
|
|
|
{ |
231
|
|
|
$this->title = $title; |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Get title. |
238
|
|
|
*/ |
239
|
|
|
public function getTitle(bool $stripTags = false): string |
240
|
|
|
{ |
241
|
|
|
if ($stripTags) { |
242
|
|
|
return strip_tags($this->title); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
return $this->title; |
246
|
|
|
} |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Set content. |
250
|
|
|
* |
251
|
|
|
* @param string $content |
252
|
|
|
* |
253
|
|
|
* @return Portfolio |
254
|
|
|
*/ |
255
|
|
|
public function setContent($content) |
256
|
|
|
{ |
257
|
|
|
$this->content = $content; |
258
|
|
|
|
259
|
|
|
return $this; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
/** |
263
|
|
|
* Get content. |
264
|
|
|
* |
265
|
|
|
* @return string |
266
|
|
|
*/ |
267
|
|
|
public function getContent() |
268
|
|
|
{ |
269
|
|
|
return $this->content; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Set creationDate. |
274
|
|
|
* |
275
|
|
|
* @return Portfolio |
276
|
|
|
*/ |
277
|
|
|
public function setCreationDate(\DateTime $creationDate) |
278
|
|
|
{ |
279
|
|
|
$this->creationDate = $creationDate; |
280
|
|
|
|
281
|
|
|
return $this; |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
/** |
285
|
|
|
* Get creationDate. |
286
|
|
|
* |
287
|
|
|
* @return \DateTime |
288
|
|
|
*/ |
289
|
|
|
public function getCreationDate() |
290
|
|
|
{ |
291
|
|
|
return $this->creationDate; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Set updateDate. |
296
|
|
|
* |
297
|
|
|
* @return Portfolio |
298
|
|
|
*/ |
299
|
|
|
public function setUpdateDate(\DateTime $updateDate) |
300
|
|
|
{ |
301
|
|
|
$this->updateDate = $updateDate; |
302
|
|
|
|
303
|
|
|
return $this; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* Get updateDate. |
308
|
|
|
* |
309
|
|
|
* @return \DateTime |
310
|
|
|
*/ |
311
|
|
|
public function getUpdateDate() |
312
|
|
|
{ |
313
|
|
|
return $this->updateDate; |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
/** |
317
|
|
|
* Get id. |
318
|
|
|
* |
319
|
|
|
* @return int |
320
|
|
|
*/ |
321
|
|
|
public function getId() |
322
|
|
|
{ |
323
|
|
|
return $this->id; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
/** |
327
|
|
|
* Set isVisible. |
328
|
|
|
*/ |
329
|
|
|
public function setVisibility(int $visibility): Portfolio |
330
|
|
|
{ |
331
|
|
|
$this->visibility = $visibility; |
|
|
|
|
332
|
|
|
|
333
|
|
|
return $this; |
334
|
|
|
} |
335
|
|
|
|
336
|
|
|
/** |
337
|
|
|
* Get isVisible. |
338
|
|
|
*/ |
339
|
|
|
public function getVisibility(): int |
340
|
|
|
{ |
341
|
|
|
return $this->visibility; |
|
|
|
|
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Get category. |
346
|
|
|
* |
347
|
|
|
* @return PortfolioCategory |
348
|
|
|
*/ |
349
|
|
|
public function getCategory() |
350
|
|
|
{ |
351
|
|
|
return $this->category; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Set category. |
356
|
|
|
* |
357
|
|
|
* @return Portfolio |
358
|
|
|
*/ |
359
|
|
|
public function setCategory(PortfolioCategory $category = null) |
360
|
|
|
{ |
361
|
|
|
$this->category = $category; |
362
|
|
|
|
363
|
|
|
return $this; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
public function getComments(): Collection |
367
|
|
|
{ |
368
|
|
|
return $this->comments; |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
public function getLastComments(int $number = 3): Collection |
372
|
|
|
{ |
373
|
|
|
$criteria = Criteria::create(); |
374
|
|
|
$criteria |
375
|
|
|
->orderBy(['date' => 'DESC']) |
376
|
|
|
->setMaxResults($number); |
377
|
|
|
|
378
|
|
|
return $this->comments->matching($criteria); |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
public function getOrigin(): ?int |
382
|
|
|
{ |
383
|
|
|
return $this->origin; |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @return \Chamilo\CoreBundle\Entity\Portfolio |
388
|
|
|
*/ |
389
|
|
|
public function setOrigin(?int $origin): Portfolio |
390
|
|
|
{ |
391
|
|
|
$this->origin = $origin; |
392
|
|
|
|
393
|
|
|
return $this; |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
public function getOriginType(): ?int |
397
|
|
|
{ |
398
|
|
|
return $this->originType; |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* @return \Chamilo\CoreBundle\Entity\Portfolio |
403
|
|
|
*/ |
404
|
|
|
public function setOriginType(?int $originType): Portfolio |
405
|
|
|
{ |
406
|
|
|
$this->originType = $originType; |
407
|
|
|
|
408
|
|
|
return $this; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
public function getExcerpt(int $count = 380): string |
412
|
|
|
{ |
413
|
|
|
return api_get_short_text_from_html($this->content, $count); |
414
|
|
|
} |
415
|
|
|
|
416
|
|
|
public function getScore(): ?float |
417
|
|
|
{ |
418
|
|
|
return $this->score; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
public function setScore(?float $score): void |
422
|
|
|
{ |
423
|
|
|
$this->score = $score; |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
public function isHighlighted(): bool |
427
|
|
|
{ |
428
|
|
|
return $this->isHighlighted; |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
public function setIsHighlighted(bool $isHighlighted): Portfolio |
432
|
|
|
{ |
433
|
|
|
$this->isHighlighted = $isHighlighted; |
434
|
|
|
|
435
|
|
|
return $this; |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
|
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.