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\LanguageMap; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* An interaction where the learner is asked to order items in a set. |
19
|
|
|
* |
20
|
|
|
* @author Christian Flothmann <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
final class SequencingInteractionDefinition extends InteractionDefinition |
23
|
|
|
{ |
24
|
|
|
private $choices; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param LanguageMap|null $name |
28
|
|
|
* @param LanguageMap|null $description |
29
|
|
|
* @param string|null $type |
30
|
|
|
* @param string|null $moreInfo |
31
|
|
|
* @param string[]|null $correctResponsesPattern |
32
|
|
|
* @param InteractionComponent[]|null $choices |
33
|
|
|
*/ |
34
|
|
|
public function __construct(LanguageMap $name = null, LanguageMap $description = null, $type = null, $moreInfo = null, array $correctResponsesPattern = null, array $choices = null) |
35
|
|
|
{ |
36
|
|
|
parent::__construct($name, $description, $type, $moreInfo, $correctResponsesPattern); |
37
|
|
|
|
38
|
|
|
$this->choices = $choices; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param InteractionComponent[]|null $choices |
43
|
|
|
* |
44
|
|
|
* @return static |
45
|
|
|
*/ |
46
|
|
|
public function withChoices(array $choices = null) |
47
|
|
|
{ |
48
|
|
|
$interaction = clone $this; |
49
|
|
|
$interaction->choices = $choices; |
50
|
|
|
|
51
|
|
|
return $interaction; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getChoices() |
55
|
|
|
{ |
56
|
|
|
return $this->choices; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function equals(Definition $definition) |
60
|
|
|
{ |
61
|
|
|
if (!parent::equals($definition)) { |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
if (!$definition instanceof SequencingInteractionDefinition) { |
66
|
|
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if (null !== $this->choices xor null !== $definition->choices) { |
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (null !== $this->choices) { |
74
|
|
|
if (count($this->choices) !== count($definition->choices)) { |
75
|
|
|
return false; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
foreach ($this->choices as $key => $choice) { |
79
|
|
|
if (!isset($definition->choices[$key])) { |
80
|
|
|
return false; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if (!$choice->equals($definition->choices[$key])) { |
84
|
|
|
return false; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return true; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|