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