Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ItemMediaCollector | |
100.00% |
20 / 20 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getItemMediaResources | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
3 | |||
| getImgElements | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getSharedStimulus | |
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) 2025 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoMediaManager\model\relation\service; |
| 24 | |
| 25 | use common_Exception; |
| 26 | use core_kernel_classes_Resource as Resource; |
| 27 | use oat\generis\model\data\Ontology; |
| 28 | use oat\taoQtiItem\model\qti\container\ContainerItemBody; |
| 29 | use oat\taoQtiItem\model\qti\Element; |
| 30 | use oat\taoQtiItem\model\qti\Service as ItemsService; |
| 31 | use tao_helpers_Uri; |
| 32 | |
| 33 | class ItemMediaCollector |
| 34 | { |
| 35 | private Ontology $ontology; |
| 36 | private ItemsService $itemsService; |
| 37 | public function __construct(Ontology $ontology, ItemsService $itemsService) |
| 38 | { |
| 39 | $this->ontology = $ontology; |
| 40 | $this->itemsService = $itemsService; |
| 41 | } |
| 42 | public function getItemMediaResources(string $itemUri): array |
| 43 | { |
| 44 | $mediaUris = []; |
| 45 | $itemResource = $this->ontology->getResource($itemUri); |
| 46 | $itemBody = $this->itemsService->getDataItemByRdfItem($itemResource)->getBody(); |
| 47 | |
| 48 | foreach ($this->getImgElements($itemBody) as $element) { |
| 49 | $mediaUris[] = tao_helpers_Uri::decode(str_replace( |
| 50 | 'taomedia://mediamanager/', |
| 51 | '', |
| 52 | $element->getAttributeValue('src') |
| 53 | )); |
| 54 | } |
| 55 | |
| 56 | foreach ($this->getSharedStimulus($itemBody) as $element) { |
| 57 | $mediaUris[] = tao_helpers_Uri::decode(str_replace( |
| 58 | 'taomedia://mediamanager/', |
| 59 | '', |
| 60 | $element->getAttributeValue('href') |
| 61 | )); |
| 62 | } |
| 63 | |
| 64 | return $mediaUris; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return Element[] |
| 69 | * @throws common_Exception |
| 70 | */ |
| 71 | private function getImgElements($itemBody): array |
| 72 | { |
| 73 | return $itemBody->getComposingElements('oat\taoQtiItem\model\qti\Img'); |
| 74 | } |
| 75 | |
| 76 | private function getSharedStimulus(ContainerItemBody $itemBody) |
| 77 | { |
| 78 | return $itemBody->getComposingElements('oat\taoQtiItem\model\qti\XInclude'); |
| 79 | } |
| 80 | } |