Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 59 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| QtiPackageImportForm | |
0.00% |
0 / 59 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| initForm | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
2 | |||
| initElements | |
0.00% |
0 / 42 |
|
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 | */ |
| 23 | |
| 24 | namespace oat\taoQtiItem\model\import; |
| 25 | |
| 26 | use oat\generis\Helper\SystemHelper; |
| 27 | use tao_helpers_form_FormContainer; |
| 28 | use tao_helpers_form_xhtml_Form; |
| 29 | use tao_helpers_form_xhtml_TagWrapper; |
| 30 | use tao_helpers_form_FormFactory; |
| 31 | use tao_helpers_Environment; |
| 32 | |
| 33 | /** |
| 34 | * Import form for QTI packages |
| 35 | * |
| 36 | * @access public |
| 37 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 38 | * @package taoQTI |
| 39 | |
| 40 | */ |
| 41 | class QtiPackageImportForm extends tao_helpers_form_FormContainer |
| 42 | { |
| 43 | public const METADATA_FORM_ELEMENT_NAME = 'metadata'; |
| 44 | |
| 45 | /** |
| 46 | * (non-PHPdoc) |
| 47 | * @see tao_helpers_form_FormContainer::initForm() |
| 48 | */ |
| 49 | public function initForm() |
| 50 | { |
| 51 | $this->form = new tao_helpers_form_xhtml_Form('export'); |
| 52 | |
| 53 | $this->form->setDecorators([ |
| 54 | 'element' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div']), |
| 55 | 'group' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-group']), |
| 56 | 'error' => new tao_helpers_form_xhtml_TagWrapper([ |
| 57 | 'tag' => 'div', |
| 58 | 'cssClass' => 'form-error ui-state-error ui-corner-all', |
| 59 | ]), |
| 60 | 'actions-bottom' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']), |
| 61 | 'actions-top' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']) |
| 62 | ]); |
| 63 | |
| 64 | $submitElt = tao_helpers_form_FormFactory::getElement('import', 'Free'); |
| 65 | $submitElt->setValue( |
| 66 | '<a href="#" class="form-submitter btn-success small"><span class="icon-import"></span> ' |
| 67 | . __('Import') . '</a>' |
| 68 | ); |
| 69 | |
| 70 | |
| 71 | $this->form->setActions([$submitElt], 'bottom'); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * (non-PHPdoc) |
| 76 | * @see tao_helpers_form_FormContainer::initElements() |
| 77 | */ |
| 78 | public function initElements() |
| 79 | { |
| 80 | //create file upload form box |
| 81 | $fileElt = tao_helpers_form_FormFactory::getElement('source', 'AsyncFile'); |
| 82 | $fileElt->setDescription(__("Add a ZIP file containing QTI/APIP items")); |
| 83 | if (isset($_POST['import_sent_qti'])) { |
| 84 | $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); |
| 85 | } else { |
| 86 | $fileElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty', ['message' => ''])); |
| 87 | } |
| 88 | $fileElt->addValidators([ |
| 89 | tao_helpers_form_FormFactory::getValidator( |
| 90 | 'FileMimeType', |
| 91 | [ |
| 92 | 'mimetype' => [ |
| 93 | 'application/zip', |
| 94 | 'application/x-zip', |
| 95 | 'application/x-zip-compressed', |
| 96 | 'application/octet-stream', |
| 97 | ], |
| 98 | 'extension' => ['zip'], |
| 99 | ] |
| 100 | ), |
| 101 | tao_helpers_form_FormFactory::getValidator('FileSize', ['max' => SystemHelper::getFileUploadLimit()]) |
| 102 | ]); |
| 103 | $this->form->addElement($fileElt); |
| 104 | |
| 105 | $rollbackElt = tao_helpers_form_FormFactory::getElement('rollback', 'Checkbox'); |
| 106 | $rollbackElt->setOptions(['error' => __('error'), 'warning' => __('warning')]); |
| 107 | $rollbackElt->setDescription(__('Rollback on...')); |
| 108 | $this->form->addElement($rollbackElt); |
| 109 | $metadataImport = tao_helpers_form_FormFactory::getElement(self::METADATA_FORM_ELEMENT_NAME, 'Checkbox'); |
| 110 | $metadataImport->setOptions(['metadata' => __('QTI metadata as properties')]); |
| 111 | $metadataImport->setDescription(__('Import')); |
| 112 | $metadataImport->setLevel(1); |
| 113 | $this->form->addElement($metadataImport); |
| 114 | |
| 115 | $this->form->createGroup( |
| 116 | 'file', |
| 117 | __('Import a QTI/APIP Content Package'), |
| 118 | [ |
| 119 | 'source', |
| 120 | 'rollback', |
| 121 | self::METADATA_FORM_ELEMENT_NAME |
| 122 | ] |
| 123 | ); |
| 124 | |
| 125 | $qtiSentElt = tao_helpers_form_FormFactory::getElement('import_sent_qti', 'Hidden'); |
| 126 | $qtiSentElt->setValue(1); |
| 127 | $this->form->addElement($qtiSentElt); |
| 128 | } |
| 129 | } |