ILIAS  Release_4_0_x_branch Revision 61816
 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->editQuestion();
321  }
322 
326  function removegap()
327  {
328  $this->writePostData(true);
329  $this->object->deleteAnswerText($this->gapIndex, key($_POST['cmd']['removegap_' . $this->gapIndex]));
330  $this->editQuestion();
331  }
332 
336  function addgap()
337  {
338  $this->writePostData(true);
339  $this->object->addGapAnswer($this->gapIndex, key($_POST['cmd']['addgap_' . $this->gapIndex])+1, "");
340  $this->editQuestion();
341  }
342 
355  function outQuestionForTest($formaction, $active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
356  {
357  $test_output = $this->getTestOutput($active_id, $pass, $is_postponed, $use_post_solutions);
358  $this->tpl->setVariable("QUESTION_OUTPUT", $test_output);
359  $this->tpl->setVariable("FORMACTION", $formaction);
360  }
361 
370  function getPreview($show_question_only = FALSE)
371  {
372  // generate the question output
373  include_once "./classes/class.ilTemplate.php";
374  $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
375  $output = $this->object->getClozeText();
376  foreach ($this->object->getGaps() as $gap_index => $gap)
377  {
378  switch ($gap->getType())
379  {
380  case CLOZE_TEXT:
381  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_text.html", TRUE, TRUE, "Modules/TestQuestionPool");
382  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
383  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
384  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
385  break;
386  case CLOZE_SELECT:
387  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE, "Modules/TestQuestionPool");
388  foreach ($gap->getItems() as $item)
389  {
390  $gaptemplate->setCurrentBlock("select_gap_option");
391  $gaptemplate->setVariable("SELECT_GAP_VALUE", $item->getOrder());
392  $gaptemplate->setVariable("SELECT_GAP_TEXT", ilUtil::prepareFormOutput($item->getAnswerText()));
393  $gaptemplate->parseCurrentBlock();
394  }
395  $gaptemplate->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
396  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
397  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
398  break;
399  case CLOZE_NUMERIC:
400  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_numeric.html", TRUE, TRUE, "Modules/TestQuestionPool");
401  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
402  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
403  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
404  break;
405  }
406  }
407  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
408  $questionoutput = $template->get();
409  if (!$show_question_only)
410  {
411  // get page object output
412  $questionoutput = $this->getILIASPage($questionoutput);
413  }
414  return $questionoutput;
415  }
416 
431  $active_id,
432  $pass = NULL,
433  $graphicalOutput = FALSE,
434  $result_output = FALSE,
435  $show_question_only = TRUE,
436  $show_feedback = FALSE,
437  $show_correct_solution = FALSE,
438  $show_manual_scoring = FALSE
439  )
440  {
441  // get the solution of the user for the active pass or from the last pass if allowed
442  $user_solution = array();
443  if ($active_id)
444  {
445  // get the solutions of a user
446  $user_solution =& $this->object->getSolutionValues($active_id, $pass);
447  if (!is_array($user_solution))
448  {
449  $user_solution = array();
450  }
451  }
452 
453  include_once "./classes/class.ilTemplate.php";
454  $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", TRUE, TRUE, "Modules/TestQuestionPool");
455  $output = $this->object->getClozeText();
456  foreach ($this->object->getGaps() as $gap_index => $gap)
457  {
458  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution_gap.html", TRUE, TRUE, "Modules/TestQuestionPool");
459  $found = array();
460  foreach ($user_solution as $solutionarray)
461  {
462  if ($solutionarray["value1"] == $gap_index) $found = $solutionarray;
463  }
464 
465  if ($active_id)
466  {
467  if ($graphicalOutput)
468  {
469  // output of ok/not ok icons for user entered solutions
470  $details = $this->object->calculateReachedPoints($active_id, $pass, TRUE);
471  $check = $details[$gap_index];
472  if ($check["best"])
473  {
474  $gaptemplate->setCurrentBlock("icon_ok");
475  $gaptemplate->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.gif"));
476  $gaptemplate->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
477  $gaptemplate->parseCurrentBlock();
478  }
479  else
480  {
481  $gaptemplate->setCurrentBlock("icon_not_ok");
482  if ($check["positive"])
483  {
484  $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_mostly_ok.gif"));
485  $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_not_correct_but_positive"));
486  }
487  else
488  {
489  $gaptemplate->setVariable("ICON_NOT_OK", ilUtil::getImagePath("icon_not_ok.gif"));
490  $gaptemplate->setVariable("TEXT_NOT_OK", $this->lng->txt("answer_is_wrong"));
491  }
492  $gaptemplate->parseCurrentBlock();
493  }
494  }
495  }
496  if ($result_output)
497  {
498  $points = $this->object->getMaximumGapPoints($gap_index);
499  $resulttext = ($points == 1) ? "(%s " . $this->lng->txt("point") . ")" : "(%s " . $this->lng->txt("points") . ")";
500  $gaptemplate->setCurrentBlock("result_output");
501  $gaptemplate->setVariable("RESULT_OUTPUT", sprintf($resulttext, $points));
502  $gaptemplate->parseCurrentBlock();
503  }
504  switch ($gap->getType())
505  {
506  case CLOZE_TEXT:
507  $solutiontext = "";
508  if (($active_id > 0) && (!$show_correct_solution))
509  {
510  if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0))
511  {
512  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
513  {
514  $solutiontext .= "&nbsp;";
515  }
516  }
517  else
518  {
519  $solutiontext = ilUtil::prepareFormOutput($found["value2"]);
520  }
521  }
522  else
523  {
524  $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
525  }
526  $gaptemplate->setVariable("SOLUTION", $solutiontext);
527  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
528  break;
529  case CLOZE_SELECT:
530  $solutiontext = "";
531  if (($active_id > 0) && (!$show_correct_solution))
532  {
533  if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0))
534  {
535  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
536  {
537  $solutiontext .= "&nbsp;";
538  }
539  }
540  else
541  {
542  $item = $gap->getItem($found["value2"]);
543  if (is_object($item))
544  {
545  $solutiontext = ilUtil::prepareFormOutput($item->getAnswertext());
546  }
547  else
548  {
549  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
550  {
551  $solutiontext .= "&nbsp;";
552  }
553  }
554  }
555  }
556  else
557  {
558  $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
559  }
560  $gaptemplate->setVariable("SOLUTION", $solutiontext);
561  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
562  break;
563  case CLOZE_NUMERIC:
564  $solutiontext = "";
565  if (($active_id > 0) && (!$show_correct_solution))
566  {
567  if ((count($found) == 0) || (strlen(trim($found["value2"])) == 0))
568  {
569  for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
570  {
571  $solutiontext .= "&nbsp;";
572  }
573  }
574  else
575  {
576  $solutiontext = ilUtil::prepareFormOutput($found["value2"]);
577  }
578  }
579  else
580  {
581  $solutiontext = ilUtil::prepareFormOutput($gap->getBestSolutionOutput());
582  }
583  $gaptemplate->setVariable("SOLUTION", $solutiontext);
584  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
585  break;
586  }
587  }
588  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
589 
590  // generate the question output
591  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html",TRUE, TRUE, "Modules/TestQuestionPool");
592  $questionoutput = $template->get();
593  $feedback = ($show_feedback) ? $this->getAnswerFeedbackOutput($active_id, $pass) : "";
594  if (strlen($feedback)) $solutiontemplate->setVariable("FEEDBACK", $feedback);
595  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
596 
597  $solutionoutput = $solutiontemplate->get();
598  if (!$show_question_only)
599  {
600  // get page object output
601  $solutionoutput = $this->getILIASPage($solutionoutput);
602  }
603  return $solutionoutput;
604  }
605 
606  function getTestOutput($active_id, $pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE)
607  {
608  // get the solution of the user for the active pass or from the last pass if allowed
609  $user_solution = array();
610  if ($active_id)
611  {
612  include_once "./Modules/Test/classes/class.ilObjTest.php";
613  if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
614  {
615  if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
616  }
617  $user_solution =& $this->object->getSolutionValues($active_id, $pass);
618  if (!is_array($user_solution))
619  {
620  $user_solution = array();
621  }
622  }
623 
624  // generate the question output
625  include_once "./classes/class.ilTemplate.php";
626  $template = new ilTemplate("tpl.il_as_qpl_cloze_question_output.html", TRUE, TRUE, "Modules/TestQuestionPool");
627  $output = $this->object->getClozeText();
628  foreach ($this->object->getGaps() as $gap_index => $gap)
629  {
630  switch ($gap->getType())
631  {
632  case CLOZE_TEXT:
633  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_text.html", TRUE, TRUE, "Modules/TestQuestionPool");
634  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
635  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
636  foreach ($user_solution as $solution)
637  {
638  if (strcmp($solution["value1"], $gap_index) == 0)
639  {
640  $gaptemplate->setVariable("VALUE_GAP", " value=\"" . ilUtil::prepareFormOutput($solution["value2"]) . "\"");
641  }
642  }
643  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
644  break;
645  case CLOZE_SELECT:
646  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE, "Modules/TestQuestionPool");
647  foreach ($gap->getItems() as $item)
648  {
649  $gaptemplate->setCurrentBlock("select_gap_option");
650  $gaptemplate->setVariable("SELECT_GAP_VALUE", $item->getOrder());
651  $gaptemplate->setVariable("SELECT_GAP_TEXT", ilUtil::prepareFormOutput($item->getAnswerText()));
652  foreach ($user_solution as $solution)
653  {
654  if (strcmp($solution["value1"], $gap_index) == 0)
655  {
656  if (strcmp($solution["value2"], $item->getOrder()) == 0)
657  {
658  $gaptemplate->setVariable("SELECT_GAP_SELECTED", " selected=\"selected\"");
659  }
660  }
661  }
662  $gaptemplate->parseCurrentBlock();
663  }
664  $gaptemplate->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
665  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
666  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
667  break;
668  case CLOZE_NUMERIC:
669  $gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_gap_numeric.html", TRUE, TRUE, "Modules/TestQuestionPool");
670  $gaptemplate->setVariable("TEXT_GAP_SIZE", $this->object->getFixedTextLength() ? $this->object->getFixedTextLength() : $gap->getMaxWidth());
671  $gaptemplate->setVariable("GAP_COUNTER", $gap_index);
672  foreach ($user_solution as $solution)
673  {
674  if (strcmp($solution["value1"], $gap_index) == 0)
675  {
676  $gaptemplate->setVariable("VALUE_GAP", " value=\"" . ilUtil::prepareFormOutput($solution["value2"]) . "\"");
677  }
678  }
679  $output = preg_replace("/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
680  break;
681  }
682  }
683  $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
684  $questionoutput = $template->get();
685  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
686  return $pageoutput;
687  }
688 
694  function saveFeedback()
695  {
696  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
697  $errors = $this->feedback(true);
698  $this->object->saveFeedbackGeneric(0, $_POST["feedback_incomplete"]);
699  $this->object->saveFeedbackGeneric(1, $_POST["feedback_complete"]);
700  $this->object->cleanupMediaObjectUsage();
702  }
703 
709  function setQuestionTabs()
710  {
711  global $rbacsystem, $ilTabs;
712 
713  $this->ctrl->setParameterByClass("ilpageobjectgui", "q_id", $_GET["q_id"]);
714  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
715  $q_type = $this->object->getQuestionType();
716 
717  if (strlen($q_type))
718  {
719  $classname = $q_type . "GUI";
720  $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
721  $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
722  }
723 
724  if ($_GET["q_id"])
725  {
726  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
727  {
728  // edit page
729  $ilTabs->addTarget("edit_content",
730  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "edit"),
731  array("edit", "insert", "exec_pg"),
732  "", "", $force_active);
733  }
734 
735  // edit page
736  $ilTabs->addTarget("preview",
737  $this->ctrl->getLinkTargetByClass("ilPageObjectGUI", "preview"),
738  array("preview"),
739  "ilPageObjectGUI", "", $force_active);
740  }
741 
742  $force_active = false;
743  $commands = $_POST["cmd"];
744  if (is_array($commands))
745  {
746  foreach ($commands as $key => $value)
747  {
748  if (preg_match("/^removegap_.*/", $key, $matches) ||
749  preg_match("/^addgap_.*/", $key, $matches)
750  )
751  {
752  $force_active = true;
753  }
754  }
755  }
756  if ($rbacsystem->checkAccess('write', $_GET["ref_id"]))
757  {
758  $url = "";
759  if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
760  // edit question properties
761  $ilTabs->addTarget("edit_properties",
762  $url,
763  array("editQuestion", "originalSyncForm", "save", "createGaps", "saveEdit"),
764  $classname, "", $force_active);
765  }
766 
767  if ($_GET["q_id"])
768  {
769  $ilTabs->addTarget("feedback",
770  $this->ctrl->getLinkTargetByClass($classname, "feedback"),
771  array("feedback", "saveFeedback"),
772  $classname, "");
773  }
774 
775  if ($_GET["q_id"])
776  {
777  $ilTabs->addTarget("solution_hint",
778  $this->ctrl->getLinkTargetByClass($classname, "suggestedsolution"),
779  array("suggestedsolution", "saveSuggestedSolution", "outSolutionExplorer", "cancel",
780  "addSuggestedSolution","cancelExplorer", "linkChilds", "removeSuggestedSolution"
781  ),
782  $classname,
783  ""
784  );
785  }
786 
787  // Assessment of questions sub menu entry
788  if ($_GET["q_id"])
789  {
790  $ilTabs->addTarget("statistics",
791  $this->ctrl->getLinkTargetByClass($classname, "assessment"),
792  array("assessment"),
793  $classname, "");
794  }
795 
796  if (($_GET["calling_test"] > 0) || ($_GET["test_ref_id"] > 0))
797  {
798  $ref_id = $_GET["calling_test"];
799  if (strlen($ref_id) == 0) $ref_id = $_GET["test_ref_id"];
800  $ilTabs->setBackTarget($this->lng->txt("backtocallingtest"), "ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
801  }
802  else
803  {
804  $ilTabs->setBackTarget($this->lng->txt("qpl"), $this->ctrl->getLinkTargetByClass("ilobjquestionpoolgui", "questions"));
805  }
806  }
807 }
808 ?>