ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilTestRandomQuestionSetSourcePoolDefinitionListTableGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Modules\Test\QuestionPoolLinkedTitleBuilder;
20use ILIAS\UI\Factory as UIFactory;
21use ILIAS\UI\Renderer as UIRenderer;
22
31{
32 use QuestionPoolLinkedTitleBuilder;
33 public const IDENTIFIER = 'tstRndPools';
36 private bool $showMappedTaxonomyFilter = false;
38
40 private UIFactory $ui_factory;
41 private UIRenderer $ui_renderer;
42
43 private \ILIAS\Test\InternalRequestService $testrequest;
44
45 public function __construct(ilCtrl $ctrl, ilLanguage $lng, $parentGUI, $parentCMD)
46 {
47 parent::__construct($parentGUI, $parentCMD);
48
49 $this->ctrl = $ctrl;
50 $this->lng = $lng;
51 global $DIC;
52 $this->testrequest = $DIC->test()->internal()->request();
53 $this->access = $DIC['ilAccess'];
54 $this->ui_factory = $DIC['ui.factory'];
55 $this->ui_renderer = $DIC['ui.renderer'];
56 $this->definitionEditModeEnabled = false;
57 $this->questionAmountColumnEnabled = false;
58 }
59
61 {
62 $this->taxonomyLabelTranslater = $translater;
63 }
64
66 {
67 $this->definitionEditModeEnabled = $definitionEditModeEnabled;
68 }
69
70 public function isDefinitionEditModeEnabled(): bool
71 {
73 }
74
76 {
77 $this->questionAmountColumnEnabled = $questionAmountColumnEnabled;
78 }
79
80 public function isQuestionAmountColumnEnabled(): bool
81 {
83 }
84
86 {
87 $this->showMappedTaxonomyFilter = $showMappedTaxonomyFilter;
88 }
89
90 public function fillRow(array $a_set): void
91 {
92 if ($this->isDefinitionEditModeEnabled()) {
93 $this->tpl->setCurrentBlock('col_selection_checkbox');
94 $this->tpl->setVariable('SELECTION_CHECKBOX_HTML', $this->getSelectionCheckboxHTML($a_set['def_id']));
95 $this->tpl->parseCurrentBlock();
96
97 $this->tpl->setCurrentBlock('col_actions');
98 $this->tpl->setVariable('ACTIONS_HTML', $this->getActionsHTML($a_set['def_id']));
99 $this->tpl->parseCurrentBlock();
100
101 $this->tpl->setCurrentBlock('col_order_checkbox');
102 $this->tpl->setVariable('ORDER_INPUT_HTML', $this->getDefinitionOrderInputHTML(
103 $a_set['def_id'],
104 $this->getOrderNumberForSequencePosition($a_set['sequence_position'])
105 ));
106 $this->tpl->parseCurrentBlock();
107 }
108 // fau: taxFilter/typeFilter - show sequence position to identify the filter in the database
109 else {
110 $this->tpl->setCurrentBlock('col_order_checkbox');
111 $this->tpl->setVariable('ORDER_INPUT_HTML', $a_set['sequence_position']);
112 $this->tpl->parseCurrentBlock();
113 }
114 // fau.
115
116 if ($this->isQuestionAmountColumnEnabled()) {
117 if ($this->isDefinitionEditModeEnabled()) {
118 $questionAmountHTML = $this->getQuestionAmountInputHTML(
119 $a_set['def_id'],
120 $a_set['question_amount']
121 );
122 } else {
123 $questionAmountHTML = $a_set['question_amount'];
124 }
125
126 $this->tpl->setCurrentBlock('col_question_amount');
127 $this->tpl->setVariable('QUESTION_AMOUNT_INPUT_HTML', $questionAmountHTML);
128 $this->tpl->parseCurrentBlock();
129 }
130
131 $this->tpl->setVariable(
132 'SOURCE_POOL_LABEL',
133 $this->buildPossiblyLinkedQuestonPoolTitle(
134 $this->ctrl,
135 $this->access,
136 $this->lng,
137 $this->ui_factory,
138 $this->ui_renderer,
139 $a_set['ref_id'],
140 $a_set['source_pool_label'],
141 true
142 )
143 );
144 // fau: taxFilter/typeFilter - set taxonomy/type filter label in a single coulumn each
145
146 $this->tpl->setVariable('TAXONOMY_FILTER', $this->taxonomyLabelTranslater->getTaxonomyFilterLabel($a_set['taxonomy_filter'], '<br />'));
147 $this->tpl->setVariable('LIFECYCLE_FILTER', $this->taxonomyLabelTranslater->getLifecycleFilterLabel($a_set['lifecycle_filter']));
148 $this->tpl->setVariable('TYPE_FILTER', $this->taxonomyLabelTranslater->getTypeFilterLabel($a_set['type_filter']));
149 // fau.
150 }
151
152 private function getSelectionCheckboxHTML($sourcePoolDefinitionId): string
153 {
154 return '<input type="checkbox" value="' . $sourcePoolDefinitionId . '" name="src_pool_def_ids[]" />';
155 }
156
157 private function getDefinitionOrderInputHTML($srcPoolDefId, $defOrderNumber): string
158 {
159 return '<input type="text" size="2" value="' . $defOrderNumber . '" name="def_order[' . $srcPoolDefId . ']" />';
160 }
161
162 private function getQuestionAmountInputHTML($srcPoolDefId, $questionAmount): string
163 {
164 return '<input type="text" size="4" value="' . $questionAmount . '" name="quest_amount[' . $srcPoolDefId . ']" />';
165 }
166
167 private function getActionsHTML($sourcePoolDefinitionId): string
168 {
169 require_once 'Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
170
171 $selectionList = new ilAdvancedSelectionListGUI();
172
173 $selectionList->setId('sourcePoolDefinitionActions_' . $sourcePoolDefinitionId);
174 $selectionList->setListTitle($this->lng->txt("actions"));
175
176 $selectionList->addItem($this->lng->txt('edit'), '', $this->getEditHref($sourcePoolDefinitionId));
177 $selectionList->addItem($this->lng->txt('delete'), '', $this->getDeleteHref($sourcePoolDefinitionId));
178
179 return $selectionList->getHTML();
180 }
181
182 private function getEditHref($sourcePoolDefinitionId): string
183 {
184 $href = $this->ctrl->getLinkTarget(
185 $this->parent_obj,
187 );
188
189 $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
190
191 return $href;
192 }
193
194 private function getDeleteHref($sourcePoolDefinitionId): string
195 {
196 $href = $this->ctrl->getLinkTarget(
197 $this->parent_obj,
199 );
200
201 $href = ilUtil::appendUrlParameterString($href, "src_pool_def_id=" . $sourcePoolDefinitionId, true);
202
203 return $href;
204 }
205
206 private function getOrderNumberForSequencePosition($sequencePosition)
207 {
208 return ($sequencePosition * 10);
209 }
210
211 private function getTaxonomyTreeLabel($taxonomyTreeId)
212 {
213 if (!$taxonomyTreeId) {
214 return '';
215 }
216
217 return $this->taxonomyLabelTranslater->getTaxonomyTreeLabel($taxonomyTreeId);
218 }
219
220 private function getTaxonomyNodeLabel($taxonomyNodeId)
221 {
222 if (!$taxonomyNodeId) {
223 return '';
224 }
225
226 return $this->taxonomyLabelTranslater->getTaxonomyNodeLabel($taxonomyNodeId);
227 }
228
229 public function build(): void
230 {
231 $this->setTableIdentifiers();
232
233 $this->setTitle($this->lng->txt('tst_src_quest_pool_def_list_table'));
234
235 $this->setRowTemplate("tpl.il_tst_rnd_quest_set_src_pool_def_row.html", "Modules/Test");
236
237 $this->enable('header');
238 $this->disable('sort');
239
240 $this->enable('select_all');
241 $this->setSelectAllCheckbox('src_pool_def_ids[]');
242
243 $this->setExternalSegmentation(true);
244 $this->setLimit(PHP_INT_MAX);
245
246 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
247
248 $this->addCommands();
249 $this->addColumns();
250 }
251
252 private function setTableIdentifiers(): void
253 {
254 $this->setId(self::IDENTIFIER);
255 $this->setPrefix(self::IDENTIFIER);
256 $this->setFormName(self::IDENTIFIER);
257 }
258
259 private function addCommands(): void
260 {
261 if ($this->isDefinitionEditModeEnabled()) {
264 }
265 }
266
267 private function addColumns(): void
268 {
269 if ($this->isDefinitionEditModeEnabled()) {
270 $this->addColumn('', 'select', '1%', true);
271 $this->addColumn('', 'order', '1%', true);
272 } else {
273 $this->addColumn($this->lng->txt("position"));
274 }
275
276 $this->addColumn($this->lng->txt("tst_source_question_pool"), 'source_question_pool', '');
277 $this->addColumn($this->lng->txt("tst_filter_taxonomy") . ' / ' . $this->lng->txt("tst_filter_tax_node"), 'tst_filter_taxonomy', '');
278 #$this->addColumn($this->lng->txt("tst_filter_taxonomy"),'tst_filter_taxonomy', '');
279 #$this->addColumn($this->lng->txt("tst_filter_tax_node"),'tst_filter_tax_node', '');
280 $this->addColumn($this->lng->txt("qst_lifecycle"), 'tst_filter_lifecycle', '');
281 $this->addColumn($this->lng->txt("tst_filter_question_type"), 'tst_filter_question_type', '');
282
283 if ($this->isQuestionAmountColumnEnabled()) {
284 $this->addColumn($this->lng->txt("tst_question_amount"), 'tst_question_amount', '');
285 }
286
287 if ($this->isDefinitionEditModeEnabled()) {
288 $this->addColumn($this->lng->txt("actions"), 'actions', '');
289 }
290 }
291
292 public function init(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList): void
293 {
294 $rows = array();
295
296 foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
299 $set = array();
300
301 $set['def_id'] = $sourcePoolDefinition->getId();
302 $set['sequence_position'] = $sourcePoolDefinition->getSequencePosition();
303 $set['source_pool_label'] = $sourcePoolDefinition->getPoolTitle();
304 // fau: taxFilter/typeFilter - get the type and taxonomy filter for display
305 if ($this->showMappedTaxonomyFilter) {
306 // mapped filter will be used after synchronisation
307 $set['taxonomy_filter'] = $sourcePoolDefinition->getMappedTaxonomyFilter();
308 } else {
309 // original filter will be used before synchronisation
310 $set['taxonomy_filter'] = $sourcePoolDefinition->getOriginalTaxonomyFilter();
311 }
312 #$set['filter_taxonomy'] = $sourcePoolDefinition->getMappedFilterTaxId();
313 #$set['filter_tax_node'] = $sourcePoolDefinition->getMappedFilterTaxNodeId();
314 $set['lifecycle_filter'] = $sourcePoolDefinition->getLifecycleFilter();
315 $set['type_filter'] = $sourcePoolDefinition->getTypeFilter();
316 // fau.
317 $set['question_amount'] = $sourcePoolDefinition->getQuestionAmount();
318 $set['ref_id'] = $sourcePoolDefinition->getPoolRefId();
319 $rows[] = $set;
320 }
321
322 $this->setData($rows);
323 }
324
325 public function applySubmit(ilTestRandomQuestionSetSourcePoolDefinitionList $sourcePoolDefinitionList): void
326 {
327 foreach ($sourcePoolDefinitionList as $sourcePoolDefinition) {
330 $orderNumber = $this->fetchOrderNumberParameter($sourcePoolDefinition);
331 $sourcePoolDefinition->setSequencePosition($orderNumber);
332
333 if ($this->isQuestionAmountColumnEnabled()) {
334 $questionAmount = $this->fetchQuestionAmountParameter($sourcePoolDefinition);
335 $sourcePoolDefinition->setQuestionAmount($questionAmount);
336 } else {
337 $sourcePoolDefinition->setQuestionAmount(null);
338 }
339 }
340 }
341
343 {
344 $def_order = $this->testrequest->raw('def_order');
345 return array_key_exists($definition->getId(), $def_order) ? (int) $def_order[$definition->getId()] : 0;
346 }
347
349 {
350 $quest_amount = $this->testrequest->raw('quest_amount');
351 return array_key_exists($definition->getId(), $quest_amount) ? (int) $quest_amount[$definition->getId()] : 0;
352 }
353}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
language handling
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setExternalSegmentation(bool $a_val)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
setFormName(string $a_name="")
addMultiCommand(string $a_cmd, string $a_text)
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setData(array $a_data)
Set table data.
ilLanguage $lng
enable(string $a_module_name)
disable(string $a_module_name)
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
global $DIC
Definition: feed.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$rows
Definition: xhr_table.php:10