ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assMatchingQuestionGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
6 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
7 
20 {
29  function __construct($id = -1)
30  {
32  include_once "./Modules/TestQuestionPool/classes/class.assMatchingQuestion.php";
33  $this->object = new assMatchingQuestion();
34  $this->setErrorMessage($this->lng->txt("msg_form_save_error"));
35  if ($id >= 0)
36  {
37  $this->object->loadFromDb($id);
38  }
39  }
40 
41  function getCommand($cmd)
42  {
43  return $cmd;
44  }
45 
52  function writePostData($always = false)
53  {
54  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
55  if (!$hasErrors)
56  {
57  $this->object->setTitle($_POST["title"]);
58  $this->object->setAuthor($_POST["author"]);
59  $this->object->setComment($_POST["comment"]);
60  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
61  $questiontext = $_POST["question"];
62  $this->object->setQuestion($questiontext);
63  if (!$this->getSelfAssessmentEditingMode())
64  {
65  $this->object->setShuffle($_POST["shuffle"]);
66  }
67  else
68  {
69  $this->object->setShuffle(1);
70  }
71  $this->object->setThumbGeometry($_POST["thumb_geometry"]);
72  $this->object->setElementHeight($_POST["element_height"]);
73  if ($this->getSelfAssessmentEditingMode())
74  {
75  $this->object->setNrOfTries($_POST['nr_of_tries']);
76  }
77  // adding estimated working time
78  $this->object->setEstimatedWorkingTime(
79  $_POST["Estimated"]["hh"],
80  $_POST["Estimated"]["mm"],
81  $_POST["Estimated"]["ss"]
82  );
83 
84  // Delete all existing answers and create new answers from the form data
85  $this->object->flushMatchingPairs();
86  $this->object->flushTerms();
87  $this->object->flushDefinitions();
88  $saved = false;
89 
90  // add terms
91  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
92  foreach ($_POST['terms']['answer'] as $index => $answer)
93  {
94  $filename = $_POST['terms']['imagename'][$index];
95  if (strlen($_FILES['terms']['name']['image'][$index]))
96  {
97  // upload the new file
98  $name = $_FILES['terms']['name']['image'][$index];
99  if ($this->object->setImageFile($_FILES['terms']['tmp_name']['image'][$index], $this->object->getEncryptedFilename($name)))
100  {
101  $filename = $this->object->getEncryptedFilename($name);
102  }
103  else
104  {
105  $filename = "";
106  }
107  }
108  $this->object->addTerm(new assAnswerMatchingTerm($answer, $filename, $_POST['terms']['identifier'][$index]));
109  }
110  // add definitions
111  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
112  foreach ($_POST['definitions']['answer'] as $index => $answer)
113  {
114  $filename = $_POST['definitions']['imagename'][$index];
115  if (strlen($_FILES['definitions']['name']['image'][$index]))
116  {
117  // upload the new file
118  $name = $_FILES['definitions']['name']['image'][$index];
119  if ($this->object->setImageFile($_FILES['definitions']['tmp_name']['image'][$index], $this->object->getEncryptedFilename($name)))
120  {
121  $filename = $this->object->getEncryptedFilename($name);
122  }
123  else
124  {
125  $filename = "";
126  }
127  }
128  $this->object->addDefinition(new assAnswerMatchingDefinition($answer, $filename, $_POST['definitions']['identifier'][$index]));
129  }
130 
131  // add matching pairs
132  if (is_array($_POST['pairs']['points']))
133  {
134  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
135  foreach ($_POST['pairs']['points'] as $index => $points)
136  {
137  $term_id = $_POST['pairs']['term'][$index];
138  $definition_id = $_POST['pairs']['definition'][$index];
139  $this->object->addMatchingPair($this->object->getTermWithIdentifier($term_id), $this->object->getDefinitionWithIdentifier($definition_id), $points);
140  }
141  }
142  return 0;
143  }
144  else
145  {
146  return 1;
147  }
148  }
149 
153  public function uploadterms()
154  {
155  $this->writePostData(true);
156  $position = key($_POST['cmd']['uploadterms']);
157  $this->editQuestion();
158  }
159 
163  public function removeimageterms()
164  {
165  $this->writePostData(true);
166  $position = key($_POST['cmd']['removeimageterms']);
167  $filename = $_POST['terms']['imagename'][$position];
168  $this->object->removeTermImage($position);
169  $this->editQuestion();
170  }
171 
175  public function uploaddefinitions()
176  {
177  $this->writePostData(true);
178  $position = key($_POST['cmd']['uploaddefinitions']);
179  $this->editQuestion();
180  }
181 
185  public function removeimagedefinitions()
186  {
187  $this->writePostData(true);
188  $position = key($_POST['cmd']['removeimagedefinitions']);
189  $filename = $_POST['definitions']['imagename'][$position];
190  $this->object->removeDefinitionImage($position);
191  $this->editQuestion();
192  }
193 
194  public function addterms()
195  {
196  $this->writePostData();
197  $position = key($_POST["cmd"]["addterms"]);
198  $this->object->insertTerm($position+1);
199  $this->editQuestion();
200  }
201 
202  public function removeterms()
203  {
204  $this->writePostData();
205  $position = key($_POST["cmd"]["removeterms"]);
206  $this->object->deleteTerm($position);
207  $this->editQuestion();
208  }
209 
210  public function adddefinitions()
211  {
212  $this->writePostData();
213  $position = key($_POST["cmd"]["adddefinitions"]);
214  $this->object->insertDefinition($position+1);
215  $this->editQuestion();
216  }
217 
218  public function removedefinitions()
219  {
220  $this->writePostData();
221  $position = key($_POST["cmd"]["removedefinitions"]);
222  $this->object->deleteDefinition($position);
223  $this->editQuestion();
224  }
225 
226  public function addpairs()
227  {
228  $this->writePostData();
229  $position = key($_POST["cmd"]["addpairs"]);
230  $this->object->insertMatchingPair($position+1);
231  $this->editQuestion();
232  }
233 
234  public function removepairs()
235  {
236  $this->writePostData();
237  $position = key($_POST["cmd"]["removepairs"]);
238  $this->object->deleteMatchingPair($position);
239  $this->editQuestion();
240  }
241 
247  function editQuestion($checkonly = FALSE)
248  {
249  $save = $this->isSaveCommand();
250  $this->getQuestionTemplate();
251 
252  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
253  $form = new ilPropertyFormGUI();
254  $form->setFormAction($this->ctrl->getFormAction($this));
255  $form->setTitle($this->outQuestionType());
256  $form->setMultipart(true);
257  $form->setTableWidth("100%");
258  $form->setId("matching");
259 
260  // Edit mode
261  $hidden = new ilHiddenInputGUI("matching_type");
262  $hidden->setValue($matchingtype);
263  $form->addItem($hidden);
264 
265  // title, author, description, question, working time (assessment mode)
266  $this->addBasicQuestionFormProperties($form);
267 
268  if (!$this->getSelfAssessmentEditingMode())
269  {
270  // shuffle
271  $shuffle = new ilSelectInputGUI($this->lng->txt("shuffle_answers"), "shuffle");
272  $shuffle_options = array(
273  0 => $this->lng->txt("no"),
274  1 => $this->lng->txt("matching_shuffle_terms_definitions"),
275  2 => $this->lng->txt("matching_shuffle_terms"),
276  3 => $this->lng->txt("matching_shuffle_definitions")
277  );
278  $shuffle->setOptions($shuffle_options);
279  $shuffle->setValue($this->object->getShuffle() != null ? $this->object->getShuffle() : 1);
280  $shuffle->setRequired(FALSE);
281  $form->addItem($shuffle);
282 
283  $element_height = new ilNumberInputGUI($this->lng->txt("element_height"), "element_height");
284  $element_height->setValue($this->object->getElementHeight());
285  $element_height->setRequired(false);
286  $element_height->setMaxLength(6);
287  $element_height->setMinValue(20);
288  $element_height->setSize(6);
289  $element_height->setInfo($this->lng->txt("element_height_info"));
290  $form->addItem($element_height);
291 
292  $geometry = new ilNumberInputGUI($this->lng->txt("thumb_geometry"), "thumb_geometry");
293  $geometry->setValue($this->object->getThumbGeometry());
294  $geometry->setRequired(true);
295  $geometry->setMaxLength(6);
296  $geometry->setMinValue(20);
297  $geometry->setSize(6);
298  $geometry->setInfo($this->lng->txt("thumb_geometry_info"));
299  $form->addItem($geometry);
300  }
301 
302  // Definitions
303  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php";
304  $definitions = new ilMatchingWizardInputGUI($this->lng->txt("definitions"), "definitions");
305  if ($this->getSelfAssessmentEditingMode()) $definitions->setHideImages(true);
306  $definitions->setRequired(true);
307  $definitions->setQuestionObject($this->object);
308  $definitions->setTextName($this->lng->txt('definition_text'));
309  $definitions->setImageName($this->lng->txt('definition_image'));
310  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingDefinition.php";
311  if (!count($this->object->getDefinitions())) $this->object->addDefinition(new assAnswerMatchingDefinition());
312  $definitionvalues = $this->object->getDefinitions();
313  $definitions->setValues($definitionvalues);
314  $definitions->checkInput();
315  $form->addItem($definitions);
316 
317  // Terms
318  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingWizardInputGUI.php";
319  $terms = new ilMatchingWizardInputGUI($this->lng->txt("terms"), "terms");
320  if ($this->getSelfAssessmentEditingMode()) $terms->setHideImages(true);
321  $terms->setRequired(true);
322  $terms->setQuestionObject($this->object);
323  $terms->setTextName($this->lng->txt('term_text'));
324  $terms->setImageName($this->lng->txt('term_image'));
325  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingTerm.php";
326  if (!count($this->object->getTerms())) $this->object->addTerm(new assAnswerMatchingTerm());
327  $termvalues = $this->object->getTerms();
328  $terms->setValues($termvalues);
329  $terms->checkInput();
330  $form->addItem($terms);
331 
332  // Matching Pairs
333  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingPairWizardInputGUI.php";
334  $pairs = new ilMatchingPairWizardInputGUI($this->lng->txt('matching_pairs'), 'pairs');
335  $pairs->setRequired(true);
336  $pairs->setTerms($this->object->getTerms());
337  $pairs->setDefinitions($this->object->getDefinitions());
338  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
339  if (count($this->object->getMatchingPairs()) == 0)
340  {
341  $this->object->addMatchingPair(new assAnswerMatchingPair($termvalues[0], $definitionvalues[0], 0));
342  }
343  $pairs->setPairs($this->object->getMatchingPairs());
344  $form->addItem($pairs);
345 
346  $this->addQuestionFormCommandButtons($form);
347 
348  $errors = false;
349 
350  if ($save)
351  {
352  $form->setValuesByPost();
353  $errors = !$form->checkInput();
354  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
355  if ((!$errors) && !$this->isValidTermAndDefinitionAmount($form)
356  && !$this->getSelfAssessmentEditingMode())
357  {
358  $errors = true;
359  $terms->setAlert($this->lng->txt("msg_number_of_terms_too_low"));
360  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
361  }
362  if ($errors) $checkonly = false;
363  }
364 
365  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
366  return $errors;
367  }
368 
374  {
375  $numTerms = count($form->getItemByPostVar('terms')->getValues());
376  $numDefinitions = count($form->getItemByPostVar('definitions')->getValues());
377 
378  if($numTerms >= $numDefinitions)
379  {
380  return true;
381  }
382 
383  return false;
384  }
385 
386  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
387  {
388  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
389  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
390  $this->tpl->setVariable("FORMACTION", $formaction);
391  }
392 
407  $active_id,
408  $pass = NULL,
409  $graphicalOutput = FALSE,
410  $result_output = FALSE,
411  $show_question_only = TRUE,
412  $show_feedback = FALSE,
413  $show_correct_solution = FALSE,
414  $show_manual_scoring = FALSE,
415  $show_question_text = TRUE
416  )
417  {
418  // generate the question output
419  include_once "./Services/UICore/classes/class.ilTemplate.php";
420  $template = new ilTemplate("tpl.il_as_qpl_matching_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
421  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
422 
423  $solutions = array();
424  if (($active_id > 0) && (!$show_correct_solution))
425  {
426  include_once "./Modules/Test/classes/class.ilObjTest.php";
427  $solutions =& $this->object->getSolutionValues($active_id, $pass);
428  $solution_script .= "";
429  }
430  else
431  {
432  foreach ($this->object->getMatchingPairs() as $pair)
433  {
434  if( $pair->points <= 0 )
435  {
436  continue;
437  }
438 
439  $solutions[] = array(
440  "value1" => $pair->term->identifier,
441  "value2" => $pair->definition->identifier,
442  'points' => $pair->points
443  );
444  }
445  }
446 
447  $i = 0;
448 
449  foreach ($solutions as $solution)
450  {
451  $definition = $this->object->getDefinitionWithIdentifier($solution['value2']);
452  $term = $this->object->getTermWithIdentifier($solution['value1']);
453  $points = $solution['points'];
454 
455  if (is_object($definition))
456  {
457  if (strlen($definition->picture))
458  {
459  $template->setCurrentBlock('definition_image');
460  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
461  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
462  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
463  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
464  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
465  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
466  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($definition->text) : $this->lng->txt('definition') . ' ' . ($i+1));
467  $template->parseCurrentBlock();
468  }
469  else
470  {
471  $template->setCurrentBlock('definition_text');
472  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, TRUE));
473  $template->parseCurrentBlock();
474  }
475  }
476  if (is_object($term))
477  {
478  if (strlen($term->picture))
479  {
480  $template->setCurrentBlock('term_image');
481  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
482  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
483  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
484  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
485  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
486  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($i+1));
487  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
488  $template->parseCurrentBlock();
489  }
490  else
491  {
492  $template->setCurrentBlock('term_text');
493  $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, TRUE));
494  $template->parseCurrentBlock();
495  }
496  $i++;
497  }
498  if (($active_id > 0) && (!$show_correct_solution))
499  {
500  if ($graphicalOutput)
501  {
502  // output of ok/not ok icons for user entered solutions
503  $ok = false;
504  foreach ($this->object->getMatchingPairs() as $pair)
505  {
506  if( $this->isCorrectMatching($pair, $definition, $term) )
507  {
508  $ok = true;
509  }
510  }
511 
512  if ($ok)
513  {
514  $template->setCurrentBlock("icon_ok");
515  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.png"));
516  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
517  $template->parseCurrentBlock();
518  }
519  else
520  {
521  $template->setCurrentBlock("icon_ok");
522  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.png"));
523  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
524  $template->parseCurrentBlock();
525  }
526  }
527  }
528 
529  if ($result_output)
530  {
531  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
532  $template->setCurrentBlock("result_output");
533  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
534  $template->parseCurrentBlock();
535  }
536 
537  $template->setCurrentBlock("row");
538  if ($this->object->getEstimatedElementHeight() > 0)
539  {
540  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
541  }
542  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
543  $template->parseCurrentBlock();
544  }
545 
546  $questiontext = $this->object->getQuestion();
547  if ($show_question_text==true)
548  {
549  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
550  }
551 
552  $questionoutput = $template->get();
553 
554  $feedback = '';
555  if($show_feedback)
556  {
557  $fb = $this->getGenericFeedbackOutput($active_id, $pass);
558  $feedback .= strlen($fb) ? $fb : '';
559 
560  $fb = $this->getSpecificFeedbackOutput($active_id, $pass);
561  $feedback .= strlen($fb) ? $fb : '';
562  }
563  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
564 
565  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
566 
567  $solutionoutput = $solutiontemplate->get();
568  if (!$show_question_only)
569  {
570  // get page object output
571  $solutionoutput = '<div class="ilc_question_Standard">'.$solutionoutput."</div>";
572  }
573  return $solutionoutput;
574  }
575 
576  public function getPreviewJS($show_question_only = FALSE)
577  {
578  global $ilUser;
579 
580  // generate the question output
581  include_once "./Services/UICore/classes/class.ilTemplate.php";
582  $template = new ilTemplate("tpl.il_as_qpl_matching_output_js.html", TRUE, TRUE, "Modules/TestQuestionPool");
583 
584  $jsswitch = "";
585  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
586  {
587  if (array_key_exists('js', $_GET))
588  {
589  $ilUser->writePref('tst_javascript', $_GET['js']);
590  }
591  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
592  if ($ilUser->getPref("tst_javascript") == 1)
593  {
594  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
595  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
596  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
597  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
598  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
599  }
600  else
601  {
602  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
603  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
604  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
605  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
606  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
607  }
608  $jsswitch = $jstemplate->get();
609  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
610  }
611 
612  // shuffle output
613  $terms = $this->object->getTerms();
614  $definitions = $this->object->getDefinitions();
615  switch ($this->object->getShuffle())
616  {
617  case 1:
618  $terms = $this->object->pcArrayShuffle($terms);
619  $definitions = $this->object->pcArrayShuffle($definitions);
620  break;
621  case 2:
622  $terms = $this->object->pcArrayShuffle($terms);
623  break;
624  case 3:
625  $definitions = $this->object->pcArrayShuffle($definitions);
626  break;
627  }
628 
629  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
631 
632  // create definitions
633  $counter = 0;
634  foreach ($definitions as $definition)
635  {
636  if (strlen($definition->picture))
637  {
638  $template->setCurrentBlock("definition_picture");
639  $template->setVariable("DEFINITION_ID", $definition->identifier);
640  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
641  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
642  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
643  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
644  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
645  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
646  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
647  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, TRUE) : '');
648  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
649  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
650  $template->parseCurrentBlock();
651  }
652  else
653  {
654  $template->setCurrentBlock("definition_text");
655  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, TRUE));
656  $template->parseCurrentBlock();
657  }
658 
659  $template->setCurrentBlock("droparea");
660  $template->setVariable("ID_DROPAREA", $definition->identifier);
661  $template->setVariable("QUESTION_ID", $this->object->getId());
662  if ($this->object->getEstimatedElementHeight() > 0)
663  {
664  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
665  }
666  $template->parseCurrentBlock();
667 
668  $template->setCurrentBlock("init_dropareas");
669  $template->setVariable("COUNTER", $counter++);
670  $template->setVariable("ID_DROPAREA", $definition->identifier);
671  $template->parseCurrentBlock();
672  }
673 
674 
675  // create terms
676  $counter = 0;
677  foreach ($terms as $term)
678  {
679  if (strlen($term->picture))
680  {
681  $template->setCurrentBlock("term_picture");
682  $template->setVariable("TERM_ID", $term->identifier);
683  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
684  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
685  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
686  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
687  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
688  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
689  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
690  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
691  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, TRUE) : '');
692  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
693  $template->parseCurrentBlock();
694  }
695  else
696  {
697  $template->setCurrentBlock("term_text");
698  $template->setVariable("TERM_TEXT", $this->object->prepareTextareaOutput($term->text, TRUE));
699  $template->parseCurrentBlock();
700  }
701  $template->setCurrentBlock("draggable");
702  $template->setVariable("ID_DRAGGABLE", $term->identifier);
703  if ($this->object->getEstimatedElementHeight() > 0)
704  {
705  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
706  }
707  $template->parseCurrentBlock();
708 
709  $template->setCurrentBlock("init_draggables");
710  $template->setVariable("COUNTER", $counter++);
711  $template->setVariable("ID_DRAGGABLE", $term->identifier);
712  $template->parseCurrentBlock();
713  }
714 
715  $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
716 
717  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
718 
719  $questiontext = $this->object->getQuestion();
720  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
721  $questionoutput = $jsswitch . $template->get();
722  if (!$show_question_only)
723  {
724  // get page object output
725  $questionoutput = $this->getILIASPage($questionoutput);
726  }
727  return $questionoutput;
728  }
729 
730  public function getPreview($show_question_only = FALSE)
731  {
732  global $ilUser;
733 
734  // generate the question output
735  include_once "./Services/UICore/classes/class.ilTemplate.php";
736  $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
737 
738  $jsswitch = "";
739  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
740  {
741  if (array_key_exists('js', $_GET))
742  {
743  $ilUser->writePref('tst_javascript', $_GET['js']);
744  }
745  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
746  if ($ilUser->getPref("tst_javascript") == 1)
747  {
748  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
749  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
750  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
751  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
752  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
753  }
754  else
755  {
756  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
757  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
758  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
759  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
760  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
761  }
762  $jsswitch = $jstemplate->get();
763  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
764  }
765 
766  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
767  {
768  return $this->getPreviewJS($show_question_only);
769  }
770 
771  // shuffle output
772  $terms = $this->object->getTerms();
773  $definitions = $this->object->getDefinitions();
774  switch ($this->object->getShuffle())
775  {
776  case 1:
777  $terms = $this->object->pcArrayShuffle($terms);
778  $definitions = $this->object->pcArrayShuffle($definitions);
779  break;
780  case 2:
781  $terms = $this->object->pcArrayShuffle($terms);
782  break;
783  case 3:
784  $definitions = $this->object->pcArrayShuffle($definitions);
785  break;
786  }
787 
788  for ($i = 0; $i < count($definitions); $i++)
789  {
790  $definition = $definitions[$i];
791  if (is_object($definition))
792  {
793  if (strlen($definition->picture))
794  {
795  $template->setCurrentBlock('definition_image');
796  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
797  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
798  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
799  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
800  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
801  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
802  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . $this->object->prepareTextareaOutput($definition->text, TRUE) : $this->lng->txt('definition') . ' ' . ($i+1));
803  $template->parseCurrentBlock();
804  }
805  else
806  {
807  $template->setCurrentBlock('definition_text');
808  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, TRUE));
809  $template->parseCurrentBlock();
810  }
811  }
812 
813  $template->setCurrentBlock('option');
814  $template->setVariable("VALUE_OPTION", 0);
815  $template->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($this->lng->txt('please_select')));
816  $template->parseCurrentBlock();
817  $j = 1;
818  foreach ($terms as $term)
819  {
820  $template->setCurrentBlock('option');
821  $template->setVariable("VALUE_OPTION", $term->identifier);
822  $template->setVariable("TEXT_OPTION", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($j) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($j));
823  $template->parseCurrentBlock();
824  $j++;
825  }
826 
827  $template->setCurrentBlock('row');
828  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
829  if ($this->object->getEstimatedElementHeight() > 0)
830  {
831  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
832  }
833  $template->setVariable("QUESTION_ID", $this->object->getId());
834  $template->setVariable("DEFINITION_ID", $definition->identifier);
835  $template->parseCurrentBlock();
836  }
837 
838  $i = 0;
839  foreach ($terms as $term)
840  {
841  if (strlen($term->picture))
842  {
843  $template->setCurrentBlock('term_image');
844  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
845  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
846  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
847  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
848  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
849  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . $this->object->prepareTextareaOutput($term->text, TRUE) : $this->lng->txt('term') . ' ' . ($i+1));
850  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
851  $template->parseCurrentBlock();
852  }
853  else
854  {
855  $template->setCurrentBlock('term_text');
856  $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, TRUE));
857  $template->parseCurrentBlock();
858  }
859  $template->touchBlock('terms');
860  $i++;
861  }
862 
863  $questiontext = $this->object->getQuestion();
864  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
865  $template->setVariable("TEXT_TERMS", ilUtil::prepareFormOutput($this->lng->txt('available_terms')));
866  $template->setVariable('TEXT_SELECTION', ilUtil::prepareFormOutput($this->lng->txt('selection')));
867  $questionoutput = $jsswitch . $template->get();
868  if (!$show_question_only)
869  {
870  // get page object output
871  $questionoutput = $this->getILIASPage($questionoutput);
872  }
873  return $questionoutput;
874  }
875 
876  protected function sortDefinitionsBySolution($solution)
877  {
878  $neworder = array();
879  foreach ($solution as $solution_values)
880  {
881  $id = $solution_values['value2'];
882  array_push($neworder, $this->object->getDefinitionWithIdentifier($id));
883  }
884  return $neworder;
885  }
886 
887  function getTestOutputJS($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
888  {
889  // generate the question output
890  include_once "./Services/UICore/classes/class.ilTemplate.php";
891  $template = new ilTemplate("tpl.il_as_qpl_matching_output_js.html", TRUE, TRUE, "Modules/TestQuestionPool");
892 
893  if ($active_id)
894  {
895  $solutions = NULL;
896  include_once "./Modules/Test/classes/class.ilObjTest.php";
897  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
898  {
899  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
900  }
901  if (is_array($user_post_solution))
902  {
903  $solutions = array();
904  foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term)
905  {
906  array_push($solutions, array("value1" => $term, "value2" => $definition));
907  }
908  }
909  else
910  {
911  $solutions =& $this->object->getSolutionValues($active_id, $pass);
912  }
913 
914  foreach ($solutions as $idx => $solution_value)
915  {
916  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
917  {
918  if (($solution_value["value2"] > -1) && ($solution_value["value1"] > -1))
919  {
920  $template->setCurrentBlock("restoreposition");
921  $template->setVariable("TERM_ID", $solution_value["value1"]);
922  $template->setVariable("PICTURE_DEFINITION_ID", $solution_value["value2"]);
923  $template->parseCurrentBlock();
924  }
925  }
926  }
927  }
928 
929  // shuffle output
930  $terms = $this->object->getTerms();
931  $definitions = $this->object->getDefinitions();
932  switch ($this->object->getShuffle())
933  {
934  case 1:
935  $terms = $this->object->pcArrayShuffle($terms);
936  if (count($solutions))
937  {
938  $definitions = $this->sortDefinitionsBySolution($solutions);
939  }
940  else
941  {
942  $definitions = $this->object->pcArrayShuffle($definitions);
943  }
944  break;
945  case 2:
946  $terms = $this->object->pcArrayShuffle($terms);
947  break;
948  case 3:
949  if (count($solutions))
950  {
951  $definitions = $this->sortDefinitionsBySolution($solutions);
952  }
953  else
954  {
955  $definitions = $this->object->pcArrayShuffle($definitions);
956  }
957  break;
958  }
959 
960  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
962 
963  // create definitions
964  $counter = 0;
965  foreach ($definitions as $definition)
966  {
967  if (strlen($definition->picture))
968  {
969  $template->setCurrentBlock("definition_picture");
970  $template->setVariable("DEFINITION_ID", $definition->identifier);
971  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
972  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
973  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
974  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
975  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
976  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
977  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
978  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : '');
979  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
980  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
981  $template->parseCurrentBlock();
982  }
983  else
984  {
985  $template->setCurrentBlock("definition_text");
986  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true));
987  $template->parseCurrentBlock();
988  }
989 
990  $template->setCurrentBlock("droparea");
991  $template->setVariable("ID_DROPAREA", $definition->identifier);
992  $template->setVariable("QUESTION_ID", $this->object->getId());
993  if ($this->object->getEstimatedElementHeight() > 0)
994  {
995  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
996  }
997  $template->parseCurrentBlock();
998 
999  $template->setCurrentBlock("init_dropareas");
1000  $template->setVariable("COUNTER", $counter++);
1001  $template->setVariable("ID_DROPAREA", $definition->identifier);
1002  $template->parseCurrentBlock();
1003  }
1004 
1005 
1006  // create terms
1007  $counter = 0;
1008  foreach ($terms as $term)
1009  {
1010  if (strlen($term->picture))
1011  {
1012  $template->setCurrentBlock("term_picture");
1013  $template->setVariable("TERM_ID", $term->identifier);
1014  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
1015  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
1016  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
1017  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
1018  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
1019  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
1020  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
1021  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1022  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : '');
1023  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
1024  $template->parseCurrentBlock();
1025  }
1026  else
1027  {
1028  $template->setCurrentBlock("term_text");
1029  $template->setVariable("TERM_TEXT", $this->object->prepareTextareaOutput($term->text, true));
1030  $template->parseCurrentBlock();
1031  }
1032  $template->setCurrentBlock("draggable");
1033  $template->setVariable("ID_DRAGGABLE", $term->identifier);
1034  if ($this->object->getEstimatedElementHeight() > 0)
1035  {
1036  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
1037  }
1038  $template->parseCurrentBlock();
1039 
1040  $template->setCurrentBlock("init_draggables");
1041  $template->setVariable("COUNTER", $counter++);
1042  $template->setVariable("ID_DRAGGABLE", $term->identifier);
1043  $template->parseCurrentBlock();
1044  }
1045 
1046  $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
1047 
1048  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
1049 
1050  $questiontext = $this->object->getQuestion();
1051  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1052  $questionoutput = $template->get();
1053  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1054  return $pageoutput;
1055  }
1056 
1057  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
1058  {
1059  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
1060  {
1061  return $this->getTestOutputJS($active_id, $pass, $is_postponed, $user_post_solution);
1062  }
1063  // generate the question output
1064  include_once "./Services/UICore/classes/class.ilTemplate.php";
1065  $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
1066 
1067  if ($active_id)
1068  {
1069  $solutions = NULL;
1070  include_once "./Modules/Test/classes/class.ilObjTest.php";
1071  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
1072  {
1073  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
1074  }
1075  if (is_array($user_post_solution))
1076  {
1077  $solutions = array();
1078  foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term)
1079  {
1080  array_push($solutions, array("value1" => $term, "value2" => $definition));
1081  }
1082  }
1083  else
1084  {
1085  $solutions =& $this->object->getSolutionValues($active_id, $pass);
1086  }
1087  }
1088 
1089 
1090  // shuffle output
1091  $terms = $this->object->getTerms();
1092  $definitions = $this->object->getDefinitions();
1093  switch ($this->object->getShuffle())
1094  {
1095  case 1:
1096  $terms = $this->object->pcArrayShuffle($terms);
1097  if (count($solutions))
1098  {
1099  $definitions = $this->sortDefinitionsBySolution($solutions);
1100  }
1101  else
1102  {
1103  $definitions = $this->object->pcArrayShuffle($definitions);
1104  }
1105  break;
1106  case 2:
1107  $terms = $this->object->pcArrayShuffle($terms);
1108  break;
1109  case 3:
1110  if (count($solutions))
1111  {
1112  $definitions = $this->sortDefinitionsBySolution($solutions);
1113  }
1114  else
1115  {
1116  $definitions = $this->object->pcArrayShuffle($definitions);
1117  }
1118  break;
1119  }
1120  $maxcount = max(count($terms), count($definitions));
1121  for ($i = 0; $i < count($definitions); $i++)
1122  {
1123  $definition = $definitions[$i];
1124  if (is_object($definition))
1125  {
1126  if (strlen($definition->picture))
1127  {
1128  $template->setCurrentBlock('definition_image');
1129  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
1130  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
1131  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
1132  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
1133  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1134  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
1135  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($definition->text) : $this->lng->txt('definition') . ' ' . ($i+1));
1136  $template->parseCurrentBlock();
1137  }
1138  else
1139  {
1140  $template->setCurrentBlock('definition_text');
1141  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true));
1142  $template->parseCurrentBlock();
1143  }
1144  }
1145 
1146  $template->setCurrentBlock('option');
1147  $template->setVariable("VALUE_OPTION", 0);
1148  $template->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($this->lng->txt('please_select')));
1149  $template->parseCurrentBlock();
1150  $j = 1;
1151  foreach ($terms as $term)
1152  {
1153  $template->setCurrentBlock('option');
1154  $template->setVariable("VALUE_OPTION", $term->identifier);
1155  $template->setVariable("TEXT_OPTION", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($j) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($j));
1156  foreach ($solutions as $solution)
1157  {
1158  if ($solution["value1"] == $term->identifier && $solution["value2"] == $definition->identifier)
1159  {
1160  $template->setVariable("SELECTED_OPTION", " selected=\"selected\"");
1161  }
1162  }
1163  $template->parseCurrentBlock();
1164  $j++;
1165  }
1166 
1167  $template->setCurrentBlock('row');
1168  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
1169  if ($this->object->getEstimatedElementHeight() > 0)
1170  {
1171  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
1172  }
1173  $template->setVariable("QUESTION_ID", $this->object->getId());
1174  $template->setVariable("DEFINITION_ID", $definition->identifier);
1175  $template->parseCurrentBlock();
1176  }
1177 
1178  $i = 0;
1179  foreach ($terms as $term)
1180  {
1181  if (strlen($term->picture))
1182  {
1183  $template->setCurrentBlock('term_image');
1184  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
1185  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
1186  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
1187  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
1188  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1189  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($i+1));
1190  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.png'));
1191  $template->parseCurrentBlock();
1192  }
1193  else
1194  {
1195  $template->setCurrentBlock('term_text');
1196  $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, true));
1197  $template->parseCurrentBlock();
1198  }
1199  $template->touchBlock('terms');
1200  $i++;
1201  }
1202 
1203  $questiontext = $this->object->getQuestion();
1204  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1205  $template->setVariable("TEXT_TERMS", ilUtil::prepareFormOutput($this->lng->txt('available_terms')));
1206  $template->setVariable('TEXT_SELECTION', ilUtil::prepareFormOutput($this->lng->txt('selection')));
1207 
1208  $questiontext = $this->object->getQuestion();
1209  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1210  $questionoutput = $template->get();
1211  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1212  return $pageoutput;
1213 
1214  }
1215 
1219  function checkInput()
1220  {
1221  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
1222  {
1223  return false;
1224  }
1225  return true;
1226  }
1227 
1228 
1232  function saveFeedback()
1233  {
1234  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1235  $errors = $this->feedback(true);
1236  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
1237  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
1238  foreach ($this->object->getMatchingPairs() as $index => $answer)
1239  {
1240  $this->object->saveFeedbackSingleAnswer($index, $_POST["feedback_answer_$index"]);
1241  }
1242  $this->object->cleanupMediaObjectUsage();
1244  }
1245 
1253  function setQuestionTabs()
1254  {
1255  global $rbacsystem, $ilTabs;
1256 
1257  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
1258  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
1259  $q_type = $this->object->getQuestionType();
1260 
1261  if (strlen($q_type))
1262  {
1263  $classname = $q_type . "GUI";
1264  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
1265  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
1266  }
1267 
1268  if ($_GET["q_id"])
1269  {
1270  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1271  {
1272  // edit page
1273  $ilTabs->addTarget("edit_page",
1274  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
1275  array("edit", "insert", "exec_pg"),
1276  "", "", $force_active);
1277  }
1278 
1279  // edit page
1280  $ilTabs->addTarget("preview",
1281  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
1282  array("preview"),
1283  "ilPageObjectGUI", "", $force_active);
1284  }
1285 
1286  $force_active = false;
1287  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1288  {
1289  $url = "";
1290  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
1291  // edit question properties
1292  $ilTabs->addTarget("edit_question",
1293  $url,
1294  array("editQuestion", "save", "saveEdit", "removeimageterms", "uploadterms", "removeimagedefinitions", "uploaddefinitions",
1295  "addpairs", "removepairs", "addterms", "removeterms", "adddefinitions", "removedefinitions", "originalSyncForm"),
1296  $classname, "", $force_active);
1297  }
1298 
1299  if ($_GET["q_id"])
1300  {
1301  $ilTabs->addTarget("feedback",
1302  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
1303  array("feedback", "saveFeedback"),
1304  $classname, "");
1305  }
1306 
1307  // add tab for question hint within common class assQuestionGUI
1308  $this->addTab_QuestionHints($ilTabs);
1309 
1310  if ($_GET["q_id"])
1311  {
1312  $ilTabs->addTarget("solution_hint",
1313  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
1314  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
1315  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
1316  ),
1317  $classname,
1318  ""
1319  );
1320  }
1321 
1322  // Assessment of questions sub menu entry
1323  if ($_GET["q_id"])
1324  {
1325  $ilTabs->addTarget("statistics",
1326  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
1327  array("assessment"),
1328  $classname, "");
1329  }
1330 
1331  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
1332  {
1333  $ref_id = $_GET["calling_test"];
1334  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
1335 
1336  global $___test_express_mode;
1337 
1338  if (!$_GET['test_express_mode'] && !$___test_express_mode) {
1339  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
1340  }
1341  else {
1343  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), $link);
1344  }
1345  }
1346  else
1347  {
1348  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
1349  }
1350  }
1351 
1352 
1358  function feedback($checkonly = false)
1359  {
1360  $save = (strcmp($this->ctrl->getCmd(), "saveFeedback") == 0) ? TRUE : FALSE;
1361  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
1362  $form = new ilPropertyFormGUI();
1363  $form->setFormAction($this->ctrl->getFormAction($this));
1364  $form->setTitle($this->lng->txt('feedback_answers'));
1365  $form->setTableWidth("98%");
1366  $form->setId("feedback");
1367 
1368  $complete = new ilTextAreaInputGUI($this->lng->txt("feedback_complete_solution"), "feedback_complete");
1369  $complete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
1370  $complete->setRequired(false);
1371  $complete->setRows(10);
1372  $complete->setCols(80);
1373  if (!$this->getPreventRteUsage())
1374  {
1375  $complete->setUseRte(true);
1376  }
1377  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1378  $complete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
1379  $complete->addPlugin("latex");
1380  $complete->addButton("latex");
1381  $complete->addButton("pastelatex");
1382  $complete->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
1383  $form->addItem($complete);
1384 
1385  $incomplete = new ilTextAreaInputGUI($this->lng->txt("feedback_incomplete_solution"), "feedback_incomplete");
1386  $incomplete->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
1387  $incomplete->setRequired(false);
1388  $incomplete->setRows(10);
1389  $incomplete->setCols(80);
1390  if (!$this->getPreventRteUsage())
1391  {
1392  $incomplete->setUseRte(true);
1393  }
1394  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1395  $incomplete->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
1396  $incomplete->addPlugin("latex");
1397  $incomplete->addButton("latex");
1398  $incomplete->addButton("pastelatex");
1399  $incomplete->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
1400  $form->addItem($incomplete);
1401 
1402  if (!$this->getSelfAssessmentEditingMode())
1403  {
1404  foreach ($this->object->getMatchingPairs() as $index => $answer)
1405  {
1406  $caption = $ordinal = $index+1;
1407  $caption .= '. <br />"' . $answer->term->text . '" =&gt; ';
1408  $caption .= '"' . $answer->definition->text . '"';
1409  $caption .= '</i>';
1410 
1411  $answerobj = new ilTextAreaInputGUI($this->object->prepareTextareaOutput($caption, true), "feedback_answer_$index");
1412  $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
1413  $answerobj->setRequired(false);
1414  $answerobj->setRows(10);
1415  $answerobj->setCols(80);
1416  $answerobj->setUseRte(true);
1417  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1418  $answerobj->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
1419  $answerobj->addPlugin("latex");
1420  $answerobj->addButton("latex");
1421  $answerobj->addButton("pastelatex");
1422  $answerobj->setRTESupport($this->object->getId(), "qpl", "assessment", null, false, '3.4.7');
1423  $form->addItem($answerobj);
1424  }
1425  }
1426 
1427  global $ilAccess;
1428  if ($ilAccess->checkAccess("write", "", $_GET['ref_id']) || $this->getSelfAssessmentEditingMode())
1429  {
1430  $form->addCommandButton("saveFeedback", $this->lng->txt("save"));
1431  }
1432  if ($save)
1433  {
1434  $form->setValuesByPost();
1435  $errors = !$form->checkInput();
1436  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
1437  }
1438  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
1439  return $errors;
1440  }
1441 
1442  function getSpecificFeedbackOutput($active_id, $pass)
1443  {
1444  $feedback = '<table><tbody>';
1445 
1446  foreach ($this->object->getMatchingPairs() as $idx => $ans)
1447  {
1448  $feedback .= '<tr><td><b><i>' . $ans->definition->text . '</i></b></td><td>'. $this->lng->txt("matches") . '&nbsp;';
1449  $feedback .= '</td><td><b><i>' . $ans->term->text . '</i></b></td><td>&nbsp;</td><td>';
1450  $feedback .= $this->object->getFeedbackSingleAnswer($idx) . '</td> </tr>';
1451  }
1452 
1453  $feedback .= '</tbody></table>';
1454  return $this->object->prepareTextareaOutput($feedback, TRUE);
1455  }
1456 
1457  private function isCorrectMatching($pair, $definition, $term)
1458  {
1459  if( !($pair->points > 0) )
1460  {
1461  return false;
1462  }
1463 
1464  if( !is_object($term) )
1465  {
1466  return false;
1467  }
1468 
1469  if( $pair->definition->identifier != $definition->identifier )
1470  {
1471  return false;
1472  }
1473 
1474  if( $pair->term->identifier != $term->identifier )
1475  {
1476  return false;
1477  }
1478 
1479  return true;
1480  }
1481 }