ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAssQuestionPreviewGUI.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 
19 {
20  const CMD_SHOW = 'show';
21  const CMD_RESET = 'reset';
22  const CMD_INSTANT_RESPONSE = 'instantResponse';
23  const CMD_HANDLE_QUESTION_ACTION = 'handleQuestionAction';
24  const CMD_GATEWAY_CONFIRM_HINT_REQUEST = 'gatewayConfirmHintRequest';
25  const CMD_GATEWAY_SHOW_HINT_LIST = 'gatewayShowHintList';
26 
27  const TAB_ID_QUESTION_PREVIEW = 'preview';
28 
32  protected $ctrl;
33 
37  protected $tabs;
38 
42  protected $tpl;
43 
47  protected $lng;
48 
52  protected $db;
53 
57  protected $questionGUI;
58 
62  protected $questionOBJ;
63 
67  protected $previewSettings;
68 
72  protected $previewSession;
73 
77  protected $hintTracking;
78 
80  {
81  $this->ctrl = $ctrl;
82  $this->tabs = $tabs;
83  $this->tpl = $tpl;
84  $this->lng = $lng;
85  $this->db = $db;
86  }
87 
88  public function initQuestion($questionId, $parentObjId)
89  {
90  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
91 
92  $this->questionGUI = assQuestion::instantiateQuestionGUI($questionId);
93  $this->questionOBJ = $this->questionGUI->object;
94 
95  $this->questionOBJ->setObjId($parentObjId);
96 
97  $this->questionGUI->setQuestionTabs();
98  $this->questionGUI->outAdditionalOutput();
99 
100  $this->questionOBJ->setOutputType(OUTPUT_JAVASCRIPT);
101 
102  $this->questionGUI->setTargetGui($this);
103  $this->questionGUI->setQuestionActionCmd(self::CMD_HANDLE_QUESTION_ACTION);
104  }
105 
106  public function initPreviewSettings($parentRefId)
107  {
108  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSettings.php';
109  $this->previewSettings = new ilAssQuestionPreviewSettings($parentRefId);
110 
111  $this->previewSettings->init();
112  }
113 
114  public function initPreviewSession($userId, $questionId)
115  {
116  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
117  $this->previewSession = new ilAssQuestionPreviewSession($userId, $questionId);
118 
119  $this->previewSession->init();
120  }
121 
122  public function initHintTracking()
123  {
124  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewHintTracking.php';
125  $this->hintTracking = new ilAssQuestionPreviewHintTracking($this->db, $this->previewSession);
126  }
127 
128  public function initStyleSheets()
129  {
130  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
131 
132  $this->tpl->setCurrentBlock("ContentStyle");
133  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
134  $this->tpl->parseCurrentBlock();
135 
136  $this->tpl->setCurrentBlock("SyntaxStyle");
137  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
138  $this->tpl->parseCurrentBlock();
139  }
140 
141  public function executeCommand()
142  {
143  $this->tabs->setTabActive(self::TAB_ID_QUESTION_PREVIEW);
144 
145  $this->lng->loadLanguageModule('content');
146 
147  $nextClass = $this->ctrl->getNextClass($this);
148 
149  switch($nextClass)
150  {
151  case 'ilassquestionhintrequestgui':
152 
153  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
154  $gui = new ilAssQuestionHintRequestGUI($this, self::CMD_SHOW, $this->questionGUI, $this->hintTracking);
155 
156  $this->ctrl->forwardCommand($gui);
157 
158  break;
159 
160  case 'ilassspecfeedbackpagegui':
161  case 'ilassgenfeedbackpagegui':
162  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackPageObjectCommandForwarder.php';
163  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->questionOBJ, $this->ctrl, $this->tabs, $this->lng);
164  $forwarder->forward();
165  break;
166 
167  default:
168 
169  $cmd = $this->ctrl->getCmd(self::CMD_SHOW).'Cmd';
170 
171  $this->$cmd();
172  }
173  }
174 
175  private function showCmd()
176  {
177  $tpl = new ilTemplate('tpl.qpl_question_preview.html', true, true, 'Modules/TestQuestionPool');
178 
179  $tpl->setVariable('PREVIEW_FORMACTION', $this->ctrl->getFormAction($this, self::CMD_SHOW));
180 
182 
184 
186 
188  {
190  }
191 
193  {
195  }
196 
197  if( $this->isShowBestSolutionRequired() )
198  {
200  }
201 
202  $this->tpl->setContent($tpl->get());
203  }
204 
205  private function resetCmd()
206  {
207  $this->previewSession->resetRequestedHints();
208  $this->previewSession->setParticipantsSolution(null);
209  $this->previewSession->setInstantResponseActive(false);
210 
211  ilUtil::sendInfo($this->lng->txt('qst_preview_reset_msg'), true);
212 
213  $this->ctrl->redirect($this, self::CMD_SHOW);
214  }
215 
216  private function instantResponseCmd()
217  {
218  $this->questionOBJ->persistPreviewState($this->previewSession);
219  $this->previewSession->setInstantResponseActive(true);
220  $this->ctrl->redirect($this, self::CMD_SHOW);
221  }
222 
223  private function handleQuestionActionCmd()
224  {
225  $this->questionOBJ->persistPreviewState($this->previewSession);
226  $this->ctrl->redirect($this, self::CMD_SHOW);
227  }
228 
230  {
231  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewToolbarGUI.php';
232  $toolbarGUI = new ilAssQuestionPreviewToolbarGUI($this->lng);
233 
234  $toolbarGUI->setFormAction($this->ctrl->getFormAction($this, self::CMD_SHOW));
235  $toolbarGUI->setResetPreviewCmd(self::CMD_RESET);
236 
237  $toolbarGUI->build();
238 
239  $tpl->setVariable('PREVIEW_TOOLBAR', $this->ctrl->getHTML($toolbarGUI));
240  }
241 
243  {
244  // FOR WHAT EXACTLY IS THIS USEFUL?
245  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
246  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
247 
248  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
249  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
250  $pageGUI->setRenderPageContainer(false);
251  $pageGUI->setEditPreview(true);
252  $pageGUI->setEnabledTabs(false);
253 
254  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
255  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) // workaround for page edit imagemaps, keep in mind
256  {
257  $this->ctrl->setCmdClass(get_class($pageGUI));
258  $this->ctrl->setCmd('preview');
259  }
260 
261  $this->questionGUI->setPreviewSession($this->previewSession);
262 
263  $questionHtml = $this->questionGUI->getPreview(true, $this->isShowSpecificQuestionFeedbackRequired());
264 
265  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $questionHtml));
266 
267  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
268  $pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
269 
270  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
271 
272  $tpl->setVariable('QUESTION_OUTPUT', $pageGUI->preview());
273  }
274 
276  {
277  // FOR WHAT EXACTLY IS THIS USEFUL?
278  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
279  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
280 
281  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
282  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
283 
284  $pageGUI->setEditPreview(true);
285  $pageGUI->setEnabledTabs(false);
286 
287  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
288  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) // workaround for page edit imagemaps, keep in mind
289  {
290  $this->ctrl->setCmdClass(get_class($pageGUI));
291  $this->ctrl->setCmd('preview');
292  }
293 
294  $this->questionGUI->setPreviewSession($this->previewSession);
295 
296  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $this->questionGUI->getSolutionOutput(0)));
297 
298  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
299  //$pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
300 
301  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
302 
303  $tpl->setCurrentBlock('solution_output');
304  $tpl->setVariable('TXT_CORRECT_SOLUTION', $this->lng->txt('tst_best_solution_is'));
305  $tpl->setVariable('SOLUTION_OUTPUT', $pageGUI->preview());
306  $tpl->parseCurrentBlock();
307  }
308 
310  {
311  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionRelatedNavigationBarGUI.php';
312  $navGUI = new ilAssQuestionRelatedNavigationBarGUI($this->ctrl, $this->lng);
313 
314  $navGUI->setInstantResponseCmd(self::CMD_INSTANT_RESPONSE);
315  $navGUI->setHintRequestCmd(self::CMD_GATEWAY_CONFIRM_HINT_REQUEST);
316  $navGUI->setHintListCmd(self::CMD_GATEWAY_SHOW_HINT_LIST);
317 
318  $navGUI->setInstantResponseEnabled($this->previewSettings->isInstantFeedbackNavigationRequired());
319  $navGUI->setHintProvidingEnabled($this->previewSettings->isHintProvidingEnabled());
320 
321  $navGUI->setHintRequestsPossible($this->hintTracking->requestsPossible());
322  $navGUI->setHintRequestsExist($this->hintTracking->requestsExist());
323 
324  $tpl->setVariable('QUESTION_NAVIGATION', $this->ctrl->getHTML($navGUI));
325  }
326 
328  {
329  if( $this->questionOBJ->isPreviewSolutionCorrect($this->previewSession) )
330  {
331  $feedback = $this->questionGUI->getGenericFeedbackOutputForCorrectSolution();
332  }
333  else
334  {
335  $feedback = $this->questionGUI->getGenericFeedbackOutputForIncorrectSolution();
336  }
337 
338  $tpl->setCurrentBlock('instant_feedback_generic');
339  $tpl->setVariable('GENERIC_FEEDBACK', $feedback);
340  $tpl->parseCurrentBlock();
341  }
342 
344  {
345  $tpl->setCurrentBlock('instant_feedback_specific');
346  $tpl->setVariable('ANSWER_FEEDBACK', $this->questionGUI->getSpecificFeedbackOutput(0, -1));
347  $tpl->parseCurrentBlock();
348  }
349 
350  private function isShowBestSolutionRequired()
351  {
352  if( !$this->previewSettings->isBestSolutionEnabled() )
353  {
354  return false;
355  }
356 
357  return $this->previewSession->isInstantResponseActive();
358  }
359 
361  {
362  if( !$this->previewSettings->isGenericFeedbackEnabled() )
363  {
364  return false;
365  }
366 
367  return $this->previewSession->isInstantResponseActive();
368  }
369 
371  {
372  if( !$this->previewSettings->isSpecificFeedbackEnabled() )
373  {
374  return false;
375  }
376 
377  return $this->previewSession->isInstantResponseActive();
378  }
379 
380  public function saveQuestionSolution()
381  {
382  $this->questionOBJ->persistPreviewState($this->previewSession);
383  }
384 
386  {
387  $this->saveQuestionSolution();
388 
389  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
390 
391  $this->ctrl->redirectByClass(
392  'ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_CONFIRM_REQUEST
393  );
394  }
395 
396  public function gatewayShowHintListCmd()
397  {
398  $this->saveQuestionSolution();
399 
400  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
401 
402  $this->ctrl->redirectByClass(
403  'ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_SHOW_LIST
404  );
405  }
406 }