Completed
Pull Request — 1.11.x (#1163)
by José
71:40 queued 25:11
created

SkillRelUser::setSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
/**
6
 * SkillRelUser Entity
7
 *
8
 * @package chamilo.skill
9
 */
10
11
namespace Chamilo\CoreBundle\Entity;
12
13
use Doctrine\ORM\Mapping as ORM;
14
15
/**
16
 * SkillRelUser
17
 *
18
 * @ORM\Table(
19
 *  name="skill_rel_user",
20
 *  indexes={
21
 *      @ORM\Index(name="idx_select_cs", columns={"course_id", "session_id"}),
22
 *      @ORM\Index(name="idx_select_s_c_u", columns={"session_id", "course_id", "user_id"}),
23
 *      @ORM\Index(name="idx_select_sk_u", columns={"skill_id", "user_id"})
24
 *  }
25
 * )
26
 * @ORM\Entity
27
 */
28
class SkillRelUser
29
{
30
    /**
31
     * @var integer
32
     *
33
     * @ORM\Column(name="user_id", type="integer", nullable=false)
34
     */
35
    private $userId;
36
37
    /**
38
     * @var integer
39
     *
40
     * @ORM\Column(name="skill_id", type="integer", nullable=false)
41
     */
42
    private $skillId;
43
44
    /**
45
     * @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User", inversedBy="achievedSkills", cascade={"persist"})
46
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
47
     */
48
    private $user;
49
    /**
50
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Skill", inversedBy="issuedSkills", cascade={"persist"})
51
     * @ORM\JoinColumn(name="skill_id", referencedColumnName="id", nullable=false)
52
     */
53
    private $skill;
54
55
    /**
56
     * @var \DateTime
57
     *
58
     * @ORM\Column(name="acquired_skill_at", type="datetime", nullable=false)
59
     */
60
    private $acquiredSkillAt;
61
62
    /**
63
     * @var integer
64
     *
65
     * @ORM\Column(name="assigned_by", type="integer", nullable=false)
66
     */
67
    private $assignedBy;
68
69
    /**
70
     * @var integer
71
     *
72
     * @ORM\Column(name="course_id", type="integer", nullable=false)
73
     */
74
    private $courseId;
75
76
    /**
77
     * @var integer
78
     *
79
     * @ORM\Column(name="session_id", type="integer", nullable=false)
80
     */
81
    private $sessionId;
82
83
    /**
84
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="issuedSkills", cascade={"persist"})
85
     * @ORM\JoinColumn(name="course_id", referencedColumnName="id")
86
     */
87
    private $course;
88
89
    /**
90
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session", inversedBy="issuedSkills", cascade={"persist"})
91
     * @ORM\JoinColumn(name="session_id", referencedColumnName="id")
92
     */
93
    private $session;
94
95
    /**
96
     * @var integer
97
     *
98
     * @ORM\Column(name="id", type="integer")
99
     * @ORM\Id
100
     * @ORM\GeneratedValue(strategy="IDENTITY")
101
     */
102
    private $id;
103
104
    /**
105
     * @var Level
106
     *
107
     * @ORM\ManyToOne(targetEntity="Chamilo\SkillBundle\Entity\Level")
108
     * @ORM\JoinColumn(name="acquired_level", referencedColumnName="id")
109
     */
110
    private $acquiredLevel;
111
112
    /**
113
     * @var string
114
     *
115
     * @ORM\Column(name="argumentation", type="text")
116
     */
117
    private $argumentation;
118
119
    /**
120
     * @var integer
121
     *
122
     * @ORM\Column(name="argumentation_author_id", type="integer")
123
     */
124
    private $argumentationAuthorId;
125
126
    /**
127
     * @ORM\OneToMany(targetEntity="SkillRelUserComment", mappedBy="skillRelUser")
128
     */
129
    protected $comments;
130
131
    public function __construct()
132
    {
133
        $this->comments = new \Doctrine\Common\Collections\ArrayCollection();
134
    }
135
136
    /**
137
     * Set userId
138
     *
139
     * @param integer $userId
140
     * @return SkillRelUser
141
     */
142
    public function setUserId($userId)
143
    {
144
        $this->userId = $userId;
145
146
        return $this;
147
    }
148
149
    /**
150
     * Get userId
151
     *
152
     * @return integer
153
     */
154
    public function getUserId()
155
    {
156
        return $this->userId;
157
    }
158
159
    /**
160
     * Set skillId
161
     *
162
     * @param integer $skillId
163
     * @return SkillRelUser
164
     */
165
    public function setSkillId($skillId)
166
    {
167
        $this->skillId = $skillId;
168
169
        return $this;
170
    }
171
172
    /**
173
     * Get skillId
174
     *
175
     * @return integer
176
     */
177
    public function getSkillId()
178
    {
179
        return $this->skillId;
180
    }
181
182
    /**
183
     * Set user
184
     * @param \Chamilo\UserBundle\Entity\User $user
185
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
186
     */
187
    public function setUser(\Chamilo\UserBundle\Entity\User $user)
188
    {
189
        $this->user = $user;
190
191
        return $this;
192
    }
193
194
    /**
195
     * Get user
196
     * @return \Chamilo\UserBundle\Entity\User
197
     */
198
    public function getUser()
199
    {
200
        return $this->user;
201
    }
202
203
    /**
204
     * Set skill
205
     * @param \Chamilo\CoreBundle\Entity\Skill $skill
206
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
207
     */
208
    public function setSkill(Skill $skill)
209
    {
210
        $this->skill = $skill;
211
212
        return $this;
213
    }
214
215
    /**
216
     * Get skill
217
     * @return \Chamilo\CoreBundle\Entity\Skill
218
     */
219
    public function getSkill()
220
    {
221
        return $this->skill;
222
    }
223
224
    /**
225
     * Set course
226
     * @param \Chamilo\CoreBundle\Entity\Course $course
227
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
228
     */
229
    public function setCourse(Course $course)
230
    {
231
        $this->course = $course;
232
233
        return $this;
234
    }
235
236
    /**
237
     * Get course
238
     * @return \Chamilo\CoreBundle\Entity\Course
239
     */
240
    public function getCourse()
241
    {
242
        return $this->course;
243
    }
244
245
    /**
246
     * Set session
247
     * @param \Chamilo\CoreBundle\Entity\Session $session
248
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
249
     */
250
    public function setSession(Session $session)
251
    {
252
        $this->session = $session;
253
254
        return $this;
255
    }
256
257
    /**
258
     * Get session
259
     * @return \Chamilo\CoreBundle\Entity\Session
260
     */
261
    public function getSession()
262
    {
263
        return $this->session;
264
    }
265
266
267
    /**
268
     * Set acquiredSkillAt
269
     *
270
     * @param \DateTime $acquiredSkillAt
271
     * @return SkillRelUser
272
     */
273
    public function setAcquiredSkillAt($acquiredSkillAt)
274
    {
275
        $this->acquiredSkillAt = $acquiredSkillAt;
276
277
        return $this;
278
    }
279
280
    /**
281
     * Get acquiredSkillAt
282
     *
283
     * @return \DateTime
284
     */
285
    public function getAcquiredSkillAt()
286
    {
287
        return $this->acquiredSkillAt;
288
    }
289
290
    /**
291
     * Set assignedBy
292
     *
293
     * @param integer $assignedBy
294
     * @return SkillRelUser
295
     */
296
    public function setAssignedBy($assignedBy)
297
    {
298
        $this->assignedBy = $assignedBy;
299
300
        return $this;
301
    }
302
303
    /**
304
     * Get assignedBy
305
     *
306
     * @return integer
307
     */
308
    public function getAssignedBy()
309
    {
310
        return $this->assignedBy;
311
    }
312
313
    /**
314
     * Set courseId
315
     *
316
     * @param integer $courseId
317
     * @return SkillRelUser
318
     */
319
    public function setCourseId($courseId)
320
    {
321
        $this->courseId = $courseId;
322
323
        return $this;
324
    }
325
326
    /**
327
     * Get courseId
328
     *
329
     * @return integer
330
     */
331
    public function getCourseId()
332
    {
333
        return $this->courseId;
334
    }
335
336
    /**
337
     * Set sessionId
338
     *
339
     * @param integer $sessionId
340
     * @return SkillRelUser
341
     */
342
    public function setSessionId($sessionId)
343
    {
344
        $this->sessionId = $sessionId;
345
346
        return $this;
347
    }
348
349
    /**
350
     * Get sessionId
351
     *
352
     * @return integer
353
     */
354
    public function getSessionId()
355
    {
356
        return $this->sessionId;
357
    }
358
359
    /**
360
     * Get id
361
     *
362
     * @return integer
363
     */
364
    public function getId()
365
    {
366
        return $this->id;
367
    }
368
369
    /**
370
     * Set acquiredLevel
371
     * @param \Chamilo\SkillBundle\Entity\Level $acquiredLevel
372
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
373
     */
374
    public function setAcquiredLevel($acquiredLevel)
375
    {
376
        $this->acquiredLevel = $acquiredLevel;
0 ignored issues
show
Documentation Bug introduced by
It seems like $acquiredLevel of type object<Chamilo\SkillBundle\Entity\Level> is incompatible with the declared type object<Chamilo\CoreBundle\Entity\Level> of property $acquiredLevel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
377
378
        return $this;
379
    }
380
381
    /**
382
     * Get acquiredLevel
383
     * @return \Chamilo\SkillBundle\Entity\Level
384
     */
385
    public function getAcquiredLevel()
386
    {
387
        return $this->acquiredLevel;
388
    }
389
390
    /**
391
     * Set argumentationAuthorId
392
     * @param integer $argumentationAuthorId
393
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
394
     */
395
    public function setArgumentationAuthorId($argumentationAuthorId)
396
    {
397
        $this->argumentationAuthorId = $argumentationAuthorId;
398
399
        return $this;
400
    }
401
402
    /**
403
     * Get argumentationAuthorId
404
     * @return integer
405
     */
406
    public function getArgumentationAuthorId()
407
    {
408
        return $this->argumentationAuthorId;
409
    }
410
411
    /**
412
     * Set argumentation
413
     * @param string $argumentation
414
     * @return \Chamilo\CoreBundle\Entity\SkillRelUser
415
     */
416
    public function setArgumentation($argumentation)
417
    {
418
        $this->argumentation = $argumentation;
419
420
        return $this;
421
    }
422
423
    /**
424
     * Get argumentation
425
     * @return string
426
     */
427
    public function getArgumentation()
428
    {
429
        return $this->argumentation;
430
    }
431
432
    /**
433
     * Get the source which the skill was obtained
434
     * @return string
435
     */
436
    public function getSourceName()
437
    {
438
        $source = '';
439
440
        if ($this->session && $this->session->getId() != 0) {
441
442
            $source .= "[{$this->session->getName()}] ";
443
        }
444
445
        if ($this->course) {
446
            $source .= $this->course->getTitle();
447
        }
448
449
        return $source;
450
    }
451
452
    /**
453
     * Get the URL for the issue
454
     * @return string
455
     */
456
    public function getIssueUrl()
457
    {
458
        return api_get_path(WEB_PATH) . "badge/{$this->id}";
459
    }
460
461
    /**
462
     * Get the URL for the All issues page
463
     * @return string
464
     */
465
    public function getIssueUrlAll()
466
    {
467
        return api_get_path(WEB_PATH) . "skill/{$this->skill->getId()}/user/{$this->user->getId()}";
468
    }
469
470
    /**
471
     * Get the URL for the assertion
472
     * @return string
473
     */
474
    public function getAssertionUrl()
475
    {
476
        $url = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?";
477
478
        $url .= http_build_query(array(
479
            'user' => $this->user->getId(),
480
            'skill' => $this->skill->getId(),
481
            'course' => $this->course ? $this->course->getId() : 0,
482
            'session' => $this->session ? $this->session->getId() : 0
483
        ));
484
485
        return $url;
486
    }
487
488
    /**
489
     * Get comments
490
     * @param boolean $sortDescByDateTime
491
     * @return ArrayCollection
492
     */
493
    public function getComments($sortDescByDateTime = false)
494
    {
495
        if ($sortDescByDateTime) {
496
            $criteria = \Doctrine\Common\Collections\Criteria::create();
497
            $criteria->orderBy([
498
                'feedbackDateTime' => \Doctrine\Common\Collections\Criteria::DESC
499
            ]);
500
501
            return $this->comments->matching($criteria);
502
        }
503
504
        return $this->comments;
505
    }
506
507
    /**
508
     * Calculate the average value from the feedback comments
509
     * @return type
510
     */
511
    public function getAverage()
512
    {
513
        $sum = 0;
514
        $average = 0;
515
        $countValues = 0;
516
517
        foreach ($this->comments as $comment) {
518
            if (!$comment->getFeedbackValue()) {
519
                continue;
520
            }
521
522
            $sum += $comment->getFeedbackValue();
523
            $countValues++;
524
        }
525
526
        $average = $countValues > 0 ? $sum / $countValues : 0;
527
528
        return number_format($average, 2);
529
    }
530
}
531