Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
GenericLomManifestClassificationExtractor
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
72
0.00% covered (danger)
0.00%
0 / 1
 extract
0.00% covered (danger)
0.00%
0 / 18
0.00% covered (danger)
0.00%
0 / 1
72
1<?php
2
3/**
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; under version 2
7 * of the License (non-upgradable).
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 *
18 * Copyright (c) 2017 (original work) Open Assessment Technologies SA
19 *
20 */
21
22namespace oat\taoQtiItem\model\qti\metadata\imsManifest\classificationMetadata;
23
24use oat\taoQtiItem\model\qti\metadata\imsManifest\ImsManifestMetadataExtractor;
25use oat\taoQtiItem\model\qti\metadata\imsManifest\ImsManifestMetadataValue;
26use oat\taoQtiItem\model\qti\metadata\LomMetadata;
27use oat\taoQtiItem\model\qti\metadata\MetadataValue;
28use oat\taoQtiItem\model\qti\metadata\simple\SimpleMetadataValue;
29
30class GenericLomManifestClassificationExtractor extends ImsManifestMetadataExtractor
31{
32    /**
33     * @see ImsManifestDataExtractor::extract()
34     *
35     * @param mixed $manifest
36     * @return array
37     */
38    public function extract($manifest)
39    {
40        $values = parent::extract($manifest);
41        $newValues = [];
42
43        foreach ($values as $resourceIdentifier => $metadataValueCollection) {
44
45            /** @var ImsManifestMetadataValue $metadataValue */
46            foreach ($metadataValueCollection as $key => $metadataValue) {
47                // If metadata is not a source or is empty then skip
48                if (
49                    $metadataValue->getValue() === ''
50                    || $metadataValue->getPath() !== ClassificationSourceMetadataValue::getSourcePath()
51                ) {
52                    continue;
53                }
54
55                // If next metadata does not exist then skip
56                if (! isset($metadataValueCollection[$key + 1])) {
57                    continue;
58                }
59
60                /** @var MetadataValue $entryMetadata */
61                $entryMetadata = $metadataValueCollection[$key + 1];
62
63                // Handle metadata if it is an entry and is not empty
64                if (
65                    $entryMetadata->getPath() === ClassificationEntryMetadataValue::getEntryPath()
66                    && $entryMetadata->getValue() !== ''
67                ) {
68                    $newValues[$resourceIdentifier][] = new SimpleMetadataValue(
69                        $resourceIdentifier,
70                        [LomMetadata::LOM_NAMESPACE . '#lom', $metadataValue->getValue()],
71                        $entryMetadata->getValue()
72                    );
73                }
74            }
75        }
76
77        return $newValues;
78    }
79}