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