ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestQuestionNavigationGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
12{
14
15 const CSS_CLASS_SUBMIT_BUTTONS = 'ilc_qsubmit_Submit';
16
20 protected $lng;
21
26
30 private $questionWorkedThrough = false;
31
36
37// fau: testNav - new variable for 'revert changes' link target
42// fau.
43
48
53
58
62 private $answerFreezingEnabled = false;
63
68
72 private $requestHintCommand = '';
73
77 private $showHintsCommand = '';
78
82 private $hintRequestsExist = false;
83
84// fau: testNav - change question mark command to link target
89// fau.
90
94 private $questionMarked = false;
95
99 private $charSelectorEnabled = false;
100
104 private $anythingRendered = false;
105
109 public function __construct(ilLanguage $lng)
110 {
111 $this->lng = $lng;
112 }
113
117 public function getEditSolutionCommand()
118 {
120 }
121
126 {
127 $this->editSolutionCommand = $editSolutionCommand;
128 }
129
133 public function isQuestionWorkedThrough()
134 {
136 }
137
142 {
143 $this->questionWorkedThrough = $questionWorkedThrough;
144 }
145
149 public function getSubmitSolutionCommand()
150 {
152 }
153
158 {
159 $this->submitSolutionCommand = $submitSolutionCommand;
160 }
161
162// fau: testNav - get/set revertChangesCommand
167 {
169 }
170
175 {
176 $this->revertChangesLinkTarget = $revertChangesLinkTarget;
177 }
178// fau.
179
184 {
186 }
187
192 {
193 $this->discardSolutionButtonEnabled = $discardSolutionButtonEnabled;
194 }
195
200 {
202 }
203
208 {
209 $this->skipQuestionLinkTarget = $skipQuestionLinkTarget;
210 }
211
216 {
218 }
219
224 {
225 $this->instantFeedbackCommand = $instantFeedbackCommand;
226 }
227
231 public function isAnswerFreezingEnabled()
232 {
234 }
235
240 {
242 }
243
248 {
249 $this->forceInstantResponseEnabled = $forceInstantResponseEnabled;
250 }
251
256 {
257 $this->answerFreezingEnabled = $answerFreezingEnabled;
258 }
259
263 public function getRequestHintCommand()
264 {
266 }
267
272 {
273 $this->requestHintCommand = $requestHintCommand;
274 }
275
279 public function getShowHintsCommand()
280 {
282 }
283
288 {
289 $this->showHintsCommand = $showHintsCommand;
290 }
291
295 public function hintRequestsExist()
296 {
298 }
299
304 {
306 }
307
308// fau: testNav - change setter/getter of question mark command to link target
313 {
315 }
316
321 {
322 $this->questionMarkLinkTarget = $questionMarkLinkTarget;
323 }
324// fau.
325
329 public function isQuestionMarked()
330 {
332 }
333
338 {
339 $this->questionMarked = $questionMarked;
340 }
341
345 public function isAnythingRendered()
346 {
348 }
349
353 public function setAnythingRendered()
354 {
355 $this->anythingRendered = true;
356 }
357
361 public function isCharSelectorEnabled()
362 {
364 }
365
370 {
371 $this->charSelectorEnabled = $charSelectorEnabled;
372 }
373
374// fau: testNav - generate question actions menu
379 public function getActionsHTML()
380 {
381 $tpl = $this->getTemplate('actions');
382
383 include_once("Services/UIComponent/GroupedList/classes/class.ilGroupedListGUI.php");
384 $actions = new ilGroupedListGUI();
385 $actions->setAsDropDown(true, true);
386
387 if( $this->getQuestionMarkLinkTarget() )
388 {
389 $actions->addEntry($this->getQuestionMarkActionLabel(), $this->getQuestionMarkLinkTarget(),
390 '','','ilTestQuestionAction','tst_mark_question_action');
391 $actions->addSeparator();
392 }
393
394 if( $this->getRevertChangesLinkTarget() )
395 {
396 $actions->addEntry($this->lng->txt('tst_revert_changes'), $this->getRevertChangesLinkTarget(),
397 '','','ilTestQuestionAction ilTestRevertChangesAction','tst_revert_changes_action');
398 }
399 else {
400 $actions->addEntry($this->lng->txt('tst_revert_changes'), '#',
401 '','','ilTestQuestionAction ilTestRevertChangesAction disabled','tst_revert_changes_action');
402 }
403
404 if( $this->isDiscardSolutionButtonEnabled() )
405 {
406 $actions->addEntry($this->lng->txt('discard_answer'),'#',
407 '','','ilTestQuestionAction ilTestDiscardSolutionAction','tst_discard_solution_action');
408 }
409 else
410 {
411 $actions->addEntry($this->lng->txt('discard_answer'),'#',
412 '','','ilTestQuestionAction ilTestDiscardSolutionAction disabled','tst_discard_solution_action');
413 }
414
415 if( $this->getSkipQuestionLinkTarget() )
416 {
417 $actions->addEntry($this->lng->txt('postpone_question'), $this->getSkipQuestionLinkTarget(),
418 '','','ilTestQuestionAction','tst_skip_question_action');
419 }
420 elseif( self::SHOW_DISABLED_COMMANDS )
421 {
422 $actions->addEntry($this->lng->txt('postpone_question'), '#',
423 '','','ilTestQuestionAction disabled','tst_skip_question_action');
424 }
425
426 if( $this->isCharSelectorEnabled() )
427 {
428 $actions->addSeparator();
429 $actions->addEntry($this->lng->txt('char_selector_btn_label'),'#',
430 '','','ilTestQuestionAction ilCharSelectorMenuToggle','ilCharSelectorMenuToggleLink');
431 }
432
433 // render the mark icon
434 if( $this->getQuestionMarkLinkTarget() )
435 {
436 $this->renderActionsIcon(
437 $tpl, $this->getQuestionMarkIconSource(), $this->getQuestionMarkIconLabel(), 'ilTestMarkQuestionIcon'
438 );
439 }
440
441 // render the action menu
442 include_once './Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php';
443 $list = new ilAdvancedSelectionListGUI();
444 $list->setSelectionHeaderClass('btn-primary');
445 $list->setId('QuestionActions');
446 $list->setListTitle($this->lng->txt("actions"));
447 $list->setStyle(1);
448 $list->setGroupedList($actions);
449 $tpl->setVariable('ACTION_MENU',$list->getHTML());
450
451 return $tpl->get();
452 }
453// fau.
454
455
459 public function getHTML()
460 {
461// fau: testNav - add parameter for toolbar template purpose
462 $tpl = $this->getTemplate('toolbar');
463// fau.
464 if( $this->getEditSolutionCommand() )
465 {
466 $this->renderSubmitButton(
468 );
469 }
470
471// fau: testNav - don't show the standard submit button.
472// fau: testNav - discard answer is moved to the actions menu.
473// fau: testNav - skip question (postpone) is moved to the actions menu.
474
475 if( $this->getInstantFeedbackCommand())
476 {
477 $this->renderSubmitButton(
480 );
481 }
482
483 if( $this->getRequestHintCommand() )
484 {
485 $this->renderSubmitButton(
487 );
488 }
489
490 if( $this->getShowHintsCommand() )
491 {
492 $this->renderSubmitButton(
493 $tpl, $this->getShowHintsCommand(), 'button_show_requested_question_hints'
494 );
495 }
496
497// fau: testNav - question mark is moved to the actions menu.
498// fau: testNav - char selector is moved to the actions menu.
499
500 if( $this->isAnythingRendered() )
501 {
502 $this->parseNavigation($tpl);
503 }
504
505 return $tpl->get();
506 }
507
508 private function getEditSolutionButtonLabel()
509 {
510 if( $this->isQuestionWorkedThrough() )
511 {
512 return 'edit_answer';
513 }
514
515 return 'answer_question';
516 }
517
519 {
520 if( $this->isForceInstantResponseEnabled() )
521 {
522 return 'submit_and_check';
523 }
524
525// fau: testNav - rename the submit button to simply "Save"
526 return 'save';
527// fau.
528 }
529
530 private function getCheckButtonLabel()
531 {
532 if( $this->isAnswerFreezingEnabled() )
533 {
534 return 'submit_and_check';
535 }
536
537 return 'check';
538 }
539
540 private function getRequestHintButtonLabel()
541 {
542 if( $this->hintRequestsExist() )
543 {
544 return 'button_request_next_question_hint';
545 }
546
547 return 'button_request_question_hint';
548 }
549
550// fau: testNav - adjust mark icon and action labels
551 private function getQuestionMarkActionLabel()
552 {
553 if( $this->isQuestionMarked() )
554 {
555 return $this->lng->txt('tst_remove_mark');
556 }
557
558 return $this->lng->txt('tst_question_mark');
559 }
560
561
562 private function getQuestionMarkIconLabel()
563 {
564 if( $this->isQuestionMarked() )
565 {
566 return $this->lng->txt('tst_question_marked');
567 }
568
569 return$this->lng->txt('tst_question_not_marked');
570 }
571// fau.
572
573 private function getQuestionMarkIconSource()
574 {
575 if( $this->isQuestionMarked() )
576 {
577 return ilUtil::getImagePath('marked.svg');
578 }
579
580 return ilUtil::getImagePath('marked_.svg');
581 }
582
583// fau: testNav - add parameter for template purpose
589 private function getTemplate($a_purpose = 'toolbar')
590 {
591 switch ($a_purpose)
592 {
593 case 'toolbar':
594 return new ilTemplate(
595 'tpl.tst_question_navigation.html', true, true, 'Modules/Test'
596 );
597
598 case 'actions':
599 return new ilTemplate(
600 'tpl.tst_question_actions.html', true, true, 'Modules/Test'
601 );
602 }
603 }
604// fau.
605
610 {
611 $tpl->setCurrentBlock('question_related_navigation');
612 $tpl->parseCurrentBlock();
613 }
614
619 {
620 $tpl->setCurrentBlock('buttons');
621 $tpl->parseCurrentBlock();
622 }
623
628 private function renderButtonInstance(ilTemplate $tpl, $button)
629 {
630 $tpl->setCurrentBlock("button_instance");
631 $tpl->setVariable("BUTTON_INSTANCE", $button->render());
632 $tpl->parseCurrentBlock();
633
634 $this->parseButtonsBlock($tpl);
635 $this->setAnythingRendered();
636 }
637
644 private function renderSubmitButton(ilTemplate $tpl, $command, $label, $primary = false)
645 {
646 $button = ilSubmitButton::getInstance();
647 $button->setCommand($command);
648 $button->setCaption($label);
649 $button->setPrimary($primary);
650 $button->addCSSClass(self::CSS_CLASS_SUBMIT_BUTTONS);
651
652 $this->renderButtonInstance($tpl, $button);
653 }
654
661 private function renderLinkButton(ilTemplate $tpl, $href, $label)
662 {
663 $button = ilLinkButton::getInstance();
664 $button->setUrl($href);
665 $button->setCaption($label);
666
667 $this->renderButtonInstance($tpl, $button);
668 }
669
676 private function renderJsLinkedButton(ilTemplate $tpl, $htmlId, $label, $cssClass)
677 {
678 $button = ilLinkButton::getInstance();
679 $button->setId($htmlId);
680 $button->addCSSClass($cssClass);
681 $button->setCaption($label);
682
683 $this->renderButtonInstance($tpl, $button);
684 }
685
693 private function renderIcon(ilTemplate $tpl, $command, $iconSrc, $label, $cssClass)
694 {
695 $tpl->setCurrentBlock("submit_icon");
696 $tpl->setVariable("SUBMIT_ICON_CMD", $command);
697 $tpl->setVariable("SUBMIT_ICON_SRC", $iconSrc);
698 $tpl->setVariable("SUBMIT_ICON_TEXT", $label);
699 $tpl->setVariable("SUBMIT_ICON_CLASS", $cssClass);
700 $tpl->parseCurrentBlock();
701
702 $this->parseButtonsBlock($tpl);
703 $this->setAnythingRendered();
704 }
705
706// fau: testNav - render an icon beneath the actions menu
707 private function renderActionsIcon(ilTemplate $tpl, $iconSrc, $label, $cssClass)
708 {
709 $tpl->setCurrentBlock("actions_icon");
710 $tpl->setVariable("ICON_SRC", $iconSrc);
711 $tpl->setVariable("ICON_TEXT", $label);
712 $tpl->setVariable("ICON_CLASS", $cssClass);
713 $tpl->parseCurrentBlock();
714 }
715// fau.
716}
global $tpl
Definition: ilias.php:8
An exception for terminatinating execution or to throw for unit testing.
User interface class for advanced drop-down selection lists.
Grouped list GUI class.
language handling
static getInstance()
Factory.
static getInstance()
Factory.
special template class to simplify handling of ITX/PEAR
getActionsHTML()
Get the HTML of an actions menu below the title.
setDiscardSolutionButtonEnabled($discardSolutionButtonEnabled)
renderJsLinkedButton(ilTemplate $tpl, $htmlId, $label, $cssClass)
renderActionsIcon(ilTemplate $tpl, $iconSrc, $label, $cssClass)
getTemplate($a_purpose='toolbar')
Get the template.
setRevertChangesLinkTarget($revertChangesLinkTarget)
renderLinkButton(ilTemplate $tpl, $href, $label)
renderIcon(ilTemplate $tpl, $command, $iconSrc, $label, $cssClass)
renderSubmitButton(ilTemplate $tpl, $command, $label, $primary=false)
setForceInstantResponseEnabled($forceInstantResponseEnabled)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)