24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
51 include_once
"./Modules/TestQuestionPool/classes/class.assClozeTest.php";
55 $this->
object->loadFromDb($id);
61 if (preg_match(
"/^(removegap|addgap)_(\d+)$/",
$cmd, $matches))
64 $this->gapIndex = $matches[2];
77 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
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"]);
88 $this->
object->setNrOfTries(
$_POST[
'nr_of_tries']);
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(
100 if (is_array(
$_POST[
'gap']))
102 if (strcmp($this->ctrl->getCmd(),
'createGaps') != 0) $this->
object->clearGapAnswers();
103 foreach (
$_POST[
'gap'] as $idx => $hidden)
105 $clozetype =
$_POST[
'clozetype_' . $idx];
106 $this->
object->setGapType($idx, $clozetype);
107 if (array_key_exists(
'shuffle_' . $idx,
$_POST))
109 $this->
object->setGapShuffle($idx,
$_POST[
'shuffle_' . $idx]);
112 if (strcmp($this->ctrl->getCmd(),
'createGaps') != 0)
114 if (is_array(
$_POST[
'gap_' . $idx][
'answer']))
116 foreach (
$_POST[
'gap_' . $idx][
'answer'] as $order => $value)
118 $this->
object->addGapAnswer($idx, $order, $value);
122 if (array_key_exists(
'gap_' . $idx .
'_numeric',
$_POST))
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']);
129 if (is_array(
$_POST[
'gap_' . $idx][
'points']))
131 foreach (
$_POST[
'gap_' . $idx][
'points'] as $order => $value)
133 $this->
object->setGapAnswerPoints($idx, $order, $value);
137 if (strcmp($this->ctrl->getCmd(),
'createGaps') != 0) $this->
object->updateClozeTextFromGaps();
154 $save = ((strcmp($this->ctrl->getCmd(),
"save") == 0) || (strcmp($this->ctrl->getCmd(),
"saveEdit") == 0)) ? TRUE : FALSE;
157 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
159 $form->setFormAction($this->ctrl->getFormAction($this));
161 $form->setMultipart(FALSE);
162 $form->setTableWidth(
"100%");
163 $form->setId(
"assclozetest");
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"));
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")
184 $textrating->setOptions($text_options);
185 $textrating->setValue($this->object->getTextgapRating());
186 $form->addItem($textrating);
189 $fixedTextLength =
new ilNumberInputGUI($this->lng->txt(
"cloze_fixed_textlength"),
"fixedTextLength");
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);
199 $identical_scoring =
new ilCheckboxInputGUI($this->lng->txt(
"identical_scoring"),
"identical_scoring");
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);
207 for ($i = 0; $i < $this->
object->getGapCount(); $i++)
209 $gap = $this->
object->getGap($i);
211 $header->setTitle($this->lng->txt(
"gap") .
" " . ($i+1));
212 $form->addItem($header);
215 $gapcounter->setValue($i);
216 $form->addItem($gapcounter);
220 0 => $this->lng->txt(
"text_gap"),
221 1 => $this->lng->txt(
"select_gap"),
222 2 => $this->lng->txt(
"numeric_gap")
225 $gaptype->setValue($gap->getType());
226 $form->addItem($gaptype);
231 include_once
"./Modules/TestQuestionPool/classes/class.ilAnswerWizardInputGUI.php";
232 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
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);
244 include_once
"./Modules/TestQuestionPool/classes/class.ilAnswerWizardInputGUI.php";
245 include_once
"./Modules/TestQuestionPool/classes/class.assAnswerCloze.php";
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);
256 $shuffle =
new ilCheckboxInputGUI($this->lng->txt(
"shuffle_answers"),
"shuffle_" . $i .
"");
258 $shuffle->setChecked($gap->getShuffle());
259 $shuffle->setRequired(FALSE);
260 $form->addItem($shuffle);
264 if (count($gap->getItemsRaw()) == 0) $gap->addItem(
new assAnswerCloze(
"", 0, 0));
265 foreach ($gap->getItemsRaw() as $item)
267 $value =
new ilFormulaInputGUI($this->lng->txt(
'value'),
"gap_" . $i .
"_numeric");
270 $value->setRequired(
true);
271 $value->setInlineStyle(
'text-align: right;');
272 $form->addItem($value);
274 $lowerbound =
new ilFormulaInputGUI($this->lng->txt(
'range_lower_limit'),
"gap_" . $i .
"_numeric_lower");
276 $lowerbound->setRequired(
true);
278 $lowerbound->setInlineStyle(
'text-align: right;');
279 $form->addItem($lowerbound);
281 $upperbound =
new ilFormulaInputGUI($this->lng->txt(
'range_upper_limit'),
"gap_" . $i .
"_numeric_upper");
283 $upperbound->setRequired(
true);
285 $upperbound->setInlineStyle(
'text-align: right;');
286 $form->addItem($upperbound);
288 $points =
new ilNumberInputGUI($this->lng->txt(
'points'),
"gap_" . $i .
"_numeric_points");
290 $points->setRequired(
true);
292 $form->addItem($points);
297 $form->addCommandButton(
'createGaps', $this->lng->txt(
'create_gaps'));
304 $form->setValuesByPost();
305 $errors = !$form->checkInput();
306 $form->setValuesByPost();
307 if (
$errors) $checkonly =
false;
310 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
320 $this->
object->saveToDb();
330 $this->
object->deleteAnswerText($this->gapIndex, key(
$_POST[
'cmd'][
'removegap_' . $this->gapIndex]));
340 $this->
object->addGapAnswer($this->gapIndex, key(
$_POST[
'cmd'][
'addgap_' . $this->gapIndex])+1,
"");
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);
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)
379 switch ($gap->getType())
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);
388 $gaptemplate =
new ilTemplate(
"tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE,
"Modules/TestQuestionPool");
389 foreach ($gap->getItems() as $item)
391 $gaptemplate->setCurrentBlock(
"select_gap_option");
392 $gaptemplate->setVariable(
"SELECT_GAP_VALUE", $item->getOrder());
394 $gaptemplate->parseCurrentBlock();
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);
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);
408 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
409 $questionoutput = $template->get();
410 if (!$show_question_only)
415 return $questionoutput;
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
443 $user_solution = array();
447 $user_solution =& $this->
object->getSolutionValues($active_id,
$pass);
448 if (!is_array($user_solution))
450 $user_solution = array();
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)
459 $gaptemplate =
new ilTemplate(
"tpl.il_as_qpl_cloze_question_output_solution_gap.html", TRUE, TRUE,
"Modules/TestQuestionPool");
461 foreach ($user_solution as $solutionarray)
463 if ($solutionarray[
"value1"] == $gap_index) $found = $solutionarray;
468 if ($graphicalOutput)
471 $details = $this->
object->calculateReachedPoints($active_id,
$pass, TRUE);
472 $check = $details[$gap_index];
475 $gaptemplate->setCurrentBlock(
"icon_ok");
477 $gaptemplate->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
478 $gaptemplate->parseCurrentBlock();
482 $gaptemplate->setCurrentBlock(
"icon_not_ok");
483 if ($check[
"positive"])
486 $gaptemplate->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
491 $gaptemplate->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
493 $gaptemplate->parseCurrentBlock();
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();
505 switch ($gap->getType())
509 if (($active_id > 0) && (!$show_correct_solution))
511 if ((count($found) == 0) || (strlen(trim($found[
"value2"])) == 0))
513 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
515 $solutiontext .=
" ";
527 $gaptemplate->setVariable(
"SOLUTION", $solutiontext);
528 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
532 if (($active_id > 0) && (!$show_correct_solution))
534 if ((count($found) == 0) || (strlen(trim($found[
"value2"])) == 0))
536 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
538 $solutiontext .=
" ";
543 $item = $gap->getItem($found[
"value2"]);
544 if (is_object($item))
550 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
552 $solutiontext .=
" ";
561 $gaptemplate->setVariable(
"SOLUTION", $solutiontext);
562 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
566 if (($active_id > 0) && (!$show_correct_solution))
568 if ((count($found) == 0) || (strlen(trim($found[
"value2"])) == 0))
570 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
572 $solutiontext .=
" ";
584 $gaptemplate->setVariable(
"SOLUTION", $solutiontext);
585 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
589 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
592 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
593 $questionoutput = $template->get();
595 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
596 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
598 $solutionoutput = $solutiontemplate->get();
599 if (!$show_question_only)
604 return $solutionoutput;
610 $user_solution = array();
613 include_once
"./Modules/Test/classes/class.ilObjTest.php";
618 $user_solution =& $this->
object->getSolutionValues($active_id,
$pass);
619 if (!is_array($user_solution))
621 $user_solution = array();
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)
631 switch ($gap->getType())
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)
639 if (strcmp($solution[
"value1"], $gap_index) == 0)
644 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
647 $gaptemplate =
new ilTemplate(
"tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE,
"Modules/TestQuestionPool");
648 foreach ($gap->getItems() as $item)
650 $gaptemplate->setCurrentBlock(
"select_gap_option");
651 $gaptemplate->setVariable(
"SELECT_GAP_VALUE", $item->getOrder());
653 foreach ($user_solution as $solution)
655 if (strcmp($solution[
"value1"], $gap_index) == 0)
657 if (strcmp($solution[
"value2"], $item->getOrder()) == 0)
659 $gaptemplate->setVariable(
"SELECT_GAP_SELECTED",
" selected=\"selected\"");
663 $gaptemplate->parseCurrentBlock();
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);
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)
675 if (strcmp($solution[
"value1"], $gap_index) == 0)
680 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
684 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
685 $questionoutput = $template->get();
686 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
697 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
699 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
700 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
701 $this->
object->cleanupMediaObjectUsage();
712 global $rbacsystem, $ilTabs;
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();
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"]);
727 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
730 $ilTabs->addTarget(
"edit_content",
731 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
732 array(
"edit",
"insert",
"exec_pg"),
733 "",
"", $force_active);
737 $ilTabs->addTarget(
"preview",
738 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
740 "ilPageObjectGUI",
"", $force_active);
743 $force_active =
false;
744 $commands =
$_POST[
"cmd"];
745 if (is_array($commands))
747 foreach ($commands as $key => $value)
749 if (preg_match(
"/^removegap_.*/", $key, $matches) ||
750 preg_match(
"/^addgap_.*/", $key, $matches)
753 $force_active =
true;
757 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
760 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
762 $ilTabs->addTarget(
"edit_properties",
764 array(
"editQuestion",
"originalSyncForm",
"save",
"createGaps",
"saveEdit"),
765 $classname,
"", $force_active);
770 $ilTabs->addTarget(
"feedback",
771 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
772 array(
"feedback",
"saveFeedback"),
778 $ilTabs->addTarget(
"solution_hint",
779 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
780 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
781 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
791 $ilTabs->addTarget(
"statistics",
792 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
797 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
801 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
805 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));