Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
80.00% |
8 / 10 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CsvTemplateRepository | |
80.00% |
8 / 10 |
|
50.00% |
1 / 2 |
5.20 | |
0.00% |
0 / 1 |
| findById | |
77.78% |
7 / 9 |
|
0.00% |
0 / 1 |
4.18 | |||
| getTemplates | |
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) 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\taoQtiItem\model\import\CsvTemplate; |
| 27 | use oat\taoQtiItem\model\import\TemplateInterface; |
| 28 | |
| 29 | class CsvTemplateRepository extends ConfigurableService implements TemplateRepositoryInterface |
| 30 | { |
| 31 | public const OPTION_TEMPLATES = 'templates'; |
| 32 | |
| 33 | public function findById(string $id): ?TemplateInterface |
| 34 | { |
| 35 | if ($id === self::DEFAULT) { |
| 36 | return new CsvTemplate( |
| 37 | TemplateRepositoryInterface::DEFAULT, |
| 38 | TemplateRepositoryInterface::DEFAULT_DEFINITION |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | foreach ($this->getTemplates() as $template) { |
| 43 | if ($template['id'] === $id) { |
| 44 | return new CsvTemplate($template['id'], $template['definition']); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return null; |
| 49 | } |
| 50 | |
| 51 | private function getTemplates(): array |
| 52 | { |
| 53 | return $this->getOption(self::OPTION_TEMPLATES, []); |
| 54 | } |
| 55 | } |