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\Interaction; |
13
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Model\Definition; |
15
|
|
|
use Xabbuh\XApi\Model\Extensions; |
16
|
|
|
use Xabbuh\XApi\Model\IRI; |
17
|
|
|
use Xabbuh\XApi\Model\IRL; |
18
|
|
|
use Xabbuh\XApi\Model\LanguageMap; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* An interaction where the learner is asked to match items in one set |
22
|
|
|
* (the source set) to items in another set (the target set). |
23
|
|
|
* |
24
|
|
|
* @author Christian Flothmann <[email protected]> |
25
|
|
|
*/ |
26
|
|
|
final class MatchingInteractionDefinition extends InteractionDefinition |
27
|
|
|
{ |
28
|
|
|
private $source; |
29
|
|
|
private $target; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string[]|null $correctResponsesPattern |
33
|
|
|
* @param InteractionComponent[]|null $source |
34
|
|
|
* @param InteractionComponent[]|null $target |
35
|
|
|
*/ |
36
|
|
|
public function __construct(LanguageMap $name = null, LanguageMap $description = null, IRI $type = null, IRL $moreInfo = null, Extensions $extensions = null, array $correctResponsesPattern = null, array $source = null, array $target = null) |
37
|
|
|
{ |
38
|
|
|
parent::__construct($name, $description, $type, $moreInfo, $extensions, $correctResponsesPattern); |
39
|
|
|
|
40
|
|
|
$this->source = $source; |
41
|
|
|
$this->target = $target; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param InteractionComponent[]|null $source |
46
|
|
|
*/ |
47
|
|
|
public function withSource(array $source = null): self |
48
|
|
|
{ |
49
|
|
|
$interaction = clone $this; |
50
|
|
|
$interaction->source = $source; |
51
|
|
|
|
52
|
|
|
return $interaction; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param InteractionComponent[]|null $target |
57
|
|
|
*/ |
58
|
|
|
public function withTarget(array $target = null): self |
59
|
|
|
{ |
60
|
|
|
$interaction = clone $this; |
61
|
|
|
$interaction->target = $target; |
62
|
|
|
|
63
|
|
|
return $interaction; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return InteractionComponent[]|null |
68
|
|
|
*/ |
69
|
|
|
public function getSource(): ?array |
70
|
|
|
{ |
71
|
|
|
return $this->source; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return InteractionComponent[]|null |
76
|
|
|
*/ |
77
|
|
|
public function getTarget(): ?array |
78
|
|
|
{ |
79
|
|
|
return $this->target; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function equals(Definition $definition): bool |
83
|
|
|
{ |
84
|
|
|
if (!parent::equals($definition)) { |
85
|
|
|
return false; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (!$definition instanceof MatchingInteractionDefinition) { |
89
|
|
|
return false; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if (null !== $this->source xor null !== $definition->source) { |
93
|
|
|
return false; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if (null !== $this->target xor null !== $definition->target) { |
97
|
|
|
return false; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (null !== $this->source) { |
101
|
|
|
if (count($this->source) !== count($definition->source)) { |
102
|
|
|
return false; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
foreach ($this->source as $key => $source) { |
106
|
|
|
if (!isset($definition->source[$key])) { |
107
|
|
|
return false; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
if (!$source->equals($definition->source[$key])) { |
111
|
|
|
return false; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
if (null !== $this->target) { |
117
|
|
|
if (count($this->target) !== count($definition->target)) { |
118
|
|
|
return false; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
foreach ($this->target as $key => $target) { |
122
|
|
|
if (!isset($definition->target[$key])) { |
123
|
|
|
return false; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
if (!$target->equals($definition->target[$key])) { |
127
|
|
|
return false; |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
return true; |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|