Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 54  | 
               | 
       0.00%  | 
       0 / 5  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| tao_actions_form_Export |         | 
       0.00%  | 
       0 / 54  | 
               | 
       0.00%  | 
       0 / 5  | 
       240 |         | 
       0.00%  | 
       0 / 1  | 
      
| __construct |         | 
       0.00%  | 
       0 / 3  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| setInfoBox |         | 
       0.00%  | 
       0 / 3  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| initForm |         | 
       0.00%  | 
       0 / 16  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| initElements |         | 
       0.00%  | 
       0 / 28  | 
               | 
       0.00%  | 
       0 / 1  | 
       110 | |||
| getFormats |         | 
       0.00%  | 
       0 / 4  | 
               | 
       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 | /** | 
| 25 | * This container initialize the export form. | 
| 26 | * | 
| 27 | * @access public | 
| 28 | * @author Joel Bout, <joel@taotesting.com> | 
| 29 | * @package tao | 
| 30 | |
| 31 | */ | 
| 32 | class tao_actions_form_Export extends tao_helpers_form_FormContainer | 
| 33 | { | 
| 34 | // --- ASSOCIATIONS --- | 
| 35 | |
| 36 | |
| 37 | // --- ATTRIBUTES --- | 
| 38 | /** | 
| 39 | * @var array | 
| 40 | */ | 
| 41 | private $exportHandlers; | 
| 42 | |
| 43 | /** | 
| 44 | * @var tao_helpers_form_Form | 
| 45 | */ | 
| 46 | private $subForm; | 
| 47 | |
| 48 | // --- OPERATIONS --- | 
| 49 | |
| 50 | public function __construct($exportHandlers, $subForm, $data) | 
| 51 | { | 
| 52 | $this->exportHandlers = $exportHandlers; | 
| 53 | $this->subForm = $subForm; | 
| 54 | parent::__construct($data); | 
| 55 | } | 
| 56 | |
| 57 | public function setInfoBox(string $msg): void | 
| 58 | { | 
| 59 | $infoElement = tao_helpers_form_FormFactory::getElement('infoBox', 'Free'); | 
| 60 | $infoElement->setValue($msg); | 
| 61 | $this->form->addElement($infoElement); | 
| 62 | } | 
| 63 | |
| 64 | /** | 
| 65 | * Short description of method initForm | 
| 66 | * | 
| 67 | * @access public | 
| 68 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 69 | * @return mixed | 
| 70 | */ | 
| 71 | public function initForm() | 
| 72 | { | 
| 73 | |
| 74 | $this->form = new tao_helpers_form_xhtml_Form('exportChooser'); | 
| 75 | |
| 76 | $this->form->setDecorators([ | 
| 77 | 'element' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div']), | 
| 78 | 'group' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-group']), | 
| 79 | 'error' => new tao_helpers_form_xhtml_TagWrapper([ | 
| 80 | 'tag' => 'div', | 
| 81 | 'cssClass' => 'form-error ui-state-error ui-corner-all' | 
| 82 | ]), | 
| 83 | 'actions-bottom' => new tao_helpers_form_xhtml_TagWrapper(['tag' => 'div', 'cssClass' => 'form-toolbar']), | 
| 84 | ]); | 
| 85 | |
| 86 | $exportElt = tao_helpers_form_FormFactory::getElement('export', 'Free'); | 
| 87 | $exportElt->setValue( | 
| 88 | '<a href="#" class="form-submitter btn-success small"><span class="icon-export"></span>' | 
| 89 | . __('Export') . '</a>' | 
| 90 | ); | 
| 91 | $this->form->setActions([$exportElt], 'bottom'); | 
| 92 | } | 
| 93 | |
| 94 | /** | 
| 95 | * Short description of method initElements | 
| 96 | * | 
| 97 | * @access public | 
| 98 | * @return mixed | 
| 99 | * @throws common_Exception | 
| 100 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 101 | */ | 
| 102 | public function initElements() | 
| 103 | { | 
| 104 | if (count($this->exportHandlers) > 1) { | 
| 105 | //create the element to select the import format | 
| 106 | $formatElt = tao_helpers_form_FormFactory::getElement('exportHandler', 'Radiobox'); | 
| 107 | $formatElt->setDescription(__('Choose export format')); | 
| 108 | |
| 109 | //mandatory field | 
| 110 | $formatElt->addValidator(tao_helpers_form_FormFactory::getValidator('NotEmpty')); | 
| 111 | $formatElt->setOptions($this->getFormats()); | 
| 112 | |
| 113 | if (isset($_POST['exportHandler'])) { | 
| 114 | if (array_key_exists($_POST['exportHandler'], $this->getFormats())) { | 
| 115 | $formatElt->setValue($_POST['exportHandler']); | 
| 116 | } | 
| 117 | } | 
| 118 | |
| 119 | $this->form->addElement($formatElt); | 
| 120 | $this->form->createGroup('formats', '<h3>' . __('Supported export formats') . '</h3>', ['exportHandler']); | 
| 121 | } | 
| 122 | |
| 123 | if (isset($this->data['instance'])) { | 
| 124 | $item = $this->data['instance']; | 
| 125 | if ($item instanceof core_kernel_classes_Resource) { | 
| 126 | //add an hidden elt for the instance Uri | 
| 127 | $uriElt = tao_helpers_form_FormFactory::getElement('uri', 'Hidden'); | 
| 128 | $uriElt->setValue($item->getUri()); | 
| 129 | $this->form->addElement($uriElt); | 
| 130 | } | 
| 131 | } | 
| 132 | if (isset($this->data['class'])) { | 
| 133 | $class = $this->data['class']; | 
| 134 | if ($class instanceof core_kernel_classes_Class) { | 
| 135 | //add an hidden elt for the class uri | 
| 136 | $classUriElt = tao_helpers_form_FormFactory::getElement('classUri', 'Hidden'); | 
| 137 | $classUriElt->setValue($class->getUri()); | 
| 138 | $this->form->addElement($classUriElt); | 
| 139 | } | 
| 140 | } | 
| 141 | |
| 142 | $idElt = tao_helpers_form_FormFactory::getElement('id', 'Hidden'); | 
| 143 | $this->form->addElement($idElt); | 
| 144 | |
| 145 | foreach ($this->subForm->getElements() as $element) { | 
| 146 | $this->form->addElement($element); | 
| 147 | } | 
| 148 | foreach ($this->subForm->getGroups() as $group) { | 
| 149 | $this->form->createGroup($group['title'], $group['title'], $group['elements'], $group['options']); | 
| 150 | } | 
| 151 | } | 
| 152 | |
| 153 | private function getFormats() | 
| 154 | { | 
| 155 | $returnValue = []; | 
| 156 | foreach ($this->exportHandlers as $exportHandler) { | 
| 157 | $returnValue[get_class($exportHandler)] = $exportHandler->getLabel(); | 
| 158 | } | 
| 159 | return $returnValue; | 
| 160 | } | 
| 161 | } |