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 Xabbuh\XApi\Model; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* An {@link Actor Actor's} outcome related to the {@link Statement} in which |
16
|
|
|
* it is included. |
17
|
|
|
* |
18
|
|
|
* @author Christian Flothmann <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
final class Result |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Score The score |
24
|
|
|
*/ |
25
|
|
|
private $score; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var bool Indicates whether or not the attempt was successful |
29
|
|
|
*/ |
30
|
|
|
private $success; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var bool Indicates whether or not the Activity was completed |
34
|
|
|
*/ |
35
|
|
|
private $completion; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var string A response for the given Activity |
39
|
|
|
*/ |
40
|
|
|
private $response; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string Period of time over which the Activity was performed |
44
|
|
|
*/ |
45
|
|
|
private $duration; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var Extensions|null Extensions associated with this result |
49
|
|
|
*/ |
50
|
|
|
private $extensions; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param Score|null $score |
54
|
|
|
* @param bool|null $success |
55
|
|
|
* @param bool|null $completion |
56
|
|
|
* @param string|null $response |
57
|
|
|
* @param string|null $duration |
58
|
|
|
* @param Extensions|null $extensions |
59
|
|
|
*/ |
60
|
|
|
public function __construct(Score $score = null, $success = null, $completion = null, $response = null, $duration = null, Extensions $extensions = null) |
61
|
|
|
{ |
62
|
|
|
$this->score = $score; |
63
|
|
|
$this->success = $success; |
64
|
|
|
$this->completion = $completion; |
65
|
|
|
$this->response = $response; |
66
|
|
|
$this->duration = $duration; |
67
|
|
|
$this->extensions = $extensions; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Returns the user's score. |
72
|
|
|
* |
73
|
|
|
* @return Score The score |
74
|
|
|
*/ |
75
|
|
|
public function getScore() |
76
|
|
|
{ |
77
|
|
|
return $this->score; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns whether or not the user finished a task successfully. |
82
|
|
|
* |
83
|
|
|
* @return bool True if the user finished an exercise successfully, false |
84
|
|
|
* otherwise |
85
|
|
|
*/ |
86
|
|
|
public function getSuccess() |
87
|
|
|
{ |
88
|
|
|
return $this->success; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Returns the completion status. |
93
|
|
|
* |
94
|
|
|
* @return bool $completion True, if the Activity was completed, false |
95
|
|
|
* otherwise |
96
|
|
|
*/ |
97
|
|
|
public function getCompletion() |
98
|
|
|
{ |
99
|
|
|
return $this->completion; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Returns the response. |
104
|
|
|
* |
105
|
|
|
* @return string The response |
106
|
|
|
*/ |
107
|
|
|
public function getResponse() |
108
|
|
|
{ |
109
|
|
|
return $this->response; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Returns the period of time over which the Activity was performed. |
114
|
|
|
* |
115
|
|
|
* @return string The duration |
116
|
|
|
*/ |
117
|
|
|
public function getDuration() |
118
|
|
|
{ |
119
|
|
|
return $this->duration; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Returns the extensions associated with the result. |
124
|
|
|
* |
125
|
|
|
* @return Extensions|null The extensions |
126
|
|
|
*/ |
127
|
|
|
public function getExtensions() |
128
|
|
|
{ |
129
|
|
|
return $this->extensions; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Checks if another result is equal. |
134
|
|
|
* |
135
|
|
|
* Two results are equal if and only if all of their properties are equal. |
136
|
|
|
* |
137
|
|
|
* @param Result $result The result to compare with |
138
|
|
|
* |
139
|
|
|
* @return bool True if the results are equal, false otherwise |
140
|
|
|
*/ |
141
|
|
|
public function equals(Result $result) |
142
|
|
|
{ |
143
|
|
|
if (null !== $this->score xor null !== $result->score) { |
144
|
|
|
return false; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if (null !== $this->score && !$this->score->equals($result->score)) { |
148
|
|
|
return false; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
if ($this->success !== $result->success) { |
152
|
|
|
return false; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
if ($this->completion !== $result->completion) { |
156
|
|
|
return false; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
if ($this->response !== $result->response) { |
160
|
|
|
return false; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
if ($this->duration !== $result->duration) { |
164
|
|
|
return false; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
if (null !== $this->extensions xor null !== $result->extensions) { |
168
|
|
|
return false; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
if (null !== $this->extensions && !$this->extensions->equals($result->extensions)) { |
|
|
|
|
172
|
|
|
return false; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
return true; |
176
|
|
|
} |
177
|
|
|
} |
178
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: