1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the xAPI package. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Flothmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace XApi\Repository\Doctrine\Mapping; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Model\Result as ResultModel; |
15
|
|
|
use Xabbuh\XApi\Model\Score; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @author Christian Flothmann <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
class Result |
21
|
|
|
{ |
22
|
|
|
public $identifier; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var bool |
26
|
|
|
*/ |
27
|
|
|
public $hasScore; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var float|null |
31
|
|
|
*/ |
32
|
|
|
public $scaled; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var float|null |
36
|
|
|
*/ |
37
|
|
|
public $raw; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var float|null |
41
|
|
|
*/ |
42
|
|
|
public $min; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var float|null |
46
|
|
|
*/ |
47
|
|
|
public $max; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var bool|null |
51
|
|
|
*/ |
52
|
|
|
public $success; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var bool|null |
56
|
|
|
*/ |
57
|
|
|
public $completion; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @var string|null |
61
|
|
|
*/ |
62
|
|
|
public $response; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @var string|null |
66
|
|
|
*/ |
67
|
|
|
public $duration; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @var Extensions|null |
71
|
|
|
*/ |
72
|
|
|
public $extensions; |
73
|
|
|
|
74
|
|
|
public static function fromModel(ResultModel $model) |
75
|
|
|
{ |
76
|
|
|
$result = new self(); |
77
|
|
|
$result->success = $model->getSuccess(); |
78
|
|
|
$result->completion = $model->getCompletion(); |
79
|
|
|
$result->response = $model->getResponse(); |
80
|
|
|
$result->duration = $model->getDuration(); |
81
|
|
|
|
82
|
|
|
if (null !== $score = $model->getScore()) { |
83
|
|
|
$result->hasScore = true; |
84
|
|
|
$result->scaled = $score->getScaled(); |
85
|
|
|
$result->raw = $score->getRaw(); |
86
|
|
|
$result->min = $score->getMin(); |
87
|
|
|
$result->max = $score->getMax(); |
88
|
|
|
} else { |
89
|
|
|
$result->hasScore = false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (null !== $extensions = $model->getExtensions()) { |
93
|
|
|
$result->extensions = Extensions::fromModel($extensions); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $result; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function getModel() |
100
|
|
|
{ |
101
|
|
|
$score = null; |
102
|
|
|
$extensions = null; |
103
|
|
|
|
104
|
|
|
if ($this->hasScore) { |
105
|
|
|
$score = new Score($this->scaled, $this->raw, $this->min, $this->max); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
if (null !== $this->extensions) { |
109
|
|
|
$extensions = $this->extensions->getModel(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return new ResultModel($score, $this->success, $this->completion, $this->response, $this->duration, $extensions); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|