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
|
|
|
* @param Score $score |
49
|
|
|
* @param bool $success |
50
|
|
|
* @param bool $completion |
51
|
|
|
* @param string|null $response |
52
|
|
|
* @param string|null $duration |
53
|
|
|
*/ |
54
|
|
|
public function __construct(Score $score, $success, $completion, $response = null, $duration = null) |
55
|
|
|
{ |
56
|
|
|
$this->score = $score; |
57
|
|
|
$this->success = $success; |
58
|
|
|
$this->completion = $completion; |
59
|
|
|
$this->response = $response; |
60
|
|
|
$this->duration = $duration; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Returns the user's score. |
65
|
|
|
* |
66
|
|
|
* @return Score The score |
67
|
|
|
*/ |
68
|
|
|
public function getScore() |
69
|
|
|
{ |
70
|
|
|
return $this->score; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns whether or not the user finished a task successfully. |
75
|
|
|
* |
76
|
|
|
* @return bool True if the user finished an exercise successfully, false |
77
|
|
|
* otherwise |
78
|
|
|
*/ |
79
|
|
|
public function getSuccess() |
80
|
|
|
{ |
81
|
|
|
return $this->success; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Returns the completion status. |
86
|
|
|
* |
87
|
|
|
* @return bool $completion True, if the Activity was completed, false |
88
|
|
|
* otherwise |
89
|
|
|
*/ |
90
|
|
|
public function getCompletion() |
91
|
|
|
{ |
92
|
|
|
return $this->completion; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the response. |
97
|
|
|
* |
98
|
|
|
* @return string The response |
99
|
|
|
*/ |
100
|
|
|
public function getResponse() |
101
|
|
|
{ |
102
|
|
|
return $this->response; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Returns the period of time over which the Activity was performed. |
107
|
|
|
* |
108
|
|
|
* @return string The duration |
109
|
|
|
*/ |
110
|
|
|
public function getDuration() |
111
|
|
|
{ |
112
|
|
|
return $this->duration; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Checks if another result is equal. |
117
|
|
|
* |
118
|
|
|
* Two results are equal if and only if all of their properties are equal. |
119
|
|
|
* |
120
|
|
|
* @param Result $result The result to compare with |
121
|
|
|
* |
122
|
|
|
* @return bool True if the results are equal, false otherwise |
123
|
|
|
*/ |
124
|
|
|
public function equals(Result $result) |
125
|
|
|
{ |
126
|
|
|
if (!$this->score->equals($result->score)) { |
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
if ($this->success !== $result->success) { |
131
|
|
|
return false; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if ($this->completion !== $result->completion) { |
135
|
|
|
return false; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
if ($this->response !== $result->response) { |
139
|
|
|
return false; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
if ($this->duration !== $result->duration) { |
143
|
|
|
return false; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
return true; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|