Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 74 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
taoQtiTest_models_classes_import_TestImportForm | |
0.00% |
0 / 74 |
|
0.00% |
0 / 5 |
90 | |
0.00% |
0 / 1 |
initForm | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
initElements | |
0.00% |
0 / 36 |
|
0.00% |
0 / 1 |
6 | |||
isFieldDisabled | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
addMetadataImportElement | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
addItemDestinationPlacementComponent | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 |
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
19 | * (under the project TAO-TRANSFER); |
20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
22 | * 2024 (update and modification) Open Assessment Technologies SA |
23 | */ |
24 | |
25 | /** |
26 | * Import form for QTI packages |
27 | * |
28 | * @access public |
29 | * @author Joel Bout, <joel.bout@tudor.lu> |
30 | * @package taoQTI |
31 | |
32 | */ |
33 | class taoQtiTest_models_classes_import_TestImportForm extends tao_helpers_form_FormContainer |
34 | { |
35 | public const FORM_NAME = 'export'; |
36 | public const METADATA_FORM_ELEMENT_NAME = 'metadata'; |
37 | public const DISABLED_FIELDS = 'disabledFields'; |
38 | |
39 | public const ITEM_CLASS_DESTINATION_FIELD = 'itemClassDestination'; |
40 | public const METADATA_FIELD = 'metadataImport'; |
41 | |
42 | /** |
43 | * (non-PHPdoc) |
44 | * @see tao_helpers_form_FormContainer::initForm() |
45 | */ |
46 | public function initForm() |
47 | { |
48 | $this->form = new tao_helpers_form_xhtml_Form(self::FORM_NAME); |
49 | |
50 | $this->form->setDecorators([ |
51 | 'element' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div']), |
52 | 'group' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-group']), |
53 | 'error' => new tao_helpers_form_xhtml_TagWrapper([ |
54 | 'tag' => 'div', |
55 | 'cssClass' => 'form-error ui-state-error ui-corner-all', |
56 | ]), |
57 | 'actions-bottom' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']), |
58 | 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']) |
59 | ]); |
60 | |
61 | $submitElt = tao_helpers_form_FormFactory::getElement('import', 'Free'); |
62 | $submitElt->setValue( |
63 | '<a href="#" class="form-submitter btn-success small"><span class="icon-import"></span> ' |
64 | . __('Import') . '</a>' |
65 | ); |
66 | |
67 | $this->form->setActions([$submitElt], 'bottom'); |
68 | } |
69 | |
70 | /** |
71 | * (non-PHPdoc) |
72 | * @see tao_helpers_form_FormContainer::initElements() |
73 | */ |
74 | public function initElements() |
75 | { |
76 | //create file upload form box |
77 | $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile'); |
78 | $fileElt->setDescription(__("Add a zip file containing QTI/APIP tests and items")); |
79 | if (isset($_POST['import_sent_qti'])) { |
80 | $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); |
81 | } else { |
82 | $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', ['message' => ''])); |
83 | } |
84 | $fileElt->addValidators([ |
85 | tao_helpers_form_FormFactory::getValidator( |
86 | 'FileMimeType', |
87 | [ |
88 | 'mimetype' => [ |
89 | 'application/zip', |
90 | 'application/x-zip', |
91 | 'application/x-zip-compressed', |
92 | 'application/octet-stream', |
93 | ], |
94 | 'extension' => ['zip'], |
95 | ] |
96 | ), |
97 | tao_helpers_form_FormFactory::getValidator( |
98 | 'FileSize', |
99 | ['max' => \oat\generis\Helper\SystemHelper::getFileUploadLimit()] |
100 | ) |
101 | ]); |
102 | |
103 | |
104 | $this->form->addElement($fileElt); |
105 | |
106 | $this->form->createGroup( |
107 | 'file', |
108 | __('Import a QTI/APIP Content Package'), |
109 | [ |
110 | 'source', |
111 | ] |
112 | ); |
113 | |
114 | $this->addMetadataImportElement(); |
115 | $this->addItemDestinationPlacementComponent(); |
116 | $qtiSentElt = tao_helpers_form_FormFactory::getElement('import_sent_qti', 'Hidden'); |
117 | $qtiSentElt->setValue(1); |
118 | $this->form->addElement($qtiSentElt); |
119 | } |
120 | |
121 | private function isFieldDisabled(string $filedName): bool |
122 | { |
123 | return isset($this->options[self::DISABLED_FIELDS]) |
124 | && in_array($filedName, $this->options[self::DISABLED_FIELDS]); |
125 | } |
126 | |
127 | private function addMetadataImportElement(): void |
128 | { |
129 | if (!$this->isFieldDisabled(self::METADATA_FIELD)) { |
130 | $metadataImport = tao_helpers_form_FormFactory::getElement( |
131 | self::METADATA_FORM_ELEMENT_NAME, |
132 | 'Checkbox' |
133 | ); |
134 | |
135 | $metadataImport->setOptions([self::METADATA_FORM_ELEMENT_NAME => __('QTI metadata as properties')]); |
136 | $metadataImport->setDescription(__('Import')); |
137 | $metadataImport->setLevel(1); |
138 | $this->form->addElement($metadataImport); |
139 | $this->form->addToGroup('file', self::METADATA_FORM_ELEMENT_NAME); |
140 | } |
141 | } |
142 | |
143 | private function addItemDestinationPlacementComponent(): void |
144 | { |
145 | if (!$this->isFieldDisabled(self::ITEM_CLASS_DESTINATION_FIELD)) { |
146 | $selectElt = tao_helpers_form_FormFactory::getElement('selectelt', 'Free'); |
147 | $selectElt->setValue('<div class="item-select-container"></div>'); |
148 | |
149 | $itemClassDestination = tao_helpers_form_FormFactory::getElement( |
150 | self::ITEM_CLASS_DESTINATION_FIELD, |
151 | 'Hidden' |
152 | ); |
153 | |
154 | $this->form->addElement($itemClassDestination); |
155 | $this->form->addElement($selectElt); |
156 | } |
157 | } |
158 | } |