ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilTestRandomQuestionSetPoolDefinitionFormGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
32 {
34 
36 
38 
39  private ?string $saveCommand = null;
40 
41  private ?string $saveAndNewCommand = null;
42 
43  public function __construct(ilCtrlInterface $ctrl, ilLanguage $lng, ilObjTest $testOBJ, ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, ilTestRandomQuestionSetConfig $questionSetConfig)
44  {
46 
47  $this->ctrl = $ctrl;
48  $this->lng = $lng;
49  $this->testOBJ = $testOBJ;
50  $this->questionSetConfigGUI = $questionSetConfigGUI;
51  $this->questionSetConfig = $questionSetConfig;
52  }
53 
54  public function setSaveCommand(string $saveCommand): void
55  {
56  $this->saveCommand = $saveCommand;
57  }
58 
59  public function getSaveCommand(): ?string
60  {
61  return $this->saveCommand;
62  }
63 
64  public function setSaveAndNewCommand(string $saveAndNewCommand): void
65  {
66  $this->saveAndNewCommand = $saveAndNewCommand;
67  }
68 
69  public function getSaveAndNewCommand(): ?string
70  {
72  }
73 
74  public function build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $available_taxonomy_ids): void
75  {
76  $this->setFormAction($this->ctrl->getFormAction($this->questionSetConfigGUI));
77 
78  $this->setTitle($this->lng->txt('tst_rnd_quest_set_cfg_pool_form'));
79  $this->setId('tstRndQuestSetCfgPoolForm');
80 
81  $this->addCommandButton(
82  $this->getSaveCommand(),
83  $this->lng->txt('save_and_back')
84  );
85 
86  if (null !== $this->getSaveAndNewCommand()) {
87  $this->addCommandButton(
88  $this->getSaveAndNewCommand(),
89  $this->lng->txt('tst_save_and_create_new_rule')
90  );
91  }
92 
93  $this->addCommandButton(
95  $this->lng->txt('cancel')
96  );
97 
98  $hiddenDefId = new ilHiddenInputGUI('src_pool_def_id');
99  $hiddenDefId->setValue((string) $sourcePool->getId());
100  $this->addItem($hiddenDefId);
101 
102  $hiddenPoolId = new ilHiddenInputGUI('quest_pool_id');
103  $hiddenPoolId->setValue((string) $sourcePool->getPoolId());
104  $this->addItem($hiddenPoolId);
105 
106  $nonEditablePoolLabel = new ilNonEditableValueGUI(
107  $this->lng->txt('tst_inp_source_pool_label'),
108  'quest_pool_label'
109  );
110  $nonEditablePoolLabel->setValue($sourcePool->getPoolInfoLabel($this->lng));
111 
112  $this->addItem($nonEditablePoolLabel);
113 
114 
115  if ($available_taxonomy_ids !== []) {
116  $filter = $sourcePool->getOriginalTaxonomyFilter();
117  foreach ($available_taxonomy_ids as $tax_id) {
118  $taxonomy = new ilObjTaxonomy($tax_id);
119  $taxLabel = sprintf($this->lng->txt('tst_inp_source_pool_filter_tax_x'), $taxonomy->getTitle());
120 
121  $taxCheckbox = new ilCheckboxInputGUI($taxLabel, "filter_tax_id_$tax_id");
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($tax_id, "filter_tax_nodes_$tax_id", true);
128  $taxSelect->setRequired(true);
129 
130  if (isset($filter[$tax_id])) {
131  $taxCheckbox->setChecked(true);
132  $taxSelect->setValue($filter[$tax_id]);
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 = [];
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(
202  ilTestRandomQuestionSetSourcePoolDefinition $source_pool_definition,
203  $available_taxonomy_ids
204  ): array {
205  $log_array = [];
206  // fau: taxFilter/typeFilter - submit multiple taxonomy and node selections - submit type selections
207  $taxonomy_filter = [];
208  foreach ($available_taxonomy_ids as $tax_id) {
209  if ($this->getItemByPostVar("filter_tax_id_{$tax_id}")->getChecked()) {
210  $node_ids = (array) $this->getItemByPostVar("filter_tax_nodes_{$tax_id}")->getValue();
211  if (!empty($node_ids)) {
212  foreach ($node_ids as $node_id) {
213  $taxonomy_filter[(int) $tax_id][] = (int) $node_id;
214  }
215  }
216  }
217  }
218  $source_pool_definition->setOriginalTaxonomyFilter($taxonomy_filter);
219 
220  $type_filter = [];
221  if ($this->getItemByPostVar('filter_type_enabled')->getChecked()) {
222  $type_filter = $this->getItemByPostVar('filter_type')->getMultiValues();
223  }
224  $source_pool_definition->setTypeFilter($type_filter);
225 
226  $life_cycle_filter = [];
227  if ($this->getItemByPostVar('filter_lifecycle_enabled')->getChecked()) {
228  $life_cycle_filter = $this->getItemByPostVar('filter_lifecycle')->getMultiValues();
229  }
230  $source_pool_definition->setLifecycleFilter($life_cycle_filter);
231 
232  // fau.
233 
234  if ($this->questionSetConfig->isQuestionAmountConfigurationModePerPool()) {
235  $question_amount = $this->getItemByPostVar('question_amount_per_pool')->getValue();
236  $source_pool_definition->setQuestionAmount(intval($question_amount));
237  $log_array[AdditionalInformationGenerator::KEY_QUESTION_AMOUNT_PER_POOL] = $question_amount;
238  }
239 
240  return [
241  AdditionalInformationGenerator::KEY_SOURCE_POOL => $source_pool_definition->getPoolId(),
242  AdditionalInformationGenerator::KEY_SOURCE_TAXONOMY_FILTER => $taxonomy_filter,
243  AdditionalInformationGenerator::KEY_SOURCE_TYPE_FILTER => $type_filter,
244  AdditionalInformationGenerator::KEY_SOURCE_LIFECYCLE_FILTER => $life_cycle_filter
245  ] + $log_array;
246  }
247 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
__construct(ilCtrlInterface $ctrl, ilLanguage $lng, ilObjTest $testOBJ, ilTestRandomQuestionSetConfigGUI $questionSetConfigGUI, ilTestRandomQuestionSetConfig $questionSetConfig)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This class represents a hidden form property in a property form.
setFormAction(string $a_formaction)
This class represents a number property in a property form.
build(ilTestRandomQuestionSetSourcePoolDefinition $sourcePool, $available_taxonomy_ids)
setRequired(bool $a_required)
addCommandButton(string $a_cmd, string $a_text, string $a_id="")
applySubmit(ilTestRandomQuestionSetSourcePoolDefinition $source_pool_definition, $available_taxonomy_ids)
__construct(Container $dic, ilPlugin $plugin)
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)