ILIAS  Release_4_1_x_branch Revision 61804
 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 
348  // Matching Pairs
349  include_once "./Modules/TestQuestionPool/classes/class.ilMatchingPairWizardInputGUI.php";
350  $pairs = new ilMatchingPairWizardInputGUI($this->lng->txt('matching_pairs'), 'pairs');
351  $pairs->setRequired(true);
352  $pairs->setTerms($this->object->getTerms());
353  $pairs->setDefinitions($this->object->getDefinitions());
354  include_once "./Modules/TestQuestionPool/classes/class.assAnswerMatchingPair.php";
355  if (count($this->object->getMatchingPairs()) == 0)
356  {
357  $this->object->addMatchingPair(new assAnswerMatchingPair($termvalues[0], $definitionvalues[0], 0));
358  }
359  $pairs->setPairs($this->object->getMatchingPairs());
360  $form->addItem($pairs);
361 
362  $this->addQuestionFormCommandButtons($form);
363 
364  $errors = false;
365 
366  if ($save)
367  {
368  $form->setValuesByPost();
369  $errors = !$form->checkInput();
370  $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
371  if ((!$errors) && (count($terms->getValues()) < (count($definitions->getValues()))))
372  {
373  $errors = true;
374  $terms->setAlert($this->lng->txt("msg_number_of_terms_too_low"));
375  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
376  }
377  if ($errors) $checkonly = false;
378  }
379 
380  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
381  return $errors;
382  }
383 
384  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
385  {
386  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $user_post_solution);
387  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
388  $this->tpl->setVariable("FORMACTION", $formaction);
389  }
390 
405  $active_id,
406  $pass = NULL,
407  $graphicalOutput = FALSE,
408  $result_output = FALSE,
409  $show_question_only = TRUE,
410  $show_feedback = FALSE,
411  $show_correct_solution = FALSE,
412  $show_manual_scoring = FALSE
413  )
414  {
415  // generate the question output
416  include_once "./classes/class.ilTemplate.php";
417  $template = new ilTemplate("tpl.il_as_qpl_matching_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
418  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
419 
420  $solutions = array();
421  if (($active_id > 0) && (!$show_correct_solution))
422  {
423  include_once "./Modules/Test/classes/class.ilObjTest.php";
424  $solutions =& $this->object->getSolutionValues($active_id, $pass);
425  $solution_script .= "";
426  }
427  else
428  {
429  foreach ($this->object->getMatchingPairs() as $pair)
430  {
431  array_push($solutions, array("value1" => $pair->term->identifier, "value2" => $pair->definition->identifier));
432  }
433  }
434 
435  $i = 0;
436  foreach ($solutions as $solution)
437  {
438  $definition = $this->object->getDefinitionWithIdentifier($solution['value2']);
439  $term = $this->object->getTermWithIdentifier($solution['value1']);
440 
441  if (is_object($definition))
442  {
443  if (strlen($definition->picture))
444  {
445  $template->setCurrentBlock('definition_image');
446  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
447  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
448  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
449  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
450  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
451  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
452  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($definition->text) : $this->lng->txt('definition') . ' ' . ($i+1));
453  $template->parseCurrentBlock();
454  }
455  else
456  {
457  $template->setCurrentBlock('definition_text');
458  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, TRUE));
459  $template->parseCurrentBlock();
460  }
461  }
462  if (is_object($term))
463  {
464  if (strlen($term->picture))
465  {
466  $template->setCurrentBlock('term_image');
467  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
468  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
469  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
470  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
471  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
472  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($i+1));
473  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
474  $template->parseCurrentBlock();
475  }
476  else
477  {
478  $template->setCurrentBlock('term_text');
479  $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, TRUE));
480  $template->parseCurrentBlock();
481  }
482  $i++;
483  }
484  if (($active_id > 0) && (!$show_correct_solution))
485  {
486  if ($graphicalOutput)
487  {
488  // output of ok/not ok icons for user entered solutions
489  $ok = FALSE;
490  foreach ($this->object->getMatchingPairs() as $pair)
491  {
492  if (is_object($term)) if (($pair->definition->identifier == $definition->identifier) && ($pair->term->identifier == $term->identifier)) $ok = true;
493  }
494  if ($ok)
495  {
496  $template->setCurrentBlock("icon_ok");
497  $template->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
498  $template->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
499  $template->parseCurrentBlock();
500  }
501  else
502  {
503  $template->setCurrentBlock("icon_ok");
504  $template->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
505  $template->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
506  $template->parseCurrentBlock();
507  }
508  }
509  }
510 
511  if ($result_output)
512  {
513  $points = 0.0;
514  foreach ($this->object->getMatchingPairs() as $pair)
515  {
516  foreach ($solutions as $solution)
517  {
518  if (($solution['value2'] == $pair->definition->identifier) && ($solution['value1'] == $pair->term->identifier))
519  {
520  $points = $pair->points;
521  }
522  }
523  }
524  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
525  $template->setCurrentBlock("result_output");
526  $template->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
527  $template->parseCurrentBlock();
528  }
529 
530  $template->setCurrentBlock("row");
531  if ($this->object->getEstimatedElementHeight() > 0)
532  {
533  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
534  }
535  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
536  $template->parseCurrentBlock();
537  }
538 
539  $questiontext = $this->object->getQuestion();
540  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
541  $questionoutput = $template->get();
542  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
543  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
544  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
545 
546  $solutionoutput = $solutiontemplate->get();
547  if (!$show_question_only)
548  {
549  // get page object output
550  $solutionoutput = $this->getILIASPage($solutionoutput);
551  }
552  return $solutionoutput;
553  }
554 
555  public function getPreviewJS($show_question_only = FALSE)
556  {
557  global $ilUser;
558 
559  // generate the question output
560  include_once "./classes/class.ilTemplate.php";
561  $template = new ilTemplate("tpl.il_as_qpl_matching_output_js.html", TRUE, TRUE, "Modules/TestQuestionPool");
562 
563  $jsswitch = "";
564  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
565  {
566  if (array_key_exists('js', $_GET))
567  {
568  $ilUser->writePref('tst_javascript', $_GET['js']);
569  }
570  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
571  if ($ilUser->getPref("tst_javascript") == 1)
572  {
573  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
574  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
575  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
576  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
577  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
578  }
579  else
580  {
581  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
582  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
583  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
584  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
585  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
586  }
587  $jsswitch = $jstemplate->get();
588  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
589  }
590 
591  // shuffle output
592  $terms = $this->object->getTerms();
593  $definitions = $this->object->getDefinitions();
594  switch ($this->object->getShuffle())
595  {
596  case 1:
597  $terms = $this->object->pcArrayShuffle($terms);
598  $definitions = $this->object->pcArrayShuffle($definitions);
599  break;
600  case 2:
601  $terms = $this->object->pcArrayShuffle($terms);
602  break;
603  case 3:
604  $definitions = $this->object->pcArrayShuffle($definitions);
605  break;
606  }
607 
608  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
610 
611  // create definitions
612  $counter = 0;
613  foreach ($definitions as $definition)
614  {
615  if (strlen($definition->picture))
616  {
617  $template->setCurrentBlock("definition_picture");
618  $template->setVariable("DEFINITION_ID", $definition->identifier);
619  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
620  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
621  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
622  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
623  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
624  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
625  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
626  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->object->prepareTextareaOutput($definition->text, TRUE) : '');
627  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
628  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
629  $template->parseCurrentBlock();
630  }
631  else
632  {
633  $template->setCurrentBlock("definition_text");
634  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, TRUE));
635  $template->parseCurrentBlock();
636  }
637 
638  $template->setCurrentBlock("droparea");
639  $template->setVariable("ID_DROPAREA", $definition->identifier);
640  $template->setVariable("QUESTION_ID", $this->object->getId());
641  if ($this->object->getEstimatedElementHeight() > 0)
642  {
643  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
644  }
645  $template->parseCurrentBlock();
646 
647  $template->setCurrentBlock("init_dropareas");
648  $template->setVariable("COUNTER", $counter++);
649  $template->setVariable("ID_DROPAREA", $definition->identifier);
650  $template->parseCurrentBlock();
651  }
652 
653 
654  // create terms
655  $counter = 0;
656  foreach ($terms as $term)
657  {
658  if (strlen($term->picture))
659  {
660  $template->setCurrentBlock("term_picture");
661  $template->setVariable("TERM_ID", $term->identifier);
662  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
663  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
664  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
665  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
666  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
667  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
668  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
669  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
670  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->object->prepareTextareaOutput($term->text, TRUE) : '');
671  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
672  $template->parseCurrentBlock();
673  }
674  else
675  {
676  $template->setCurrentBlock("term_text");
677  $template->setVariable("TERM_TEXT", $this->object->prepareTextareaOutput($term->text, TRUE));
678  $template->parseCurrentBlock();
679  }
680  $template->setCurrentBlock("draggable");
681  $template->setVariable("ID_DRAGGABLE", $term->identifier);
682  if ($this->object->getEstimatedElementHeight() > 0)
683  {
684  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
685  }
686  $template->parseCurrentBlock();
687 
688  $template->setCurrentBlock("init_draggables");
689  $template->setVariable("COUNTER", $counter++);
690  $template->setVariable("ID_DRAGGABLE", $term->identifier);
691  $template->parseCurrentBlock();
692  }
693 
694  $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
695 
696  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
697 
698  $questiontext = $this->object->getQuestion();
699  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
700  $questionoutput = $jsswitch . $template->get();
701  if (!$show_question_only)
702  {
703  // get page object output
704  $questionoutput = $this->getILIASPage($questionoutput);
705  }
706  return $questionoutput;
707  }
708 
709  public function getPreview($show_question_only = FALSE)
710  {
711  global $ilUser;
712 
713  // generate the question output
714  include_once "./classes/class.ilTemplate.php";
715  $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
716 
717  $jsswitch = "";
718  if (strcmp($this->ctrl->getCmd(), 'preview') == 0)
719  {
720  if (array_key_exists('js', $_GET))
721  {
722  $ilUser->writePref('tst_javascript', $_GET['js']);
723  }
724  $jstemplate = new ilTemplate("tpl.il_as_qpl_javascript_switch.html", TRUE, TRUE, "Modules/TestQuestionPool");
725  if ($ilUser->getPref("tst_javascript") == 1)
726  {
727  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript_disable.png"));
728  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("disable_javascript"));
729  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("disable_javascript"));
730  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "0");
731  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
732  }
733  else
734  {
735  $jstemplate->setVariable("JAVASCRIPT_IMAGE", ilUtil::getImagePath("javascript.png"));
736  $jstemplate->setVariable("JAVASCRIPT_IMAGE_ALT", $this->lng->txt("enable_javascript"));
737  $jstemplate->setVariable("JAVASCRIPT_IMAGE_TITLE", $this->lng->txt("enable_javascript"));
738  $this->ctrl->setParameterByClass($this->ctrl->getCmdClass(), "js", "1");
739  $jstemplate->setVariable("JAVASCRIPT_URL", $this->ctrl->getLinkTargetByClass($this->ctrl->getCmdClass(), $this->ctrl->getCmd()));
740  }
741  $jsswitch = $jstemplate->get();
742  if ($ilUser->getPref('tst_javascript')) $this->object->setOutputType(OUTPUT_JAVASCRIPT);
743  }
744 
745  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
746  {
747  return $this->getPreviewJS($show_question_only);
748  }
749 
750  // shuffle output
751  $terms = $this->object->getTerms();
752  $definitions = $this->object->getDefinitions();
753  switch ($this->object->getShuffle())
754  {
755  case 1:
756  $terms = $this->object->pcArrayShuffle($terms);
757  $definitions = $this->object->pcArrayShuffle($definitions);
758  break;
759  case 2:
760  $terms = $this->object->pcArrayShuffle($terms);
761  break;
762  case 3:
763  $definitions = $this->object->pcArrayShuffle($definitions);
764  break;
765  }
766 
767  for ($i = 0; $i < count($definitions); $i++)
768  {
769  $definition = $definitions[$i];
770  if (is_object($definition))
771  {
772  if (strlen($definition->picture))
773  {
774  $template->setCurrentBlock('definition_image');
775  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
776  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
777  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
778  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
779  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
780  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
781  $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));
782  $template->parseCurrentBlock();
783  }
784  else
785  {
786  $template->setCurrentBlock('definition_text');
787  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, TRUE));
788  $template->parseCurrentBlock();
789  }
790  }
791 
792  $template->setCurrentBlock('option');
793  $template->setVariable("VALUE_OPTION", 0);
794  $template->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($this->lng->txt('please_select')));
795  $template->parseCurrentBlock();
796  $j = 1;
797  foreach ($terms as $term)
798  {
799  $template->setCurrentBlock('option');
800  $template->setVariable("VALUE_OPTION", $term->identifier);
801  $template->setVariable("TEXT_OPTION", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($j) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($j));
802  $template->parseCurrentBlock();
803  $j++;
804  }
805 
806  $template->setCurrentBlock('row');
807  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
808  if ($this->object->getEstimatedElementHeight() > 0)
809  {
810  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
811  }
812  $template->setVariable("QUESTION_ID", $this->object->getId());
813  $template->setVariable("DEFINITION_ID", $definition->identifier);
814  $template->parseCurrentBlock();
815  }
816 
817  $i = 0;
818  foreach ($terms as $term)
819  {
820  if (strlen($term->picture))
821  {
822  $template->setCurrentBlock('term_image');
823  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
824  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
825  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
826  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
827  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
828  $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));
829  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
830  $template->parseCurrentBlock();
831  }
832  else
833  {
834  $template->setCurrentBlock('term_text');
835  $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, TRUE));
836  $template->parseCurrentBlock();
837  }
838  $template->touchBlock('terms');
839  $i++;
840  }
841 
842  $questiontext = $this->object->getQuestion();
843  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
844  $template->setVariable("TEXT_TERMS", ilUtil::prepareFormOutput($this->lng->txt('available_terms')));
845  $template->setVariable('TEXT_SELECTION', ilUtil::prepareFormOutput($this->lng->txt('selection')));
846  $questionoutput = $jsswitch . $template->get();
847  if (!$show_question_only)
848  {
849  // get page object output
850  $questionoutput = $this->getILIASPage($questionoutput);
851  }
852  return $questionoutput;
853  }
854 
855  protected function sortDefinitionsBySolution($solution)
856  {
857  $neworder = array();
858  foreach ($solution as $solution_values)
859  {
860  $id = $solution_values['value2'];
861  array_push($neworder, $this->object->getDefinitionWithIdentifier($id));
862  }
863  return $neworder;
864  }
865 
866  function getTestOutputJS($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
867  {
868  // generate the question output
869  include_once "./classes/class.ilTemplate.php";
870  $template = new ilTemplate("tpl.il_as_qpl_matching_output_js.html", TRUE, TRUE, "Modules/TestQuestionPool");
871 
872  if ($active_id)
873  {
874  $solutions = NULL;
875  include_once "./Modules/Test/classes/class.ilObjTest.php";
876  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
877  {
878  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
879  }
880  if (is_array($user_post_solution))
881  {
882  $solutions = array();
883  foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term)
884  {
885  array_push($solutions, array("value1" => $term, "value2" => $definition));
886  }
887  }
888  else
889  {
890  $solutions =& $this->object->getSolutionValues($active_id, $pass);
891  }
892 
893  foreach ($solutions as $idx => $solution_value)
894  {
895  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
896  {
897  if (($solution_value["value2"] > -1) && ($solution_value["value1"] > -1))
898  {
899  $template->setCurrentBlock("restoreposition");
900  $template->setVariable("TERM_ID", $solution_value["value1"]);
901  $template->setVariable("PICTURE_DEFINITION_ID", $solution_value["value2"]);
902  $template->parseCurrentBlock();
903  }
904  }
905  }
906  }
907 
908  // shuffle output
909  $terms = $this->object->getTerms();
910  $definitions = $this->object->getDefinitions();
911  switch ($this->object->getShuffle())
912  {
913  case 1:
914  $terms = $this->object->pcArrayShuffle($terms);
915  if (count($solutions))
916  {
917  $definitions = $this->sortDefinitionsBySolution($solutions);
918  }
919  else
920  {
921  $definitions = $this->object->pcArrayShuffle($definitions);
922  }
923  break;
924  case 2:
925  $terms = $this->object->pcArrayShuffle($terms);
926  break;
927  case 3:
928  if (count($solutions))
929  {
930  $definitions = $this->sortDefinitionsBySolution($solutions);
931  }
932  else
933  {
934  $definitions = $this->object->pcArrayShuffle($definitions);
935  }
936  break;
937  }
938 
939  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
941 
942  // create definitions
943  $counter = 0;
944  foreach ($definitions as $definition)
945  {
946  if (strlen($definition->picture))
947  {
948  $template->setCurrentBlock("definition_picture");
949  $template->setVariable("DEFINITION_ID", $definition->identifier);
950  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $definition->picture);
951  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture;
952  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $definition->picture;
953  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
954  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
955  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
956  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
957  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : '');
958  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
959  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
960  $template->parseCurrentBlock();
961  }
962  else
963  {
964  $template->setCurrentBlock("definition_text");
965  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true));
966  $template->parseCurrentBlock();
967  }
968 
969  $template->setCurrentBlock("droparea");
970  $template->setVariable("ID_DROPAREA", $definition->identifier);
971  $template->setVariable("QUESTION_ID", $this->object->getId());
972  if ($this->object->getEstimatedElementHeight() > 0)
973  {
974  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
975  }
976  $template->parseCurrentBlock();
977 
978  $template->setCurrentBlock("init_dropareas");
979  $template->setVariable("COUNTER", $counter++);
980  $template->setVariable("ID_DROPAREA", $definition->identifier);
981  $template->parseCurrentBlock();
982  }
983 
984 
985  // create terms
986  $counter = 0;
987  foreach ($terms as $term)
988  {
989  if (strlen($term->picture))
990  {
991  $template->setCurrentBlock("term_picture");
992  $template->setVariable("TERM_ID", $term->identifier);
993  $template->setVariable("IMAGE_HREF", $this->object->getImagePathWeb() . $term->picture);
994  $thumbweb = $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture;
995  $thumb = $this->object->getImagePath() . $this->object->getThumbPrefix() . $term->picture;
996  if (!@file_exists($thumb)) $this->object->rebuildThumbnails();
997  $template->setVariable("THUMBNAIL_HREF", $thumbweb);
998  $template->setVariable("THUMB_ALT", $this->lng->txt("image"));
999  $template->setVariable("THUMB_TITLE", $this->lng->txt("image"));
1000  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1001  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : '');
1002  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
1003  $template->parseCurrentBlock();
1004  }
1005  else
1006  {
1007  $template->setCurrentBlock("term_text");
1008  $template->setVariable("TERM_TEXT", $this->object->prepareTextareaOutput($term->text, true));
1009  $template->parseCurrentBlock();
1010  }
1011  $template->setCurrentBlock("draggable");
1012  $template->setVariable("ID_DRAGGABLE", $term->identifier);
1013  if ($this->object->getEstimatedElementHeight() > 0)
1014  {
1015  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
1016  }
1017  $template->parseCurrentBlock();
1018 
1019  $template->setCurrentBlock("init_draggables");
1020  $template->setVariable("COUNTER", $counter++);
1021  $template->setVariable("ID_DRAGGABLE", $term->identifier);
1022  $template->parseCurrentBlock();
1023  }
1024 
1025  $template->setVariable("RESET_BUTTON", $this->lng->txt("reset_terms"));
1026 
1027  $this->tpl->setVariable("LOCATION_ADDITIONAL_STYLESHEET", ilUtil::getStyleSheetLocation("output", "test_javascript.css", "Modules/TestQuestionPool"));
1028 
1029  $questiontext = $this->object->getQuestion();
1030  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1031  $questionoutput = $template->get();
1032  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1033  return $pageoutput;
1034  }
1035 
1036  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $user_post_solution = FALSE)
1037  {
1038  if ($this->object->getOutputType() == OUTPUT_JAVASCRIPT)
1039  {
1040  return $this->getTestOutputJS($active_id, $pass, $is_postponed, $user_post_solution);
1041  }
1042  // generate the question output
1043  include_once "./classes/class.ilTemplate.php";
1044  $template = new ilTemplate("tpl.il_as_qpl_matching_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
1045 
1046  if ($active_id)
1047  {
1048  $solutions = NULL;
1049  include_once "./Modules/Test/classes/class.ilObjTest.php";
1050  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
1051  {
1052  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
1053  }
1054  if (is_array($user_post_solution))
1055  {
1056  $solutions = array();
1057  foreach ($user_post_solution['matching'][$this->object->getId()] as $definition => $term)
1058  {
1059  array_push($solutions, array("value1" => $term, "value2" => $definition));
1060  }
1061  }
1062  else
1063  {
1064  $solutions =& $this->object->getSolutionValues($active_id, $pass);
1065  }
1066  }
1067 
1068 
1069  // shuffle output
1070  $terms = $this->object->getTerms();
1071  $definitions = $this->object->getDefinitions();
1072  switch ($this->object->getShuffle())
1073  {
1074  case 1:
1075  $terms = $this->object->pcArrayShuffle($terms);
1076  if (count($solutions))
1077  {
1078  $definitions = $this->sortDefinitionsBySolution($solutions);
1079  }
1080  else
1081  {
1082  $definitions = $this->object->pcArrayShuffle($definitions);
1083  }
1084  break;
1085  case 2:
1086  $terms = $this->object->pcArrayShuffle($terms);
1087  break;
1088  case 3:
1089  if (count($solutions))
1090  {
1091  $definitions = $this->sortDefinitionsBySolution($solutions);
1092  }
1093  else
1094  {
1095  $definitions = $this->object->pcArrayShuffle($definitions);
1096  }
1097  break;
1098  }
1099  $maxcount = max(count($terms), count($definitions));
1100  for ($i = 0; $i < count($definitions); $i++)
1101  {
1102  $definition = $definitions[$i];
1103  if (is_object($definition))
1104  {
1105  if (strlen($definition->picture))
1106  {
1107  $template->setCurrentBlock('definition_image');
1108  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $definition->picture);
1109  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
1110  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($definition->text)) ? ilUtil::prepareFormOutput($definition->text) : ilUtil::prepareFormOutput($definition->picture));
1111  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $definition->picture);
1112  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1113  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
1114  $template->setVariable("TEXT_DEFINITION", (strlen($definition->text)) ? $this->lng->txt('definition') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($definition->text) : $this->lng->txt('definition') . ' ' . ($i+1));
1115  $template->parseCurrentBlock();
1116  }
1117  else
1118  {
1119  $template->setCurrentBlock('definition_text');
1120  $template->setVariable("DEFINITION", $this->object->prepareTextareaOutput($definition->text, true));
1121  $template->parseCurrentBlock();
1122  }
1123  }
1124 
1125  $template->setCurrentBlock('option');
1126  $template->setVariable("VALUE_OPTION", 0);
1127  $template->setVariable("TEXT_OPTION", ilUtil::prepareFormOutput($this->lng->txt('please_select')));
1128  $template->parseCurrentBlock();
1129  $j = 1;
1130  foreach ($terms as $term)
1131  {
1132  $template->setCurrentBlock('option');
1133  $template->setVariable("VALUE_OPTION", $term->identifier);
1134  $template->setVariable("TEXT_OPTION", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($j) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($j));
1135  foreach ($solutions as $solution)
1136  {
1137  if ($solution["value1"] == $term->identifier && $solution["value2"] == $definition->identifier)
1138  {
1139  $template->setVariable("SELECTED_OPTION", " selected=\"selected\"");
1140  }
1141  }
1142  $template->parseCurrentBlock();
1143  $j++;
1144  }
1145 
1146  $template->setCurrentBlock('row');
1147  $template->setVariable("TEXT_MATCHES", $this->lng->txt("matches"));
1148  if ($this->object->getEstimatedElementHeight() > 0)
1149  {
1150  $template->setVariable("ELEMENT_HEIGHT", " style=\"height: " . $this->object->getEstimatedElementHeight() . "px;\"");
1151  }
1152  $template->setVariable("QUESTION_ID", $this->object->getId());
1153  $template->setVariable("DEFINITION_ID", $definition->identifier);
1154  $template->parseCurrentBlock();
1155  }
1156 
1157  $i = 0;
1158  foreach ($terms as $term)
1159  {
1160  if (strlen($term->picture))
1161  {
1162  $template->setCurrentBlock('term_image');
1163  $template->setVariable('ANSWER_IMAGE_URL', $this->object->getImagePathWeb() . $this->object->getThumbPrefix() . $term->picture);
1164  $template->setVariable('ANSWER_IMAGE_ALT', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
1165  $template->setVariable('ANSWER_IMAGE_TITLE', (strlen($term->text)) ? ilUtil::prepareFormOutput($term->text) : ilUtil::prepareFormOutput($term->picture));
1166  $template->setVariable('URL_PREVIEW', $this->object->getImagePathWeb() . $term->picture);
1167  $template->setVariable("TEXT_PREVIEW", $this->lng->txt('preview'));
1168  $template->setVariable("TEXT_TERM", (strlen($term->text)) ? $this->lng->txt('term') . ' ' . ($i+1) . ': ' . ilUtil::prepareFormOutput($term->text) : $this->lng->txt('term') . ' ' . ($i+1));
1169  $template->setVariable("IMG_PREVIEW", ilUtil::getImagePath('enlarge.gif'));
1170  $template->parseCurrentBlock();
1171  }
1172  else
1173  {
1174  $template->setCurrentBlock('term_text');
1175  $template->setVariable("TERM", $this->object->prepareTextareaOutput($term->text, true));
1176  $template->parseCurrentBlock();
1177  }
1178  $template->touchBlock('terms');
1179  $i++;
1180  }
1181 
1182  $questiontext = $this->object->getQuestion();
1183  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1184  $template->setVariable("TEXT_TERMS", ilUtil::prepareFormOutput($this->lng->txt('available_terms')));
1185  $template->setVariable('TEXT_SELECTION', ilUtil::prepareFormOutput($this->lng->txt('selection')));
1186 
1187  $questiontext = $this->object->getQuestion();
1188  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
1189  $questionoutput = $template->get();
1190  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
1191  return $pageoutput;
1192 
1193  }
1194 
1198  function checkInput()
1199  {
1200  if ((!$_POST["title"]) or (!$_POST["author"]) or (!$_POST["question"]))
1201  {
1202  return false;
1203  }
1204  return true;
1205  }
1206 
1207 
1211  function saveFeedback()
1212  {
1213  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
1214  $errors = $this->feedback(true);
1215  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
1216  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
1217  $this->object->cleanupMediaObjectUsage();
1219  }
1220 
1226  function setQuestionTabs()
1227  {
1228  global $rbacsystem, $ilTabs;
1229 
1230  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
1231  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
1232  $q_type = $this->object->getQuestionType();
1233 
1234  if (strlen($q_type))
1235  {
1236  $classname = $q_type . "GUI";
1237  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
1238  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
1239  }
1240 
1241  if ($_GET["q_id"])
1242  {
1243  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1244  {
1245  // edit page
1246  $ilTabs->addTarget("edit_content",
1247  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
1248  array("edit", "insert", "exec_pg"),
1249  "", "", $force_active);
1250  }
1251 
1252  // edit page
1253  $ilTabs->addTarget("preview",
1254  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
1255  array("preview"),
1256  "ilPageObjectGUI", "", $force_active);
1257  }
1258 
1259  $force_active = false;
1260  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
1261  {
1262  $url = "";
1263  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
1264  // edit question properties
1265  $ilTabs->addTarget("edit_properties",
1266  $url,
1267  array("editQuestion", "save", "saveEdit", "removeimageterms", "uploadterms", "removeimagedefinitions", "uploaddefinitions",
1268  "addpairs", "removepairs", "addterms", "removeterms", "adddefinitions", "removedefinitions", "originalSyncForm"),
1269  $classname, "", $force_active);
1270  }
1271 
1272  if ($_GET["q_id"])
1273  {
1274  $ilTabs->addTarget("feedback",
1275  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
1276  array("feedback", "saveFeedback"),
1277  $classname, "");
1278  }
1279 
1280  if ($_GET["q_id"])
1281  {
1282  $ilTabs->addTarget("solution_hint",
1283  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
1284  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
1285  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
1286  ),
1287  $classname,
1288  ""
1289  );
1290  }
1291 
1292  // Assessment of questions sub menu entry
1293  if ($_GET["q_id"])
1294  {
1295  $ilTabs->addTarget("statistics",
1296  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
1297  array("assessment"),
1298  $classname, "");
1299  }
1300 
1301  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
1302  {
1303  $ref_id = $_GET["calling_test"];
1304  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
1305  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
1306  }
1307  else
1308  {
1309  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
1310  }
1311  }
1312 }
1313 ?>