ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 {
32 
34 
36 
37  private ?string $saveCommand = null;
38 
39  private ?string $saveAndNewCommand = null;
40 
41  public function __construct(ilCtrlInterface $ctrl, ilLanguage $lng, ilObjTest $testOBJ, ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, ilTestRandomQuestionSetConfig $questionSetConfig)
42  {
44 
45  $this->ctrl = $ctrl;
46  $this->lng = $lng;
47  $this->testOBJ = $testOBJ;
48  $this->questionSetConfigGUI = $questionSetConfigGUI;
49  $this->questionSetConfig = $questionSetConfig;
50  }
51 
52  public function setSaveCommand(string $saveCommand): void
53  {
54  $this->saveCommand = $saveCommand;
55  }
56 
57  public function getSaveCommand(): ?string
58  {
59  return $this->saveCommand;
60  }
61 
62  public function setSaveAndNewCommand(string $saveAndNewCommand): void
63  {
64  $this->saveAndNewCommand = $saveAndNewCommand;
65  }
66 
67  public function getSaveAndNewCommand(): ?string
68  {
70  }
71 
72  public function build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $availableTaxonomyIds): void
73  {
74  $this->setFormAction($this->ctrl->getFormAction($this->questionSetConfigGUI));
75 
76  $this->setTitle($this->lng->txt('tst_rnd_quest_set_cfg_pool_form'));
77  $this->setId('tstRndQuestSetCfgPoolForm');
78 
79  $this->addCommandButton(
80  $this->getSaveCommand(),
81  $this->lng->txt('save_and_back')
82  );
83 
84  if (null !== $this->getSaveAndNewCommand()) {
85  $this->addCommandButton(
86  $this->getSaveAndNewCommand(),
87  $this->lng->txt('tst_save_and_create_new_rule')
88  );
89  }
90 
91  $this->addCommandButton(
93  $this->lng->txt('cancel')
94  );
95 
96  $hiddenDefId = new ilHiddenInputGUI('src_pool_def_id');
97  $hiddenDefId->setValue((string) $sourcePool->getId());
98  $this->addItem($hiddenDefId);
99 
100  $hiddenPoolId = new ilHiddenInputGUI('quest_pool_id');
101  $hiddenPoolId->setValue((string) $sourcePool->getPoolId());
102  $this->addItem($hiddenPoolId);
103 
104  $nonEditablePoolLabel = new ilNonEditableValueGUI(
105  $this->lng->txt('tst_inp_source_pool_label'),
106  'quest_pool_label'
107  );
108  $nonEditablePoolLabel->setValue($sourcePool->getPoolInfoLabel($this->lng));
109 
110  $this->addItem($nonEditablePoolLabel);
111 
112 
113  if (count($availableTaxonomyIds)) {
114  ilOverlayGUI::initJavaScript();
115 
116  $filter = $sourcePool->getOriginalTaxonomyFilter();
117  foreach ($availableTaxonomyIds as $taxId) {
118  $taxonomy = new ilObjTaxonomy($taxId);
119  $taxLabel = sprintf($this->lng->txt('tst_inp_source_pool_filter_tax_x'), $taxonomy->getTitle());
120 
121  $taxCheckbox = new ilCheckboxInputGUI($taxLabel, "filter_tax_id_$taxId");
122 
123 
124 
125  $this->ctrl->setParameterByClass('iltaxselectinputgui', 'src_pool_def_id', $sourcePool->getId());
126  $this->ctrl->setParameterByClass('iltaxselectinputgui', 'quest_pool_id', $sourcePool->getPoolId());
127  $taxSelect = new ilTaxSelectInputGUI($taxId, "filter_tax_nodes_$taxId", true);
128  $taxSelect->setRequired(true);
129 
130  if (isset($filter[$taxId])) {
131  $taxCheckbox->setChecked(true);
132  $taxSelect->setValue($filter[$taxId]);
133  }
134  $taxCheckbox->addSubItem($taxSelect);
135  $this->addItem($taxCheckbox);
136  }
137  // fau.
138  } else {
139  $hiddenNoTax = new ilHiddenInputGUI('filter_tax');
140  $hiddenNoTax->setValue('0');
141  $this->addItem($hiddenNoTax);
142 
143  $nonEditableNoTax = new ilNonEditableValueGUI(
144  $this->lng->txt('tst_inp_source_pool_filter_tax'),
145  'no_tax_label'
146  );
147  $nonEditableNoTax->setValue($this->lng->txt('tst_inp_no_available_tax_hint'));
148  $this->addItem($nonEditableNoTax);
149  }
150 
151  $lifecycleFilterValues = $sourcePool->getLifecycleFilter();
152  $lifecycleCheckbox = new ilCheckboxInputGUI($this->lng->txt('tst_filter_lifecycle_enabled'), 'filter_lifecycle_enabled');
153  $lifecycleCheckbox->setChecked(!empty($lifecycleFilterValues));
154  $lifecycleFilter = new ilSelectInputGUI($this->lng->txt('qst_lifecycle'), 'filter_lifecycle');
155  $lifecycleFilter->setRequired(true);
156  $lifecycleFilter->setMulti(true);
157  $lifecycleFilter->setOptions(ilAssQuestionLifecycle::getDraftInstance()->getSelectOptions($this->lng));
158  $lifecycleFilter->setValue($lifecycleFilterValues);
159  $lifecycleCheckbox->addSubItem($lifecycleFilter);
160  $this->addItem($lifecycleCheckbox);
161 
162  // fau: taxFilter/typeFilter - show type filter selection
163  $typeFilterOptions = array();
164  foreach (ilObjQuestionPool::_getQuestionTypes(true) as $translation => $data) {
165  $typeFilterOptions[$data['question_type_id']] = $translation;
166  }
167  $filterIds = $sourcePool->getTypeFilter();
168  $typeCheckbox = new ilCheckboxInputGUI($this->lng->txt('tst_filter_question_type_enabled'), 'filter_type_enabled');
169  $typeCheckbox->setChecked(!empty($filterIds));
170  $typeFilter = new ilSelectInputGUI($this->lng->txt('tst_filter_question_type'), 'filter_type');
171  $typeFilter->setRequired(true);
172  $typeFilter->setMulti(true);
173  $typeFilter->setOptions($typeFilterOptions);
174  $typeFilter->setValue($filterIds);
175  $typeCheckbox->addSubItem($typeFilter);
176  $this->addItem($typeCheckbox);
177  // fau.
178 
179  if ($this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
180  $questionAmountPerSourcePool = new ilNumberInputGUI(
181  $this->lng->txt('tst_inp_quest_amount_per_source_pool'),
182  'question_amount_per_pool'
183  );
184 
185  $questionAmountPerSourcePool->setRequired(true);
186  $questionAmountPerSourcePool->allowDecimals(false);
187  $questionAmountPerSourcePool->setMinValue(0);
188  $questionAmountPerSourcePool->setMinvalueShouldBeGreater(true);
189  $questionAmountPerSourcePool->setSize(4);
190 
191  if ($sourcePool->getQuestionAmount()) {
192  $questionAmountPerSourcePool->setValue(
193  $sourcePool->getQuestionAmount() ? (string) $sourcePool->getQuestionAmount() : null
194  );
195  }
196 
197  $this->addItem($questionAmountPerSourcePool);
198  }
199  }
200 
201  public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $availableTaxonomyIds): void
202  {
203  // fau: taxFilter/typeFilter - submit multiple taxonomy and node selections - submit type selections
204  $filter = array();
205  foreach ($availableTaxonomyIds as $taxId) {
206  if ($this->getItemByPostVar("filter_tax_id_$taxId")->getChecked()) {
207  $nodeIds = (array) $this->getItemByPostVar("filter_tax_nodes_$taxId")->getValue();
208  if (!empty($nodeIds)) {
209  foreach ($nodeIds as $nodeId) {
210  $filter[(int) $taxId][] = (int) $nodeId;
211  }
212  }
213  }
214  }
215  $sourcePoolDefinition->setOriginalTaxonomyFilter($filter);
216 
217  $filter = array();
218  if ($this->getItemByPostVar("filter_type_enabled")->getChecked()) {
219  $filter = $this->getItemByPostVar("filter_type")->getMultiValues();
220  }
221  $sourcePoolDefinition->setTypeFilter($filter);
222 
223  $filter = array();
224  if ($this->getItemByPostVar("filter_lifecycle_enabled")->getChecked()) {
225  $filter = $this->getItemByPostVar("filter_lifecycle")->getMultiValues();
226  }
227  $sourcePoolDefinition->setLifecycleFilter($filter);
228 
229  // fau.
230 
231  if ($this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
232  $sourcePoolDefinition->setQuestionAmount(intval($this->getItemByPostVar('question_amount_per_pool')->getValue()));
233  }
234  }
235 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $availableTaxonomyIds)
setId(string $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a selection list property in a property form.
getItemByPostVar(string $a_post_var)
getValue()
Get the value that is displayed in the input client side.
Definition: Group.php:46
__construct(ilCtrlInterface $ctrl, ilLanguage $lng, ilObjTest $testOBJ, ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, ilTestRandomQuestionSetConfig $questionSetConfig)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(VocabulariesInterface $vocabularies)
setFormAction(string $a_formaction)
setRequired(bool $a_required)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
applySubmit(ilTestRandomQuestionSetSourcePoolDefinition $sourcePoolDefinition, $availableTaxonomyIds)
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)