ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
5 
17 {
23  public $ctrl = null;
24 
30  public $lng = null;
31 
37  public $testOBJ = null;
38 
44  public $questionSetConfigGUI = null;
45 
51  public $questionSetConfig = null;
52 
53  private $saveCommand = null;
54 
58  private $saveAndNewCommand = null;
59 
61  {
62  $this->ctrl = $ctrl;
63  $this->lng = $lng;
64  $this->testOBJ = $testOBJ;
65  $this->questionSetConfigGUI = $questionSetConfigGUI;
66  $this->questionSetConfig = $questionSetConfig;
67  }
68 
69  public function setSaveCommand($saveCommand)
70  {
71  $this->saveCommand = $saveCommand;
72  }
73 
74  public function getSaveCommand()
75  {
76  return $this->saveCommand;
77  }
78 
83  {
84  $this->saveAndNewCommand = $saveAndNewCommand;
85  }
86 
90  public function getSaveAndNewCommand()
91  {
93  }
94 
95  public function build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $availableTaxonomyIds)
96  {
97  $this->setFormAction( $this->ctrl->getFormAction($this->questionSetConfigGUI) );
98 
99  $this->setTitle( $this->lng->txt('tst_rnd_quest_set_cfg_pool_form') );
100  $this->setId('tstRndQuestSetCfgPoolForm');
101 
102  $this->addCommandButton(
103  $this->getSaveCommand(), $this->lng->txt('save_and_back')
104  );
105 
106  if(null !== $this->getSaveAndNewCommand())
107  {
108  $this->addCommandButton(
109  $this->getSaveAndNewCommand(), $this->lng->txt('tst_save_and_create_new_rule')
110  );
111  }
112 
113  $this->addCommandButton(
115  );
116 
117  $hiddenDefId = new ilHiddenInputGUI('src_pool_def_id');
118  $hiddenDefId->setValue( $sourcePool->getId() );
119  $this->addItem($hiddenDefId);
120 
121  $hiddenPoolId = new ilHiddenInputGUI('quest_pool_id');
122  $hiddenPoolId->setValue( $sourcePool->getPoolId() );
123  $this->addItem($hiddenPoolId);
124 
125  $nonEditablePoolLabel = new ilNonEditableValueGUI(
126  $this->lng->txt('tst_inp_source_pool_label'), 'quest_pool_label'
127  );
128  $nonEditablePoolLabel->setValue( $sourcePool->getPoolInfoLabel($this->lng) );
129 
130  $this->addItem($nonEditablePoolLabel);
131 
132 
133  if( count($availableTaxonomyIds) )
134  {
135  $taxRadio = new ilRadioGroupInputGUI(
136  $this->lng->txt('tst_inp_source_pool_filter_tax'), 'filter_tax'
137  );
138 
139  $taxRadio->setRequired(true);
140 
141  $taxRadio->addOption(new ilRadioOption(
142  $this->lng->txt('tst_inp_source_pool_no_tax_filter'), 0
143  ));
144 
145  $taxRadio->setValue(0);
146 
147  require_once 'Services/Taxonomy/classes/class.ilTaxSelectInputGUI.php';
148 
149  foreach($availableTaxonomyIds as $taxId)
150  {
151  $taxonomy = new ilObjTaxonomy($taxId);
152  $label = sprintf($this->lng->txt('tst_inp_source_pool_filter_tax_x'), $taxonomy->getTitle());
153 
154  $taxRadioOption = new ilRadioOption($label, $taxId);
155 
156  $taxRadio->addOption($taxRadioOption);
157 
158  $this->ctrl->setParameterByClass('iltaxselectinputgui', 'src_pool_def_id', $sourcePool->getId());
159  $this->ctrl->setParameterByClass('iltaxselectinputgui', 'quest_pool_id', $sourcePool->getPoolId());
160  $taxSelect = new ilTaxSelectInputGUI($taxId, "filter_tax_$taxId", false);
161  $taxSelect->setRequired(true);
162  $taxRadioOption->addSubItem($taxSelect);
163 
164  if( $taxId == $sourcePool->getOriginalFilterTaxId() )
165  {
166  $taxRadio->setValue( $sourcePool->getOriginalFilterTaxId() );
167  $taxSelect->setValue( $sourcePool->getOriginalFilterTaxNodeId() );
168  }
169  }
170 
171  $this->addItem($taxRadio);
172  }
173  else
174  {
175  $hiddenNoTax = new ilHiddenInputGUI('filter_tax');
176  $hiddenNoTax->setValue(0);
177  $this->addItem($hiddenNoTax);
178 
179  $nonEditableNoTax = new ilNonEditableValueGUI(
180  $this->lng->txt('tst_inp_source_pool_filter_tax'), 'no_tax_label'
181  );
182  $nonEditableNoTax->setValue( $this->lng->txt('tst_inp_no_available_tax_hint') );
183  $this->addItem($nonEditableNoTax);
184  }
185 
186 
187  if( $this->questionSetConfig->isQuestionAmountConfigurationModePerPool() )
188  {
189  $questionAmountPerSourcePool = new ilNumberInputGUI(
190  $this->lng->txt('tst_inp_quest_amount_per_source_pool'), 'question_amount_per_pool'
191  );
192 
193  $questionAmountPerSourcePool->setRequired(true);
194  $questionAmountPerSourcePool->allowDecimals(false);
195  $questionAmountPerSourcePool->setMinValue(0);
196  $questionAmountPerSourcePool->setMinvalueShouldBeGreater(true);
197  $questionAmountPerSourcePool->setSize(4);
198 
199  if( $sourcePool->getQuestionAmount() )
200  {
201  $questionAmountPerSourcePool->setValue( $sourcePool->getQuestionAmount() );
202  }
203 
204  $this->addItem($questionAmountPerSourcePool);
205  }
206  }
207 
208  public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $availableTaxonomyIds)
209  {
210  switch( true )
211  {
212  case $this->getItemByPostVar('source_pool_filter_tax') === null:
213 
214  case !in_array($this->getItemByPostVar('filter_tax')->getValue(), $availableTaxonomyIds):
215 
216  $sourcePoolDefinition->setOriginalFilterTaxId(null);
217  $sourcePoolDefinition->setOriginalFilterTaxNodeId(null);
218  break;
219 
220  default:
221 
222  $taxId = $this->getItemByPostVar('filter_tax')->getValue();
223 
224  $sourcePoolDefinition->setOriginalFilterTaxId( $taxId );
225 
226  $sourcePoolDefinition->setOriginalFilterTaxNodeId( $this->getItemByPostVar("filter_tax_$taxId")->getValue() );
227  }
228 
229  if( $this->questionSetConfig->isQuestionAmountConfigurationModePerPool() )
230  {
231  $sourcePoolDefinition->setQuestionAmount( $this->getItemByPostVar('question_amount_per_pool')->getValue() );
232  }
233  }
234 }
This class represents an option in a radio group.
This class provides processing control methods.
build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $availableTaxonomyIds)
Select taxonomy nodes input GUI.
getItemByPostVar($a_post_var)
Get Item by POST variable.
setId($a_id)
Set Id.
This class represents a property form user interface.
__construct(ilCtrl $ctrl, ilLanguage $lng, ilObjTest $testOBJ, ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, ilTestRandomQuestionSetConfig $questionSetConfig)
setFormAction($a_formaction)
Set FormAction.
addItem($a_item)
Add Item (Property, SectionHeader).
This class represents a hidden form property in a property form.
This class represents a property in a property form.
setTitle($a_title)
Set Title.
This class represents a number property in a property form.
addCommandButton($a_cmd, $a_text, $a_id="")
Add Command button.
This class represents a non editable value in a property form.
applySubmit(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $availableTaxonomyIds)
language handling
setRequired($a_required)
Set Required.