ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 $user;
58 
62  protected $questionGUI;
63 
67  protected $questionOBJ;
68 
72  protected $previewSettings;
73 
77  protected $previewSession;
78 
82  protected $hintTracking;
83 
85  {
86  $this->ctrl = $ctrl;
87  $this->tabs = $tabs;
88  $this->tpl = $tpl;
89  $this->lng = $lng;
90  $this->db = $db;
91  $this->user = $user;
92  }
93 
94  public function initQuestion($questionId, $parentObjId)
95  {
96  require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
97 
98  $this->questionGUI = assQuestion::instantiateQuestionGUI($questionId);
99  $this->questionOBJ = $this->questionGUI->object;
100 
101  $this->questionOBJ->setObjId($parentObjId);
102 
103  $this->questionGUI->setQuestionTabs();
104  $this->questionGUI->outAdditionalOutput();
105 
106  $this->questionOBJ->setOutputType(OUTPUT_JAVASCRIPT);
107 
108  $this->questionGUI->setTargetGui($this);
109  $this->questionGUI->setQuestionActionCmd(self::CMD_HANDLE_QUESTION_ACTION);
110  }
111 
112  public function initPreviewSettings($parentRefId)
113  {
114  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSettings.php';
115  $this->previewSettings = new ilAssQuestionPreviewSettings($parentRefId);
116 
117  $this->previewSettings->init();
118  }
119 
120  public function initPreviewSession($userId, $questionId)
121  {
122  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
123  $this->previewSession = new ilAssQuestionPreviewSession($userId, $questionId);
124 
125  $this->previewSession->init();
126  }
127 
128  public function initHintTracking()
129  {
130  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewHintTracking.php';
131  $this->hintTracking = new ilAssQuestionPreviewHintTracking($this->db, $this->previewSession);
132  }
133 
134  public function initStyleSheets()
135  {
136  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
137 
138  $this->tpl->setCurrentBlock("ContentStyle");
139  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
140  $this->tpl->parseCurrentBlock();
141 
142  $this->tpl->setCurrentBlock("SyntaxStyle");
143  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
144  $this->tpl->parseCurrentBlock();
145  }
146 
147  public function executeCommand()
148  {
149  $this->tabs->setTabActive(self::TAB_ID_QUESTION_PREVIEW);
150 
151  $this->lng->loadLanguageModule('content');
152 
153  $nextClass = $this->ctrl->getNextClass($this);
154 
155  switch($nextClass)
156  {
157  case 'ilassquestionhintrequestgui':
158 
159  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
160  $gui = new ilAssQuestionHintRequestGUI($this, self::CMD_SHOW, $this->questionGUI, $this->hintTracking);
161 
162  $this->ctrl->forwardCommand($gui);
163 
164  break;
165 
166  case 'ilassspecfeedbackpagegui':
167  case 'ilassgenfeedbackpagegui':
168  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackPageObjectCommandForwarder.php';
169  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->questionOBJ, $this->ctrl, $this->tabs, $this->lng);
170  $forwarder->forward();
171  break;
172 
173  default:
174 
175  $cmd = $this->ctrl->getCmd(self::CMD_SHOW).'Cmd';
176 
177  $this->$cmd();
178  }
179  }
180 
181  private function showCmd()
182  {
183  $tpl = new ilTemplate('tpl.qpl_question_preview.html', true, true, 'Modules/TestQuestionPool');
184 
185  $tpl->setVariable('PREVIEW_FORMACTION', $this->ctrl->getFormAction($this, self::CMD_SHOW));
186 
188 
190 
192 
194  {
196  }
197 
199  {
201  }
202 
203  if( $this->isShowBestSolutionRequired() )
204  {
206  }
207 
208  $this->tpl->setContent($tpl->get());
209  }
210 
211  private function resetCmd()
212  {
213  $this->previewSession->setRandomizerSeed(null);
214  $this->previewSession->setParticipantsSolution(null);
215  $this->previewSession->resetRequestedHints();
216  $this->previewSession->setInstantResponseActive(false);
217 
218  ilUtil::sendInfo($this->lng->txt('qst_preview_reset_msg'), true);
219 
220  $this->ctrl->redirect($this, self::CMD_SHOW);
221  }
222 
223  private function instantResponseCmd()
224  {
225  $this->questionOBJ->persistPreviewState($this->previewSession);
226  $this->previewSession->setInstantResponseActive(true);
227  $this->ctrl->redirect($this, self::CMD_SHOW);
228  }
229 
230  private function handleQuestionActionCmd()
231  {
232  $this->questionOBJ->persistPreviewState($this->previewSession);
233  $this->ctrl->redirect($this, self::CMD_SHOW);
234  }
235 
237  {
238  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewToolbarGUI.php';
239  $toolbarGUI = new ilAssQuestionPreviewToolbarGUI($this->lng);
240 
241  $toolbarGUI->setFormAction($this->ctrl->getFormAction($this, self::CMD_SHOW));
242  $toolbarGUI->setResetPreviewCmd(self::CMD_RESET);
243 
244  $toolbarGUI->build();
245 
246  $tpl->setVariable('PREVIEW_TOOLBAR', $this->ctrl->getHTML($toolbarGUI));
247  }
248 
250  {
251  // FOR WHAT EXACTLY IS THIS USEFUL?
252  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
253  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
254 
255  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
256  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
257  $pageGUI->setRenderPageContainer(false);
258  $pageGUI->setEditPreview(true);
259  $pageGUI->setEnabledTabs(false);
260 
261  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
262  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) // workaround for page edit imagemaps, keep in mind
263  {
264  $this->ctrl->setCmdClass(get_class($pageGUI));
265  $this->ctrl->setCmd('preview');
266  }
267 
268  $this->questionGUI->setPreviewSession($this->previewSession);
269  $this->questionGUI->object->setShuffler($this->getQuestionAnswerShuffler());
270 
271  $questionHtml = $this->questionGUI->getPreview(true, $this->isShowSpecificQuestionFeedbackRequired());
272  $this->questionGUI->magicAfterTestOutput();
273 
274  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $questionHtml));
275 
276  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
277  $pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
278 
279  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
280 
281  $tpl->setVariable('QUESTION_OUTPUT', $pageGUI->preview());
282  }
283 
285  {
286  // FOR WHAT EXACTLY IS THIS USEFUL?
287  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
288  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
289 
290  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
291  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
292 
293  $pageGUI->setEditPreview(true);
294  $pageGUI->setEnabledTabs(false);
295 
296  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
297  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) // workaround for page edit imagemaps, keep in mind
298  {
299  $this->ctrl->setCmdClass(get_class($pageGUI));
300  $this->ctrl->setCmd('preview');
301  }
302 
303  $this->questionGUI->setPreviewSession($this->previewSession);
304 
305  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $this->questionGUI->getSolutionOutput(
306  0, null, false, false, true, false,
307  true, false, false
308  )));
309 
310  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
311  //$pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
312 
313  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
314 
315  $tpl->setCurrentBlock('solution_output');
316  $tpl->setVariable('TXT_CORRECT_SOLUTION', $this->lng->txt('tst_best_solution_is'));
317  $tpl->setVariable('SOLUTION_OUTPUT', $pageGUI->preview());
318  $tpl->parseCurrentBlock();
319  }
320 
322  {
323  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionRelatedNavigationBarGUI.php';
324  $navGUI = new ilAssQuestionRelatedNavigationBarGUI($this->ctrl, $this->lng);
325 
326  $navGUI->setInstantResponseCmd(self::CMD_INSTANT_RESPONSE);
327  $navGUI->setHintRequestCmd(self::CMD_GATEWAY_CONFIRM_HINT_REQUEST);
328  $navGUI->setHintListCmd(self::CMD_GATEWAY_SHOW_HINT_LIST);
329 
330  $navGUI->setInstantResponseEnabled($this->previewSettings->isInstantFeedbackNavigationRequired());
331  $navGUI->setHintProvidingEnabled($this->previewSettings->isHintProvidingEnabled());
332 
333  $navGUI->setHintRequestsPossible($this->hintTracking->requestsPossible());
334  $navGUI->setHintRequestsExist($this->hintTracking->requestsExist());
335 
336  $tpl->setVariable('QUESTION_NAVIGATION', $this->ctrl->getHTML($navGUI));
337  }
338 
340  {
341  if( $this->questionOBJ->isPreviewSolutionCorrect($this->previewSession) )
342  {
343  $feedback = $this->questionGUI->getGenericFeedbackOutputForCorrectSolution();
345  }
346  else
347  {
348  $feedback = $this->questionGUI->getGenericFeedbackOutputForIncorrectSolution();
350  }
351 
352  if( strlen($feedback) )
353  {
354  $tpl->setCurrentBlock('instant_feedback_generic');
355  $tpl->setVariable('GENERIC_FEEDBACK', $feedback);
356  $tpl->setVariable('ILC_FB_CSS_CLASS', $cssClass);
357  $tpl->parseCurrentBlock();
358  }
359  }
360 
362  {
363  $tpl->setCurrentBlock('instant_feedback_specific');
364  $tpl->setVariable('ANSWER_FEEDBACK', $this->questionGUI->getSpecificFeedbackOutput(0, -1));
365  $tpl->parseCurrentBlock();
366  }
367 
368  private function isShowBestSolutionRequired()
369  {
370  if( !$this->previewSettings->isBestSolutionEnabled() )
371  {
372  return false;
373  }
374 
375  return $this->previewSession->isInstantResponseActive();
376  }
377 
379  {
380  if( !$this->previewSettings->isGenericFeedbackEnabled() )
381  {
382  return false;
383  }
384 
385  return $this->previewSession->isInstantResponseActive();
386  }
387 
389  {
390  if( !$this->previewSettings->isSpecificFeedbackEnabled() )
391  {
392  return false;
393  }
394 
395  return $this->previewSession->isInstantResponseActive();
396  }
397 
398  public function saveQuestionSolution()
399  {
400  $this->questionOBJ->persistPreviewState($this->previewSession);
401  }
402 
404  {
405  $this->saveQuestionSolution();
406 
407  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
408 
409  $this->ctrl->redirectByClass(
410  'ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_CONFIRM_REQUEST
411  );
412  }
413 
414  public function gatewayShowHintListCmd()
415  {
416  $this->saveQuestionSolution();
417 
418  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
419 
420  $this->ctrl->redirectByClass(
421  'ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_SHOW_LIST
422  );
423  }
424 
428  private function getQuestionAnswerShuffler()
429  {
430  require_once 'Services/Randomization/classes/class.ilArrayElementShuffler.php';
431  $shuffler = new ilArrayElementShuffler();
432 
433  if( !$this->previewSession->randomizerSeedExists() )
434  {
435  $this->previewSession->setRandomizerSeed($shuffler->buildRandomSeed());
436  }
437 
438  $shuffler->setSeed($this->previewSession->getRandomizerSeed());
439 
440  return $shuffler;
441  }
442 }
This class provides processing control methods.
setEditPreview($a_editpreview)
Set Display first Edit tab, then Preview tab, instead of Page and Edit.
$_POST['username']
Definition: cron.php:12
Tabs GUI.
__construct(ilCtrl $ctrl, ilTabsGUI $tabs, ilTemplate $tpl, ilLanguage $lng, ilDB $db, ilObjUser $user)
$cmd
Definition: sahs_server.php:35
const OUTPUT_JAVASCRIPT
Question page GUI class.
getSyntaxStylePath()
get syntax style path
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:626
special template class to simplify handling of ITX/PEAR
setRenderPageContainer($a_val)
Set render page container.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
Database Wrapper.
Definition: class.ilDB.php:28
getContentStylePath($a_style_id)
get content style path
initQuestion($questionId, $parentObjId)
language handling
parseCurrentBlock($part="DEFAULT")
Überladene Funktion, die auf den aktuelle Block vorher noch ein replace ausführt public...
static instantiateQuestionGUI($a_question_id)
Creates an instance of a question gui with a given question id.