Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
79.49% |
31 / 39 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| ItemsQtiTemplateRender | |
79.49% |
31 / 39 |
|
50.00% |
2 / 4 |
8.55 | |
0.00% |
0 / 1 |
| processItem | |
100.00% |
27 / 27 |
|
100.00% |
1 / 1 |
3 | |||
| processResultSet | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| withRenderer | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getRenderer | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
| 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-2023 (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\Template; |
| 24 | |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\taoQtiItem\model\import\ItemImportResult; |
| 27 | use oat\taoQtiItem\model\import\ItemInterface; |
| 28 | use oat\taoQtiItem\model\import\Decorator\CvsToQtiTemplateDecorator; |
| 29 | use oat\taoQtiItem\model\import\ProcessedItemResult; |
| 30 | use oat\taoQtiItem\model\import\TemplateInterface; |
| 31 | use Renderer; |
| 32 | |
| 33 | class ItemsQtiTemplateRender extends ConfigurableService implements ItemsTemplateRenderInterface |
| 34 | { |
| 35 | /** @var Renderer */ |
| 36 | private $renderer; |
| 37 | |
| 38 | public function processItem(ItemInterface $item, TemplateInterface $xmlQtiTemplate): string |
| 39 | { |
| 40 | $renderer = $this->getRenderer(); |
| 41 | |
| 42 | $decorator = new CvsToQtiTemplateDecorator($xmlQtiTemplate); |
| 43 | |
| 44 | $templatePath = $decorator->getQtiTemplatePath($item); |
| 45 | |
| 46 | $correctChoices = $item->getCorrectChoices(); |
| 47 | |
| 48 | $renderer->setTemplate($templatePath); |
| 49 | $renderer->setMultipleData( |
| 50 | [ |
| 51 | 'isMapResponse' => $item->isMapResponse(), |
| 52 | 'isMatchCorrectResponse' => $item->isMatchCorrectResponse(), |
| 53 | 'isNoneResponse' => $item->isNoneResponse(), |
| 54 | 'choices' => $item->getChoices(), |
| 55 | 'hasCorrectChoices' => !empty($correctChoices), |
| 56 | 'correctChoices' => $correctChoices, |
| 57 | 'language' => $item->getLanguage(), |
| 58 | 'maxChoices' => $item->getMaxChoices(), |
| 59 | 'maxScore' => $item->getMaxScore(), |
| 60 | 'metaData' => $item->getMetadata(), |
| 61 | 'minChoices' => $item->getMinChoices(), |
| 62 | 'name' => $item->getName(), |
| 63 | 'question' => $item->getQuestion(), |
| 64 | 'shuffle' => $item->isShuffle() ? 'true' : 'false', |
| 65 | 'responseDeclarationCardinality' => $item->getMaxChoices() === 1 ? 'single' : 'multiple', |
| 66 | 'outcomeDeclarationScoreCardinality' => 'single', |
| 67 | 'outcomeDeclarationMaxScoreCardinality' => 'single' |
| 68 | ] |
| 69 | ); |
| 70 | |
| 71 | return $renderer->render(); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * @return iterable<ProcessedItemResult> |
| 76 | */ |
| 77 | public function processResultSet(ItemImportResult $itemResults, TemplateInterface $xmlQtiTemplate): iterable |
| 78 | { |
| 79 | $result = []; |
| 80 | foreach ($itemResults->getItems() as $lineNumber => $item) { |
| 81 | $result[$lineNumber] = new ProcessedItemResult( |
| 82 | $this->processItem($item, $xmlQtiTemplate), |
| 83 | $item->getMetadata() |
| 84 | ); |
| 85 | } |
| 86 | |
| 87 | return $result; |
| 88 | } |
| 89 | |
| 90 | public function withRenderer(Renderer $renderer): self |
| 91 | { |
| 92 | $this->renderer = $renderer; |
| 93 | return $this; |
| 94 | } |
| 95 | |
| 96 | private function getRenderer(): Renderer |
| 97 | { |
| 98 | if (!$this->renderer) { |
| 99 | $this->renderer = new Renderer(); |
| 100 | } |
| 101 | return $this->renderer; |
| 102 | } |
| 103 | } |