ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
4 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
5 require_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 $testOutputGUI = null;
33 
37  protected $testSession = null;
38 
47  {
48  $this->testOutputGUI = $testOutputGUI;
49  $this->testSession = $testSession;
50 
51  parent::__construct($questionGUI);
52  }
53 
61  public function executeCommand()
62  {
63  global $ilCtrl, $ilTabs, $lng;
64 
65  $cmd = $ilCtrl->getCmd(self::CMD_SHOW_LIST);
66  $nextClass = $ilCtrl->getNextClass($this);
67 
68  switch($nextClass)
69  {
70  case 'ilasshintpagegui':
71 
72  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
73  $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
75  $forwarder->forward();
76  break;
77 
78  default:
79 
80  $cmd .= 'Cmd';
81  return $this->$cmd();
82  break;
83  }
84  }
85 
91  private function showListCmd()
92  {
93  global $ilCtrl, $tpl;
94 
95  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsTableGUI.php';
96 
98  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
99  );
100 
101  $table = new ilAssQuestionHintsTableGUI(
102  $this->questionOBJ, $questionHintList, $this, self::CMD_SHOW_LIST
103  );
104 
105  $this->populateContent( $ilCtrl->getHtml($table) );
106  }
107 
116  private function showHintCmd()
117  {
118  global $ilCtrl, $tpl, $lng;
119 
120  if( !isset($_GET['hintId']) || !(int)$_GET['hintId'] )
121  {
122  throw new ilTestException('no hint id given');
123  }
124 
126  (int)$_GET['hintId'], $this->testSession->getActiveId(), $this->testSession->getPass()
127  );
128 
129  if( !$isRequested )
130  {
131  throw new ilTestException('hint with given id is not yet requested for given testactive and testpass');
132  }
133 
134  $questionHint = ilAssQuestionHint::getInstanceById((int)$_GET['hintId']);
135 
136  require_once 'Services/Utilities/classes/class.ilUtil.php';
137  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
138  require_once 'Services/Form/classes/class.ilNonEditableValueGUI.php';
139 
140  // build form
141 
142  $form = new ilPropertyFormGUI();
143 
144  $form->setFormAction($ilCtrl->getFormAction($this));
145 
146  $form->setTableWidth('100%');
147 
148  $form->setTitle(sprintf(
149  $lng->txt('tst_question_hints_form_header_edit'),
150  $questionHint->getIndex(),
151  $this->questionOBJ->getTitle()
152  ));
153 
154  $form->addCommandButton(self::CMD_BACK_TO_QUESTION, $lng->txt('tst_question_hints_back_to_question'));
155 
157  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
158  );
159 
160  if($numExistingRequests > 1)
161  {
162  $form->addCommandButton(self::CMD_SHOW_LIST, $lng->txt('button_show_requested_question_hints'));
163  }
164 
165  // form input: hint text
166 
167  $nonEditableHintText = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
168  $nonEditableHintText->setValue( ilUtil::prepareTextareaOutput($questionHint->getText(), true) );
169  $form->addItem($nonEditableHintText);
170 
171  // form input: hint points
172 
173  $nonEditableHintPoints = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
174  $nonEditableHintPoints->setValue($questionHint->getPoints());
175  $form->addItem($nonEditableHintPoints);
176 
177  $this->populateContent( $ilCtrl->getHtml($form) );
178  }
179 
188  private function confirmRequestCmd()
189  {
190  global $ilCtrl, $tpl, $lng;
191 
193  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
194  );
195 
196  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
197 
198  $confirmation = new ilConfirmationGUI();
199 
200  $formAction = ilUtil::appendUrlParameterString(
201  $ilCtrl->getFormAction($this), "hintId={$nextRequestableHint->getId()}"
202  );
203 
204  $confirmation->setFormAction($formAction);
205 
206  $confirmation->setConfirm($lng->txt('tst_question_hints_confirm_request'), self::CMD_PERFORM_REQUEST);
207  $confirmation->setCancel($lng->txt('tst_question_hints_cancel_request'), self::CMD_BACK_TO_QUESTION);
208 
209  $confirmation->setHeaderText(sprintf(
210  $lng->txt('tst_question_hints_request_confirmation'),
211  $nextRequestableHint->getIndex(),
212  $nextRequestableHint->getPoints()
213  ));
214 
215  $this->populateContent( $ilCtrl->getHtml($confirmation) );
216  }
217 
225  private function performRequestCmd()
226  {
227  global $ilCtrl;
228 
229  if( !isset($_GET['hintId']) || !(int)$_GET['hintId'] )
230  {
231  throw new ilTestException('no hint id given');
232  }
233 
235  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
236  );
237 
238  if( $nextRequestableHint->getId() != (int)$_GET['hintId'] )
239  {
240  throw new ilTestException('given hint id does not relate to the next requestable hint');
241  }
242 
244  $nextRequestableHint, $this->questionOBJ->getId(),
245  $this->testSession->getActiveId(), $this->testSession->getPass()
246  );
247 
248  $redirectTarget = $this->getHintPresentationLinkTarget($nextRequestableHint->getId(), false);
249 
250  ilUtil::redirect($redirectTarget);
251  }
252 
259  private function backToQuestionCmd()
260  {
261  global $ilCtrl;
262 
263  $ilCtrl->redirectByClass('ilTestOutputGUI', 'redirectQuestion');
264  }
265 
273  private function populateContent($content)
274  {
275  global $tpl;
276 
277  if( $this->testOutputGUI->object->getKioskMode() )
278  {
279  $tpl->setBodyClass('kiosk');
280  $tpl->setAddFooter(false);
281 
282  $tpl->addBlockFile(
283  'CONTENT', 'content', 'tpl.il_tst_question_hints_kiosk_page.html', 'Modules/TestQuestionPool'
284  );
285 
286  $tpl->setVariable('KIOSK_HEAD', $this->testOutputGUI->getKioskHead());
287 
288  $tpl->setVariable('KIOSK_CONTENT', $content);
289  }
290  else
291  {
292  $tpl->setContent($content);
293  }
294  }
295 
304  public function getHintPresentationLinkTarget($hintId, $xmlStyle = true)
305  {
306  global $ilCtrl;
307 
308  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
309  {
310  $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $hintId);
311  $linkTarget = $ilCtrl->getLinkTargetByClass('ilAssHintPageGUI', '', '', false, $xmlStyle);
312  }
313  else
314  {
315  $ilCtrl->setParameter($this, 'hintId', $hintId);
316  $linkTarget = $ilCtrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, $xmlStyle);
317  }
318 
319  return $linkTarget;
320  }
321 }