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