Completed
Push — master ( ee3fd0...6da8b5 )
by Julito
22:54
created

SkillRelUser::getArgumentation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
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\SkillBundle\Entity\Level;
7
use Doctrine\Common\Collections\Criteria;
8
use Doctrine\ORM\Mapping as ORM;
9
use Chamilo\UserBundle\Entity\User;
10
use Doctrine\Common\Collections\ArrayCollection;
11
12
/**
13
 * SkillRelUser
14
 *
15
 * @ORM\Table(
16
 *  name="skill_rel_user",
17
 *  indexes={
18
 *      @ORM\Index(name="idx_select_cs", columns={"course_id", "session_id"}),
19
 *      @ORM\Index(name="idx_select_s_c_u", columns={"session_id", "course_id", "user_id"}),
20
 *      @ORM\Index(name="idx_select_sk_u", columns={"skill_id", "user_id"})
21
 *  }
22
 * )
23
 * @ORM\Entity
24
 */
25
class SkillRelUser
26
{
27
    /**
28
     * @var integer
29
     *
30
     * @ORM\Column(name="id", type="integer")
31
     * @ORM\Id
32
     * @ORM\GeneratedValue
33
     */
34
    private $id;
35
36
    /**
37
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="achievedSkills", cascade={"persist"})
38
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
39
     */
40
    private $user;
41
42
    /**
43
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Skill", inversedBy="issuedSkills", cascade={"persist"})
44
     * @ORM\JoinColumn(name="skill_id", referencedColumnName="id", nullable=false)
45
     */
46
    private $skill;
47
48
    /**
49
     * @var \DateTime
50
     *
51
     * @ORM\Column(name="acquired_skill_at", type="datetime", nullable=false)
52
     */
53
    private $acquiredSkillAt;
54
55
    /**
56
     * @var integer
57
     *
58
     * @ORM\Column(name="assigned_by", type="integer", nullable=false)
59
     */
60
    private $assignedBy;
61
62
    /**
63
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="issuedSkills", cascade={"persist"})
64
     * @ORM\JoinColumn(name="course_id", referencedColumnName="id", nullable=true)
65
     */
66
    private $course;
67
68
    /**
69
     * @var Session
70
     *
71
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="issuedSkills", cascade={"persist"})
72
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true)
73
     */
74
    private $session;
75
76
    /**
77
     * @var Level
78
     *
79
     * @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Level")
80
     * @ORM\JoinColumn(name="acquired_level", referencedColumnName="id")
81
     */
82
    private $acquiredLevel;
83
84
    /**
85
     * @var string
86
     *
87
     * @ORM\Column(name="argumentation", type="text")
88
     */
89
    private $argumentation;
90
91
    /**
92
     * @var integer
93
     *
94
     * @ORM\Column(name="argumentation_author_id", type="integer")
95
     */
96
    private $argumentationAuthorId;
97
98
    /**
99
     * @ORM\OneToMany(targetEntity="SkillRelUserComment", mappedBy="skillRelUser")
100
     */
101
    protected $comments;
102
103
    /**
104
     * Whether this has been confirmed by a teacher or not
105
     * Only set to 0 when the skill_rel_item says requires_validation = 1
106
     * @var integer
107
     *
108
     * // uncomment if api_get_configuration_value('allow_skill_rel_items')
109
     * @ORM\Column(name="validation_status", type="integer")
110
     */
111
    protected $validationStatus;
112
113
    /**
114
     * SkillRelUser constructor.
115
     */
116
    public function __construct()
117
    {
118
        $this->comments = new ArrayCollection();
119
    }
120
121
    /**
122
     * Set user
123
     * @param User $user
124
     * @return SkillRelUser
125
     */
126
    public function setUser(User $user)
127
    {
128
        $this->user = $user;
129
130
        return $this;
131
    }
132
133
    /**
134
     * Get user
135
     * @return User
136
     */
137
    public function getUser()
138
    {
139
        return $this->user;
140
    }
141
142
    /**
143
     * Set skill
144
     * @param Skill $skill
145
     * @return SkillRelUser
146
     */
147
    public function setSkill(Skill $skill)
148
    {
149
        $this->skill = $skill;
150
151
        return $this;
152
    }
153
154
    /**
155
     * Get skill
156
     * @return Skill
157
     */
158
    public function getSkill()
159
    {
160
        return $this->skill;
161
    }
162
163
    /**
164
     * Set course
165
     * @param Course $course
166
     * @return SkillRelUser
167
     */
168
    public function setCourse(Course $course)
169
    {
170
        $this->course = $course;
171
172
        return $this;
173
    }
174
175
    /**
176
     * Get course
177
     * @return Course
178
     */
179
    public function getCourse()
180
    {
181
        return $this->course;
182
    }
183
184
    /**
185
     * Set session
186
     * @param Session $session
187
     * @return SkillRelUser
188
     */
189
    public function setSession(Session $session)
190
    {
191
        $this->session = $session;
192
193
        return $this;
194
    }
195
196
    /**
197
     * Get session
198
     * @return Session
199
     */
200
    public function getSession()
201
    {
202
        return $this->session;
203
    }
204
205
206
    /**
207
     * Set acquiredSkillAt
208
     *
209
     * @param \DateTime $acquiredSkillAt
210
     * @return SkillRelUser
211
     */
212
    public function setAcquiredSkillAt($acquiredSkillAt)
213
    {
214
        $this->acquiredSkillAt = $acquiredSkillAt;
215
216
        return $this;
217
    }
218
219
    /**
220
     * Get acquiredSkillAt
221
     *
222
     * @return \DateTime
223
     */
224
    public function getAcquiredSkillAt()
225
    {
226
        return $this->acquiredSkillAt;
227
    }
228
229
    /**
230
     * Set assignedBy
231
     *
232
     * @param integer $assignedBy
233
     * @return SkillRelUser
234
     */
235
    public function setAssignedBy($assignedBy)
236
    {
237
        $this->assignedBy = $assignedBy;
238
239
        return $this;
240
    }
241
242
    /**
243
     * Get assignedBy
244
     *
245
     * @return integer
246
     */
247
    public function getAssignedBy()
248
    {
249
        return $this->assignedBy;
250
    }
251
252
    /**
253
     * Get id
254
     *
255
     * @return integer
256
     */
257
    public function getId()
258
    {
259
        return $this->id;
260
    }
261
262
    /**
263
     * Set acquiredLevel
264
     * @param Level $acquiredLevel
265
     *
266
     * @return SkillRelUser
267
     */
268
    public function setAcquiredLevel($acquiredLevel)
269
    {
270
        $this->acquiredLevel = $acquiredLevel;
271
272
        return $this;
273
    }
274
275
    /**
276
     * Get acquiredLevel
277
     * @return Level
278
     */
279
    public function getAcquiredLevel()
280
    {
281
        return $this->acquiredLevel;
282
    }
283
284
    /**
285
     * Set argumentationAuthorId
286
     * @param int $argumentationAuthorId
287
     * @return SkillRelUser
288
     */
289
    public function setArgumentationAuthorId($argumentationAuthorId)
290
    {
291
        $this->argumentationAuthorId = $argumentationAuthorId;
292
293
        return $this;
294
    }
295
296
    /**
297
     * Get argumentationAuthorId
298
     * @return integer
299
     */
300
    public function getArgumentationAuthorId()
301
    {
302
        return $this->argumentationAuthorId;
303
    }
304
305
    /**
306
     * Set argumentation
307
     * @param string $argumentation
308
     *
309
     * @return SkillRelUser
310
     */
311
    public function setArgumentation($argumentation)
312
    {
313
        $this->argumentation = $argumentation;
314
315
        return $this;
316
    }
317
318
    /**
319
     * Get argumentation
320
     * @return string
321
     */
322
    public function getArgumentation()
323
    {
324
        return $this->argumentation;
325
    }
326
327
    /**
328
     * Get the source which the skill was obtained
329
     * @return string
330
     */
331
    public function getSourceName()
332
    {
333
        $source = '';
334
335
        if ($this->session && $this->session->getId() != 0) {
336
            $source .= "[{$this->session->getName()}] ";
337
        }
338
339
        if ($this->course) {
340
            $source .= $this->course->getTitle();
341
        }
342
343
        return $source;
344
    }
345
346
    /**
347
     * Get the URL for the issue
348
     * @return string
349
     */
350
    public function getIssueUrl()
351
    {
352
        return api_get_path(WEB_PATH)."badge/{$this->id}";
353
    }
354
355
    /**
356
     * Get the URL for the All issues page
357
     * @return string
358
     */
359
    public function getIssueUrlAll()
360
    {
361
        return api_get_path(WEB_PATH)."skill/{$this->skill->getId()}/user/{$this->user->getId()}";
362
    }
363
364
    /**
365
     * Get the URL for the assertion
366
     * @return string
367
     */
368
    public function getAssertionUrl()
369
    {
370
        $url = api_get_path(WEB_CODE_PATH)."badge/assertion.php?";
371
372
        $url .= http_build_query([
373
            'user' => $this->user->getId(),
374
            'skill' => $this->skill->getId(),
375
            'course' => $this->course ? $this->course->getId() : 0,
376
            'session' => $this->session ? $this->session->getId() : 0
377
        ]);
378
379
        return $url;
380
    }
381
382
    /**
383
     * Get comments
384
     * @param boolean $sortDescByDateTime
385
     * @return ArrayCollection
386
     */
387
    public function getComments($sortDescByDateTime = false)
388
    {
389
        if ($sortDescByDateTime) {
390
            $criteria = Criteria::create();
391
            $criteria->orderBy([
392
                'feedbackDateTime' => Criteria::DESC
393
            ]);
394
395
            return $this->comments->matching($criteria);
396
        }
397
398
        return $this->comments;
399
    }
400
401
    /**
402
     * Calculate the average value from the feedback comments
403
     * @return string
404
     */
405
    public function getAverage()
406
    {
407
        $sum = 0;
408
        $countValues = 0;
409
410
        foreach ($this->comments as $comment) {
411
            if (!$comment->getFeedbackValue()) {
412
                continue;
413
            }
414
415
            $sum += $comment->getFeedbackValue();
416
            $countValues++;
417
        }
418
419
        $average = $countValues > 0 ? $sum / $countValues : 0;
420
421
        return number_format($average, 2);
422
    }
423
424
    /**
425
     * @return int
426
     */
427
    public function getValidationStatus()
428
    {
429
        return $this->validationStatus;
430
    }
431
432
    /**
433
     * @param int $validationStatus
434
     * @return SkillRelUser
435
     */
436
    public function setValidationStatus($validationStatus)
437
    {
438
        $this->validationStatus = $validationStatus;
439
        return $this;
440
    }
441
}
442