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
|
|
|
* Base class for interaction definitions of an {@link Activity}. |
19
|
|
|
* |
20
|
|
|
* @author Christian Flothmann <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
abstract class InteractionDefinition extends Definition |
23
|
|
|
{ |
24
|
|
|
private $correctResponsesPattern; |
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
|
|
|
*/ |
33
|
|
|
public function __construct(LanguageMap $name = null, LanguageMap $description = null, $type = null, $moreInfo = null, array $correctResponsesPattern = null) |
34
|
|
|
{ |
35
|
|
|
parent::__construct($name, $description, $type, $moreInfo); |
36
|
|
|
|
37
|
|
|
$this->correctResponsesPattern = $correctResponsesPattern; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string[]|null $correctResponsesPattern |
42
|
|
|
* |
43
|
|
|
* @return static |
44
|
|
|
*/ |
45
|
|
|
public function withCorrectResponsesPattern(array $correctResponsesPattern = null) |
46
|
|
|
{ |
47
|
|
|
$interaction = clone $this; |
48
|
|
|
$interaction->correctResponsesPattern = $correctResponsesPattern; |
49
|
|
|
|
50
|
|
|
return $interaction; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function getCorrectResponsesPattern() |
54
|
|
|
{ |
55
|
|
|
return $this->correctResponsesPattern; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function equals(Definition $definition) |
59
|
|
|
{ |
60
|
|
|
if (!parent::equals($definition)) { |
61
|
|
|
return false; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
if (!$definition instanceof InteractionDefinition) { |
65
|
|
|
return false; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
if (null !== $this->correctResponsesPattern xor null !== $definition->correctResponsesPattern) { |
69
|
|
|
return false; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (null !== $this->correctResponsesPattern) { |
73
|
|
|
if (count($this->correctResponsesPattern) !== count($definition->correctResponsesPattern)) { |
74
|
|
|
return false; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
foreach ($this->correctResponsesPattern as $value) { |
78
|
|
|
if (!in_array($value, $definition->correctResponsesPattern, true)) { |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return true; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|