ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestQuestionNavigationGUI.php
Go to the documentation of this file.
1 <?php
2 
26 {
27  public const SHOW_DISABLED_COMMANDS = false;
28 
29  public const CSS_CLASS_SUBMIT_BUTTONS = 'ilc_qsubmit_Submit';
30 
34  protected $lng;
35 
39  private $editSolutionCommand = '';
40 
44  private $questionWorkedThrough = false;
45 
49  private $submitSolutionCommand = '';
50 
51  // fau: testNav - new variable for 'revert changes' link target
56  // fau.
57 
62 
67 
72 
76  private $answerFreezingEnabled = false;
77 
82 
86  private $requestHintCommand = '';
87 
91  private $showHintsCommand = '';
92 
96  private $hintRequestsExist = false;
97 
98  // fau: testNav - change question mark command to link target
103  // fau.
104 
108  private $questionMarked = false;
109 
113  private $charSelectorEnabled = false;
114 
118  private $anythingRendered = false;
119 
123  public function __construct(ilLanguage $lng)
124  {
125  $this->lng = $lng;
126  }
127 
131  public function getEditSolutionCommand(): string
132  {
134  }
135 
140  {
141  $this->editSolutionCommand = $editSolutionCommand;
142  }
143 
147  public function isQuestionWorkedThrough(): bool
148  {
150  }
151 
156  {
157  $this->questionWorkedThrough = $questionWorkedThrough;
158  }
159 
163  public function getSubmitSolutionCommand(): string
164  {
166  }
167 
172  {
173  $this->submitSolutionCommand = $submitSolutionCommand;
174  }
175 
176  // fau: testNav - get/set revertChangesCommand
180  public function getRevertChangesLinkTarget(): string
181  {
183  }
184 
189  {
190  $this->revertChangesLinkTarget = $revertChangesLinkTarget;
191  }
192  // fau.
193 
197  public function isDiscardSolutionButtonEnabled(): bool
198  {
200  }
201 
206  {
207  $this->discardSolutionButtonEnabled = $discardSolutionButtonEnabled;
208  }
209 
213  public function getSkipQuestionLinkTarget(): string
214  {
216  }
217 
222  {
223  $this->skipQuestionLinkTarget = $skipQuestionLinkTarget;
224  }
225 
229  public function getInstantFeedbackCommand(): string
230  {
232  }
233 
238  {
239  $this->instantFeedbackCommand = $instantFeedbackCommand;
240  }
241 
245  public function isAnswerFreezingEnabled(): bool
246  {
248  }
249 
253  public function isForceInstantResponseEnabled(): bool
254  {
256  }
257 
262  {
263  $this->forceInstantResponseEnabled = $forceInstantResponseEnabled;
264  }
265 
270  {
271  $this->answerFreezingEnabled = $answerFreezingEnabled;
272  }
273 
277  public function getRequestHintCommand(): string
278  {
280  }
281 
286  {
287  $this->requestHintCommand = $requestHintCommand;
288  }
289 
293  public function getShowHintsCommand(): string
294  {
296  }
297 
302  {
303  $this->showHintsCommand = $showHintsCommand;
304  }
305 
309  public function hintRequestsExist(): bool
310  {
312  }
313 
318  {
320  }
321 
322  // fau: testNav - change setter/getter of question mark command to link target
326  public function getQuestionMarkLinkTarget(): string
327  {
329  }
330 
335  {
336  $this->questionMarkLinkTarget = $questionMarkLinkTarget;
337  }
338  // fau.
339 
343  public function isQuestionMarked(): bool
344  {
345  return $this->questionMarked;
346  }
347 
352  {
353  $this->questionMarked = $questionMarked;
354  }
355 
359  public function isAnythingRendered(): bool
360  {
362  }
363 
367  public function setAnythingRendered()
368  {
369  $this->anythingRendered = true;
370  }
371 
375  public function isCharSelectorEnabled(): bool
376  {
378  }
379 
384  {
385  $this->charSelectorEnabled = $charSelectorEnabled;
386  }
387 
388  // fau: testNav - generate question actions menu
393  public function getActionsHTML(): string
394  {
395  $tpl = $this->getTemplate('actions');
396 
397  include_once("Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
398  $actions = new ilGroupedListGUI();
399  $actions->setAsDropDown(true, true);
400 
401  if ($this->getQuestionMarkLinkTarget()) {
402  $actions->addEntry(
404  $this->getQuestionMarkLinkTarget(),
405  '',
406  '',
407  'ilTestQuestionAction',
408  'tst_mark_question_action'
409  );
410  $actions->addSeparator();
411  }
412 
413  if ($this->getRevertChangesLinkTarget()) {
414  $actions->addEntry(
415  $this->lng->txt('tst_revert_changes'),
417  '',
418  '',
419  'ilTestQuestionAction ilTestRevertChangesAction',
420  'tst_revert_changes_action'
421  );
422  } else {
423  $actions->addEntry(
424  $this->lng->txt('tst_revert_changes'),
425  '#',
426  '',
427  '',
428  'ilTestQuestionAction ilTestRevertChangesAction disabled',
429  'tst_revert_changes_action'
430  );
431  }
432 
433  if ($this->isDiscardSolutionButtonEnabled()) {
434  $actions->addEntry(
435  $this->lng->txt('discard_answer'),
436  '#',
437  '',
438  '',
439  'ilTestQuestionAction ilTestDiscardSolutionAction',
440  'tst_discard_solution_action'
441  );
442  } else {
443  $actions->addEntry(
444  $this->lng->txt('discard_answer'),
445  '#',
446  '',
447  '',
448  'ilTestQuestionAction ilTestDiscardSolutionAction disabled',
449  'tst_discard_solution_action'
450  );
451  }
452 
453  if ($this->getSkipQuestionLinkTarget()) {
454  $actions->addEntry(
455  $this->lng->txt('postpone_question'),
456  $this->getSkipQuestionLinkTarget(),
457  '',
458  '',
459  'ilTestQuestionAction',
460  'tst_skip_question_action'
461  );
462  } elseif (self::SHOW_DISABLED_COMMANDS) {
463  $actions->addEntry(
464  $this->lng->txt('postpone_question'),
465  '#',
466  '',
467  '',
468  'ilTestQuestionAction disabled',
469  'tst_skip_question_action'
470  );
471  }
472 
473  if ($this->isCharSelectorEnabled()) {
474  $actions->addSeparator();
475  $actions->addEntry(
476  $this->lng->txt('char_selector_btn_label'),
477  '#',
478  '',
479  '',
480  'ilTestQuestionAction ilCharSelectorMenuToggle',
481  'ilCharSelectorMenuToggleLink'
482  );
483  }
484 
485  // render the mark icon
486  if ($this->getQuestionMarkLinkTarget()) {
487  $this->renderActionsIcon(
488  $tpl,
489  $this->getQuestionMarkIconSource(),
490  $this->getQuestionMarkIconLabel(),
491  'ilTestMarkQuestionIcon'
492  );
493  }
494 
495  // render the action menu
496  include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
497  $list = new ilAdvancedSelectionListGUI();
498  $list->setSelectionHeaderClass('btn-primary');
499  $list->setId('QuestionActions');
500  $list->setListTitle($this->lng->txt("actions"));
501  $list->setStyle(1);
502  $list->setGroupedList($actions);
503  $tpl->setVariable('ACTION_MENU', $list->getHTML());
504 
505  return $tpl->get();
506  }
507  // fau.
508 
509 
513  public function getHTML(): string
514  {
515  // fau: testNav - add parameter for toolbar template purpose
516  $tpl = $this->getTemplate('toolbar');
517  // fau.
518  if ($this->getEditSolutionCommand()) {
519  $this->renderSubmitButton(
520  $tpl,
521  $this->getEditSolutionCommand(),
523  );
524  }
525 
526  // fau: testNav - don't show the standard submit button.
527  // fau: testNav - discard answer is moved to the actions menu.
528  // fau: testNav - skip question (postpone) is moved to the actions menu.
529 
530  if ($this->getInstantFeedbackCommand()) {
531  $this->renderSubmitButton(
532  $tpl,
533  $this->getInstantFeedbackCommand(),
534  $this->getCheckButtonLabel(),
536  );
537  }
538 
539  if ($this->getRequestHintCommand()) {
540  $this->renderSubmitButton(
541  $tpl,
542  $this->getRequestHintCommand(),
544  );
545  }
546 
547  if ($this->getShowHintsCommand()) {
548  $this->renderSubmitButton(
549  $tpl,
550  $this->getShowHintsCommand(),
551  'show_requested_question_hints'
552  );
553  }
554 
555  // fau: testNav - question mark is moved to the actions menu.
556  // fau: testNav - char selector is moved to the actions menu.
557 
558  if ($this->isAnythingRendered()) {
559  $this->parseNavigation($tpl);
560  }
561 
562  return $tpl->get();
563  }
564 
565  private function getEditSolutionButtonLabel(): string
566  {
567  if ($this->isQuestionWorkedThrough()) {
568  return 'edit_answer';
569  }
570 
571  return 'answer_question';
572  }
573 
574  private function getSubmitSolutionButtonLabel(): string
575  {
576  if ($this->isForceInstantResponseEnabled()) {
577  return 'submit_and_check';
578  }
579 
580  // fau: testNav - rename the submit button to simply "Save"
581  return 'save';
582  // fau.
583  }
584 
585  private function getCheckButtonLabel(): string
586  {
587  if ($this->isAnswerFreezingEnabled()) {
588  return 'submit_and_check';
589  }
590 
591  return 'check';
592  }
593 
594  private function getRequestHintButtonLabel(): string
595  {
596  if ($this->hintRequestsExist()) {
597  return 'button_request_next_question_hint';
598  }
599 
600  return 'button_request_question_hint';
601  }
602 
603  // fau: testNav - adjust mark icon and action labels
604  private function getQuestionMarkActionLabel(): string
605  {
606  if ($this->isQuestionMarked()) {
607  return $this->lng->txt('tst_remove_mark');
608  }
609 
610  return $this->lng->txt('tst_question_mark');
611  }
612 
613 
614  private function getQuestionMarkIconLabel(): string
615  {
616  if ($this->isQuestionMarked()) {
617  return $this->lng->txt('tst_question_marked');
618  }
619 
620  return$this->lng->txt('tst_question_not_marked');
621  }
622  // fau.
623 
624  private function getQuestionMarkIconSource(): string
625  {
626  if ($this->isQuestionMarked()) {
627  return ilUtil::getImagePath('marked.svg');
628  }
629 
630  return ilUtil::getImagePath('marked_.svg');
631  }
632 
633  // fau: testNav - add parameter for template purpose
639  private function getTemplate($a_purpose = 'toolbar'): ilTemplate
640  {
641  switch ($a_purpose) {
642  case 'toolbar':
643  return new ilTemplate(
644  'tpl.tst_question_navigation.html',
645  true,
646  true,
647  'Modules/Test'
648  );
649  default:
650  case 'actions':
651  return new ilTemplate(
652  'tpl.tst_question_actions.html',
653  true,
654  true,
655  'Modules/Test'
656  );
657  }
658  }
659  // fau.
660 
664  private function parseNavigation(ilTemplate $tpl)
665  {
666  $tpl->setCurrentBlock('question_related_navigation');
667  $tpl->parseCurrentBlock();
668  }
669 
674  {
675  $tpl->setCurrentBlock('buttons');
676  $tpl->parseCurrentBlock();
677  }
678 
683  private function renderButtonInstance(ilTemplate $tpl, $button)
684  {
685  $tpl->setCurrentBlock("button_instance");
686  $tpl->setVariable("BUTTON_INSTANCE", $button->render());
687  $tpl->parseCurrentBlock();
688 
689  $this->parseButtonsBlock($tpl);
690  $this->setAnythingRendered();
691  }
692 
699  private function renderSubmitButton(ilTemplate $tpl, $command, $label, $primary = false)
700  {
701  $button = ilSubmitButton::getInstance();
702  $button->setCommand($command);
703  $button->setCaption($label);
704  $button->setPrimary($primary);
705  $button->addCSSClass(self::CSS_CLASS_SUBMIT_BUTTONS);
706 
707  $this->renderButtonInstance($tpl, $button);
708  }
709 
716  private function renderLinkButton(ilTemplate $tpl, $href, $label)
717  {
718  $button = ilLinkButton::getInstance();
719  $button->setUrl($href);
720  $button->setCaption($label);
721 
722  $this->renderButtonInstance($tpl, $button);
723  }
724 
731  private function renderJsLinkedButton(ilTemplate $tpl, $htmlId, $label, $cssClass)
732  {
733  $button = ilLinkButton::getInstance();
734  $button->setId($htmlId);
735  $button->addCSSClass($cssClass);
736  $button->setCaption($label);
737 
738  $this->renderButtonInstance($tpl, $button);
739  }
740 
748  private function renderIcon(ilTemplate $tpl, $command, $iconSrc, $label, $cssClass)
749  {
750  $tpl->setCurrentBlock("submit_icon");
751  $tpl->setVariable("SUBMIT_ICON_CMD", $command);
752  $tpl->setVariable("SUBMIT_ICON_SRC", $iconSrc);
753  $tpl->setVariable("SUBMIT_ICON_TEXT", $label);
754  $tpl->setVariable("SUBMIT_ICON_CLASS", $cssClass);
755  $tpl->parseCurrentBlock();
756 
757  $this->parseButtonsBlock($tpl);
758  $this->setAnythingRendered();
759  }
760 
761  // fau: testNav - render an icon beneath the actions menu
762  private function renderActionsIcon(ilTemplate $tpl, $iconSrc, $label, $cssClass)
763  {
764  $tpl->setCurrentBlock("actions_icon");
765  $tpl->setVariable("ICON_SRC", $iconSrc);
766  $tpl->setVariable("ICON_TEXT", $label);
767  $tpl->setVariable("ICON_CLASS", $cssClass);
768  $tpl->parseCurrentBlock();
769  }
770  // fau.
771 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
renderSubmitButton(ilTemplate $tpl, $command, $label, $primary=false)
renderActionsIcon(ilTemplate $tpl, $iconSrc, $label, $cssClass)
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
renderIcon(ilTemplate $tpl, $command, $iconSrc, $label, $cssClass)
setDiscardSolutionButtonEnabled($discardSolutionButtonEnabled)
setRevertChangesLinkTarget($revertChangesLinkTarget)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
renderJsLinkedButton(ilTemplate $tpl, $htmlId, $label, $cssClass)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setForceInstantResponseEnabled($forceInstantResponseEnabled)
getActionsHTML()
Get the HTML of an actions menu below the title.
renderLinkButton(ilTemplate $tpl, $href, $label)
getTemplate($a_purpose='toolbar')
Get the template.
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41