ILIAS  release_8 Revision v8.24
class.ilTestQuestionsTableGUI.php
Go to the documentation of this file.
1<?php
2
19use ILIAS\Modules\Test\QuestionPoolLinkedTitleBuilder;
20
30{
31 use QuestionPoolLinkedTitleBuilder;
32 private const CLASS_PATH_FOR_QUESTION_EDIT_LINKS = [ilRepositoryGUI::class, ilObjQuestionPoolGUI::class];
33
38
42 protected $questionManagingEnabled = false;
43
48
52 protected $questionPositioningEnabled = false;
53
58
59 protected float $totalPoints = 0;
60 protected string $totalWorkingTime = '';
61 private int $position = 0;
62 private int $parent_ref_id;
63
64 protected \ILIAS\UI\Renderer $renderer;
65 protected \ILIAS\UI\Factory $factory;
67
68 public function __construct($a_parent_obj, $a_parent_cmd, $parentRefId)
69 {
70 global $DIC;
71
72 $this->renderer = $DIC->ui()->renderer();
73 $this->factory = $DIC->ui()->factory();
74 $this->access = $DIC['ilAccess'];
75
76 $this->setId('tst_qst_lst_' . $parentRefId);
77
78 $this->parent_ref_id = (int) $parentRefId;
79
80 parent::__construct($a_parent_obj, $a_parent_cmd);
81
82 $this->setFormName('questionbrowser');
83 $this->setStyle('table', 'fullwidth');
84
85 $this->setExternalSegmentation(true);
86
87 $this->setRowTemplate("tpl.il_as_tst_questions_row.html", "Modules/Test");
88
89 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
90
91 $this->disable('sort');
92 $this->enable('header');
93
94 $this->setShowRowsSelector(false);
95 }
96
97 public function getSelectableColumns(): array
98 {
99 $cols = array(
100 'qid' => array('txt' => $this->lng->txt('question_id'), 'default' => true),
101 'description' => array('txt' => $this->lng->txt('description'), 'default' => false),
102 'author' => array('txt' => $this->lng->txt('author'), 'default' => false),
103 'lifecycle' => array('txt' => $this->lng->txt('qst_lifecycle'), 'default' => true)
104 );
105
106 return $cols;
107 }
108
109 public function init(): void
110 {
111 $this->initColumns();
112 $this->initCommands();
113
114 if ($this->isQuestionManagingEnabled()) {
115 $this->setSelectAllCheckbox('q_id');
116 }
117 }
118
119 protected function initColumns(): void
120 {
121 if ($this->isCheckboxColumnRequired()) {
122 $this->addColumn('', 'f', '1%', true);
123 }
124
125 if ($this->isQuestionPositioningEnabled()) {
126 $this->addColumn($this->lng->txt('order'), 'f', '1%');
127 }
128
129 if ($this->isColumnSelected('qid')) {
130 $this->addColumn($this->lng->txt('question_id'), 'qid', '');
131 }
132
133 $this->addColumn($this->lng->txt("tst_question_title"), 'title', '');
134
136 $this->addColumn($this->lng->txt("obligatory"), 'obligatory', '');
137 }
138
139 if ($this->isColumnSelected('description')) {
140 $this->addColumn($this->lng->txt('description'), 'description', '');
141 }
142
143 $this->addColumn($this->lng->txt("tst_question_type"), 'type', '');
144 $this->addColumn($this->buildPointsHeader(), '', '');
145
146 if ($this->isColumnSelected('author')) {
147 $this->addColumn($this->lng->txt('author'), 'author', '');
148 }
149 if ($this->isColumnSelected('lifecycle')) {
150 $this->addColumn($this->lng->txt('qst_lifecycle'), 'lifecycle', '');
151 }
152
153 $this->addColumn($this->lng->txt('qpl'), 'qpl', '');
154
155 $this->addColumn($this->lng->txt('actions'), '', '1%');
156 }
157
158 protected function initCommands(): void
159 {
160 if ($this->isQuestionManagingEnabled()) {
161 $this->addMultiCommand('removeQuestions', $this->lng->txt('remove_question'));
162 $this->addMultiCommand('moveQuestions', $this->lng->txt('move'));
163 }
164
165 if ($this->isPositionInsertCommandsEnabled()) {
166 $this->addMultiCommand('insertQuestionsBefore', $this->lng->txt('insert_before'));
167 $this->addMultiCommand('insertQuestionsAfter', $this->lng->txt('insert_after'));
168 }
169
170 if ($this->isQuestionManagingEnabled()) {
171 $this->addMultiCommand('copyQuestion', $this->lng->txt('copy'));
172 $this->addMultiCommand('copyAndLinkToQuestionpool', $this->lng->txt('copy_and_link_to_questionpool'));
173 }
174
175 if ($this->isTableSaveCommandRequired()) {
176 $this->addCommandButton('saveOrderAndObligations', $this->buildTableSaveCommandLabel());
177 }
178 }
179
180 public function fillRow(array $a_set): void
181 {
182 if ($this->isCheckboxColumnRequired()) {
183 $this->tpl->setVariable("CHECKBOX_QID", $a_set['question_id']);
184 }
185
186 if ($this->isQuestionPositioningEnabled()) {
187 $this->position += 10;
188 $inputField = $this->buildPositionInput($a_set['question_id'], $this->position);
189
190 $this->tpl->setVariable("QUESTION_POSITION", $inputField);
191 $this->tpl->setVariable("POSITION_QID", $a_set['question_id']);
192 }
193
194 if ($this->isColumnSelected('qid')) {
195 $this->tpl->setVariable("QUESTION_ID_PRESENTATION", $a_set['question_id']);
196 }
197
198 $this->tpl->setVariable("QUESTION_TITLE", $this->buildQuestionTitleLink($a_set));
199
200 if (!$a_set['complete']) {
201 $this->tpl->setVariable("QUESTION_INCOMPLETE_WARNING", $this->lng->txt("warning_question_not_complete"));
202 }
203
205 $this->tpl->setVariable("QUESTION_OBLIGATORY", $this->buildObligatoryColumnContent($a_set));
206 }
207
208 if ($this->isColumnSelected('description')) {
209 $this->tpl->setVariable("QUESTION_COMMENT", $a_set["description"] ? $a_set["description"] : '&nbsp;');
210 }
211
212 $this->tpl->setVariable("QUESTION_TYPE", assQuestion::_getQuestionTypeName($a_set["type_tag"]));
213 $this->tpl->setVariable("QUESTION_POINTS", $a_set["points"]);
214
215 if ($this->isColumnSelected('author')) {
216 $this->tpl->setVariable("QUESTION_AUTHOR", $a_set["author"]);
217 }
218
219 if ($this->isColumnSelected('lifecycle')) {
220 try {
221 $lifecycle = ilAssQuestionLifecycle::getInstance($a_set['lifecycle'])->getTranslation($this->lng);
222 $this->tpl->setVariable("QUESTION_LIFECYCLE", $lifecycle);
224 $this->tpl->setVariable("QUESTION_LIFECYCLE", '');
225 }
226 }
227
228 $question_pool_title = $this->lng->txt('tst_question_not_from_pool_info');
229
230 if (isset($a_set['orig_obj_fi']) && ilObject::_lookupTitle($a_set['orig_obj_fi']) !== null) {
231 $question_pool_title = $this->buildPossiblyLinkedQuestonPoolTitle(
232 $this->ctrl,
233 $this->access,
234 $this->lng,
235 $this->factory,
236 $this->renderer,
237 $a_set["orig_obj_fi"],
238 ilObject::_lookupTitle($a_set["orig_obj_fi"])
239 );
240 }
241
242 $this->tpl->setVariable(
243 "QUESTION_POOL",
244 $question_pool_title
245 );
246
247 $actions = new ilAdvancedSelectionListGUI();
248 $actions->setId('qst' . $a_set["question_id"]);
249 $actions->setListTitle($this->lng->txt('actions'));
250
251 $actions->addItem(
252 $this->lng->txt('preview'),
253 '',
254 $this->getPreviewLink($a_set)
255 );
256
257 $actions->addItem(
258 $this->lng->txt('statistics'),
259 '',
260 $this->getQuestionEditLink($a_set, 'ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_STATISTICS)
261 );
262
263 if ($this->isQuestionManagingEnabled()) {
264 $editHref = $this->getQuestionEditLink($a_set, $a_set['type_tag'] . 'GUI', 'editQuestion');
265 $actions->addItem($this->lng->txt('edit_question'), '', $editHref);
266
267 $editPageHref = $this->getQuestionEditLink($a_set, 'ilAssQuestionPageGUI', 'edit');
268 $actions->addItem($this->lng->txt('edit_page'), '', $editPageHref);
269
270 $moveHref = $this->getEditLink($a_set, get_class($this->getParentObject()), 'moveQuestions');
271 $actions->addItem($this->lng->txt('move'), '', $moveHref);
272
273 $copyHref = $this->getEditLink($a_set, get_class($this->getParentObject()), 'copyQuestion');
274 $actions->addItem($this->lng->txt('copy'), '', $copyHref);
275
276 $deleteHref = $this->getEditLink($a_set, get_class($this->getParentObject()), 'removeQuestions');
277 $actions->addItem($this->lng->txt('delete'), '', $deleteHref);
278
279 $feedbackHref = $this->getQuestionEditLink($a_set, 'ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW);
280 $actions->addItem($this->lng->txt('tst_feedback'), '', $feedbackHref);
281
282 $hintsHref = $this->getQuestionEditLink($a_set, 'ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST);
283 $actions->addItem($this->lng->txt('tst_question_hints_tab'), '', $hintsHref);
284 }
285 $this->tpl->setVariable('ROW_ACTIONS', $actions->getHTML());
287 $this->tpl->setVariable('ROW_ACTIONS', $this->buildQuestionRemoveButton($a_set));
288 }
289 }
290
291 protected function buildQuestionRemoveButton(array $rowData): string
292 {
293 $this->ctrl->setParameter($this->getParentObject(), 'removeQid', $rowData['question_id']);
294 $removeUrl = $this->ctrl->getLinkTarget($this->getParentObject(), $this->getParentCmd());
295 $this->ctrl->setParameter($this->getParentObject(), 'removeQid', '');
296
297 $button = ilLinkButton::getInstance();
298 $button->setCaption('remove_question');
299 $button->setUrl($removeUrl);
300
301 return $button->render();
302 }
303
304 protected function buildQuestionTitleLink(array $rowData): string
305 {
306 return '<a href="' . $this->getPreviewLink($rowData) . '">' . $rowData["title"] . '</a>';
307 }
308
309 protected function getPreviewLink(array $rowData): string
310 {
311 $target_class = get_class($this->getParentObject());
312 $this->ctrl->setParameterByClass(
313 $target_class,
314 'ref_id',
315 current(ilObject::_getAllReferences($rowData['obj_fi']))
316 );
317
318 $this->ctrl->setParameterByClass(
319 $target_class,
320 'eqpl',
321 current(ilObject::_getAllReferences($rowData['obj_fi']))
322 );
323
324 $this->ctrl->setParameterByClass(
325 $target_class,
326 'eqid',
327 $rowData['question_id']
328 );
329
330 $this->ctrl->setParameterByClass(
331 $target_class,
332 'q_id',
333 $rowData['question_id']
334 );
335
336 $this->ctrl->setParameterByClass(
337 $target_class,
338 'calling_test',
339 (string) $this->parent_ref_id
340 );
341
342 $question_href = $this->ctrl->getLinkTargetByClass(
343 $target_class,
344 $this->getParentCmd()
345 );
346 $this->ctrl->setParameterByClass($target_class, 'eqpl', '');
347 $this->ctrl->setParameterByClass($target_class, 'eqid', '');
348 $this->ctrl->setParameterByClass($target_class, 'q_id', '');
349 $this->ctrl->setParameterByClass($target_class, 'calling_test', '');
350
351 return $question_href;
352 }
353
354 protected function getQuestionEditLink(array $rowData, string $target_class, string $cmd, array $target_class_path = []): string
355 {
356 $target_class_path = array_merge(self::CLASS_PATH_FOR_QUESTION_EDIT_LINKS, [$target_class]);
357 return $this->getEditLink($rowData, $target_class, $cmd, $target_class_path);
358 }
359
360 protected function getEditLink(array $rowData, string $target_class, string $cmd, array $target_class_path = []): string
361 {
362 if ($target_class_path === []) {
363 $target_class_path = $target_class;
364 }
365 $this->ctrl->setParameterByClass(
366 $target_class,
367 'ref_id',
368 current(ilObject::_getAllReferences($rowData['obj_fi']))
369 );
370
371 $this->ctrl->setParameterByClass(
372 $target_class,
373 'q_id',
374 $rowData['question_id']
375 );
376 $this->ctrl->setParameterByClass(
377 $target_class,
378 'calling_test',
379 $_GET['ref_id']
380 );
381
382 $link = $this->ctrl->getLinkTargetByClass($target_class_path, $cmd);
383
384 $this->ctrl->setParameterByClass($target_class, 'ref_id', '');
385 $this->ctrl->setParameterByClass($target_class, 'q_id', '');
386 $this->ctrl->setParameterByClass($target_class, 'calling_test', '');
387 return $link;
388 }
389
390 protected function buildObligatoryColumnContent(array $rowData): string
391 {
392 if (!$rowData['obligationPossible']) {
393 return '&nbsp;';
394 }
395
396 if ($rowData['obligatory'] && !$this->isQuestionManagingEnabled()) {
397 $icon = $this->factory->symbol()->icon()->custom(
398 ilUtil::getImagePath("icon_checked.svg"),
399 $this->lng->txt('question_obligatory')
400 );
401 return $this->renderer->render($icon);
402 }
403
404 $checkedAttr = $rowData['obligatory'] ? 'checked="checked"' : '';
405 return '<input type="checkbox" name="obligatory[' . $rowData['question_id'] . ']" value="1" ' . $checkedAttr . ' />';
406 }
407
408 protected function buildPositionInput($questionId, $position): string
409 {
410 return '<input type="text" name="order[q_' . $questionId . ']" value="' . $position . '" maxlength="4" size="4" />';
411 }
412
413 protected function buildTableSaveCommandLabel(): string
414 {
416 return $this->lng->txt('saveOrderAndObligations');
417 }
418
420 return $this->lng->txt('saveObligations');
421 }
422
423 if ($this->isQuestionPositioningEnabled()) {
424 return $this->lng->txt('saveOrder');
425 }
426
427 return $this->lng->txt('save');
428 }
429
430 protected function buildPointsHeader(): string
431 {
432 if ($this->getTotalPoints()) {
433 return $this->lng->txt('points') . ' (' . $this->getTotalPoints() . ')';
434 }
435
436 return $this->lng->txt('points');
437 }
438
439 protected function isTableSaveCommandRequired(): bool
440 {
441 if (!$this->isQuestionManagingEnabled()) {
442 return false;
443 }
444
446 }
447
448 protected function isCheckboxColumnRequired(): bool
449 {
451 }
452
453 public function isQuestionManagingEnabled(): bool
454 {
456 }
457
459 {
460 $this->questionManagingEnabled = $questionManagingEnabled;
461 }
462
463 public function isPositionInsertCommandsEnabled(): bool
464 {
466 }
467
469 {
470 $this->positionInsertCommandsEnabled = $positionInsertCommandsEnabled;
471 }
472
473 public function isQuestionPositioningEnabled(): bool
474 {
476 }
477
479 {
480 $this->questionPositioningEnabled = $questionPositioningEnabled;
481 }
482
484 {
486 }
487
489 {
490 $this->obligatoryQuestionsHandlingEnabled = $obligatoryQuestionsHandlingEnabled;
491 }
492
493 public function getTotalPoints(): float
494 {
495 return $this->totalPoints;
496 }
497
498 public function setTotalPoints(float $totalPoints): void
499 {
500 $this->totalPoints = $totalPoints;
501 }
502
503 public function getTotalWorkingTime(): string
504 {
506 }
507
508 public function isQuestionRemoveRowButtonEnabled(): bool
509 {
511 }
512
514 {
515 $this->questionRemoveRowButtonEnabled = $questionRemoveRowButtonEnabled;
516 }
517}
static _getQuestionTypeName($type_tag)
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...
const CMD_SHOW_LIST
command constants
static _getAllReferences(int $id)
get all reference ids for object ID
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isColumnSelected(string $col)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
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)
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)
enable(string $a_module_name)
setStyle(string $a_element, string $a_style)
disable(string $a_module_name)
setQuestionRemoveRowButtonEnabled(bool $questionRemoveRowButtonEnabled)
getSelectableColumns()
Get selectable columns.
setQuestionManagingEnabled(bool $questionManagingEnabled)
setPositionInsertCommandsEnabled(bool $positionInsertCommandsEnabled)
__construct($a_parent_obj, $a_parent_cmd, $parentRefId)
buildPositionInput($questionId, $position)
fillRow(array $a_set)
Standard Version of Fill Row.
getEditLink(array $rowData, string $target_class, string $cmd, array $target_class_path=[])
setQuestionPositioningEnabled(bool $questionPositioningEnabled)
getQuestionEditLink(array $rowData, string $target_class, string $cmd, array $target_class_path=[])
setObligatoryQuestionsHandlingEnabled(bool $obligatoryQuestionsHandlingEnabled)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$_GET['client_id']
Definition: saml1-acs.php:21
$cols
Definition: xhr_table.php:11