1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\PluginBundle\XApi\ToolExperience\Statement; |
8
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Entity\TrackEExercises; |
10
|
|
|
use Chamilo\CourseBundle\Entity\CQuiz; |
11
|
|
|
use Chamilo\PluginBundle\XApi\ToolExperience\Activity\Quiz as QuizActivity; |
12
|
|
|
use Chamilo\PluginBundle\XApi\ToolExperience\Actor\User as UserActor; |
13
|
|
|
use Chamilo\PluginBundle\XApi\ToolExperience\Verb\Completed as CompletedVerb; |
14
|
|
|
use Xabbuh\XApi\Model\Result; |
15
|
|
|
use Xabbuh\XApi\Model\Score; |
16
|
|
|
use Xabbuh\XApi\Model\Statement; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class QuizCompleted. |
20
|
|
|
*/ |
21
|
|
|
class QuizCompleted extends BaseStatement |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var TrackEExercises |
25
|
|
|
*/ |
26
|
|
|
private $exe; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var CQuiz |
30
|
|
|
*/ |
31
|
|
|
private $quiz; |
32
|
|
|
|
33
|
|
|
public function __construct(TrackEExercises $exe, CQuiz $quiz) |
34
|
|
|
{ |
35
|
|
|
$this->exe = $exe; |
36
|
|
|
$this->quiz = $quiz; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function generate(): Statement |
40
|
|
|
{ |
41
|
|
|
$user = api_get_user_entity($this->exe->getExeUserId()); |
42
|
|
|
|
43
|
|
|
$userActor = new UserActor($user); |
44
|
|
|
$completedVerb = new CompletedVerb(); |
45
|
|
|
$quizActivity = new QuizActivity($this->quiz); |
46
|
|
|
|
47
|
|
|
$rawResult = $this->exe->getExeResult(); |
48
|
|
|
$maxResult = $this->exe->getExeWeighting(); |
49
|
|
|
$scaledResult = $rawResult / $maxResult; |
50
|
|
|
|
51
|
|
|
$duration = $this->exe->getExeDuration(); |
52
|
|
|
|
53
|
|
|
return new Statement( |
54
|
|
|
$this->generateStatementId('exercise'), |
55
|
|
|
$userActor->generate(), |
56
|
|
|
$completedVerb->generate(), |
57
|
|
|
$quizActivity->generate(), |
58
|
|
|
new Result( |
59
|
|
|
new Score($scaledResult, $rawResult, 0, $maxResult), |
60
|
|
|
null, |
61
|
|
|
true, |
62
|
|
|
null, |
63
|
|
|
$duration ? "PT{$duration}S" : null |
64
|
|
|
), |
65
|
|
|
null, |
66
|
|
|
$this->exe->getExeDate(), |
67
|
|
|
null, |
68
|
|
|
$this->generateContext() |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|