Passed
Push — portfolio ( 1f492e )
by Angel Fernando Quiroz
11:49
created

Portfolio::getExcerpt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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