ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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->questionGUI->populateJavascriptFilesRequiredForWorkForm($this->tpl);
107  $this->questionOBJ->setOutputType(OUTPUT_JAVASCRIPT); // TODO: remove including depending stuff
108 
109  $this->questionGUI->setTargetGui($this);
110  $this->questionGUI->setQuestionActionCmd(self::CMD_HANDLE_QUESTION_ACTION);
111 
112  $this->questionGUI->setRenderPurpose(assQuestionGUI::RENDER_PURPOSE_DEMOPLAY);
113  }
114 
115  public function initPreviewSettings($parentRefId)
116  {
117  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSettings.php';
118  $this->previewSettings = new ilAssQuestionPreviewSettings($parentRefId);
119 
120  $this->previewSettings->init();
121  }
122 
123  public function initPreviewSession($userId, $questionId)
124  {
125  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewSession.php';
126  $this->previewSession = new ilAssQuestionPreviewSession($userId, $questionId);
127 
128  $this->previewSession->init();
129  }
130 
131  public function initHintTracking()
132  {
133  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewHintTracking.php';
134  $this->hintTracking = new ilAssQuestionPreviewHintTracking($this->db, $this->previewSession);
135  }
136 
137  public function initStyleSheets()
138  {
139  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
140 
141  $this->tpl->setCurrentBlock("ContentStyle");
142  $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
143  $this->tpl->parseCurrentBlock();
144 
145  $this->tpl->setCurrentBlock("SyntaxStyle");
146  $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
147  $this->tpl->parseCurrentBlock();
148  }
149 
150  public function executeCommand()
151  {
152  global $DIC; /* @var \ILIAS\DI\Container $DIC */
153  $ilHelp = $DIC['ilHelp']; /* @var ilHelpGUI $ilHelp */
154  $ilHelp->setScreenIdComponent('qpl');
155 
156  $this->tabs->setTabActive(self::TAB_ID_QUESTION_PREVIEW);
157 
158  $this->lng->loadLanguageModule('content');
159 
160  $nextClass = $this->ctrl->getNextClass($this);
161 
162  switch($nextClass)
163  {
164  case 'ilassquestionhintrequestgui':
165 
166  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
167  $gui = new ilAssQuestionHintRequestGUI($this, self::CMD_SHOW, $this->questionGUI, $this->hintTracking);
168 
169  $this->ctrl->forwardCommand($gui);
170 
171  break;
172 
173  case 'ilassspecfeedbackpagegui':
174  case 'ilassgenfeedbackpagegui':
175  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackPageObjectCommandForwarder.php';
176  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->questionOBJ, $this->ctrl, $this->tabs, $this->lng);
177  $forwarder->forward();
178  break;
179 
180  default:
181 
182  $cmd = $this->ctrl->getCmd(self::CMD_SHOW).'Cmd';
183 
184  $this->$cmd();
185  }
186  }
187 
188  private function showCmd()
189  {
190  $tpl = new ilTemplate('tpl.qpl_question_preview.html', true, true, 'Modules/TestQuestionPool');
191 
192  $tpl->setVariable('PREVIEW_FORMACTION', $this->ctrl->getFormAction($this, self::CMD_SHOW));
193 
195 
197 
199 
201  {
203  }
204 
206  {
208  }
209 
210  if( $this->isShowBestSolutionRequired() )
211  {
213  }
214 
215  $this->tpl->setContent($tpl->get());
216  }
217 
218  private function resetCmd()
219  {
220  $this->previewSession->setRandomizerSeed(null);
221  $this->previewSession->setParticipantsSolution(null);
222  $this->previewSession->resetRequestedHints();
223  $this->previewSession->setInstantResponseActive(false);
224 
225  ilUtil::sendInfo($this->lng->txt('qst_preview_reset_msg'), true);
226 
227  $this->ctrl->redirect($this, self::CMD_SHOW);
228  }
229 
230  private function instantResponseCmd()
231  {
232  if( $this->saveQuestionSolution() )
233  {
234  $this->previewSession->setInstantResponseActive(true);
235  }
236  else
237  {
238  $this->previewSession->setInstantResponseActive(false);
239  }
240 
241  $this->ctrl->redirect($this, self::CMD_SHOW);
242  }
243 
244  private function handleQuestionActionCmd()
245  {
246  $this->questionOBJ->persistPreviewState($this->previewSession);
247  $this->ctrl->redirect($this, self::CMD_SHOW);
248  }
249 
251  {
252  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewToolbarGUI.php';
253  $toolbarGUI = new ilAssQuestionPreviewToolbarGUI($this->lng);
254 
255  $toolbarGUI->setFormAction($this->ctrl->getFormAction($this, self::CMD_SHOW));
256  $toolbarGUI->setResetPreviewCmd(self::CMD_RESET);
257 
258  $toolbarGUI->build();
259 
260  $tpl->setVariable('PREVIEW_TOOLBAR', $this->ctrl->getHTML($toolbarGUI));
261  }
262 
264  {
265  // FOR WHAT EXACTLY IS THIS USEFUL?
266  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
267  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
268 
269  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
270  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
271  $pageGUI->setRenderPageContainer(false);
272  $pageGUI->setEditPreview(true);
273  $pageGUI->setEnabledTabs(false);
274 
275  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
276  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) // workaround for page edit imagemaps, keep in mind
277  {
278  $this->ctrl->setCmdClass(get_class($pageGUI));
279  $this->ctrl->setCmd('preview');
280  }
281 
282  $this->questionGUI->setPreviewSession($this->previewSession);
283  $this->questionGUI->object->setShuffler($this->getQuestionAnswerShuffler());
284 
285  $questionHtml = $this->questionGUI->getPreview(true, $this->isShowSpecificQuestionFeedbackRequired());
286  $this->questionGUI->magicAfterTestOutput();
287 
288  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $questionHtml));
289 
290  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
291  $pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
292 
293  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
294 
295  $tpl->setVariable('QUESTION_OUTPUT', $pageGUI->preview());
296  }
297 
299  {
300  // FOR WHAT EXACTLY IS THIS USEFUL?
301  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
302  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
303 
304  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
305  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
306 
307  $pageGUI->setEditPreview(true);
308  $pageGUI->setEnabledTabs(false);
309 
310  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
311  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) // workaround for page edit imagemaps, keep in mind
312  {
313  $this->ctrl->setCmdClass(get_class($pageGUI));
314  $this->ctrl->setCmd('preview');
315  }
316 
317  $this->questionGUI->setPreviewSession($this->previewSession);
318 
319  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $this->questionGUI->getSolutionOutput(
320  0, null, false, false, true, false,
321  true, false, false
322  )));
323 
324  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
325  //$pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
326 
327  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
328 
329  $tpl->setCurrentBlock('solution_output');
330  $tpl->setVariable('TXT_CORRECT_SOLUTION', $this->lng->txt('tst_best_solution_is'));
331  $tpl->setVariable('SOLUTION_OUTPUT', $pageGUI->preview());
332  $tpl->parseCurrentBlock();
333  }
334 
336  {
337  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionRelatedNavigationBarGUI.php';
338  $navGUI = new ilAssQuestionRelatedNavigationBarGUI($this->ctrl, $this->lng);
339 
340  $navGUI->setInstantResponseCmd(self::CMD_INSTANT_RESPONSE);
341  $navGUI->setHintRequestCmd(self::CMD_GATEWAY_CONFIRM_HINT_REQUEST);
342  $navGUI->setHintListCmd(self::CMD_GATEWAY_SHOW_HINT_LIST);
343 
344  $navGUI->setInstantResponseEnabled($this->previewSettings->isInstantFeedbackNavigationRequired());
345  $navGUI->setHintProvidingEnabled($this->previewSettings->isHintProvidingEnabled());
346 
347  $navGUI->setHintRequestsPossible($this->hintTracking->requestsPossible());
348  $navGUI->setHintRequestsExist($this->hintTracking->requestsExist());
349 
350  $tpl->setVariable('QUESTION_NAVIGATION', $this->ctrl->getHTML($navGUI));
351  }
352 
354  {
355  if( $this->questionOBJ->isPreviewSolutionCorrect($this->previewSession) )
356  {
357  $feedback = $this->questionGUI->getGenericFeedbackOutputForCorrectSolution();
359  }
360  else
361  {
362  $feedback = $this->questionGUI->getGenericFeedbackOutputForIncorrectSolution();
364  }
365 
366  if( strlen($feedback) )
367  {
368  $tpl->setCurrentBlock('instant_feedback_generic');
369  $tpl->setVariable('GENERIC_FEEDBACK', $feedback);
370  $tpl->setVariable('ILC_FB_CSS_CLASS', $cssClass);
371  $tpl->parseCurrentBlock();
372  }
373  }
374 
376  {
377  $tpl->setCurrentBlock('instant_feedback_specific');
378  $tpl->setVariable('ANSWER_FEEDBACK', $this->questionGUI->getSpecificFeedbackOutput(0, -1));
379  $tpl->parseCurrentBlock();
380  }
381 
382  private function isShowBestSolutionRequired()
383  {
384  if( !$this->previewSettings->isBestSolutionEnabled() )
385  {
386  return false;
387  }
388 
389  return $this->previewSession->isInstantResponseActive();
390  }
391 
393  {
394  if( !$this->previewSettings->isGenericFeedbackEnabled() )
395  {
396  return false;
397  }
398 
399  return $this->previewSession->isInstantResponseActive();
400  }
401 
403  {
404  if( !$this->previewSettings->isSpecificFeedbackEnabled() )
405  {
406  return false;
407  }
408 
409  return $this->previewSession->isInstantResponseActive();
410  }
411 
412  public function saveQuestionSolution()
413  {
414  return $this->questionOBJ->persistPreviewState($this->previewSession);
415  }
416 
418  {
419  if( !$this->saveQuestionSolution() )
420  {
421  $this->previewSession->setInstantResponseActive(false);
422  $this->showCmd();
423  return;
424  }
425 
426  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
427 
428  $this->ctrl->redirectByClass(
429  'ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_CONFIRM_REQUEST
430  );
431  }
432 
433  public function gatewayShowHintListCmd()
434  {
435  if( !$this->saveQuestionSolution() )
436  {
437  $this->previewSession->setInstantResponseActive(false);
438  $this->showCmd();
439  return;
440  }
441 
442  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
443 
444  $this->ctrl->redirectByClass(
445  'ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_SHOW_LIST
446  );
447  }
448 
452  private function getQuestionAnswerShuffler()
453  {
454  require_once 'Services/Randomization/classes/class.ilArrayElementShuffler.php';
455  $shuffler = new ilArrayElementShuffler();
456 
457  if( !$this->previewSession->randomizerSeedExists() )
458  {
459  $this->previewSession->setRandomizerSeed($shuffler->buildRandomSeed());
460  }
461 
462  $shuffler->setSeed($this->previewSession->getRandomizerSeed());
463 
464  return $shuffler;
465  }
466 }
This class provides processing control methods.
setEditPreview($a_editpreview)
Set Display first Edit tab, then Preview tab, instead of Page and Edit.
__construct(ilCtrl $ctrl, ilTabsGUI $tabs, ilTemplate $tpl, ilLanguage $lng, ilDBInterface $db, ilObjUser $user)
Tabs GUI.
$cmd
Definition: sahs_server.php:35
const OUTPUT_JAVASCRIPT
Question page GUI class.
user()
Definition: user.php:4
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Interface ilDBInterface.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:613
special template class to simplify handling of ITX/PEAR
setRenderPageContainer($a_val)
Set render page container.
static getSyntaxStylePath()
get syntax style path
Create styles array
The data for the language used.
setCurrentBlock($part="DEFAULT")
Überladene Funktion, die sich hier lokal noch den aktuellen Block merkt.
static getContentStylePath($a_style_id)
get content style path
initQuestion($questionId, $parentObjId)
language handling
global $DIC
$_POST["username"]
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.