ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAssQuestionHintRequestGUI.php
Go to the documentation of this file.
1 <?php
2 
31 {
35  public const CMD_SHOW_LIST = 'showList';
36  public const CMD_SHOW_HINT = 'showHint';
37  public const CMD_CONFIRM_REQUEST = 'confirmRequest';
38  public const CMD_PERFORM_REQUEST = 'performRequest';
39  public const CMD_BACK_TO_QUESTION = 'backToQuestion';
40 
44  protected $parentGUI = null;
45 
49  protected $parentCMD = null;
50 
54  protected $questionHintTracking = null;
55 
60  {
61  $this->parentGUI = $parentGUI;
62  $this->parentCMD = $parentCMD;
63  $this->questionHintTracking = $questionHintTracking;
64 
65  parent::__construct($questionGUI);
66  }
67 
68  public function executeCommand()
69  {
70  global $DIC;
71  $ilCtrl = $DIC['ilCtrl'];
72  $ilTabs = $DIC['ilTabs'];
73  $lng = $DIC['lng'];
74 
75  $cmd = $ilCtrl->getCmd(self::CMD_SHOW_LIST);
76  $nextClass = $ilCtrl->getNextClass($this);
77 
78  switch ($nextClass) {
79  case 'ilasshintpagegui':
80 
81  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
82  $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
84  $forwarder->forward();
85  break;
86 
87  default:
88 
89  $cmd .= 'Cmd';
90  return $this->$cmd();
91  break;
92  }
93  return '';
94  }
95 
101  private function showListCmd(): void
102  {
103  global $DIC;
104  $ilCtrl = $DIC['ilCtrl'];
105  $tpl = $DIC['tpl'];
106  $lng = $DIC['lng'];
107 
108  if ($DIC->globalScreen()->tool()->context()->current()->getAdditionalData()
110  $DIC->globalScreen()->tool()->context()->current()->getAdditionalData()->replace(
112  $this->parentGUI->getObject()->getTitle() . ' - ' . $lng->txt('show_requested_question_hints')
113  );
114  }
115 
116  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsTableGUI.php';
117 
118  $questionHintList = $this->questionHintTracking->getRequestedHintsList();
119 
120  $table = new ilAssQuestionHintsTableGUI(
121  $this->questionOBJ,
122  $questionHintList,
123  $this,
124  self::CMD_SHOW_LIST
125  );
126 
127  $this->populateContent($ilCtrl->getHtml($table), $tpl);
128  }
129 
138  private function showHintCmd(): void
139  {
140  global $DIC;
141  $ilCtrl = $DIC['ilCtrl'];
142  $tpl = $DIC['tpl'];
143  $lng = $DIC['lng'];
144 
145  if (!$this->request->isset('hintId') || !(int) $this->request->raw('hintId')) {
146  throw new ilTestException('no hint id given');
147  }
148 
149  $isRequested = $this->questionHintTracking->isRequested((int) $this->request->raw('hintId'));
150 
151  if (!$isRequested) {
152  throw new ilTestException('hint with given id is not yet requested for given testactive and testpass');
153  }
154 
155  $questionHint = ilAssQuestionHint::getInstanceById((int) $this->request->raw('hintId'));
156 
157  require_once 'Services/Utilities/classes/class.ilUtil.php';
158  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
159  require_once 'Services/Form/classes/class.ilNonEditableValueGUI.php';
160 
161  if ($DIC->globalScreen()->tool()->context()->current()->getAdditionalData()
163  $DIC->globalScreen()->tool()->context()->current()->getAdditionalData()->replace(
165  $this->parentGUI->getObject()->getTitle() . ' - ' . sprintf(
166  $lng->txt('tst_question_hints_form_header_edit'),
167  $questionHint->getIndex(),
168  $this->request->int('sequence') ?? 0
169  )
170  );
171  }
172 
173  $form = new ilPropertyFormGUI();
174 
175  $form->setFormAction($ilCtrl->getFormAction($this));
176 
177  $form->setTableWidth('100%');
178 
179  $form->setTitle(sprintf(
180  $lng->txt('tst_question_hints_form_header_edit'),
181  $questionHint->getIndex(),
182  $this->questionOBJ->getTitleForHTMLOutput()
183  ));
184 
185  $form->addCommandButton(self::CMD_BACK_TO_QUESTION, $lng->txt('tst_question_hints_back_to_question'));
186 
187  $numExistingRequests = $this->questionHintTracking->getNumExistingRequests();
188 
189  if ($numExistingRequests > 1) {
190  $form->addCommandButton(self::CMD_SHOW_LIST, $lng->txt('show_requested_question_hints'));
191  }
192 
193  // form input: hint text
194 
195  $nonEditableHintText = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
196  $nonEditableHintText->setValue(ilLegacyFormElementsUtil::prepareTextareaOutput($questionHint->getText(), true));
197  $form->addItem($nonEditableHintText);
198 
199  // form input: hint points
200 
201  $nonEditableHintPoints = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
202  $nonEditableHintPoints->setValue($questionHint->getPoints());
203  $form->addItem($nonEditableHintPoints);
204 
205  $this->populateContent($ilCtrl->getHtml($form), $tpl);
206  }
207 
216  private function confirmRequestCmd(): void
217  {
219  global $DIC;
220  $ilCtrl = $DIC['ilCtrl'];
221  $tpl = $DIC['tpl'];
222  $lng = $DIC['lng'];
223 
224 
225  if ($DIC->globalScreen()->tool()->context()->current()->getAdditionalData()
227  $DIC->globalScreen()->tool()->context()->current()->getAdditionalData()->replace(
229  $this->parentGUI->getObject()->getTitle() . ' - ' . $lng->txt('tst_question_hints_confirm_request')
230  );
231  }
232 
233  try {
234  $nextRequestableHint = $this->questionHintTracking->getNextRequestableHint();
236  $ilCtrl->redirect($this, self::CMD_BACK_TO_QUESTION);
237  }
238 
239 
240  $confirmation = new ilConfirmationGUI();
241 
242  $formAction = ilUtil::appendUrlParameterString(
243  $ilCtrl->getFormAction($this),
244  "hintId={$nextRequestableHint->getId()}"
245  );
246 
247  $confirmation->setFormAction($formAction);
248 
249  $confirmation->setConfirm($lng->txt('tst_question_hints_confirm_request'), self::CMD_PERFORM_REQUEST);
250  $confirmation->setCancel($lng->txt('tst_question_hints_cancel_request'), self::CMD_BACK_TO_QUESTION);
251 
252  if ($nextRequestableHint->getPoints() == 0.0) {
253  $confirmation->setHeaderText($lng->txt('tst_question_hints_request_confirmation_no_deduction'));
254  } else {
255  $confirmation->setHeaderText(sprintf(
256  $lng->txt('tst_question_hints_request_confirmation'),
257  $nextRequestableHint->getIndex(),
258  $nextRequestableHint->getPoints()
259  ));
260  }
261 
262  $this->populateContent($ilCtrl->getHtml($confirmation), $tpl);
263  }
264 
272  private function performRequestCmd(): void
273  {
274  global $DIC;
275  $ilCtrl = $DIC['ilCtrl'];
276 
277  if (!$this->request->isset('hintId') || !(int) $this->request->raw('hintId')) {
278  throw new ilTestException('no hint id given');
279  }
280 
281  try {
282  $nextRequestableHint = $this->questionHintTracking->getNextRequestableHint();
284  $ilCtrl->redirect($this, self::CMD_BACK_TO_QUESTION);
285  }
286 
287  if ($nextRequestableHint->getId() != (int) $this->request->raw('hintId')) {
288  throw new ilTestException('given hint id does not relate to the next requestable hint');
289  }
290 
291  $this->questionHintTracking->storeRequest($nextRequestableHint);
292 
293  $redirectTarget = $this->getHintPresentationLinkTarget($nextRequestableHint->getId(), false);
294 
295  ilUtil::redirect($redirectTarget);
296  }
297 
304  private function backToQuestionCmd(): void
305  {
306  global $DIC;
307  $ilCtrl = $DIC['ilCtrl'];
308 
309  $ilCtrl->redirect($this->parentGUI, $this->parentCMD);
310  }
311 
319  private function populateContent($content, $tpl): void
320  {
321  global $DIC;
322  $tpl = $DIC['tpl'];
323 
324  if (!$this->isQuestionPreview() && $this->parentGUI->object->getKioskMode()) {
325  $tpl->hideFooter();
326 
327  $tpl->addBlockFile(
328  'CONTENT',
329  'kiosk_content',
330  'tpl.il_tst_question_hints_kiosk_page.html',
331  'Modules/TestQuestionPool'
332  );
333 
334  $tpl->setVariable('KIOSK_HEAD', $this->parentGUI->getKioskHead());
335 
336  $tpl->setVariable('KIOSK_CONTENT', $content);
337  } else {
338  $tpl->setContent($content);
339  }
340  }
341 
342  private function isQuestionPreview(): bool
343  {
344  if ($this->questionHintTracking instanceof ilAssQuestionPreviewHintTracking) {
345  return true;
346  }
347 
348  return false;
349  }
350 
359  public function getHintPresentationLinkTarget($hintId, $xmlStyle = true): string
360  {
361  global $DIC;
362  $ilCtrl = $DIC['ilCtrl'];
363 
364  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
365  $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $hintId);
366  $linkTarget = $ilCtrl->getLinkTargetByClass('ilAssHintPageGUI', '', '', false, $xmlStyle);
367  } else {
368  $ilCtrl->setParameter($this, 'hintId', $hintId);
369  $linkTarget = $ilCtrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, $xmlStyle);
370  }
371 
372  return $linkTarget;
373  }
374 }
showListCmd()
shows the list of allready requested hints
static appendUrlParameterString(string $a_url, string $a_par, bool $xml_style=false)
__construct($parentGUI, $parentCMD, assQuestionGUI $questionGUI, $questionHintTracking)
Constructor.
getHintPresentationLinkTarget($hintId, $xmlStyle=true)
returns the link target for hint request presentation
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
populateContent($content, $tpl)
populates the rendered questin hint relating output content to global template depending on possibly ...
$lng
backToQuestionCmd()
gateway command method to jump back to test session output
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
showHintCmd()
shows an allready requested hint
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
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...
performRequestCmd()
Performs a hint request and invokes the (re-)saving the question solution.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...