ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilAssQuestionHintRequestGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
5require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintTracking.php';
6
19{
23 const CMD_SHOW_LIST = 'showList';
24 const CMD_SHOW_HINT = 'showHint';
25 const CMD_CONFIRM_REQUEST = 'confirmRequest';
26 const CMD_PERFORM_REQUEST = 'performRequest';
27 const CMD_BACK_TO_QUESTION = 'backToQuestion';
28
32 protected $parentGUI = null;
33
37 protected $parentCMD = null;
38
42 protected $questionHintTracking = null;
43
48 {
49 $this->parentGUI = $parentGUI;
50 $this->parentCMD = $parentCMD;
51 $this->questionHintTracking = $questionHintTracking;
52
54 }
55
63 public function executeCommand()
64 {
65 global $DIC;
66 $ilCtrl = $DIC['ilCtrl'];
67 $ilTabs = $DIC['ilTabs'];
68 $lng = $DIC['lng'];
69
70 $cmd = $ilCtrl->getCmd(self::CMD_SHOW_LIST);
71 $nextClass = $ilCtrl->getNextClass($this);
72
73 switch ($nextClass) {
74 case 'ilasshintpagegui':
75
76 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
77 $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
79 $forwarder->forward();
80 break;
81
82 default:
83
84 $cmd .= 'Cmd';
85 return $this->$cmd();
86 break;
87 }
88 }
89
95 private function showListCmd()
96 {
97 global $DIC;
98 $ilCtrl = $DIC['ilCtrl'];
99 $tpl = $DIC['tpl'];
100
101 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsTableGUI.php';
102
103 $questionHintList = $this->questionHintTracking->getRequestedHintsList();
104
105 $table = new ilAssQuestionHintsTableGUI(
106 $this->questionOBJ,
107 $questionHintList,
108 $this,
109 self::CMD_SHOW_LIST
110 );
111
112 $this->populateContent($ilCtrl->getHtml($table), $tpl);
113 }
114
123 private function showHintCmd()
124 {
125 global $DIC;
126 $ilCtrl = $DIC['ilCtrl'];
127 $tpl = $DIC['tpl'];
128 $lng = $DIC['lng'];
129
130 if (!isset($_GET['hintId']) || !(int) $_GET['hintId']) {
131 throw new ilTestException('no hint id given');
132 }
133
134 $isRequested = $this->questionHintTracking->isRequested((int) $_GET['hintId']);
135
136 if (!$isRequested) {
137 throw new ilTestException('hint with given id is not yet requested for given testactive and testpass');
138 }
139
140 $questionHint = ilAssQuestionHint::getInstanceById((int) $_GET['hintId']);
141
142 require_once 'Services/Utilities/classes/class.ilUtil.php';
143 require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
144 require_once 'Services/Form/classes/class.ilNonEditableValueGUI.php';
145
146 // build form
147
148 $form = new ilPropertyFormGUI();
149
150 $form->setFormAction($ilCtrl->getFormAction($this));
151
152 $form->setTableWidth('100%');
153
154 $form->setTitle(sprintf(
155 $lng->txt('tst_question_hints_form_header_edit'),
156 $questionHint->getIndex(),
157 $this->questionOBJ->getTitle()
158 ));
159
160 $form->addCommandButton(self::CMD_BACK_TO_QUESTION, $lng->txt('tst_question_hints_back_to_question'));
161
162 $numExistingRequests = $this->questionHintTracking->getNumExistingRequests();
163
164 if ($numExistingRequests > 1) {
165 $form->addCommandButton(self::CMD_SHOW_LIST, $lng->txt('button_show_requested_question_hints'));
166 }
167
168 // form input: hint text
169
170 $nonEditableHintText = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
171 $nonEditableHintText->setValue(ilUtil::prepareTextareaOutput($questionHint->getText(), true));
172 $form->addItem($nonEditableHintText);
173
174 // form input: hint points
175
176 $nonEditableHintPoints = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
177 $nonEditableHintPoints->setValue($questionHint->getPoints());
178 $form->addItem($nonEditableHintPoints);
179
180 $this->populateContent($ilCtrl->getHtml($form), $tpl);
181 }
182
191 private function confirmRequestCmd()
192 {
193 global $DIC;
194 $ilCtrl = $DIC['ilCtrl'];
195 $tpl = $DIC['tpl'];
196 $lng = $DIC['lng'];
197
198 try {
199 $nextRequestableHint = $this->questionHintTracking->getNextRequestableHint();
201 $ilCtrl->redirect($this, self::CMD_BACK_TO_QUESTION);
202 }
203
204 require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
205
206 $confirmation = new ilConfirmationGUI();
207
209 $ilCtrl->getFormAction($this),
210 "hintId={$nextRequestableHint->getId()}"
211 );
212
213 $confirmation->setFormAction($formAction);
214
215 $confirmation->setConfirm($lng->txt('tst_question_hints_confirm_request'), self::CMD_PERFORM_REQUEST);
216 $confirmation->setCancel($lng->txt('tst_question_hints_cancel_request'), self::CMD_BACK_TO_QUESTION);
217
218 if ($nextRequestableHint->getPoints() == 0.0){
219 $confirmation->setHeaderText($lng->txt('tst_question_hints_request_confirmation_no_deduction'));
220 } else {
221 $confirmation->setHeaderText(sprintf(
222 $lng->txt('tst_question_hints_request_confirmation'),
223 $nextRequestableHint->getIndex(),
224 $nextRequestableHint->getPoints()
225 ));
226 }
227
228 $this->populateContent($ilCtrl->getHtml($confirmation), $tpl);
229 }
230
238 private function performRequestCmd()
239 {
240 global $DIC;
241 $ilCtrl = $DIC['ilCtrl'];
242
243 if (!isset($_GET['hintId']) || !(int) $_GET['hintId']) {
244 throw new ilTestException('no hint id given');
245 }
246
247 try {
248 $nextRequestableHint = $this->questionHintTracking->getNextRequestableHint();
250 $ilCtrl->redirect($this, self::CMD_BACK_TO_QUESTION);
251 }
252
253 if ($nextRequestableHint->getId() != (int) $_GET['hintId']) {
254 throw new ilTestException('given hint id does not relate to the next requestable hint');
255 }
256
257 $this->questionHintTracking->storeRequest($nextRequestableHint);
258
259 $redirectTarget = $this->getHintPresentationLinkTarget($nextRequestableHint->getId(), false);
260
261 ilUtil::redirect($redirectTarget);
262 }
263
270 private function backToQuestionCmd()
271 {
272 global $DIC;
273 $ilCtrl = $DIC['ilCtrl'];
274
275 $ilCtrl->redirect($this->parentGUI, $this->parentCMD);
276 }
277
285 private function populateContent($content, $tpl)
286 {
287 if (!$this->isQuestionPreview() && $this->parentGUI->object->getKioskMode()) {
288 $tpl->hideFooter();
289
290 $tpl->addBlockFile(
291 'CONTENT',
292 'kiosk_content',
293 'tpl.il_tst_question_hints_kiosk_page.html',
294 'Modules/TestQuestionPool'
295 );
296
297 $tpl->setVariable('KIOSK_HEAD', $this->parentGUI->getKioskHead());
298 $tpl->setVariable('KIOSK_CONTENT', $content);
299 } else {
300 $tpl->setContent($content);
301 }
302 }
303
304 private function isQuestionPreview()
305 {
306 if ($this->questionHintTracking instanceof ilAssQuestionPreviewHintTracking) {
307 return true;
308 }
309
310 return false;
311 }
312
321 public function getHintPresentationLinkTarget($hintId, $xmlStyle = true)
322 {
323 global $DIC;
324 $ilCtrl = $DIC['ilCtrl'];
325
326 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
327 $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $hintId);
328 $linkTarget = $ilCtrl->getLinkTargetByClass('ilAssHintPageGUI', '', '', false, $xmlStyle);
329 } else {
330 $ilCtrl->setParameter($this, 'hintId', $hintId);
331 $linkTarget = $ilCtrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, $xmlStyle);
332 }
333
334 return $linkTarget;
335 }
336}
$_GET["client_id"]
An exception for terminatinating execution or to throw for unit testing.
Basic GUI class for assessment questions.
populateContent($content, $tpl)
populates the rendered questin hint relating output content to global template depending on possibly ...
__construct($parentGUI, $parentCMD, assQuestionGUI $questionGUI, $questionHintTracking)
Constructor.
getHintPresentationLinkTarget($hintId, $xmlStyle=true)
returns the link target for hint request presentation
performRequestCmd()
Performs a hint request and invokes the (re-)saving the question solution.
confirmRequestCmd()
shows a confirmation screen for a hint request
showListCmd()
shows the list of allready requested hints
backToQuestionCmd()
gateway command method to jump back to test session output
showHintCmd()
shows an allready requested hint
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
Confirmation screen class.
This class represents a non editable value in a property form.
This class represents a property form user interface.
Base Exception for all Exceptions relating to Modules/Test.
static appendUrlParameterString($a_url, $a_par, $xml_style=false)
append URL parameter string ("par1=value1&par2=value2...") to given URL string
static prepareTextareaOutput($txt_output, $prepare_for_latex_output=false, $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free,...
static redirect($a_script)
global $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$lng