|
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\Serializer\Normalizer; |
|
13
|
|
|
|
|
14
|
|
|
use Xabbuh\XApi\Model\StatementResult; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Normalizes and denormalizes xAPI statement collections. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Christian Flothmann <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
final class StatementResultNormalizer extends Normalizer |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* {@inheritdoc} |
|
25
|
|
|
*/ |
|
26
|
2 |
|
public function normalize($object, $format = null, array $context = array()) |
|
27
|
|
|
{ |
|
28
|
2 |
|
if (!$object instanceof StatementResult) { |
|
29
|
|
|
return null; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
$data = array( |
|
33
|
2 |
|
'statements' => array(), |
|
34
|
|
|
); |
|
35
|
|
|
|
|
36
|
2 |
|
foreach ($object->getStatements() as $statement) { |
|
37
|
2 |
|
$data['statements'][] = $this->normalizeAttribute($statement, $format, $context); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
2 |
|
if (null !== $moreUrlPath = $object->getMoreUrlPath()) { |
|
41
|
1 |
|
$data['more'] = $moreUrlPath; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
return $data; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
9 |
|
public function supportsNormalization($data, $format = null) |
|
51
|
|
|
{ |
|
52
|
9 |
|
return $data instanceof StatementResult; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
2 |
|
public function denormalize($data, $class, $format = null, array $context = array()) |
|
59
|
|
|
{ |
|
60
|
2 |
|
$statements = $this->denormalizeData($data['statements'], 'Xabbuh\XApi\Model\Statement[]'); |
|
61
|
|
|
|
|
62
|
2 |
|
return new StatementResult($statements, isset($data['more']) ? $data['more'] : null); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
*/ |
|
68
|
10 |
|
public function supportsDenormalization($data, $type, $format = null) |
|
69
|
|
|
{ |
|
70
|
10 |
|
return 'Xabbuh\XApi\Model\StatementResult' === $type; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|