ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  case 'ilassquestionhintrequestgui':
164 
165  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
166  $gui = new ilAssQuestionHintRequestGUI($this, self::CMD_SHOW, $this->questionGUI, $this->hintTracking);
167 
168  $this->ctrl->forwardCommand($gui);
169 
170  break;
171 
172  case 'ilassspecfeedbackpagegui':
173  case 'ilassgenfeedbackpagegui':
174  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackPageObjectCommandForwarder.php';
175  $forwarder = new ilAssQuestionFeedbackPageObjectCommandForwarder($this->questionOBJ, $this->ctrl, $this->tabs, $this->lng);
176  $forwarder->forward();
177  break;
178 
179  default:
180 
181  $cmd = $this->ctrl->getCmd(self::CMD_SHOW) . 'Cmd';
182 
183  $this->$cmd();
184  }
185  }
186 
187  private function showCmd()
188  {
189  $tpl = new ilTemplate('tpl.qpl_question_preview.html', true, true, 'Modules/TestQuestionPool');
190 
191  $tpl->setVariable('PREVIEW_FORMACTION', $this->ctrl->getFormAction($this, self::CMD_SHOW));
192 
194 
196 
198 
201  }
202 
205  }
206 
207  if ($this->isShowBestSolutionRequired()) {
209  }
210 
211  $this->tpl->setContent($tpl->get());
212  }
213 
214  private function resetCmd()
215  {
216  $this->previewSession->setRandomizerSeed(null);
217  $this->previewSession->setParticipantsSolution(null);
218  $this->previewSession->resetRequestedHints();
219  $this->previewSession->setInstantResponseActive(false);
220 
221  ilUtil::sendInfo($this->lng->txt('qst_preview_reset_msg'), true);
222 
223  $this->ctrl->redirect($this, self::CMD_SHOW);
224  }
225 
226  private function instantResponseCmd()
227  {
228  if ($this->saveQuestionSolution()) {
229  $this->previewSession->setInstantResponseActive(true);
230  } else {
231  $this->previewSession->setInstantResponseActive(false);
232  }
233 
234  $this->ctrl->redirect($this, self::CMD_SHOW);
235  }
236 
237  private function handleQuestionActionCmd()
238  {
239  $this->questionOBJ->persistPreviewState($this->previewSession);
240  $this->ctrl->redirect($this, self::CMD_SHOW);
241  }
242 
244  {
245  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionPreviewToolbarGUI.php';
246  $toolbarGUI = new ilAssQuestionPreviewToolbarGUI($this->lng);
247 
248  $toolbarGUI->setFormAction($this->ctrl->getFormAction($this, self::CMD_SHOW));
249  $toolbarGUI->setResetPreviewCmd(self::CMD_RESET);
250 
251  $toolbarGUI->build();
252 
253  $tpl->setVariable('PREVIEW_TOOLBAR', $this->ctrl->getHTML($toolbarGUI));
254  }
255 
257  {
258  // FOR WHAT EXACTLY IS THIS USEFUL?
259  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
260  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
261 
262  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
263  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
264  $pageGUI->setRenderPageContainer(false);
265  $pageGUI->setEditPreview(true);
266  $pageGUI->setEnabledTabs(false);
267 
268  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
269  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) { // workaround for page edit imagemaps, keep in mind
270  $this->ctrl->setCmdClass(get_class($pageGUI));
271  $this->ctrl->setCmd('preview');
272  }
273 
274  $this->questionGUI->setPreviewSession($this->previewSession);
275  $this->questionGUI->object->setShuffler($this->getQuestionAnswerShuffler());
276 
277  $questionHtml = $this->questionGUI->getPreview(true, $this->isShowSpecificQuestionFeedbackRequired());
278  $this->questionGUI->magicAfterTestOutput();
279 
280  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $questionHtml));
281 
282  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
283  $pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
284 
285  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
286 
287  $tpl->setVariable('QUESTION_OUTPUT', $pageGUI->preview());
288  }
289 
291  {
292  // FOR WHAT EXACTLY IS THIS USEFUL?
293  $this->ctrl->setReturnByClass('ilAssQuestionPageGUI', 'view');
294  $this->ctrl->setReturnByClass('ilObjQuestionPoolGUI', 'questions');
295 
296  include_once("./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php");
297  $pageGUI = new ilAssQuestionPageGUI($this->questionOBJ->getId());
298 
299  $pageGUI->setEditPreview(true);
300  $pageGUI->setEnabledTabs(false);
301 
302  // FOR WHICH SITUATION IS THIS WORKAROUND NECCESSARY? (sure .. imagemaps, but where this can be done?)
303  if (strlen($this->ctrl->getCmd()) == 0 && !isset($_POST['editImagemapForward_x'])) { // workaround for page edit imagemaps, keep in mind
304  $this->ctrl->setCmdClass(get_class($pageGUI));
305  $this->ctrl->setCmd('preview');
306  }
307 
308  $this->questionGUI->setPreviewSession($this->previewSession);
309 
310  $pageGUI->setQuestionHTML(array($this->questionOBJ->getId() => $this->questionGUI->getSolutionOutput(
311  0,
312  null,
313  false,
314  false,
315  true,
316  false,
317  true,
318  false,
319  false
320  )));
321 
322  //$pageGUI->setHeader($this->questionOBJ->getTitle()); // NO ADDITIONAL HEADER
323  //$pageGUI->setPresentationTitle($this->questionOBJ->getTitle());
324 
325  //$pageGUI->setTemplateTargetVar("ADM_CONTENT"); // NOT REQUIRED, OR IS?
326 
327  $tpl->setCurrentBlock('solution_output');
328  $tpl->setVariable('TXT_CORRECT_SOLUTION', $this->lng->txt('tst_best_solution_is'));
329  $tpl->setVariable('SOLUTION_OUTPUT', $pageGUI->preview());
330  $tpl->parseCurrentBlock();
331  }
332 
334  {
335  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionRelatedNavigationBarGUI.php';
336  $navGUI = new ilAssQuestionRelatedNavigationBarGUI($this->ctrl, $this->lng);
337 
338  $navGUI->setInstantResponseCmd(self::CMD_INSTANT_RESPONSE);
339  $navGUI->setHintRequestCmd(self::CMD_GATEWAY_CONFIRM_HINT_REQUEST);
340  $navGUI->setHintListCmd(self::CMD_GATEWAY_SHOW_HINT_LIST);
341 
342  $navGUI->setInstantResponseEnabled($this->previewSettings->isInstantFeedbackNavigationRequired());
343  $navGUI->setHintProvidingEnabled($this->previewSettings->isHintProvidingEnabled());
344 
345  $navGUI->setHintRequestsPossible($this->hintTracking->requestsPossible());
346  $navGUI->setHintRequestsExist($this->hintTracking->requestsExist());
347 
348  $tpl->setVariable('QUESTION_NAVIGATION', $this->ctrl->getHTML($navGUI));
349  }
350 
352  {
353  if ($this->questionOBJ->isPreviewSolutionCorrect($this->previewSession)) {
354  $feedback = $this->questionGUI->getGenericFeedbackOutputForCorrectSolution();
356  } else {
357  $feedback = $this->questionGUI->getGenericFeedbackOutputForIncorrectSolution();
359  }
360 
361  if (strlen($feedback)) {
362  $tpl->setCurrentBlock('instant_feedback_generic');
363  $tpl->setVariable('GENERIC_FEEDBACK', $feedback);
364  $tpl->setVariable('ILC_FB_CSS_CLASS', $cssClass);
365  $tpl->parseCurrentBlock();
366  }
367  }
368 
370  {
371  $tpl->setCurrentBlock('instant_feedback_specific');
372  $tpl->setVariable('ANSWER_FEEDBACK', $this->questionGUI->getSpecificFeedbackOutput(0, -1));
373  $tpl->parseCurrentBlock();
374  }
375 
376  private function isShowBestSolutionRequired()
377  {
378  if (!$this->previewSettings->isBestSolutionEnabled()) {
379  return false;
380  }
381 
382  return $this->previewSession->isInstantResponseActive();
383  }
384 
386  {
387  if (!$this->previewSettings->isGenericFeedbackEnabled()) {
388  return false;
389  }
390 
391  return $this->previewSession->isInstantResponseActive();
392  }
393 
395  {
396  if (!$this->previewSettings->isSpecificFeedbackEnabled()) {
397  return false;
398  }
399 
400  return $this->previewSession->isInstantResponseActive();
401  }
402 
403  public function saveQuestionSolution()
404  {
405  return $this->questionOBJ->persistPreviewState($this->previewSession);
406  }
407 
409  {
410  if (!$this->saveQuestionSolution()) {
411  $this->previewSession->setInstantResponseActive(false);
412  $this->showCmd();
413  return;
414  }
415 
416  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
417 
418  $this->ctrl->redirectByClass(
419  'ilAssQuestionHintRequestGUI',
421  );
422  }
423 
424  public function gatewayShowHintListCmd()
425  {
426  if (!$this->saveQuestionSolution()) {
427  $this->previewSession->setInstantResponseActive(false);
428  $this->showCmd();
429  return;
430  }
431 
432  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintRequestGUI.php';
433 
434  $this->ctrl->redirectByClass(
435  'ilAssQuestionHintRequestGUI',
437  );
438  }
439 
443  private function getQuestionAnswerShuffler()
444  {
445  require_once 'Services/Randomization/classes/class.ilArrayElementShuffler.php';
446  $shuffler = new ilArrayElementShuffler();
447 
448  if (!$this->previewSession->randomizerSeedExists()) {
449  $this->previewSession->setRandomizerSeed($shuffler->buildRandomSeed());
450  }
451 
452  $shuffler->setSeed($this->previewSession->getRandomizerSeed());
453 
454  return $shuffler;
455  }
456 }
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.
global $DIC
Definition: saml.php:7
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
static getContentStylePath($a_style_id, $add_random=true)
get content 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.
initQuestion($questionId, $parentObjId)
language handling
$_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.