Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
88.24% covered (warning)
88.24%
15 / 17
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
MetadataLomService
88.24% covered (warning)
88.24%
15 / 17
0.00% covered (danger)
0.00%
0 / 1
4.03
0.00% covered (danger)
0.00%
0 / 1
 addPropertiesToMetadataBlock
88.24% covered (warning)
88.24%
15 / 17
0.00% covered (danger)
0.00%
0 / 1
4.03
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) 2024 (original work) Open Assessment Technologies SA;
19 */
20
21declare(strict_types=1);
22
23namespace oat\taoQtiTest\models\classes\metadata;
24
25use DOMDocument;
26use DOMNodeList;
27
28class MetadataLomService
29{
30    public const FEATURE_FLAG = 'FEATURE_FLAG_METADATA_LOM_SERVICE';
31
32    public function addPropertiesToMetadataBlock(array $properties, DOMDocument $manifest): void
33    {
34        /** @var DOMNodeList $metadataBlock */
35        $metadataBlock = $manifest->getElementsByTagName('metadata');
36
37        if ($metadataBlock === null) {
38            $metadataBlock = $manifest->createElement('metadata');
39            $manifest->documentElement->appendChild($metadataBlock);
40        }
41
42        $metadataBlock->item(0)
43            ->appendChild($manifest->createElement('imsmd:lom'))
44            ->appendChild($manifest->createElement('imsmd:metaMetadata'))
45            ->appendChild($manifest->createElement('extension'))
46            ->appendChild($manifest->createElement('customProperties'));
47
48        foreach ($properties as $property) {
49            $propertyNode = $manifest->createElement('property');
50            foreach ($property as $key => $value) {
51                $propertyNode->appendChild($manifest->createElement($key, $value));
52            }
53            $metadataBlock->item(0)
54                ->getElementsByTagName('customProperties')
55                ->item(0)
56                ->appendChild($propertyNode);
57        }
58    }
59}