Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
12 / 14 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| MetadataRepository | |
85.71% |
12 / 14 |
|
50.00% |
1 / 2 |
7.14 | |
0.00% |
0 / 1 |
| findMetadataByClassUri | |
83.33% |
10 / 12 |
|
0.00% |
0 / 1 |
6.17 | |||
| isTextWidget | |
100.00% |
2 / 2 |
|
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) 2021 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiItem\model\import\Repository; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\generis\model\GenerisRdf; |
| 27 | use oat\generis\model\OntologyAwareTrait; |
| 28 | use tao_helpers_form_elements_Htmlarea as HtmlArea; |
| 29 | use tao_helpers_form_elements_Textarea as TextArea; |
| 30 | use tao_helpers_form_elements_Textbox as TextBox; |
| 31 | use core_kernel_classes_Property; |
| 32 | |
| 33 | class MetadataRepository extends ConfigurableService |
| 34 | { |
| 35 | use OntologyAwareTrait; |
| 36 | |
| 37 | private const TEXT_WIDGETS = [ |
| 38 | TextBox::WIDGET_ID, |
| 39 | TextArea::WIDGET_ID, |
| 40 | HtmlArea::WIDGET_ID, |
| 41 | ]; |
| 42 | |
| 43 | public function findMetadataByClassUri(string $uri): array |
| 44 | { |
| 45 | $metaDataArray = []; |
| 46 | $class = $this->getClass($uri); |
| 47 | $aliasProperty = $class->getProperty(GenerisRdf::PROPERTY_ALIAS); |
| 48 | $classProperties = $class->getProperties(true); |
| 49 | |
| 50 | if ($classProperties) { |
| 51 | foreach ($classProperties as $property) { |
| 52 | $aliasName = (string)$property->getOnePropertyValue($aliasProperty); |
| 53 | if (!$property->getWidget()) { |
| 54 | continue; |
| 55 | } |
| 56 | if ($aliasName && $this->isTextWidget($property)) { |
| 57 | $metaDataArray[] = $property; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | return $metaDataArray; |
| 62 | } |
| 63 | |
| 64 | private function isTextWidget(core_kernel_classes_Property $property): bool |
| 65 | { |
| 66 | $widgetUri = $property->getWidget()->getUri(); |
| 67 | return in_array($widgetUri, self::TEXT_WIDGETS, true); |
| 68 | } |
| 69 | } |