ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionHintRequestGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
6 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintTracking.php';
7 
20 {
24  const CMD_SHOW_LIST = 'showList';
25  const CMD_SHOW_HINT = 'showHint';
26  const CMD_CONFIRM_REQUEST = 'confirmRequest';
27  const CMD_PERFORM_REQUEST = 'performRequest';
28  const CMD_BACK_TO_QUESTION = 'backToQuestion';
29 
33  protected $testOutputGUI = null;
34 
38  protected $testSession = null;
39 
48  {
49  $this->testOutputGUI = $testOutputGUI;
50  $this->testSession = $testSession;
51 
52  parent::__construct($questionGUI);
53  }
54 
62  public function executeCommand()
63  {
64  global $ilCtrl;
65 
66  $cmd = $ilCtrl->getCmd(self::CMD_SHOW_LIST);
67  $nextClass = $ilCtrl->getNextClass($this);
68 
69  switch($nextClass)
70  {
71  default:
72 
73  $cmd .= 'Cmd';
74  return $this->$cmd();
75  break;
76  }
77  }
78 
84  private function showListCmd()
85  {
86  global $ilCtrl, $tpl;
87 
88  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsTableGUI.php';
89 
91  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
92  );
93 
94  $table = new ilAssQuestionHintsTableGUI(
95  $this->questionOBJ, $questionHintList, $this, self::CMD_SHOW_LIST
96  );
97 
98  $this->populateContent( $ilCtrl->getHtml($table) );
99  }
100 
109  private function showHintCmd()
110  {
111  global $ilCtrl, $tpl, $lng;
112 
113  if( !isset($_GET['hintId']) || !(int)$_GET['hintId'] )
114  {
115  throw new ilTestException('no hint id given');
116  }
117 
119  (int)$_GET['hintId'], $this->testSession->getActiveId(), $this->testSession->getPass()
120  );
121 
122  if( !$isRequested )
123  {
124  throw new ilTestException('hint with given id is not yet requested for given testactive and testpass');
125  }
126 
127  $questionHint = ilAssQuestionHint::getInstanceById((int)$_GET['hintId']);
128 
129  require_once 'Services/Utilities/classes/class.ilUtil.php';
130  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
131  require_once 'Services/Form/classes/class.ilNonEditableValueGUI.php';
132 
133  // build form
134 
135  $form = new ilPropertyFormGUI();
136 
137  $form->setFormAction($ilCtrl->getFormAction($this));
138 
139  $form->setTableWidth('100%');
140 
141  $form->setTitle(sprintf(
142  $lng->txt('tst_question_hints_form_header_edit'),
143  $questionHint->getIndex(),
144  $this->questionOBJ->getTitle()
145  ));
146 
147  $form->addCommandButton(self::CMD_BACK_TO_QUESTION, $lng->txt('tst_question_hints_back_to_question'));
148 
150  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
151  );
152 
153  if($numExistingRequests > 1)
154  {
155  $form->addCommandButton(self::CMD_SHOW_LIST, $lng->txt('button_show_requested_question_hints'));
156  }
157 
158  // form input: hint text
159 
160  $nonEditableHintText = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
161  $nonEditableHintText->setValue( ilUtil::prepareTextareaOutput($questionHint->getText(), true) );
162  $form->addItem($nonEditableHintText);
163 
164  // form input: hint points
165 
166  $nonEditableHintPoints = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
167  $nonEditableHintPoints->setValue($questionHint->getPoints());
168  $form->addItem($nonEditableHintPoints);
169 
170  $this->populateContent( $ilCtrl->getHtml($form) );
171  }
172 
181  private function confirmRequestCmd()
182  {
183  global $ilCtrl, $tpl, $lng;
184 
186  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
187  );
188 
189  require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
190 
191  $confirmation = new ilConfirmationGUI();
192 
193  $formAction = ilUtil::appendUrlParameterString(
194  $ilCtrl->getFormAction($this), "hintId={$nextRequestableHint->getId()}"
195  );
196 
197  $confirmation->setFormAction($formAction);
198 
199  $confirmation->setConfirm($lng->txt('tst_question_hints_confirm_request'), self::CMD_PERFORM_REQUEST);
200  $confirmation->setCancel($lng->txt('tst_question_hints_cancel_request'), self::CMD_BACK_TO_QUESTION);
201 
202  $confirmation->setHeaderText(sprintf(
203  $lng->txt('tst_question_hints_request_confirmation'),
204  $nextRequestableHint->getIndex(),
205  $nextRequestableHint->getPoints()
206  ));
207 
208  $this->populateContent( $ilCtrl->getHtml($confirmation) );
209  }
210 
218  private function performRequestCmd()
219  {
220  global $ilCtrl;
221 
222  if( !isset($_GET['hintId']) || !(int)$_GET['hintId'] )
223  {
224  throw new ilTestException('no hint id given');
225  }
226 
228  $this->questionOBJ->getId(), $this->testSession->getActiveId(), $this->testSession->getPass()
229  );
230 
231  if( $nextRequestableHint->getId() != (int)$_GET['hintId'] )
232  {
233  throw new ilTestException('given hint id does not relate to the next requestable hint');
234  }
235 
237  $nextRequestableHint, $this->questionOBJ->getId(),
238  $this->testSession->getActiveId(), $this->testSession->getPass()
239  );
240 
241  $redirectTarget = ilUtil::appendUrlParameterString(
242  $ilCtrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, false), "hintId={$nextRequestableHint->getId()}"
243  );
244 
245  ilUtil::redirect($redirectTarget);
246  }
247 
254  private function backToQuestionCmd()
255  {
256  global $ilCtrl;
257 
258  $ilCtrl->redirectByClass('ilTestOutputGUI', 'redirectQuestion');
259  }
260 
268  private function populateContent($content)
269  {
270  global $tpl;
271 
272  if( $this->testOutputGUI->object->getKioskMode() )
273  {
274  $tpl->setBodyClass('kiosk');
275  $tpl->setAddFooter(false);
276 
277  $tpl->addBlockFile(
278  'CONTENT', 'content', 'tpl.il_tst_question_hints_kiosk_page.html', 'Modules/TestQuestionPool'
279  );
280 
281  $tpl->setVariable('KIOSK_HEAD', $this->testOutputGUI->getKioskHead());
282 
283  $tpl->setVariable('KIOSK_CONTENT', $content);
284  }
285  else
286  {
287  $tpl->setContent($content);
288  }
289  }
290 }