Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| MetadataExporter | |
0.00% |
0 / 17 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| export | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| extract | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| inject | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| registerMetadataService | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | |
| 22 | namespace oat\taoQtiItem\model\qti\metadata\exporter; |
| 23 | |
| 24 | use oat\tao\model\metadata\exception\MetadataExportException; |
| 25 | use oat\taoQtiItem\model\qti\metadata\AbstractMetadataService; |
| 26 | use oat\taoQtiItem\model\qti\metadata\MetadataService; |
| 27 | |
| 28 | /** |
| 29 | * Class MetadataExporter |
| 30 | * Export metadata service |
| 31 | * |
| 32 | * @package oat\taoQtiItem\model\qti\metadata\exporter |
| 33 | */ |
| 34 | class MetadataExporter extends AbstractMetadataService |
| 35 | { |
| 36 | public function export(\core_kernel_classes_Resource $resource, \DOMDocument $imsManifest) |
| 37 | { |
| 38 | $this->setMetadataValues($this->extract($resource)); |
| 39 | foreach (array_keys($this->getMetadataValues()) as $identifier) { |
| 40 | $this->inject($identifier, $imsManifest); |
| 41 | } |
| 42 | return $imsManifest; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Extract metadata value form a resource |
| 47 | * |
| 48 | * {@inheritdoc} |
| 49 | */ |
| 50 | public function extract($resource) |
| 51 | { |
| 52 | if (! $resource instanceof \core_kernel_classes_Resource) { |
| 53 | throw new MetadataExportException( |
| 54 | __('Metadata export requires an instance of core_kernel_classes_Resource to extract metadata') |
| 55 | ); |
| 56 | } |
| 57 | return parent::extract($resource); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Inject an identified metadata value to a dom IMS manifest |
| 62 | * |
| 63 | * {@inheritdoc} |
| 64 | */ |
| 65 | public function inject($identifier, $imsManifest) |
| 66 | { |
| 67 | if (! $imsManifest instanceof \DOMDocument) { |
| 68 | throw new MetadataExportException( |
| 69 | __('Metadata export requires an instance of DomManifest to inject metadata') |
| 70 | ); |
| 71 | } |
| 72 | |
| 73 | parent::inject($identifier, $imsManifest); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Allow to register, into the config, the current exporter service |
| 78 | */ |
| 79 | protected function registerMetadataService() |
| 80 | { |
| 81 | $metadataService = $this->getServiceLocator()->get(MetadataService::SERVICE_ID); |
| 82 | $metadataService->setOption(MetadataService::EXPORTER_KEY, $this); |
| 83 | $this->getServiceManager()->register(MetadataService::SERVICE_ID, $metadataService); |
| 84 | } |
| 85 | } |