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