ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilQuestionBrowserTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24
35{
38 protected \ILIAS\Notes\Service $notes;
39 protected \ILIAS\UI\Factory $ui_factory;
40 protected \ILIAS\UI\Renderer $renderer;
41 protected $editable = true;
42 protected $writeAccess = false;
43 protected $totalPoints = 0;
44 protected $confirmdelete;
45 protected array $filter = [];
46
47 protected $taxIds = [];
48
52 protected $questionCommentingEnabled = false;
53
54 public function __construct(
55 $a_parent_obj,
56 $a_parent_cmd,
57 $a_write_access = false,
58 $confirmdelete = false,
59 $taxIds = [],
60 $enableCommenting = false
61 ) {
62 $this->setQuestionCommentingEnabled($enableCommenting);
63
64 // Bugfix: #0019539
65 if ($confirmdelete) {
66 $this->setId("qpl_confirm_del_" . $a_parent_obj->getObject()->getRefId());
67 } else {
68 $this->setId("qpl_qst_brows_" . $a_parent_obj->getObject()->getRefId());
69 }
70
71 parent::__construct($a_parent_obj, $a_parent_cmd);
72
73 global $DIC;
74 $this->lng = $DIC['lng'];
75 $this->ctrl = $DIC['ilCtrl'];
76 $this->renderer = $DIC->ui()->renderer();
77 $this->ui_factory = $DIC->ui()->factory();
78
79 $local_dic = QuestionPoolDIC::dic();
80 $this->request = $local_dic['request_data_collector'];
81 $this->questionrepository = $local_dic['question.general_properties.repository'];
82
83 $this->confirmdelete = $confirmdelete;
84 $this->setWriteAccess($a_write_access);
85 $this->taxIds = $taxIds;
86
87 $qplSetting = new ilSetting("qpl");
88
89 $this->setFormName('questionbrowser');
90 $this->setStyle('table', 'fullwidth');
91 if (!$confirmdelete) {
92 $this->addColumn('', '', '1%');
93 $this->addColumn($this->lng->txt("title"), 'title', '');
94 foreach ($this->getSelectedColumns() as $c) {
95 if (strcmp($c, 'description') == 0) {
96 $this->addColumn($this->lng->txt("description"), 'description', '');
97 }
98 if (strcmp($c, 'type') == 0) {
99 $this->addColumn($this->lng->txt("question_type"), 'ttype', '');
100 }
101 // According to mantis #12713
102 if (strcmp($c, 'points') == 0) {
103 $this->addColumn($this->lng->txt("points"), 'points', '', false, 'ilCenterForced');
104 }
105 if (strcmp($c, 'statistics') == 0) {
106 $this->addColumn($this->lng->txt('statistics'), '', '');
107 }
108 if (strcmp($c, 'author') == 0) {
109 $this->addColumn($this->lng->txt("author"), 'author', '');
110 }
111 if ($c == 'lifecycle') {
112 $this->addColumn($this->lng->txt('qst_lifecycle'), 'lifecycle', '');
113 }
114 if ($this->isQuestionCommentingEnabled() && $c == 'comments') {
115 $this->addColumn($this->lng->txt("ass_comments"), 'comments', '');
116 }
117 if (strcmp($c, 'created') == 0) {
118 $this->addColumn($this->lng->txt("create_date"), 'created', '');
119 }
120 if (strcmp($c, 'tstamp') == 0) {
121 $this->addColumn($this->lng->txt("last_update"), 'tstamp', '');
122 }
123 }
124 $this->addColumn($this->lng->txt('actions'), '');
125 $this->setSelectAllCheckbox('q_id');
126 } else {
127 $this->addColumn($this->lng->txt("title"), 'title', '');
128 foreach ($this->getSelectedColumns() as $c) {
129 if (strcmp($c, 'description') == 0) {
130 $this->addColumn($this->lng->txt("description"), 'description', '');
131 }
132 if (strcmp($c, 'type') == 0) {
133 $this->addColumn($this->lng->txt("question_type"), 'ttype', '');
134 }
135 }
136 }
137
138 if ($this->getWriteAccess()) {
139 if ($confirmdelete) {
140 $this->addCommandButton('confirmDeleteQuestions', $this->lng->txt('confirm'));
141 $this->addCommandButton('cancelDeleteQuestions', $this->lng->txt('cancel'));
142 } else {
143 $this->addMultiCommand('copy', $this->lng->txt('copy'));
144 $this->addMultiCommand('move', $this->lng->txt('move'));
145 $this->addMultiCommand('exportQuestion', $this->lng->txt('export'));
146 $this->addMultiCommand('deleteQuestions', $this->lng->txt('delete'));
147 }
148 }
149
150 $this->setRowTemplate("tpl.il_as_qpl_questionbrowser_row.html", "components/ILIAS/TestQuestionPool");
151
152 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj, $a_parent_cmd));
153 $this->setDefaultOrderField("title");
154 $this->setDefaultOrderDirection("asc");
155
156 $this->setShowRowsSelector(true);
157
158 if ($confirmdelete) {
159 $this->disable('sort');
160 $this->disable('select_all');
161 } else {
162 $this->enable('sort');
163 $this->enable('header');
164 $this->enable('select_all');
165 $this->setFilterCommand('filterQuestionBrowser');
166 $this->setResetCommand('resetQuestionBrowser');
167 $this->initFilter();
168 }
169 $this->notes = $DIC->notes();
170 if ($this->isQuestionCommentingEnabled()) {
171 $this->notes->gui()->initJavascript();
172 }
173 }
174
178 public function isQuestionCommentingEnabled(): bool
179 {
181 }
182
187 {
188 $this->questionCommentingEnabled = $questionCommentingEnabled;
189 }
190
191 protected function isCommentsColumnSelected(): bool
192 {
193 return in_array('comments', $this->getSelectedColumns());
194 }
195
196 public function setQuestionData($questionData): void
197 {
198 if ($this->isQuestionCommentingEnabled() && ($this->isCommentsColumnSelected() || $this->filter['commented'])) {
199 foreach ($questionData as $key => $data) {
200 $notes_context = $this->notes
201 ->data()
202 ->context(
203 $this->parent_obj->getObject()->getId(),
204 $data['question_id'],
205 'quest'
206 );
207 $numComments = $this->notes
208 ->domain()
209 ->getNrOfCommentsForContext($notes_context);
210
211 if ($this->filter['commented'] && !$numComments) {
212 unset($questionData[$key]);
213 continue;
214 }
215
216 $questionData[$key]['comments'] = $numComments;
217 }
218 }
219
220 $this->setData($questionData);
221 }
222
223 public function getSelectableColumns(): array
224 {
225 global $DIC;
226 $lng = $DIC['lng'];
227 $cols["description"] = [
228 "txt" => $lng->txt("description"),
229 "default" => true
230 ];
231 $cols["type"] = [
232 "txt" => $lng->txt("question_type"),
233 "default" => true
234 ];
235 if (!$this->confirmdelete) {
236 $cols["points"] = [
237 "txt" => $lng->txt("points"),
238 "default" => true
239 ];
240 $cols["statistics"] = [
241 "txt" => $lng->txt("statistics"),
242 "default" => true
243 ];
244 $cols["author"] = [
245 "txt" => $lng->txt("author"),
246 "default" => true
247 ];
248 $cols['lifecycle'] = [
249 'txt' => $lng->txt('qst_lifecycle'),
250 'default' => true
251 ];
252 if ($this->isQuestionCommentingEnabled()) {
253 $cols["comments"] = [
254 "txt" => $lng->txt("comments"),
255 "default" => true
256 ];
257 }
258 $cols["created"] = [
259 "txt" => $lng->txt("create_date"),
260 "default" => true
261 ];
262 $cols["tstamp"] = [
263 "txt" => $lng->txt("last_update"),
264 "default" => true
265 ];
266 }
267 return $cols;
268 }
269
273 public function initFilter(): void
274 {
275 global $DIC;
276 $lng = $DIC['lng'];
277
278 $ti = new ilTextInputGUI($lng->txt("title"), "title");
279 $ti->setMaxLength(64);
280 $ti->setValidationRegexp('/^[^%]+$/is');
281 $ti->setSize(20);
282 $this->addFilterItem($ti);
283 $ti->readFromSession();
284 $this->filter["title"] = $ti->getValue();
285
286 // description
287 $ti = new ilTextInputGUI($lng->txt("description"), "description");
288 $ti->setMaxLength(64);
289 $ti->setSize(20);
290 $ti->setValidationRegexp('/^[^%]+$/is');
291 $this->addFilterItem($ti);
292 $ti->readFromSession();
293 $this->filter["description"] = $ti->getValue();
294
295 if (!$this->confirmdelete) {
296 // author
297 $ti = new ilTextInputGUI($lng->txt("author"), "author");
298 $ti->setMaxLength(64);
299 $ti->setSize(20);
300 $ti->setValidationRegexp('/^[^%]+$/is');
301 $this->addFilterItem($ti);
302 $ti->readFromSession();
303 $this->filter["author"] = $ti->getValue();
304 }
305
306 // lifecycle
307 $lifecycleOptions = array_merge(
308 ['' => $this->lng->txt('qst_lifecycle_filter_all')],
309 ilAssQuestionLifecycle::getDraftInstance()->getSelectOptions($this->lng)
310 );
311 $lifecycleInp = new ilSelectInputGUI($this->lng->txt('qst_lifecycle'), 'lifecycle');
312 $lifecycleInp->setOptions($lifecycleOptions);
313 $this->addFilterItem($lifecycleInp);
314 $lifecycleInp->readFromSession();
315 $this->filter['lifecycle'] = $lifecycleInp->getValue();
316
318 $options = [];
319 $options[""] = $lng->txt('filter_all_question_types');
320 foreach ($types as $translation => $row) {
321 $options[$row['type_tag']] = $translation;
322 }
323
324 $si = new ilSelectInputGUI($this->lng->txt("question_type"), "type");
325 $si->setOptions($options);
326 $this->addFilterItem($si);
327 $si->readFromSession();
328 $this->filter["type"] = $si->getValue();
329
330 foreach ($this->taxIds as $taxId) {
331 $postvar = "tax_$taxId";
332
333 $inp = new ilTaxSelectInputGUI($taxId, $postvar, true);
334 $this->addFilterItem($inp);
335 $inp->readFromSession();
336 $this->filter[$postvar] = $inp->getValue();
337 }
338
339 // comments
340 if ($this->isQuestionCommentingEnabled()) {
341 $comments = new ilCheckboxInputGUI($lng->txt('ass_commented_questions_only'), 'commented');
342 $this->addFilterItem($comments);
343 $comments->readFromSession();
344 $this->filter['commented'] = $comments->getChecked();
345 }
346 }
347
348 public function fillHeader(): void
349 {
350 foreach ($this->column as $key => $column) {
351 if (strcmp($column['text'], $this->lng->txt("points")) == 0) {
352 $this->column[$key]['text'] = $this->lng->txt("points") . "&nbsp;(" . $this->totalPoints . ")";
353 }
354 }
355 parent::fillHeader();
356 }
357
364 public function fillRow(array $a_set): void
365 {
366 $class = strtolower($this->questionrepository->getForQuestionId($a_set['question_id'])->getGuiClassName());
367 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $a_set["question_id"]);
368 $this->ctrl->setParameterByClass("ilAssQuestionPreviewGUI", "q_id", $a_set["question_id"]);
369 $this->ctrl->setParameterByClass($class, "q_id", $a_set["question_id"]);
370 $points = 0;
371
372 $actions = [];
373
374 if (!$this->confirmdelete) {
375 $this->tpl->setCurrentBlock('checkbox');
376 $this->tpl->setVariable('CB_QUESTION_ID', $a_set["question_id"]);
377 $this->tpl->parseCurrentBlock();
378
379 if ($a_set["complete"] == 0) {
380 $icon = $this->ui_factory->symbol()->icon()->custom(ilUtil::getImagePath("standard/icon_alert.svg"), $this->lng->txt("warning_question_not_complete"));
381 $this->tpl->setCurrentBlock("qpl_warning");
382 $this->tpl->setVariable("ICON_WARNING", $this->renderer->render($icon));
383 $this->tpl->parseCurrentBlock();
384 } else {
385 $points = $a_set["points"];
386 }
387 $this->totalPoints += $points;
388
389 foreach ($this->getSelectedColumns() as $c) {
390 if (strcmp($c, 'points') == 0) {
391 $this->tpl->setCurrentBlock('points');
392 $this->tpl->setVariable("QUESTION_POINTS", $points);
393 $this->tpl->parseCurrentBlock();
394 }
395 if (strcmp($c, 'statistics') == 0) {
396 $this->tpl->setCurrentBlock('statistics');
397 $this->tpl->setVariable("LINK_ASSESSMENT", $this->ctrl->getLinkTargetByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_STATISTICS));
398 $this->tpl->setVariable("TXT_ASSESSMENT", $this->lng->txt("statistics"));
399 $this->tpl->setVariable("IMG_ASSESSMENT", ilUtil::getImagePath("assessment.gif", "components/ILIAS/TestQuestionPool"));
400 $this->tpl->parseCurrentBlock();
401 }
402 if (strcmp($c, 'author') == 0) {
403 $this->tpl->setCurrentBlock('author');
404 $this->tpl->setVariable("QUESTION_AUTHOR", $a_set["author"]);
405 $this->tpl->parseCurrentBlock();
406 }
407 if ($c == 'lifecycle') {
408 $lifecycle = ilAssQuestionLifecycle::getInstance($a_set['lifecycle']);
409
410 $this->tpl->setCurrentBlock('lifecycle');
411 $this->tpl->setVariable("QUESTION_LIFECYCLE", $lifecycle->getTranslation($this->lng));
412 $this->tpl->parseCurrentBlock();
413 }
414 if ($c == 'comments' && $this->isQuestionCommentingEnabled()) {
415 $this->tpl->setCurrentBlock('comments');
416 $this->tpl->setVariable("COMMENTS", $this->getCommentsHtml($a_set));
417 $this->tpl->parseCurrentBlock();
418 }
419 if (strcmp($c, 'created') == 0) {
420 $this->tpl->setCurrentBlock('created');
421 $this->tpl->setVariable('QUESTION_CREATED', ilDatePresentation::formatDate(new ilDateTime($a_set['created'], IL_CAL_UNIX)));
422 $this->tpl->parseCurrentBlock();
423 }
424 if (strcmp($c, 'tstamp') == 0) {
425 $this->tpl->setCurrentBlock('updated');
426 $this->tpl->setVariable('QUESTION_UPDATED', ilDatePresentation::formatDate(new ilDateTime($a_set['tstamp'], IL_CAL_UNIX)));
427 $this->tpl->parseCurrentBlock();
428 }
429 }
430
431 $actions[] = $this->ui_factory->link()->standard(
432 $this->lng->txt('preview'),
433 $this->ctrl->getLinkTargetByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW)
434 );
435
436 $actions[] = $this->ui_factory->link()->standard(
437 $this->lng->txt('statistics'),
438 $this->ctrl->getLinkTargetByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_STATISTICS)
439 );
440
441 if ($this->getEditable()) {
442 $this->ctrl->setParameterByClass($a_set['type_tag'] . 'GUI', 'q_id', $a_set['question_id']);
443 $editHref = $this->ctrl->getLinkTargetByClass($a_set['type_tag'] . 'GUI', 'editQuestion');
444 $this->ctrl->setParameterByClass($a_set['type_tag'] . 'GUI', 'q_id', null);
445 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('edit_question'), $editHref);
446
447 $editPageHref = $this->ctrl->getLinkTargetByClass('ilAssQuestionPageGUI', 'edit');
448 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('edit_page'), $editPageHref);
449 }
450
451 if ($this->getWriteAccess()) {
452 $this->ctrl->setParameter($this->parent_obj, 'q_id', $a_set['question_id']);
453 $moveHref = $this->ctrl->getLinkTarget($this->parent_obj, 'move');
454 $this->ctrl->setParameter($this->parent_obj, 'q_id', null);
455 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('move'), $moveHref);
456
457 $this->ctrl->setParameter($this->parent_obj, 'q_id', $a_set['question_id']);
458 $copyHref = $this->ctrl->getLinkTarget($this->parent_obj, 'copy');
459 $this->ctrl->setParameter($this->parent_obj, 'q_id', null);
460 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('copy'), $copyHref);
461
462 $this->ctrl->setParameter($this->parent_obj, 'q_id', $a_set['question_id']);
463 $deleteHref = $this->ctrl->getLinkTarget($this->parent_obj, 'deleteQuestions');
464 $this->ctrl->setParameter($this->parent_obj, 'q_id', null);
465 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('delete'), $deleteHref);
466 }
467
468 if ($this->getEditable()) {
469 $this->ctrl->setParameterByClass('ilAssQuestionFeedbackEditingGUI', 'q_id', $a_set['question_id']);
470 $feedbackHref = $this->ctrl->getLinkTargetByClass('ilAssQuestionFeedbackEditingGUI', ilAssQuestionFeedbackEditingGUI::CMD_SHOW);
471 $this->ctrl->setParameterByClass('ilAssQuestionFeedbackEditingGUI', 'q_id', null);
472 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('tst_feedback'), $feedbackHref);
473 }
474
475 if ($this->isQuestionCommentingEnabled()) {
476 $actions[] = $this->ui_factory->link()->standard($this->lng->txt('ass_comments'), $this->getCommentsAjaxLink($a_set['question_id']));
477 }
478 } else {
479 $this->tpl->setCurrentBlock('hidden');
480 $this->tpl->setVariable('HIDDEN_QUESTION_ID', $a_set["question_id"]);
481 $this->tpl->parseCurrentBlock();
482 }
483
484 foreach ($this->getSelectedColumns() as $c) {
485 if (strcmp($c, 'description') == 0) {
486 $this->tpl->setCurrentBlock('description');
487 $this->tpl->setVariable("QUESTION_COMMENT", $a_set['description']);
488 $this->tpl->parseCurrentBlock();
489 }
490 if (strcmp($c, 'type') == 0) {
491 $this->tpl->setCurrentBlock('type');
492 $this->tpl->setVariable("QUESTION_TYPE", $this->questionrepository->getForQuestionId($a_set["question_id"])->getTypeName($this->lng));
493 $this->tpl->parseCurrentBlock();
494 }
495 }
496 $this->tpl->setVariable('QUESTION_ID', $a_set["question_id"]);
497 if (!$this->confirmdelete) {
498 $this->tpl->setVariable('QUESTION_HREF_LINKED', $this->ctrl->getLinkTargetByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW));
499 $this->tpl->setVariable('QUESTION_TITLE_LINKED', $a_set['title']);
500
501 $dropdown = $this->ui_factory->dropdown()->standard($actions)->withLabel($this->lng->txt('actions'));
502
503 $this->tpl->setVariable('ACTIONS', $this->renderer->render($dropdown));
504 } else {
505 $this->tpl->setVariable('QUESTION_ID_UNLINKED', $a_set['question_id']);
506 $this->tpl->setVariable('QUESTION_TITLE_UNLINKED', $a_set['title']);
507 }
508 }
509
510 public function setEditable($value): void
511 {
512 $this->editable = $value;
513 }
514
515 public function getEditable(): bool
516 {
517 return $this->editable;
518 }
519
520 public function setWriteAccess($value): void
521 {
522 $this->writeAccess = $value;
523 }
524
525 public function getWriteAccess(): bool
526 {
527 return $this->writeAccess;
528 }
529
534 public function numericOrdering(string $a_field): bool
535 {
536 if (in_array($a_field, ['points', 'created', 'tstamp', 'comments'])) {
537 return true;
538 }
539
540 return false;
541 }
542
543 protected function getCommentsHtml($qData): string
544 {
545 if (!$qData['comments']) {
546 return '';
547 }
548
549 $ajax_link = $this->getCommentsAjaxLink($qData['question_id']);
550
551 $comment_glyph = $this->ui_factory->symbol()->glyph()->comment()->withCounter(
552 $this->ui_factory->counter()->status($qData['comments'])
553 )->withAdditionalOnLoadCode(function ($id) use ($ajax_link): string {
554 return "document.getElementById('$id').onclick = function (event) { $ajax_link; };";
555 });
556 return $this->renderer->render($comment_glyph);
557 }
558
559 protected function getCommentsAjaxLink($questionId): string
560 {
561 $ajax_hash = ilCommonActionDispatcherGUI::buildAjaxHash(1, $this->request->getRefId(), 'quest', $this->parent_obj->getObject()->getId(), 'quest', $questionId);
562 $update_code = "il.UI.counter.getCounterObject($(\".ilTableOuter\")).incrementStatusCount(1);";
563 return ilCommentGUI::getListCommentsJSCall($ajax_hash, $update_code);
564 }
565}
$lifecycle
renderer()
const IL_CAL_UNIX
return true
This class represents a checkbox property in a property form.
static buildAjaxHash(int $node_type, ?int $node_id, string $obj_type, int $obj_id, ?string $sub_type=null, ?int $sub_id=null, int $news_id=0)
Build ajax hash.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
static getListCommentsJSCall(string $a_hash, ?string $a_update_code=null)
Get list comments js call.
static _getQuestionTypes($all_tags=false, $fixOrder=false, $withDeprecatedTypes=true)
setQuestionCommentingEnabled(bool $questionCommentingEnabled)
__construct( $a_parent_obj, $a_parent_cmd, $a_write_access=false, $confirmdelete=false, $taxIds=[], $enableCommenting=false)
getSelectableColumns()
Get selectable columns.
GeneralQuestionPropertiesRepository $questionrepository
fillRow(array $a_set)
fill row @access public
This class represents a selection list property in a property form.
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setFilterCommand(string $a_val, string $a_caption="")
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
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)
setDefaultOrderField(string $a_defaultorderfield)
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)
setDefaultOrderDirection(string $a_defaultorderdirection)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
ilLanguage $lng
enable(string $a_module_name)
setStyle(string $a_element, string $a_style)
disable(string $a_module_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text property in a property form.
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
$c
Definition: deliver.php:25
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26
$comments