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