Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| tao_actions_form_Import | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
6 | |||
| initForm | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| initElements | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
| 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 | |
| 25 | /** |
| 26 | * This container initialize the import form. |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 30 | * @package tao |
| 31 | |
| 32 | */ |
| 33 | class tao_actions_form_Import extends tao_helpers_form_FormContainer |
| 34 | { |
| 35 | // --- ASSOCIATIONS --- |
| 36 | |
| 37 | |
| 38 | // --- ATTRIBUTES --- |
| 39 | |
| 40 | private $importHandlers = []; |
| 41 | |
| 42 | /** |
| 43 | * @var tao_helpers_form_Form |
| 44 | */ |
| 45 | private $subForm = null; |
| 46 | // --- OPERATIONS --- |
| 47 | |
| 48 | /** |
| 49 | * Initialise the form for the given importHandlers |
| 50 | * |
| 51 | * @param tao_models_classes_import_ImportHandler $importHandler |
| 52 | * @param array $availableHandlers |
| 53 | * @param core_kernel_classes_Resource $class |
| 54 | * @param array $options |
| 55 | * @internal param array $importHandlers |
| 56 | * @internal param tao_helpers_form_Form $subForm |
| 57 | */ |
| 58 | public function __construct($importHandler, $availableHandlers, $class, $options = []) |
| 59 | { |
| 60 | $this->importHandlers = $availableHandlers; |
| 61 | if (!is_null($importHandler)) { |
| 62 | $this->subForm = $importHandler->getForm(); |
| 63 | } |
| 64 | parent::__construct( |
| 65 | [ |
| 66 | 'importHandler' => get_class($importHandler), |
| 67 | 'classUri' => $class->getUri(), |
| 68 | 'id' => $class->getUri() |
| 69 | ], |
| 70 | $options |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * inits the import form |
| 76 | * |
| 77 | * @access public |
| 78 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 79 | * @return mixed |
| 80 | */ |
| 81 | public function initForm() |
| 82 | { |
| 83 | $this->form = tao_helpers_form_FormFactory::getForm('import'); |
| 84 | |
| 85 | $this->form->setActions(is_null($this->subForm) ? [] : $this->subForm->getActions('top'), 'top'); |
| 86 | $this->form->setActions(is_null($this->subForm) ? [] : $this->subForm->getActions('bottom'), 'bottom'); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Inits the element to select the importhandler |
| 91 | * and takes over the elements of the import form |
| 92 | * |
| 93 | * @access public |
| 94 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 95 | * @return mixed |
| 96 | */ |
| 97 | public function initElements() |
| 98 | { |
| 99 | //create the element to select the import format |
| 100 | $formatElt = tao_helpers_form_FormFactory::getElement('importHandler', 'Radiobox'); |
| 101 | $formatElt->setDescription(__('Choose import format')); |
| 102 | $formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); // should never happen anyway |
| 103 | $importHandlerOptions = []; |
| 104 | foreach ($this->importHandlers as $importHandler) { |
| 105 | $importHandlerOptions[get_class($importHandler)] = $importHandler->getLabel(); |
| 106 | } |
| 107 | $formatElt->setOptions($importHandlerOptions); |
| 108 | |
| 109 | |
| 110 | $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); |
| 111 | // $classUriElt->setValue($class->getUri()); |
| 112 | $this->form->addElement($classUriElt); |
| 113 | |
| 114 | $classUriElt = tao_helpers_form_FormFactory::getElement('id', 'Hidden'); |
| 115 | $this->form->addElement($classUriElt); |
| 116 | |
| 117 | $this->form->addElement($formatElt); |
| 118 | |
| 119 | if (!is_null($this->subForm)) { |
| 120 | // load dynamically the method regarding the selected format |
| 121 | $this->form->setElements(array_merge($this->form->getElements(), $this->subForm->getElements())); |
| 122 | foreach ($this->subForm->getGroups() as $key => $group) { |
| 123 | $this->form->createGroup($key, $group['title'], $group['elements'], $group['options']); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |