Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.00% |
17 / 20 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| TemplateHeaderParser | |
85.00% |
17 / 20 |
|
0.00% |
0 / 1 |
9.27 | |
0.00% |
0 / 1 |
| parse | |
85.00% |
17 / 20 |
|
0.00% |
0 / 1 |
9.27 | |||
| 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\Parser; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\taoQtiItem\model\import\TemplateInterface; |
| 27 | use oat\generis\model\GenerisRdf; |
| 28 | use oat\generis\model\OntologyAwareTrait; |
| 29 | |
| 30 | class TemplateHeaderParser extends ConfigurableService |
| 31 | { |
| 32 | use OntologyAwareTrait; |
| 33 | |
| 34 | public function parse(TemplateInterface $template, array $metaDataArray): array |
| 35 | { |
| 36 | $headers = []; |
| 37 | $csvColumns = $template->getDefinition()['columns'] ?? []; |
| 38 | foreach ($csvColumns as $key => $val) { |
| 39 | if (strpos($key, "_score") !== false) { |
| 40 | for ($i = 1; $i <= 4; $i++) { |
| 41 | $headers[] = 'choice_' . $i . '_score'; |
| 42 | } |
| 43 | |
| 44 | continue; |
| 45 | } |
| 46 | |
| 47 | if (strpos($key, 'choice_') !== false) { |
| 48 | for ($i = 1; $i <= 4; $i++) { |
| 49 | $headers[] = 'choice_' . $i; |
| 50 | } |
| 51 | |
| 52 | continue; |
| 53 | } |
| 54 | |
| 55 | if (strpos($key, 'metadata') !== false) { |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | $headers[] = $key; |
| 60 | } |
| 61 | |
| 62 | if (isset($metaDataArray)) { |
| 63 | foreach ($metaDataArray as $property) { |
| 64 | $aliasProperty = $property->getProperty(GenerisRdf::PROPERTY_ALIAS); |
| 65 | $aliasName = (string)$property->getOnePropertyValue($aliasProperty); |
| 66 | $headers[] = "metadata_" . $aliasName; |
| 67 | } |
| 68 | } |
| 69 | return $headers; |
| 70 | } |
| 71 | } |