Passed
Pull Request — 1.11.x (#4368)
by Angel Fernando Quiroz
08:07
created

Portfolio::setTitle()   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
/* 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
     * @var bool
149
     *
150
     * @ORM\Column(name="is_template", type="boolean", options={"default": false})
151
     */
152
    private $isTemplate = false;
153
154
    /**
155
     * Portfolio constructor.
156
     */
157
    public function __construct()
158
    {
159
        $this->category = null;
160
        $this->comments = new ArrayCollection();
161
    }
162
163
    /**
164
     * Set user.
165
     *
166
     * @return Portfolio
167
     */
168
    public function setUser(User $user)
169
    {
170
        $this->user = $user;
171
172
        return $this;
173
    }
174
175
    /**
176
     * Get user.
177
     *
178
     * @return User
179
     */
180
    public function getUser()
181
    {
182
        return $this->user;
183
    }
184
185
    /**
186
     * Set course.
187
     *
188
     * @return Portfolio
189
     */
190
    public function setCourse(Course $course = null)
191
    {
192
        $this->course = $course;
193
194
        return $this;
195
    }
196
197
    /**
198
     * Get course.
199
     *
200
     * @return Course
201
     */
202
    public function getCourse()
203
    {
204
        return $this->course;
205
    }
206
207
    /**
208
     * Get session.
209
     *
210
     * @return Session
211
     */
212
    public function getSession()
213
    {
214
        return $this->session;
215
    }
216
217
    /**
218
     * Set session.
219
     *
220
     * @return Portfolio
221
     */
222
    public function setSession(Session $session = null)
223
    {
224
        $this->session = $session;
225
226
        return $this;
227
    }
228
229
    /**
230
     * Set title.
231
     *
232
     * @param string $title
233
     *
234
     * @return Portfolio
235
     */
236
    public function setTitle($title)
237
    {
238
        $this->title = $title;
239
240
        return $this;
241
    }
242
243
    /**
244
     * Get title.
245
     */
246
    public function getTitle(bool $stripTags = false): string
247
    {
248
        if ($stripTags) {
249
            return strip_tags($this->title);
250
        }
251
252
        return $this->title;
253
    }
254
255
    /**
256
     * Set content.
257
     *
258
     * @param string $content
259
     *
260
     * @return Portfolio
261
     */
262
    public function setContent($content)
263
    {
264
        $this->content = $content;
265
266
        return $this;
267
    }
268
269
    /**
270
     * Get content.
271
     *
272
     * @return string
273
     */
274
    public function getContent()
275
    {
276
        return $this->content;
277
    }
278
279
    /**
280
     * Set creationDate.
281
     *
282
     * @return Portfolio
283
     */
284
    public function setCreationDate(\DateTime $creationDate)
285
    {
286
        $this->creationDate = $creationDate;
287
288
        return $this;
289
    }
290
291
    /**
292
     * Get creationDate.
293
     *
294
     * @return \DateTime
295
     */
296
    public function getCreationDate()
297
    {
298
        return $this->creationDate;
299
    }
300
301
    /**
302
     * Set updateDate.
303
     *
304
     * @return Portfolio
305
     */
306
    public function setUpdateDate(\DateTime $updateDate)
307
    {
308
        $this->updateDate = $updateDate;
309
310
        return $this;
311
    }
312
313
    /**
314
     * Get updateDate.
315
     *
316
     * @return \DateTime
317
     */
318
    public function getUpdateDate()
319
    {
320
        return $this->updateDate;
321
    }
322
323
    /**
324
     * Get id.
325
     *
326
     * @return int
327
     */
328
    public function getId()
329
    {
330
        return $this->id;
331
    }
332
333
    /**
334
     * Set isVisible.
335
     */
336
    public function setVisibility(int $visibility): Portfolio
337
    {
338
        $this->visibility = $visibility;
0 ignored issues
show
Documentation Bug introduced by
The property $visibility was declared of type boolean, but $visibility is of type integer. Maybe add a type cast?

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.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
339
340
        return $this;
341
    }
342
343
    /**
344
     * Get isVisible.
345
     */
346
    public function getVisibility(): int
347
    {
348
        return $this->visibility;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->visibility returns the type boolean which is incompatible with the type-hinted return integer.
Loading history...
349
    }
350
351
    /**
352
     * Get category.
353
     *
354
     * @return PortfolioCategory
355
     */
356
    public function getCategory()
357
    {
358
        return $this->category;
359
    }
360
361
    /**
362
     * Set category.
363
     *
364
     * @return Portfolio
365
     */
366
    public function setCategory(PortfolioCategory $category = null)
367
    {
368
        $this->category = $category;
369
370
        return $this;
371
    }
372
373
    public function getComments(): Collection
374
    {
375
        return $this->comments;
376
    }
377
378
    public function getLastComments(int $number = 3): Collection
379
    {
380
        $criteria = Criteria::create();
381
        $criteria
382
            ->orderBy(['date' => 'DESC'])
383
            ->setMaxResults($number);
384
385
        return $this->comments->matching($criteria);
386
    }
387
388
    public function getOrigin(): ?int
389
    {
390
        return $this->origin;
391
    }
392
393
    /**
394
     * @return \Chamilo\CoreBundle\Entity\Portfolio
395
     */
396
    public function setOrigin(?int $origin): Portfolio
397
    {
398
        $this->origin = $origin;
399
400
        return $this;
401
    }
402
403
    public function getOriginType(): ?int
404
    {
405
        return $this->originType;
406
    }
407
408
    /**
409
     * @return \Chamilo\CoreBundle\Entity\Portfolio
410
     */
411
    public function setOriginType(?int $originType): Portfolio
412
    {
413
        $this->originType = $originType;
414
415
        return $this;
416
    }
417
418
    public function getExcerpt(int $count = 380): string
419
    {
420
        return api_get_short_text_from_html($this->content, $count);
421
    }
422
423
    public function getScore(): ?float
424
    {
425
        return $this->score;
426
    }
427
428
    public function setScore(?float $score): void
429
    {
430
        $this->score = $score;
431
    }
432
433
    public function isHighlighted(): bool
434
    {
435
        return $this->isHighlighted;
436
    }
437
438
    public function setIsHighlighted(bool $isHighlighted): Portfolio
439
    {
440
        $this->isHighlighted = $isHighlighted;
441
442
        return $this;
443
    }
444
445
    public function isTemplate(): bool
446
    {
447
        return $this->isTemplate;
448
    }
449
450
    public function setIsTemplate(bool $isTemplate): Portfolio
451
    {
452
        $this->isTemplate = $isTemplate;
453
454
        return $this;
455
    }
456
}
457