Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
93.33% |
14 / 15 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
ItemToMediaUnitProcessor | |
93.33% |
14 / 15 |
|
80.00% |
4 / 5 |
7.01 | |
0.00% |
0 / 1 |
process | |
90.91% |
10 / 11 |
|
0.00% |
0 / 1 |
3.01 | |||
getItemRelationUpdateService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getElementReferencesExtractor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getQtiService | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getIdDiscoverService | |
100.00% |
1 / 1 |
|
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) 2020 (original work) Open Assessment Technologies SA; |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\taoMediaManager\model\relation\task; |
24 | |
25 | use common_Exception; |
26 | use core_kernel_classes_Resource; |
27 | use Exception; |
28 | use oat\generis\model\OntologyAwareTrait; |
29 | use oat\oatbox\service\ConfigurableService; |
30 | use oat\tao\model\task\migration\service\ResultUnitProcessorInterface; |
31 | use oat\tao\model\task\migration\ResultUnit; |
32 | use oat\taoMediaManager\model\relation\service\IdDiscoverService; |
33 | use oat\taoMediaManager\model\relation\service\update\ItemRelationUpdateService; |
34 | use oat\taoQtiItem\model\qti\parser\ElementReferencesExtractor; |
35 | use oat\taoQtiItem\model\qti\Service; |
36 | |
37 | class ItemToMediaUnitProcessor extends ConfigurableService implements ResultUnitProcessorInterface |
38 | { |
39 | use OntologyAwareTrait; |
40 | |
41 | /** |
42 | * @throws common_Exception |
43 | */ |
44 | public function process(ResultUnit $unit): void |
45 | { |
46 | /** @var core_kernel_classes_Resource $resource */ |
47 | $resource = $unit->getResult(); |
48 | |
49 | if (!($unit->getResult() instanceof core_kernel_classes_Resource)) { |
50 | throw new Exception('Unit is not a resource'); |
51 | } |
52 | $qtiItem = $this->getQtiService()->getDataItemByRdfItem($resource); |
53 | |
54 | $elementReferences = $this->getElementReferencesExtractor() |
55 | ->extractAll($qtiItem) |
56 | ->getAllReferences(); |
57 | |
58 | if (!empty($elementReferences)) { |
59 | $ids = $this->getIdDiscoverService()->discover($elementReferences); |
60 | |
61 | $this->getItemRelationUpdateService() |
62 | ->updateByTargetId($resource->getUri(), $ids); |
63 | } |
64 | } |
65 | |
66 | private function getItemRelationUpdateService(): ItemRelationUpdateService |
67 | { |
68 | return $this->getServiceLocator()->get(ItemRelationUpdateService::class); |
69 | } |
70 | |
71 | private function getElementReferencesExtractor(): ElementReferencesExtractor |
72 | { |
73 | return $this->getServiceLocator()->get(ElementReferencesExtractor::class); |
74 | } |
75 | |
76 | private function getQtiService(): Service |
77 | { |
78 | return $this->getServiceLocator()->get(Service::class); |
79 | } |
80 | |
81 | private function getIdDiscoverService(): IdDiscoverService |
82 | { |
83 | return $this->getServiceLocator()->get(IdDiscoverService::class); |
84 | } |
85 | } |