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
|
|
|
public function withScore(Score $score = null) |
71
|
|
|
{ |
72
|
|
|
$result = clone $this; |
73
|
|
|
$result->score = $score; |
74
|
|
|
|
75
|
|
|
return $result; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param bool|null $success |
80
|
|
|
* |
81
|
|
|
* @return Result |
82
|
|
|
*/ |
83
|
|
|
public function withSuccess($success) |
84
|
|
|
{ |
85
|
|
|
$result = clone $this; |
86
|
|
|
$result->success = $success; |
87
|
|
|
|
88
|
|
|
return $result; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param bool|null $completion |
93
|
|
|
* |
94
|
|
|
* @return Result |
95
|
|
|
*/ |
96
|
|
|
public function withCompletion($completion) |
97
|
|
|
{ |
98
|
|
|
$result = clone $this; |
99
|
|
|
$result->completion = $completion; |
100
|
|
|
|
101
|
|
|
return $result; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string|null $response |
106
|
|
|
* |
107
|
|
|
* @return Result |
108
|
|
|
*/ |
109
|
|
|
public function withResponse($response) |
110
|
|
|
{ |
111
|
|
|
$result = clone $this; |
112
|
|
|
$result->response = $response; |
113
|
|
|
|
114
|
|
|
return $result; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @param string|null $duration |
119
|
|
|
* |
120
|
|
|
* @return Result |
121
|
|
|
*/ |
122
|
|
|
public function withDuration($duration) |
123
|
|
|
{ |
124
|
|
|
$result = clone $this; |
125
|
|
|
$result->duration = $duration; |
126
|
|
|
|
127
|
|
|
return $result; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function withExtensions(Extensions $extensions = null) |
131
|
|
|
{ |
132
|
|
|
$result = clone $this; |
133
|
|
|
$result->extensions = $extensions; |
134
|
|
|
|
135
|
|
|
return $result; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Returns the user's score. |
140
|
|
|
* |
141
|
|
|
* @return Score The score |
142
|
|
|
*/ |
143
|
|
|
public function getScore() |
144
|
|
|
{ |
145
|
|
|
return $this->score; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Returns whether or not the user finished a task successfully. |
150
|
|
|
* |
151
|
|
|
* @return bool True if the user finished an exercise successfully, false |
152
|
|
|
* otherwise |
153
|
|
|
*/ |
154
|
|
|
public function getSuccess() |
155
|
|
|
{ |
156
|
|
|
return $this->success; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Returns the completion status. |
161
|
|
|
* |
162
|
|
|
* @return bool $completion True, if the Activity was completed, false |
163
|
|
|
* otherwise |
164
|
|
|
*/ |
165
|
|
|
public function getCompletion() |
166
|
|
|
{ |
167
|
|
|
return $this->completion; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Returns the response. |
172
|
|
|
* |
173
|
|
|
* @return string The response |
174
|
|
|
*/ |
175
|
|
|
public function getResponse() |
176
|
|
|
{ |
177
|
|
|
return $this->response; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns the period of time over which the Activity was performed. |
182
|
|
|
* |
183
|
|
|
* @return string The duration |
184
|
|
|
*/ |
185
|
|
|
public function getDuration() |
186
|
|
|
{ |
187
|
|
|
return $this->duration; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Returns the extensions associated with the result. |
192
|
|
|
* |
193
|
|
|
* @return Extensions|null The extensions |
194
|
|
|
*/ |
195
|
|
|
public function getExtensions() |
196
|
|
|
{ |
197
|
|
|
return $this->extensions; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Checks if another result is equal. |
202
|
|
|
* |
203
|
|
|
* Two results are equal if and only if all of their properties are equal. |
204
|
|
|
* |
205
|
|
|
* @param Result $result The result to compare with |
206
|
|
|
* |
207
|
|
|
* @return bool True if the results are equal, false otherwise |
208
|
|
|
*/ |
209
|
|
|
public function equals(Result $result) |
210
|
|
|
{ |
211
|
|
|
if (null !== $this->score xor null !== $result->score) { |
212
|
|
|
return false; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
if (null !== $this->score && !$this->score->equals($result->score)) { |
216
|
|
|
return false; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
if ($this->success !== $result->success) { |
220
|
|
|
return false; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
if ($this->completion !== $result->completion) { |
224
|
|
|
return false; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if ($this->response !== $result->response) { |
228
|
|
|
return false; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
if ($this->duration !== $result->duration) { |
232
|
|
|
return false; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
if (null !== $this->extensions xor null !== $result->extensions) { |
236
|
|
|
return false; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
if (null !== $this->extensions && null !== $result->extensions && !$this->extensions->equals($result->extensions)) { |
240
|
|
|
return false; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
return true; |
244
|
|
|
} |
245
|
|
|
} |
246
|
|
|
|