Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 47 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FileImportForm | |
0.00% |
0 / 47 |
|
0.00% |
0 / 3 |
72 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| initForm | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| initElements | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
42 | |||
| 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) 2014 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoMediaManager\model; |
| 24 | |
| 25 | use core_kernel_classes_Resource; |
| 26 | use oat\generis\Helper\SystemHelper; |
| 27 | use oat\tao\model\TaoOntology; |
| 28 | |
| 29 | /** |
| 30 | * Service methods to manage the Media |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Antoine Robin, <antoine.robin@vesperiagroup.com> |
| 34 | * @package taoMediaManager |
| 35 | */ |
| 36 | class FileImportForm extends \tao_helpers_form_FormContainer |
| 37 | { |
| 38 | private $instanceUri; |
| 39 | |
| 40 | public function __construct($instanceUri) |
| 41 | { |
| 42 | $this->instanceUri = $instanceUri; |
| 43 | parent::__construct(); |
| 44 | } |
| 45 | |
| 46 | protected function initForm() |
| 47 | { |
| 48 | $this->form = new \tao_helpers_form_xhtml_Form('export'); |
| 49 | $submitElt = \tao_helpers_form_FormFactory::getElement('import', 'Free'); |
| 50 | $submitElt->setValue( |
| 51 | '<a href="#" class="form-submitter btn-success small"><span class="icon-import"></span> ' |
| 52 | . __('Import') . '</a>' |
| 53 | ); |
| 54 | |
| 55 | $this->form->setActions([$submitElt], 'bottom'); |
| 56 | $this->form->setActions([], 'top'); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Used to create the form elements and bind them to the form instance |
| 61 | * |
| 62 | * @access protected |
| 63 | * @return mixed |
| 64 | */ |
| 65 | protected function initElements() |
| 66 | { |
| 67 | //create file upload form box |
| 68 | $fileElt = \tao_helpers_form_FormFactory::getElement('source', 'AsyncFile'); |
| 69 | $fileElt->setDescription(__("Add a media file")); |
| 70 | if (isset($_POST['import_sent_file'])) { |
| 71 | $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty')); |
| 72 | } else { |
| 73 | $fileElt->addValidator(\tao_helpers_form_FormFactory::getValidator('NotEmpty', ['message' => ''])); |
| 74 | } |
| 75 | $fileElt->addValidators([ |
| 76 | \tao_helpers_form_FormFactory::getValidator('FileSize', ['max' => SystemHelper::getFileUploadLimit()]) |
| 77 | ]); |
| 78 | |
| 79 | $this->form->addElement($fileElt); |
| 80 | |
| 81 | $langService = \tao_models_classes_LanguageService::singleton(); |
| 82 | $dataUsage = new core_kernel_classes_Resource(TaoOntology::PROPERTY_STANCE_LANGUAGE_USAGE_DATA); |
| 83 | $dataLang = \common_session_SessionManager::getSession()->getDataLanguage(); |
| 84 | $dataLang = 'http://www.tao.lu/Ontologies/TAO.rdf#Lang' . $dataLang; |
| 85 | if (!is_null($this->instanceUri)) { |
| 86 | $instance = new core_kernel_classes_Resource($this->instanceUri); |
| 87 | $lang = $instance->getOnePropertyValue( |
| 88 | new \core_kernel_classes_Property(TaoMediaOntology::PROPERTY_LANGUAGE) |
| 89 | ); |
| 90 | |
| 91 | if ($lang instanceof core_kernel_classes_Resource) { |
| 92 | $dataLang = $lang->getUri(); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | $langOptions = []; |
| 97 | foreach ($langService->getAvailableLanguagesByUsage($dataUsage) as $lang) { |
| 98 | $langOptions[\tao_helpers_Uri::encode($lang->getUri())] = $lang->getLabel(); |
| 99 | } |
| 100 | $langElt = \tao_helpers_form_FormFactory::getElement('lang', 'Combobox'); |
| 101 | $langElt->setValue(\tao_helpers_Uri::encode($dataLang)); |
| 102 | $langElt->setOptions($langOptions); |
| 103 | $this->form->addElement($langElt); |
| 104 | |
| 105 | |
| 106 | $this->form->createGroup('options', __('Media Options'), [ |
| 107 | $langElt |
| 108 | ]); |
| 109 | |
| 110 | $fileSentElt = \tao_helpers_form_FormFactory::getElement('import_sent_file', 'Hidden'); |
| 111 | $fileSentElt->setValue(1); |
| 112 | $this->form->addElement($fileSentElt); |
| 113 | |
| 114 | if (!is_null($this->instanceUri)) { |
| 115 | $instanceElt = \tao_helpers_form_FormFactory::getElement('instanceUri', 'Hidden'); |
| 116 | $instanceElt->setValue($this->instanceUri); |
| 117 | $this->form->addElement($instanceElt); |
| 118 | } |
| 119 | } |
| 120 | } |