Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| taoTests_actions_TestExport | |
0.00% |
0 / 19 |
|
0.00% |
0 / 3 |
132 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAvailableExportHandlers | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
56 | |||
| isHandlerEnabled | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * 2012-2025 (update and modification) Open Assessment Technologies SA; |
| 25 | */ |
| 26 | |
| 27 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
| 28 | use oat\taoTests\models\MissingTestmodelException; |
| 29 | use Psr\Container\ContainerExceptionInterface; |
| 30 | use Psr\Container\NotFoundExceptionInterface; |
| 31 | use tao_models_classes_export_ExportHandler as ExportHandlerInterface; |
| 32 | |
| 33 | /** |
| 34 | * This controller provide the actions to export tests |
| 35 | * |
| 36 | * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} |
| 37 | * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php |
| 38 | * @package taoTests |
| 39 | * |
| 40 | */ |
| 41 | class taoTests_actions_TestExport extends tao_actions_Export |
| 42 | { |
| 43 | private const FEATURE_FLAG_QTI3_EXPORT = 'FEATURE_FLAG_QTI3_EXPORT'; |
| 44 | |
| 45 | /** |
| 46 | * overwrite the parent index to add the requiresRight for Tests |
| 47 | * |
| 48 | * @requiresRight id READ |
| 49 | * @see tao_actions_Export::index() |
| 50 | */ |
| 51 | public function index() |
| 52 | { |
| 53 | parent::index(); |
| 54 | } |
| 55 | |
| 56 | protected function getAvailableExportHandlers() |
| 57 | { |
| 58 | $returnValue = parent::getAvailableExportHandlers(); |
| 59 | |
| 60 | $resources = $this->getResourcesToExport(); |
| 61 | $testModels = []; |
| 62 | foreach ($resources as $resource) { |
| 63 | try { |
| 64 | $model = taoTests_models_classes_TestsService::singleton()->getTestModel($resource); |
| 65 | $testModels[$model->getUri()] = $model; |
| 66 | } catch (MissingTestmodelException $e) { |
| 67 | // no model found, skip exporter retrieval |
| 68 | } |
| 69 | } |
| 70 | foreach ($testModels as $model) { |
| 71 | $impl = taoTests_models_classes_TestsService::singleton()->getTestModelImplementation($model); |
| 72 | if (in_array('tao_models_classes_export_ExportProvider', class_implements($impl))) { |
| 73 | foreach ($impl->getExportHandlers() as $handler) { |
| 74 | if ($this->isHandlerEnabled($handler)) { |
| 75 | array_unshift($returnValue, $handler); |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return $returnValue; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * TODO: This was created only to temporary handle QTI3 Export feature. Will be removed. |
| 86 | * @throws ContainerExceptionInterface |
| 87 | * @throws NotFoundExceptionInterface |
| 88 | */ |
| 89 | private function isHandlerEnabled(ExportHandlerInterface $handler): bool |
| 90 | { |
| 91 | if ( |
| 92 | !$this->getPsrContainer()->get(FeatureFlagChecker::class)->isEnabled(self::FEATURE_FLAG_QTI3_EXPORT) |
| 93 | && $handler instanceof oat\taoQtiTest\models\export\Formats\Package3p0\TestPackageExport |
| 94 | ) { |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | return true; |
| 99 | } |
| 100 | } |