1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4require_once 'Services/Form/classes/class.ilPropertyFormGUI.php'; 5 6/** 7 * GUI class for random question set pool config form 8 * 9 * @author Björn Heyser <bheyser@databay.de> 10 * @version $Id$ 11 * 12 * @package Modules/Test 13 * 14 * @ilCtrl_Calls ilTestRandomQuestionSetPoolDefinitionFormGUI: ilFormPropertyDispatchGUI 15 */ 16class ilTestRandomQuestionSetPoolDefinitionFormGUI extends ilPropertyFormGUI 17{ 18 /** 19 * global $ilCtrl object 20 * 21 * @var ilCtrl 22 */ 23 public $ctrl = null; 24 25 /** 26 * global $lng object 27 * 28 * @var ilLanguage 29 */ 30 public $lng = null; 31 32 /** 33 * object instance for current test 34 * 35 * @var ilObjTest 36 */ 37 public $testOBJ = null; 38 39 /** 40 * global $lng object 41 * 42 * @var ilTestRandomQuestionSetConfigGUI 43 */ 44 public $questionSetConfigGUI = null; 45 46 /** 47 * global $lng object 48 * 49 * @var ilTestRandomQuestionSetConfig 50 */ 51 public $questionSetConfig = null; 52 53 private $saveCommand = null; 54 55 /** 56 * @var null|string 57 */ 58 private $saveAndNewCommand = null; 59 60 public function __construct(ilCtrl $ctrl, ilLanguage $lng, ilObjTest $testOBJ, ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, ilTestRandomQuestionSetConfig $questionSetConfig) 61 { 62 parent::__construct(); 63 64 $this->ctrl = $ctrl; 65 $this->lng = $lng; 66 $this->testOBJ = $testOBJ; 67 $this->questionSetConfigGUI = $questionSetConfigGUI; 68 $this->questionSetConfig = $questionSetConfig; 69 } 70 71 public function setSaveCommand($saveCommand) 72 { 73 $this->saveCommand = $saveCommand; 74 } 75 76 public function getSaveCommand() 77 { 78 return $this->saveCommand; 79 } 80 81 /** 82 * @param null|string $saveAndNewCommand 83 */ 84 public function setSaveAndNewCommand($saveAndNewCommand) 85 { 86 $this->saveAndNewCommand = $saveAndNewCommand; 87 } 88 89 /** 90 * @return null|string 91 */ 92 public function getSaveAndNewCommand() 93 { 94 return $this->saveAndNewCommand; 95 } 96 97 public function build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $availableTaxonomyIds) 98 { 99 $this->setFormAction($this->ctrl->getFormAction($this->questionSetConfigGUI)); 100 101 $this->setTitle($this->lng->txt('tst_rnd_quest_set_cfg_pool_form')); 102 $this->setId('tstRndQuestSetCfgPoolForm'); 103 104 $this->addCommandButton( 105 $this->getSaveCommand(), 106 $this->lng->txt('save_and_back') 107 ); 108 109 if (null !== $this->getSaveAndNewCommand()) { 110 $this->addCommandButton( 111 $this->getSaveAndNewCommand(), 112 $this->lng->txt('tst_save_and_create_new_rule') 113 ); 114 } 115 116 $this->addCommandButton( 117 ilTestRandomQuestionSetConfigGUI::CMD_SHOW_SRC_POOL_DEF_LIST, 118 $this->lng->txt('cancel') 119 ); 120 121 $hiddenDefId = new ilHiddenInputGUI('src_pool_def_id'); 122 $hiddenDefId->setValue($sourcePool->getId()); 123 $this->addItem($hiddenDefId); 124 125 $hiddenPoolId = new ilHiddenInputGUI('quest_pool_id'); 126 $hiddenPoolId->setValue($sourcePool->getPoolId()); 127 $this->addItem($hiddenPoolId); 128 129 $nonEditablePoolLabel = new ilNonEditableValueGUI( 130 $this->lng->txt('tst_inp_source_pool_label'), 131 'quest_pool_label' 132 ); 133 $nonEditablePoolLabel->setValue($sourcePool->getPoolInfoLabel($this->lng)); 134 135 $this->addItem($nonEditablePoolLabel); 136 137 138 if (count($availableTaxonomyIds)) { 139 // fau: taxFilter/typeFilter - edit multiple taxonomy and node selections 140 require_once 'Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php'; 141 142 // this is needed by ilTaxSelectInputGUI in some cases 143 require_once 'Services/UIComponent/Overlay/classes/class.ilOverlayGUI.php'; 144 ilOverlayGUI::initJavaScript(); 145 146 $filter = $sourcePool->getOriginalTaxonomyFilter(); 147 foreach ($availableTaxonomyIds as $taxId) { 148 $taxonomy = new ilObjTaxonomy($taxId); 149 $taxLabel = sprintf($this->lng->txt('tst_inp_source_pool_filter_tax_x'), $taxonomy->getTitle()); 150 151 $taxCheckbox = new ilCheckboxInputGUI($taxLabel, "filter_tax_id_$taxId"); 152 153 154 155 $this->ctrl->setParameterByClass('iltaxselectinputgui', 'src_pool_def_id', $sourcePool->getId()); 156 $this->ctrl->setParameterByClass('iltaxselectinputgui', 'quest_pool_id', $sourcePool->getPoolId()); 157 $taxSelect = new ilTaxSelectInputGUI($taxId, "filter_tax_nodes_$taxId", true); 158 $taxSelect->setRequired(true); 159 160 if (isset($filter[$taxId])) { 161 $taxCheckbox->setChecked(true); 162 $taxSelect->setValue($filter[$taxId]); 163 } 164 $taxCheckbox->addSubItem($taxSelect); 165 $this->addItem($taxCheckbox); 166 } 167 168 #$taxRadio = new ilRadioGroupInputGUI( 169 # $this->lng->txt('tst_inp_source_pool_filter_tax'), 'filter_tax' 170 #); 171 172 #$taxRadio->setRequired(true); 173 174 #$taxRadio->addOption(new ilRadioOption( 175 # $this->lng->txt('tst_inp_source_pool_no_tax_filter'), 0 176 #)); 177 178 #$taxRadio->setValue(0); 179 180 #require_once 'Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php'; 181 182 #foreach($availableTaxonomyIds as $taxId) 183 #{ 184 # $taxonomy = new ilObjTaxonomy($taxId); 185 # $label = sprintf($this->lng->txt('tst_inp_source_pool_filter_tax_x'), $taxonomy->getTitle()); 186 187 # $taxRadioOption = new ilRadioOption($label, $taxId); 188 189 # $taxRadio->addOption($taxRadioOption); 190 191 # $taxSelect = new ilTaxSelectInputGUI($taxId, "filter_tax_$taxId", false); 192 # $taxSelect->setRequired(true); 193 # $taxRadioOption->addSubItem($taxSelect); 194 195 # if( $taxId == $sourcePool->getOriginalFilterTaxId() ) 196 # { 197 # $taxRadio->setValue( $sourcePool->getOriginalFilterTaxId() ); 198 # $taxSelect->setValue( $sourcePool->getOriginalFilterTaxNodeId() ); 199 # } 200 #} 201 202 #$this->addItem($taxRadio); 203 // fau. 204 } else { 205 $hiddenNoTax = new ilHiddenInputGUI('filter_tax'); 206 $hiddenNoTax->setValue(0); 207 $this->addItem($hiddenNoTax); 208 209 $nonEditableNoTax = new ilNonEditableValueGUI( 210 $this->lng->txt('tst_inp_source_pool_filter_tax'), 211 'no_tax_label' 212 ); 213 $nonEditableNoTax->setValue($this->lng->txt('tst_inp_no_available_tax_hint')); 214 $this->addItem($nonEditableNoTax); 215 } 216 217 // fau: taxFilter/typeFilter - show type filter selection 218 $typeFilterOptions = array(); 219 require_once("./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"); 220 foreach (ilObjQuestionPool::_getQuestionTypes(true) as $translation => $data) { 221 $typeFilterOptions[$data['question_type_id']] = $translation; 222 } 223 $filterIds = $sourcePool->getTypeFilter(); 224 $typeCheckbox = new ilCheckboxInputGUI($this->lng->txt('tst_filter_question_type_enabled'), 'filter_type_enabled'); 225 $typeCheckbox->setChecked(!empty($filterIds)); 226 $typeFilter = new ilSelectInputGUI($this->lng->txt('tst_filter_question_type'), 'filter_type'); 227 $typeFilter->setRequired(true); 228 $typeFilter->setMulti(true); 229 $typeFilter->setOptions($typeFilterOptions); 230 $typeFilter->setValue($filterIds); 231 $typeCheckbox->addSubItem($typeFilter); 232 $this->addItem($typeCheckbox); 233 // fau. 234 235 if ($this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) { 236 $questionAmountPerSourcePool = new ilNumberInputGUI( 237 $this->lng->txt('tst_inp_quest_amount_per_source_pool'), 238 'question_amount_per_pool' 239 ); 240 241 $questionAmountPerSourcePool->setRequired(true); 242 $questionAmountPerSourcePool->allowDecimals(false); 243 $questionAmountPerSourcePool->setMinValue(0); 244 $questionAmountPerSourcePool->setMinvalueShouldBeGreater(true); 245 $questionAmountPerSourcePool->setSize(4); 246 247 if ($sourcePool->getQuestionAmount()) { 248 $questionAmountPerSourcePool->setValue($sourcePool->getQuestionAmount()); 249 } 250 251 $this->addItem($questionAmountPerSourcePool); 252 } 253 } 254 255 public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $availableTaxonomyIds) 256 { 257 // fau: taxFilter/typeFilter - submit multiple taxonomy and node selections - submit type selections 258 $filter = array(); 259 foreach ($availableTaxonomyIds as $taxId) { 260 if ($this->getItemByPostVar("filter_tax_id_$taxId")->getChecked()) { 261 $nodeIds = (array) $this->getItemByPostVar("filter_tax_nodes_$taxId")->getValue(); 262 if (!empty($nodeIds)) { 263 foreach ($nodeIds as $nodeId) { 264 $filter[(int) $taxId][] = (int) $nodeId; 265 } 266 } 267 } 268 } 269 $sourcePoolDefinition->setOriginalTaxonomyFilter($filter); 270 271 #switch( true ) 272 #{ 273 # case $this->getItemByPostVar('source_pool_filter_tax') === null: 274 275 # case !in_array($this->getItemByPostVar('filter_tax')->getValue(), $availableTaxonomyIds): 276 277 # $sourcePoolDefinition->setOriginalFilterTaxId(null); 278 # $sourcePoolDefinition->setOriginalFilterTaxNodeId(null); 279 # break; 280 281 # default: 282 283 # $taxId = $this->getItemByPostVar('filter_tax')->getValue(); 284 285 # $sourcePoolDefinition->setOriginalFilterTaxId( $taxId ); 286 287 # $sourcePoolDefinition->setOriginalFilterTaxNodeId( $this->getItemByPostVar("filter_tax_$taxId")->getValue() ); 288 #} 289 290 $filter = array(); 291 if ($this->getItemByPostVar("filter_type_enabled")->getChecked()) { 292 $filter = $this->getItemByPostVar("filter_type")->getMultiValues(); 293 } 294 $sourcePoolDefinition->setTypeFilter($filter); 295 // fau. 296 297 if ($this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) { 298 $sourcePoolDefinition->setQuestionAmount($this->getItemByPostVar('question_amount_per_pool')->getValue()); 299 } 300 } 301} 302