Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
taoItems_actions_ItemImport | |
0.00% |
0 / 23 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 1 |
index | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAvailableImportHandlers | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
replaceAvailableImportHandlers | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
getFeatureFlagChecker | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
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-2021 (update and modification) Open Assessment Technologies SA; |
25 | */ |
26 | |
27 | declare(strict_types=1); |
28 | |
29 | use oat\taoQtiItem\model\import\CsvItemImporter; |
30 | use oat\tao\model\featureFlag\FeatureFlagChecker; |
31 | use oat\tao\model\featureFlag\FeatureFlagCheckerInterface; |
32 | |
33 | /** |
34 | * This controller provide the actions to import items |
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 taoItems |
39 | * |
40 | */ |
41 | class taoItems_actions_ItemImport extends tao_actions_Import |
42 | { |
43 | /** @deprecated Use oat\tao\model\featureFlag\FeatureFlagCheckerInterface::FEATURE_FLAG_TABULAR_IMPORT */ |
44 | public const FEATURE_FLAG_TABULAR_IMPORT = FeatureFlagCheckerInterface::FEATURE_FLAG_TABULAR_IMPORT; |
45 | |
46 | /** |
47 | * overwrite the parent index to add the requiresRight for Items only |
48 | * |
49 | * @requiresRight id WRITE |
50 | * @requiresRight classUri WRITE |
51 | */ |
52 | public function index() |
53 | { |
54 | parent::index(); |
55 | } |
56 | |
57 | protected function getAvailableImportHandlers() |
58 | { |
59 | $returnValue = $this->replaceAvailableImportHandlers(); |
60 | |
61 | $itemModelClass = $this->getClass(taoItems_models_classes_itemModel::CLASS_URI_MODELS); |
62 | foreach ($itemModelClass->getInstances() as $model) { |
63 | $impl = taoItems_models_classes_ItemsService::singleton()->getItemModelImplementation($model); |
64 | if (in_array('tao_models_classes_import_ImportProvider', class_implements($impl))) { |
65 | foreach ($impl->getImportHandlers() as $handler) { |
66 | array_unshift($returnValue, $handler); |
67 | } |
68 | } |
69 | } |
70 | |
71 | return $returnValue; |
72 | } |
73 | |
74 | private function replaceAvailableImportHandlers(): array |
75 | { |
76 | $returnValue = parent::getAvailableImportHandlers(); |
77 | |
78 | foreach (array_keys($returnValue) as $key) { |
79 | if ($returnValue[$key] instanceof \tao_models_classes_import_CsvImporter) { |
80 | $tabularImportEnabled = $this |
81 | ->getFeatureFlagChecker() |
82 | ->isEnabled(FeatureFlagCheckerInterface::FEATURE_FLAG_TABULAR_IMPORT); |
83 | |
84 | if ($tabularImportEnabled) { |
85 | $importer = new CsvItemImporter($this->getPsrRequest()); |
86 | $importer->setServiceLocator($this->getServiceLocator()); |
87 | $returnValue[$key] = $importer; |
88 | |
89 | continue; |
90 | } |
91 | |
92 | unset($returnValue[$key]); |
93 | } |
94 | } |
95 | |
96 | return $returnValue; |
97 | } |
98 | |
99 | private function getFeatureFlagChecker(): FeatureFlagCheckerInterface |
100 | { |
101 | return $this->getServiceLocator()->get(FeatureFlagChecker::class); |
102 | } |
103 | } |