Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| ImportHandlerFactory | |
0.00% |
0 / 14 |
|
0.00% |
0 / 5 |
56 | |
0.00% |
0 / 1 |
| createAvailable | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| createByMediaId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| isQtiMedia | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getOntology | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSharedStimulusImporter | |
0.00% |
0 / 1 |
|
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoMediaManager\model; |
| 22 | |
| 23 | use oat\generis\model\data\Ontology; |
| 24 | use oat\oatbox\service\ConfigurableService; |
| 25 | use tao_models_classes_import_ImportHandler; |
| 26 | use Throwable; |
| 27 | |
| 28 | class ImportHandlerFactory extends ConfigurableService |
| 29 | { |
| 30 | /** |
| 31 | * @return tao_models_classes_import_ImportHandler[] |
| 32 | */ |
| 33 | public function createAvailable(): array |
| 34 | { |
| 35 | return [ |
| 36 | new FileImporter(), |
| 37 | $this->getSharedStimulusImporter() |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | public function createByMediaId(string $id): tao_models_classes_import_ImportHandler |
| 42 | { |
| 43 | return $this->isQtiMedia($id) |
| 44 | ? $this->getSharedStimulusImporter()->setInstanceUri($id) |
| 45 | : new FileImporter($id); |
| 46 | } |
| 47 | |
| 48 | private function isQtiMedia(string $id): bool |
| 49 | { |
| 50 | try { |
| 51 | $class = $this->getOntology()->getClass($id); |
| 52 | |
| 53 | $mimeType = $class->getProperty('http://www.tao.lu/Ontologies/TAOMedia.rdf#mimeType'); |
| 54 | |
| 55 | return (string)$class->getOnePropertyValue($mimeType) === MediaService::SHARED_STIMULUS_MIME_TYPE; |
| 56 | } catch (Throwable $exception) { |
| 57 | return false; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | private function getOntology(): Ontology |
| 62 | { |
| 63 | return $this->getServiceLocator()->get(Ontology::SERVICE_ID); |
| 64 | } |
| 65 | |
| 66 | private function getSharedStimulusImporter(): SharedStimulusImporter |
| 67 | { |
| 68 | return $this->getServiceLocator()->get(SharedStimulusImporter::class); |
| 69 | } |
| 70 | } |