| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 100.00% | 19 / 19 |  | 100.00% | 4 / 4 | CRAP |  | 100.00% | 1 / 1 | 
| PropertyMapper |  | 100.00% | 19 / 19 |  | 100.00% | 4 / 4 | 9 |  | 100.00% | 1 / 1 | 
| __construct |  | 100.00% | 2 / 2 |  | 100.00% | 1 / 1 | 1 | |||
| getMetadataProperties |  | 100.00% | 11 / 11 |  | 100.00% | 1 / 1 | 5 | |||
| isIgnoredForCollectionGathering |  | 100.00% | 1 / 1 |  | 100.00% | 1 / 1 | 2 | |||
| getIgnoredProperties |  | 100.00% | 5 / 5 |  | 100.00% | 1 / 1 | 1 | |||
| 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 | |
| 21 | declare(strict_types=1); | 
| 22 | |
| 23 | namespace oat\taoQtiTest\models\classes\metadata\metaMetadata; | 
| 24 | |
| 25 | use core_kernel_classes_Property as Property; | 
| 26 | use core_kernel_classes_Resource as Resource; | 
| 27 | use oat\generis\model\OntologyRdf; | 
| 28 | use oat\taoQtiItem\model\import\ChecksumGenerator; | 
| 29 | use taoTests_models_classes_TestsService; | 
| 30 | |
| 31 | class PropertyMapper | 
| 32 | { | 
| 33 | public const DATATYPE_CHECKSUM = 'checksum'; | 
| 34 | |
| 35 | private array $metaMetadataCollectionToExport; | 
| 36 | private ChecksumGenerator $checksumGenerator; | 
| 37 | |
| 38 | public function __construct(ChecksumGenerator $checksumGenerator, array $metaMetadataCollectionToExport) | 
| 39 | { | 
| 40 | $this->metaMetadataCollectionToExport = $metaMetadataCollectionToExport; | 
| 41 | $this->checksumGenerator = $checksumGenerator; | 
| 42 | } | 
| 43 | |
| 44 | public function getMetadataProperties(Property $property): array | 
| 45 | { | 
| 46 | $fields = []; | 
| 47 | |
| 48 | foreach ($this->metaMetadataCollectionToExport as $key => $stringProperty) { | 
| 49 | $fields['uri'] = $property->getUri(); | 
| 50 | $metaProperty = $property->getOnePropertyValue(new Property($stringProperty)); | 
| 51 | if ($metaProperty !== null) { | 
| 52 | $fields[$key] = $metaProperty instanceof Resource | 
| 53 | ? $metaProperty->getUri() | 
| 54 | : (string) $metaProperty; | 
| 55 | } | 
| 56 | } | 
| 57 | |
| 58 | if (!$this->isIgnoredForCollectionGathering($property)) { | 
| 59 | $fields[self::DATATYPE_CHECKSUM] = $this->checksumGenerator->getRangeChecksum($property); | 
| 60 | } | 
| 61 | |
| 62 | return $fields; | 
| 63 | } | 
| 64 | |
| 65 | private function isIgnoredForCollectionGathering(Property $property): bool | 
| 66 | { | 
| 67 | return in_array($property->getUri(), $this->getIgnoredProperties()) || $property->getRange() === null; | 
| 68 | } | 
| 69 | |
| 70 | private function getIgnoredProperties(): array | 
| 71 | { | 
| 72 | return [ | 
| 73 | OntologyRdf::RDF_TYPE, | 
| 74 | taoTests_models_classes_TestsService::PROPERTY_TEST_TESTMODEL, | 
| 75 | RDFS_LABEL | 
| 76 | ]; | 
| 77 | } | 
| 78 | } |