ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAssQuestionHintRequestGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
33 {
34  public const CMD_SHOW_LIST = 'showList';
35  public const CMD_SHOW_HINT = 'showHint';
36  public const CMD_CONFIRM_REQUEST = 'confirmRequest';
37  public const CMD_PERFORM_REQUEST = 'performRequest';
38  public const CMD_BACK_TO_QUESTION = 'backToQuestion';
39 
40  public function __construct(
41  private ilTestOutputGUI|ilAssQuestionPreviewGUI $parent_gui,
42  private string $parent_cmd,
43  assQuestionGUI $question_gui,
44  private $question_hint_tracking,
45  private ilCtrl $ctrl,
46  private ilLanguage $lng,
47  private ilGlobalTemplateInterface $tpl,
48  protected ilTabsGUI $tabs,
49  private GlobalScreen $global_screen
50  ) {
51 
52  parent::__construct($question_gui);
53  }
54 
55  public function executeCommand()
56  {
57  $cmd = $this->ctrl->getCmd(self::CMD_SHOW_LIST);
58  $next_class = $this->ctrl->getNextClass($this);
59 
60  switch ($next_class) {
61  case 'ilasshintpagegui':
63  $this->questionOBJ,
64  $this->ctrl,
65  $this->tabs,
66  $this->lng
67  );
69  $forwarder->forward();
70  return '';
71 
72  default:
73  $cmd .= 'Cmd';
74  return $this->$cmd();
75  }
76  }
77 
78  private function showListCmd(): void
79  {
80  if ($this->global_screen->tool()->context()->current()->getAdditionalData()
82  $this->global_screen->tool()->context()->current()->getAdditionalData()->replace(
84  $this->parent_gui->getObject()->getTitle() . ' - ' . $this->lng->txt('show_requested_question_hints')
85  );
86  }
87 
88  $question_hint_list = $this->question_hint_tracking->getRequestedHintsList();
89 
90  $table = new ilAssQuestionHintsTableGUI(
91  $this->questionOBJ,
92  $question_hint_list,
93  $this,
94  self::CMD_SHOW_LIST
95  );
96 
97  $this->populateContent($this->ctrl->getHtml($table), $this->tpl);
98  }
99 
100  private function showHintCmd(): void
101  {
102  if (!$this->request->isset('hintId') || $this->request->int('hintId') === 0) {
103  throw new ilTestException('no hint id given');
104  }
105 
106  $is_requested = $this->question_hint_tracking->isRequested($this->request->int('hintId'));
107 
108  if (!$is_requested) {
109  throw new ilTestException('hint with given id is not yet requested for given testactive and testpass');
110  }
111 
112  $question_hint = ilAssQuestionHint::getInstanceById((int) $this->request->raw('hintId'));
113 
114  if ($this->global_screen->tool()->context()->current()->getAdditionalData()
116  $this->global_screen->tool()->context()->current()->getAdditionalData()->replace(
118  $this->parent_gui->getObject()->getTitle() . ' - ' . sprintf(
119  $this->lng->txt('tst_question_hints_form_header_edit'),
120  $question_hint->getIndex(),
121  $this->request->int('sequence') ?? 0
122  )
123  );
124  }
125 
126  $form = new ilPropertyFormGUI();
127  $form->setFormAction($this->ctrl->getFormAction($this));
128  $form->setTableWidth('100%');
129  $form->setTitle(sprintf(
130  $this->lng->txt('tst_question_hints_form_header_edit'),
131  $question_hint->getIndex(),
132  $this->questionOBJ->getTitleForHTMLOutput()
133  ));
134  $form->addCommandButton(self::CMD_BACK_TO_QUESTION, $this->lng->txt('tst_question_hints_back_to_question'));
135 
136  $num_existing_requests = $this->question_hint_tracking->getNumExistingRequests();
137 
138  if ($num_existing_requests > 1) {
139  $form->addCommandButton(self::CMD_SHOW_LIST, $this->lng->txt('show_requested_question_hints'));
140  }
141 
142  // form input: hint text
143 
144  $non_editable_hint_text = new ilNonEditableValueGUI($this->lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
145  $non_editable_hint_text->setValue(ilLegacyFormElementsUtil::prepareTextareaOutput($question_hint->getText(), true));
146  $form->addItem($non_editable_hint_text);
147 
148  // form input: hint points
149 
150  $non_editable_hint_point = new ilNonEditableValueGUI($this->lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
151  $non_editable_hint_point->setValue($question_hint->getPoints());
152  $form->addItem($non_editable_hint_point);
153 
154  $this->populateContent($this->ctrl->getHtml($form), $this->tpl);
155  }
156 
157  private function confirmRequestCmd(): void
158  {
159  if ($this->global_screen->tool()->context()->current()->getAdditionalData()
161  $this->global_screen->tool()->context()->current()->getAdditionalData()->replace(
163  $this->parent_gui->getObject()->getTitle() . ' - ' . $this->lng->txt('tst_question_hints_confirm_request')
164  );
165  }
166 
167  try {
168  $next_requestable_hint = $this->question_hint_tracking->getNextRequestableHint();
170  $this->ctrl->redirect($this, self::CMD_BACK_TO_QUESTION);
171  }
172 
173  $confirmation = new ilConfirmationGUI();
174 
175  $form_action = ilUtil::appendUrlParameterString(
176  $this->ctrl->getFormAction($this),
177  "hintId={$next_requestable_hint->getId()}"
178  );
179 
180  $confirmation->setFormAction($form_action);
181 
182  $confirmation->setConfirm($this->lng->txt('tst_question_hints_confirm_request'), self::CMD_PERFORM_REQUEST);
183  $confirmation->setCancel($this->lng->txt('tst_question_hints_cancel_request'), self::CMD_BACK_TO_QUESTION);
184 
185  if ($next_requestable_hint->getPoints() == 0.0) {
186  $confirmation->setHeaderText($this->lng->txt('tst_question_hints_request_confirmation_no_deduction'));
187  } else {
188  $confirmation->setHeaderText(sprintf(
189  $this->lng->txt('tst_question_hints_request_confirmation'),
190  $next_requestable_hint->getIndex(),
191  $next_requestable_hint->getPoints()
192  ));
193  }
194 
195  $this->populateContent($this->ctrl->getHtml($confirmation), $this->tpl);
196  }
197 
198  private function performRequestCmd(): void
199  {
200  if (!$this->request->isset('hintId') || !(int) $this->request->raw('hintId')) {
201  throw new ilTestException('no hint id given');
202  }
203 
204  try {
205  $next_requestable_hint = $this->question_hint_tracking->getNextRequestableHint();
207  $this->ctrl->redirect($this, self::CMD_BACK_TO_QUESTION);
208  }
209 
210  if ($next_requestable_hint->getId() != (int) $this->request->raw('hintId')) {
211  throw new ilTestException('given hint id does not relate to the next requestable hint');
212  }
213 
214  $this->question_hint_tracking->storeRequest($next_requestable_hint);
215 
216  $redirectTarget = $this->getHintPresentationLinkTarget($next_requestable_hint->getId(), false);
217 
218  ilUtil::redirect($redirectTarget);
219  }
220 
221  private function backToQuestionCmd(): void
222  {
223  $this->ctrl->redirect($this->parent_gui, $this->parent_cmd);
224  }
225 
226  private function populateContent($content, $tpl): void
227  {
228  $tpl->setContent($content);
229  return;
230  }
231 
232  public function getHintPresentationLinkTarget($hint_id, $xml_style = true): string
233  {
234  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
235  $this->ctrl->setParameterByClass('ilasshintpagegui', 'hint_id', $hint_id);
236  return $this->ctrl->getLinkTargetByClass('ilAssHintPageGUI', '', '', false, $xml_style);
237  }
238 
239  $this->ctrl->setParameter($this, 'hintId', $hint_id);
240  return $this->ctrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, $xml_style);
241  }
242 }
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Output class for assessment test execution.
Base Exception for all Exceptions relating to Modules/Test.
__construct(VocabulariesInterface $vocabularies)
$lng
__construct(private ilTestOutputGUI|ilAssQuestionPreviewGUI $parent_gui, private string $parent_cmd, assQuestionGUI $question_gui, private $question_hint_tracking, private ilCtrl $ctrl, private ilLanguage $lng, private ilGlobalTemplateInterface $tpl, protected ilTabsGUI $tabs, private GlobalScreen $global_screen)
Basic GUI class for assessment questions.
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free...
getHintPresentationLinkTarget($hint_id, $xml_style=true)