Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
taoItems_actions_ItemExport | |
0.00% |
0 / 42 |
|
0.00% |
0 / 6 |
272 | |
0.00% |
0 / 1 |
index | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getAvailableExportHandlers | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
42 | |||
getClassInstances | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
getFormFactory | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
getResourcesToExport | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
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 Psr\Container\ContainerExceptionInterface; |
29 | use Psr\Container\NotFoundExceptionInterface; |
30 | use tao_models_classes_export_ExportHandler as ExportHandlerInterface; |
31 | |
32 | /** |
33 | * This controller provide the actions to export items |
34 | * |
35 | * @author CRP Henri Tudor - TAO Team - {@link http://www.tao.lu} |
36 | * @license GPLv2 http://www.opensource.org/licenses/gpl-2.0.php |
37 | * @package taoItems |
38 | * |
39 | */ |
40 | class taoItems_actions_ItemExport extends tao_actions_Export |
41 | { |
42 | private const FEATURE_FLAG_QTI3_EXPORT = 'FEATURE_FLAG_QTI3_EXPORT'; |
43 | |
44 | /** |
45 | * overwrite the parent index to add the requiresRight for Items only |
46 | * |
47 | * @requiresRight id READ |
48 | * @throws common_Exception |
49 | * @see tao_actions_Import::index() |
50 | */ |
51 | public function index() |
52 | { |
53 | parent::index(); |
54 | } |
55 | |
56 | protected function getAvailableExportHandlers(): array |
57 | { |
58 | $returnValue = parent::getAvailableExportHandlers(); |
59 | |
60 | $itemModelClass = $this->getClass(taoItems_models_classes_itemModel::CLASS_URI_MODELS); |
61 | $itemModels = $itemModelClass->getInstances(); |
62 | foreach ($itemModels as $model) { |
63 | $impl = taoItems_models_classes_ItemsService::singleton()->getItemModelImplementation($model); |
64 | if (in_array('tao_models_classes_export_ExportProvider', class_implements($impl), true)) { |
65 | foreach ($impl->getExportHandlers() as $handler) { |
66 | if ($this->isHandlerEnabled($handler)) { |
67 | array_unshift($returnValue, $handler); |
68 | } |
69 | } |
70 | } |
71 | } |
72 | |
73 | $instances = $this->getClassInstances(); |
74 | if (!count($instances)) { |
75 | $returnValue = array_filter( |
76 | $returnValue, |
77 | static function (ExportHandlerInterface $handler) { |
78 | return $handler instanceof tao_models_classes_export_RdfExporter; |
79 | } |
80 | ); |
81 | } |
82 | |
83 | |
84 | return $returnValue; |
85 | } |
86 | |
87 | public function getClassInstances(): array |
88 | { |
89 | $instances = []; |
90 | $classUri = $this->hasPostParameter('classUri') ? $this->getPostParameter('classUri') : ''; |
91 | if ($classUri) { |
92 | $class = $this->getClass(tao_helpers_Uri::decode($classUri)); |
93 | $instances = $class->getInstances(true); |
94 | } |
95 | return $instances; |
96 | } |
97 | |
98 | protected function getFormFactory( |
99 | array $handlers, |
100 | ExportHandlerInterface $exporter, |
101 | core_kernel_classes_Resource $selectedResource, |
102 | array $formData |
103 | ): tao_actions_form_Export { |
104 | $formFactory = parent::getFormFactory($handlers, $exporter, $selectedResource, $formData); |
105 | $instances = $this->getClassInstances(); |
106 | if (!count($instances)) { |
107 | $formFactory->setInfoBox( |
108 | __('<b>Note</b>: For empty classes, the RDF format<br />is the only available format.') |
109 | ); |
110 | } |
111 | return $formFactory; |
112 | } |
113 | |
114 | /** |
115 | * Function returns items to export. |
116 | * Items that has no content (<b>QTI items</b> without <i>qti.xml</i> file or empty <b>Open Web Items</b>) will be |
117 | * filtered |
118 | * |
119 | * @return core_kernel_classes_Resource[] An array of items. |
120 | */ |
121 | protected function getResourcesToExport() |
122 | { |
123 | $resources = parent::getResourcesToExport(); |
124 | $service = taoItems_models_classes_ItemsService::singleton(); |
125 | |
126 | $resources = array_filter($resources, function ($val) use ($service) { |
127 | return $service->hasItemContent($val); |
128 | }); |
129 | |
130 | return $resources; |
131 | } |
132 | |
133 | /** |
134 | * TODO: This was created only to temporary handle QTI3 Export feature. Will be removed. |
135 | * @throws ContainerExceptionInterface |
136 | * @throws NotFoundExceptionInterface |
137 | */ |
138 | private function isHandlerEnabled(ExportHandlerInterface $handler): bool |
139 | { |
140 | if ( |
141 | !$this->getPsrContainer()->get(FeatureFlagChecker::class)->isEnabled(self::FEATURE_FLAG_QTI3_EXPORT) |
142 | && $handler instanceof oat\taoQtiItem\model\Export\Qti3Package\Handler |
143 | ) { |
144 | return false; |
145 | } |
146 | |
147 | return true; |
148 | } |
149 | } |