-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathObjectDefinition.php
37 lines (32 loc) · 1.32 KB
/
ObjectDefinition.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php namespace Locker\XApi;
class ObjectDefinition extends Definition {
protected $props = [
'interactionType' => 'Locker\XApi\InteractionType',
'correctResponsesPattern' => 'Locker\XApi\Strings',
'choices' => 'Locker\XApi\InteractionComponents',
'scale' => 'Locker\XApi\InteractionComponents',
'source' => 'Locker\XApi\InteractionComponents',
'target' => 'Locker\XApi\InteractionComponents',
'steps' => 'Locker\XApi\InteractionComponents'
];
protected $knowable_props = ['choices', 'scale', 'source', 'target', 'steps'];
protected $type_map = [
'choice' => ['choices'],
'sequencing' => ['choices'],
'likert' => ['scale'],
'matching' => ['source', 'target'],
'performance' => ['steps']
];
public function validate() {
$errors = [];
// Finds allowed props.
$interaction_type = $this->getProp('interactionType');
$interaction_type = $interaction_type instanceof Atom ? $interaction_type->getValue() : null;
$allowed_props = isset($this->type_map[$interaction_type]) ? $this->type_map[$interaction_type] : [];
// Changes known_props.
$disallowed_props = array_diff($this->knowable_props, $allowed_props);
$known_props = array_keys($this->props);
$this->known_props = array_diff($known_props, $disallowed_props);
return parent::validate();
}
}