ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.assClozeTestGUI.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 
37 {
41  private $gapIndex;
42 
48  function __construct($id = -1)
49  {
51  include_once "./Modules/TestQuestionPool/classes/class.assClozeTest.php";
52  $this->object = new assClozeTest();
53  if ($id >= 0)
54  {
55  $this->object->loadFromDb($id);
56  }
57  }
58 
59  function getCommand($cmd)
60  {
61  if (preg_match("/^(removegap|addgap)_(\d+)$/", $cmd, $matches))
62  {
63  $cmd = $matches[1];
64  $this->gapIndex = $matches[2];
65  }
66  return $cmd;
67  }
68 
75  function writePostData($always = false)
76  {
77  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
78  if (!$hasErrors)
79  {
80  $this->object->flushGaps();
81  $this->object->setTitle($_POST["title"]);
82  $this->object->setAuthor($_POST["author"]);
83  $this->object->setComment($_POST["comment"]);
84  $this->object->setTextgapRating($_POST["textgap_rating"]);
85  $this->object->setIdenticalScoring($_POST["identical_scoring"]);
86  if ($this->getSelfAssessmentEditingMode())
87  {
88  $this->object->setNrOfTries($_POST['nr_of_tries']);
89  }
90  $this->object->setFixedTextLength($_POST["fixedTextLength"]);
91  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
92  $cloze_text = $_POST["question"];
93  $this->object->setClozeText($cloze_text);
94  $this->object->setEstimatedWorkingTime(
95  $_POST["Estimated"]["hh"],
96  $_POST["Estimated"]["mm"],
97  $_POST["Estimated"]["ss"]
98  );
99 
100  if (is_array($_POST['gap']))
101  {
102  if (strcmp($this->ctrl->getCmd(), 'createGaps') != 0) $this->object->clearGapAnswers();
103  foreach ($_POST['gap'] as $idx => $hidden)
104  {
105  $clozetype = $_POST['clozetype_' . $idx];
106  $this->object->setGapType($idx, $clozetype);
107  if (array_key_exists('shuffle_' . $idx, $_POST))
108  {
109  $this->object->setGapShuffle($idx, $_POST['shuffle_' . $idx]);
110  }
111 
112  if (strcmp($this->ctrl->getCmd(), 'createGaps') != 0)
113  {
114  if (is_array($_POST['gap_' . $idx]['answer']))
115  {
116  foreach ($_POST['gap_' . $idx]['answer'] as $order => $value)
117  {
118  $this->object->addGapAnswer($idx, $order, $value);
119  }
120  }
121  }
122  if (array_key_exists('gap_' . $idx . '_numeric', $_POST))
123  {
124  if (strcmp($this->ctrl->getCmd(), 'createGaps') != 0) $this->object->addGapAnswer($idx, 0, str_replace(",", ".", $_POST['gap_' . $idx . '_numeric']));
125  $this->object->setGapAnswerLowerBound($idx, 0, str_replace(",", ".", $_POST['gap_' . $idx . '_numeric_lower']));
126  $this->object->setGapAnswerUpperBound($idx, 0, str_replace(",", ".", $_POST['gap_' . $idx . '_numeric_upper']));
127  $this->object->setGapAnswerPoints($idx, 0, $_POST['gap_' . $idx . '_numeric_points']);
128  }
129  if (is_array($_POST['gap_' . $idx]['points']))
130  {
131  foreach ($_POST['gap_' . $idx]['points'] as $order => $value)
132  {
133  $this->object->setGapAnswerPoints($idx, $order, $value);
134  }
135  }
136  }
137  if (strcmp($this->ctrl->getCmd(), 'createGaps') != 0) $this->object->updateClozeTextFromGaps();
138  }
139  return 0;
140  }
141  else
142  {
143  return 1;
144  }
145  }
146 
152  public function editQuestion($checkonly = FALSE)
153  {
154  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
155  $this->getQuestionTemplate();
156 
157  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
158  $form = new ilPropertyFormGUI();
159  $form->setFormAction($this->ctrl->getFormAction($this));
160  $form->setTitle($this->outQuestionType());
161  $form->setMultipart(FALSE);
162  $form->setTableWidth("100%");
163  $form->setId("assclozetest");
164 
165  // title, author, description, question, working time (assessment mode)
166  $this->addBasicQuestionFormProperties($form);
167  $q_item = $form->getItemByPostVar("question");
168  $q_item->setInfo($this->lng->txt("close_text_hint"));
169  $q_item->setTitle($this->lng->txt("cloze_text"));
170 
171  // text rating
172  if (!$this->getSelfAssessmentEditingMode())
173  {
174  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "textgap_rating");
175  $text_options = array(
176  "ci" => $this->lng->txt("cloze_textgap_case_insensitive"),
177  "cs" => $this->lng->txt("cloze_textgap_case_sensitive"),
178  "l1" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1"),
179  "l2" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2"),
180  "l3" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3"),
181  "l4" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4"),
182  "l5" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5")
183  );
184  $textrating->setOptions($text_options);
185  $textrating->setValue($this->object->getTextgapRating());
186  $form->addItem($textrating);
187 
188  // text field length
189  $fixedTextLength = new ilNumberInputGUI($this->lng->txt("cloze_fixed_textlength"), "fixedTextLength");
190  $fixedTextLength->setValue(ilUtil::prepareFormOutput($this->object->getFixedTextLength()));
191  $fixedTextLength->setMinValue(0);
192  $fixedTextLength->setSize(3);
193  $fixedTextLength->setMaxLength(6);
194  $fixedTextLength->setInfo($this->lng->txt('cloze_fixed_textlength_description'));
195  $fixedTextLength->setRequired(false);
196  $form->addItem($fixedTextLength);
197 
198  // identical scoring
199  $identical_scoring = new ilCheckboxInputGUI($this->lng->txt("identical_scoring"), "identical_scoring");
200  $identical_scoring->setValue(1);
201  $identical_scoring->setChecked($this->object->getIdenticalScoring());
202  $identical_scoring->setInfo($this->lng->txt('identical_scoring_desc'));
203  $identical_scoring->setRequired(FALSE);
204  $form->addItem($identical_scoring);
205  }
206 
207  for ($i = 0; $i < $this->object->getGapCount(); $i++)
208  {
209  $gap = $this->object->getGap($i);
210  $header = new ilFormSectionHeaderGUI();
211  $header->setTitle($this->lng->txt("gap") . " " . ($i+1));
212  $form->addItem($header);
213 
214  $gapcounter = new ilHiddenInputGUI("gap[$i]");
215  $gapcounter->setValue($i);
216  $form->addItem($gapcounter);
217 
218  $gaptype = new ilSelectInputGUI($this->lng->txt('type'), "clozetype_$i");
219  $options = array(
220  0 => $this->lng->txt("text_gap"),
221  1 => $this->lng->txt("select_gap"),
222  2 => $this->lng->txt("numeric_gap")
223  );
224  $gaptype->setOptions($options);
225  $gaptype->setValue($gap->getType());
226  $form->addItem($gaptype);
227 
228  if ($gap->getType() == CLOZE_TEXT)
229  {
230  // Choices
231  include_once "./Modules/TestQuestionPool/classes/class.ilAnswerWizardInputGUI.php";
232  include_once "./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
233  $values = new ilAnswerWizardInputGUI($this->lng->txt("values"), "gap_" . $i . "");
234  $values->setRequired(true);
235  $values->setQuestionObject($this->object);
236  $values->setSingleline(true);
237  $values->setAllowMove(false);
238  if (count($gap->getItemsRaw()) == 0) $gap->addItem(new assAnswerCloze("", 0, 0));
239  $values->setValues($gap->getItemsRaw());
240  $form->addItem($values);
241  }
242  else if ($gap->getType() == CLOZE_SELECT)
243  {
244  include_once "./Modules/TestQuestionPool/classes/class.ilAnswerWizardInputGUI.php";
245  include_once "./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
246  $values = new ilAnswerWizardInputGUI($this->lng->txt("values"), "gap_" . $i . "");
247  $values->setRequired(true);
248  $values->setQuestionObject($this->object);
249  $values->setSingleline(true);
250  $values->setAllowMove(false);
251  if (count($gap->getItemsRaw()) == 0) $gap->addItem(new assAnswerCloze("", 0, 0));
252  $values->setValues($gap->getItemsRaw());
253  $form->addItem($values);
254 
255  // shuffle
256  $shuffle = new ilCheckboxInputGUI($this->lng->txt("shuffle_answers"), "shuffle_" . $i . "");
257  $shuffle->setValue(1);
258  $shuffle->setChecked($gap->getShuffle());
259  $shuffle->setRequired(FALSE);
260  $form->addItem($shuffle);
261  }
262  else if ($gap->getType() == CLOZE_NUMERIC)
263  {
264  if (count($gap->getItemsRaw()) == 0) $gap->addItem(new assAnswerCloze("", 0, 0));
265  foreach ($gap->getItemsRaw() as $item)
266  {
267  $value = new ilFormulaInputGUI($this->lng->txt('value'), "gap_" . $i . "_numeric");
268  $value->setSize(10);
269  $value->setValue(ilUtil::prepareFormOutput($item->getAnswertext()));
270  $value->setRequired(true);
271  $value->setInlineStyle('text-align: right;');
272  $form->addItem($value);
273 
274  $lowerbound = new ilFormulaInputGUI($this->lng->txt('range_lower_limit'), "gap_" . $i . "_numeric_lower");
275  $lowerbound->setSize(10);
276  $lowerbound->setRequired(true);
277  $lowerbound->setValue(ilUtil::prepareFormOutput($item->getLowerBound()));
278  $lowerbound->setInlineStyle('text-align: right;');
279  $form->addItem($lowerbound);
280 
281  $upperbound = new ilFormulaInputGUI($this->lng->txt('range_upper_limit'), "gap_" . $i . "_numeric_upper");
282  $upperbound->setSize(10);
283  $upperbound->setRequired(true);
284  $upperbound->setValue(ilUtil::prepareFormOutput($item->getUpperBound()));
285  $upperbound->setInlineStyle('text-align: right;');
286  $form->addItem($upperbound);
287 
288  $points = new ilNumberInputGUI($this->lng->txt('points'), "gap_" . $i . "_numeric_points");
289  $points->setSize(3);
290  $points->setRequired(true);
291  $points->setValue(ilUtil::prepareFormOutput($item->getPoints()));
292  $form->addItem($points);
293  }
294  }
295  }
296 
297  $form->addCommandButton('createGaps', $this->lng->txt('create_gaps'));
298  $this->addQuestionFormCommandButtons($form);
299 
300  $errors = false;
301 
302  if ($save)
303  {
304  $form->setValuesByPost();
305  $errors = !$form->checkInput();
306  $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
307  if ($errors) $checkonly = false;
308  }
309 
310  if (!$checkonly) $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
311  return $errors;
312  }
313 
317  public function createGaps()
318  {
319  $this->writePostData(true);
320  $this->object->saveToDb();
321  $this->editQuestion();
322  }
323 
327  function removegap()
328  {
329  $this->writePostData(true);
330  $this->object->deleteAnswerText($this->gapIndex, key($_POST['cmd']['removegap_' . $this->gapIndex]));
331  $this->editQuestion();
332  }
333 
337  function addgap()
338  {
339  $this->writePostData(true);
340  $this->object->addGapAnswer($this->gapIndex, key($_POST['cmd']['addgap_' . $this->gapIndex])+1, "");
341  $this->editQuestion();
342  }
343 
356  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
357  {
358  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
359  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
360  $this->tpl->setVariable("FORMACTION", $formaction);
361  }
362 
371  function getPreview($show_question_only = FALSE)
372  {
373  // generate the question output
374  include_once "./classes/class.ilTemplate.php";
375  $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
376  $output = $this->object->getClozeText();
377  foreach ($this->object->getGaps() as $gap_index => $gap)
378  {
379  switch ($gap->getType())
380  {
381  case CLOZE_TEXT:
382  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_text.html", TRUE, TRUE, "Modules/TestQuestionPool");
383  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
384  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
385  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
386  break;
387  case CLOZE_SELECT:
388  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE, "Modules/TestQuestionPool");
389  foreach ($gap->getItems() as $item)
390  {
391  $gaptemplate->setCurrentBlock("select_gap_option");
392  $gaptemplate->setVariable("SELECT_GAP_VALUE", $item->getOrder());
393  $gaptemplate->setVariable("SELECT_GAP_TEXT", ilUtil::prepareFormOutput($item->getAnswerText()));
394  $gaptemplate->parseCurrentBlock();
395  }
396  $gaptemplate->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
397  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
398  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
399  break;
400  case CLOZE_NUMERIC:
401  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_numeric.html", TRUE, TRUE, "Modules/TestQuestionPool");
402  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
403  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
404  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
405  break;
406  }
407  }
408  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
409  $questionoutput = $template->get();
410  if (!$show_question_only)
411  {
412  // get page object output
413  $questionoutput = $this->getILIASPage($questionoutput);
414  }
415  return $questionoutput;
416  }
417 
432  $active_id,
433  $pass = NULL,
434  $graphicalOutput = FALSE,
435  $result_output = FALSE,
436  $show_question_only = TRUE,
437  $show_feedback = FALSE,
438  $show_correct_solution = FALSE,
439  $show_manual_scoring = FALSE
440  )
441  {
442  // get the solution of the user for the active pass or from the last pass if allowed
443  $user_solution = array();
444  if ($active_id)
445  {
446  // get the solutions of a user
447  $user_solution =& $this->object->getSolutionValues($active_id, $pass);
448  if (!is_array($user_solution))
449  {
450  $user_solution = array();
451  }
452  }
453 
454  include_once "./classes/class.ilTemplate.php";
455  $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
456  $output = $this->object->getClozeText();
457  foreach ($this->object->getGaps() as $gap_index => $gap)
458  {
459  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution_gap.html", TRUE, TRUE, "Modules/TestQuestionPool");
460  $found = array();
461  foreach ($user_solution as $solutionarray)
462  {
463  if ($solutionarray["value1"] == $gap_index) $found = $solutionarray;
464  }
465 
466  if ($active_id)
467  {
468  if ($graphicalOutput)
469  {
470  // output of ok/not ok icons for user entered solutions
471  $details = $this->object->calculateReachedPoints($active_id, $pass, TRUE);
472  $check = $details[$gap_index];
473  if ($check["best"])
474  {
475  $gaptemplate->setCurrentBlock("icon_ok");
476  $gaptemplate->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
477  $gaptemplate->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
478  $gaptemplate->parseCurrentBlock();
479  }
480  else
481  {
482  $gaptemplate->setCurrentBlock("icon_not_ok");
483  if ($check["positive"])
484  {
485  $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
486  $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
487  }
488  else
489  {
490  $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
491  $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
492  }
493  $gaptemplate->parseCurrentBlock();
494  }
495  }
496  }
497  if ($result_output)
498  {
499  $points = $this->object->getMaximumGapPoints($gap_index);
500  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
501  $gaptemplate->setCurrentBlock("result_output");
502  $gaptemplate->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
503  $gaptemplate->parseCurrentBlock();
504  }
505  switch ($gap->getType())
506  {
507  case CLOZE_TEXT:
508  $solutiontext = "";
509  if (($active_id > 0) && (!$show_correct_solution))
510  {
511  if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0))
512  {
513  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
514  {
515  $solutiontext .= "&nbsp;";
516  }
517  }
518  else
519  {
520  $solutiontext = ilUtil::prepareFormOutput($found["value2"]);
521  }
522  }
523  else
524  {
525  $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
526  }
527  $gaptemplate->setVariable("SOLUTION", $solutiontext);
528  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
529  break;
530  case CLOZE_SELECT:
531  $solutiontext = "";
532  if (($active_id > 0) && (!$show_correct_solution))
533  {
534  if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0))
535  {
536  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
537  {
538  $solutiontext .= "&nbsp;";
539  }
540  }
541  else
542  {
543  $item = $gap->getItem($found["value2"]);
544  if (is_object($item))
545  {
546  $solutiontext = ilUtil::prepareFormOutput($item->getAnswertext());
547  }
548  else
549  {
550  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
551  {
552  $solutiontext .= "&nbsp;";
553  }
554  }
555  }
556  }
557  else
558  {
559  $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
560  }
561  $gaptemplate->setVariable("SOLUTION", $solutiontext);
562  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
563  break;
564  case CLOZE_NUMERIC:
565  $solutiontext = "";
566  if (($active_id > 0) && (!$show_correct_solution))
567  {
568  if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0))
569  {
570  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
571  {
572  $solutiontext .= "&nbsp;";
573  }
574  }
575  else
576  {
577  $solutiontext = ilUtil::prepareFormOutput($found["value2"]);
578  }
579  }
580  else
581  {
582  $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
583  }
584  $gaptemplate->setVariable("SOLUTION", $solutiontext);
585  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
586  break;
587  }
588  }
589  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
590 
591  // generate the question output
592  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
593  $questionoutput = $template->get();
594  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
595  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
596  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
597 
598  $solutionoutput = $solutiontemplate->get();
599  if (!$show_question_only)
600  {
601  // get page object output
602  $solutionoutput = $this->getILIASPage($solutionoutput);
603  }
604  return $solutionoutput;
605  }
606 
607  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
608  {
609  // get the solution of the user for the active pass or from the last pass if allowed
610  $user_solution = array();
611  if ($active_id)
612  {
613  include_once "./Modules/Test/classes/class.ilObjTest.php";
614  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
615  {
616  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
617  }
618  $user_solution =& $this->object->getSolutionValues($active_id, $pass);
619  if (!is_array($user_solution))
620  {
621  $user_solution = array();
622  }
623  }
624 
625  // generate the question output
626  include_once "./classes/class.ilTemplate.php";
627  $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
628  $output = $this->object->getClozeText();
629  foreach ($this->object->getGaps() as $gap_index => $gap)
630  {
631  switch ($gap->getType())
632  {
633  case CLOZE_TEXT:
634  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_text.html", TRUE, TRUE, "Modules/TestQuestionPool");
635  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
636  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
637  foreach ($user_solution as $solution)
638  {
639  if (strcmp($solution["value1"], $gap_index) == 0)
640  {
641  $gaptemplate->setVariable("VALUE_GAP", " value=\"" . ilUtil::prepareFormOutput($solution["value2"]) . "\"");
642  }
643  }
644  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
645  break;
646  case CLOZE_SELECT:
647  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE, "Modules/TestQuestionPool");
648  foreach ($gap->getItems() as $item)
649  {
650  $gaptemplate->setCurrentBlock("select_gap_option");
651  $gaptemplate->setVariable("SELECT_GAP_VALUE", $item->getOrder());
652  $gaptemplate->setVariable("SELECT_GAP_TEXT", ilUtil::prepareFormOutput($item->getAnswerText()));
653  foreach ($user_solution as $solution)
654  {
655  if (strcmp($solution["value1"], $gap_index) == 0)
656  {
657  if (strcmp($solution["value2"], $item->getOrder()) == 0)
658  {
659  $gaptemplate->setVariable("SELECT_GAP_SELECTED", " selected=\"selected\"");
660  }
661  }
662  }
663  $gaptemplate->parseCurrentBlock();
664  }
665  $gaptemplate->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
666  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
667  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
668  break;
669  case CLOZE_NUMERIC:
670  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_numeric.html", TRUE, TRUE, "Modules/TestQuestionPool");
671  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
672  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
673  foreach ($user_solution as $solution)
674  {
675  if (strcmp($solution["value1"], $gap_index) == 0)
676  {
677  $gaptemplate->setVariable("VALUE_GAP", " value=\"" . ilUtil::prepareFormOutput($solution["value2"]) . "\"");
678  }
679  }
680  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
681  break;
682  }
683  }
684  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
685  $questionoutput = $template->get();
686  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
687  return $pageoutput;
688  }
689 
695  function saveFeedback()
696  {
697  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
698  $errors = $this->feedback(true);
699  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
700  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
701  $this->object->cleanupMediaObjectUsage();
703  }
704 
710  function setQuestionTabs()
711  {
712  global $rbacsystem, $ilTabs;
713 
714  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
715  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
716  $q_type = $this->object->getQuestionType();
717 
718  if (strlen($q_type))
719  {
720  $classname = $q_type . "GUI";
721  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
722  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
723  }
724 
725  if ($_GET["q_id"])
726  {
727  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
728  {
729  // edit page
730  $ilTabs->addTarget("edit_content",
731  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
732  array("edit", "insert", "exec_pg"),
733  "", "", $force_active);
734  }
735 
736  // edit page
737  $ilTabs->addTarget("preview",
738  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
739  array("preview"),
740  "ilPageObjectGUI", "", $force_active);
741  }
742 
743  $force_active = false;
744  $commands = $_POST["cmd"];
745  if (is_array($commands))
746  {
747  foreach ($commands as $key => $value)
748  {
749  if (preg_match("/^removegap_.*/", $key, $matches) ||
750  preg_match("/^addgap_.*/", $key, $matches)
751  )
752  {
753  $force_active = true;
754  }
755  }
756  }
757  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
758  {
759  $url = "";
760  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
761  // edit question properties
762  $ilTabs->addTarget("edit_properties",
763  $url,
764  array("editQuestion", "originalSyncForm", "save", "createGaps", "saveEdit"),
765  $classname, "", $force_active);
766  }
767 
768  if ($_GET["q_id"])
769  {
770  $ilTabs->addTarget("feedback",
771  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
772  array("feedback", "saveFeedback"),
773  $classname, "");
774  }
775 
776  if ($_GET["q_id"])
777  {
778  $ilTabs->addTarget("solution_hint",
779  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
780  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
781  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
782  ),
783  $classname,
784  ""
785  );
786  }
787 
788  // Assessment of questions sub menu entry
789  if ($_GET["q_id"])
790  {
791  $ilTabs->addTarget("statistics",
792  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
793  array("assessment"),
794  $classname, "");
795  }
796 
797  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
798  {
799  $ref_id = $_GET["calling_test"];
800  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
801  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
802  }
803  else
804  {
805  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
806  }
807  }
808 }
809 ?>