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