|
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
|
|
|
* Contextual information for an xAPI statement. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Christian Flothmann <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
final class Context |
|
20
|
|
|
{ |
|
21
|
|
|
private $registration; |
|
22
|
|
|
private $instructor; |
|
23
|
|
|
private $team; |
|
24
|
|
|
private $contextActivities; |
|
25
|
|
|
private $revision; |
|
26
|
|
|
private $platform; |
|
27
|
|
|
private $language; |
|
28
|
|
|
private $statement; |
|
29
|
|
|
private $extensions; |
|
30
|
|
|
|
|
31
|
|
|
public function withRegistration(string $registration): self |
|
32
|
|
|
{ |
|
33
|
|
|
$context = clone $this; |
|
34
|
|
|
$context->registration = $registration; |
|
35
|
|
|
|
|
36
|
|
|
return $context; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function withInstructor(Actor $instructor): self |
|
40
|
|
|
{ |
|
41
|
|
|
$context = clone $this; |
|
42
|
|
|
$context->instructor = $instructor; |
|
43
|
|
|
|
|
44
|
|
|
return $context; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function withTeam(Group $team): self |
|
48
|
|
|
{ |
|
49
|
|
|
$context = clone $this; |
|
50
|
|
|
$context->team = $team; |
|
51
|
|
|
|
|
52
|
|
|
return $context; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function withContextActivities(ContextActivities $contextActivities): self |
|
56
|
|
|
{ |
|
57
|
|
|
$context = clone $this; |
|
58
|
|
|
$context->contextActivities = $contextActivities; |
|
59
|
|
|
|
|
60
|
|
|
return $context; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function withRevision(string $revision): self |
|
64
|
|
|
{ |
|
65
|
|
|
$context = clone $this; |
|
66
|
|
|
$context->revision = $revision; |
|
67
|
|
|
|
|
68
|
|
|
return $context; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function withPlatform(string $platform): self |
|
72
|
|
|
{ |
|
73
|
|
|
$context = clone $this; |
|
74
|
|
|
$context->platform = $platform; |
|
75
|
|
|
|
|
76
|
|
|
return $context; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function withLanguage(string $language): self |
|
80
|
|
|
{ |
|
81
|
|
|
$context = clone $this; |
|
82
|
|
|
$context->language = $language; |
|
83
|
|
|
|
|
84
|
|
|
return $context; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function withStatement(StatementReference $statement): self |
|
88
|
|
|
{ |
|
89
|
|
|
$context = clone $this; |
|
90
|
|
|
$context->statement = $statement; |
|
91
|
|
|
|
|
92
|
|
|
return $context; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function withExtensions(Extensions $extensions): self |
|
96
|
|
|
{ |
|
97
|
|
|
$context = clone $this; |
|
98
|
|
|
$context->extensions = $extensions; |
|
99
|
|
|
|
|
100
|
|
|
return $context; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getRegistration(): ?string |
|
104
|
|
|
{ |
|
105
|
|
|
return $this->registration; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function getInstructor(): ?Actor |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->instructor; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
public function getTeam(): ?Group |
|
114
|
|
|
{ |
|
115
|
|
|
return $this->team; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
public function getContextActivities(): ?ContextActivities |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->contextActivities; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
public function getRevision(): ?string |
|
124
|
|
|
{ |
|
125
|
|
|
return $this->revision; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
public function getPlatform(): ?string |
|
129
|
|
|
{ |
|
130
|
|
|
return $this->platform; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
public function getLanguage(): ?string |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->language; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function getStatement(): ?StatementReference |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->statement; |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
public function getExtensions(): ?Extensions |
|
144
|
|
|
{ |
|
145
|
|
|
return $this->extensions; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
public function equals(Context $context): bool |
|
149
|
|
|
{ |
|
150
|
|
|
if ($this->registration !== $context->registration) { |
|
151
|
|
|
return false; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
if (null !== $this->instructor xor null !== $context->instructor) { |
|
155
|
|
|
return false; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
if (null !== $this->instructor && null !== $context->instructor && !$this->instructor->equals($context->instructor)) { |
|
159
|
|
|
return false; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
if (null !== $this->team xor null !== $context->team) { |
|
163
|
|
|
return false; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
if (null !== $this->team && null !== $context->team && !$this->team->equals($context->team)) { |
|
167
|
|
|
return false; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
if ($this->contextActivities != $context->contextActivities) { |
|
171
|
|
|
return false; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
if ($this->revision !== $context->revision) { |
|
175
|
|
|
return false; |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
if ($this->platform !== $context->platform) { |
|
179
|
|
|
return false; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
if ($this->language !== $context->language) { |
|
183
|
|
|
return false; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
if (null !== $this->statement xor null !== $context->statement) { |
|
187
|
|
|
return false; |
|
188
|
|
|
} |
|
189
|
|
|
|
|
190
|
|
|
if (null !== $this->statement && null !== $context->statement && !$this->statement->equals($context->statement)) { |
|
191
|
|
|
return false; |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
if (null !== $this->extensions xor null !== $context->extensions) { |
|
195
|
|
|
return false; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
if (null !== $this->extensions && null !== $context->extensions && !$this->extensions->equals($context->extensions)) { |
|
199
|
|
|
return false; |
|
200
|
|
|
} |
|
201
|
|
|
|
|
202
|
|
|
return true; |
|
203
|
|
|
} |
|
204
|
|
|
} |
|
205
|
|
|
|