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);
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());
329 $this->
object->deleteAnswerText($this->gapIndex, key(
$_POST[
'cmd'][
'removegap_' . $this->gapIndex]));
339 $this->
object->addGapAnswer($this->gapIndex, key(
$_POST[
'cmd'][
'addgap_' . $this->gapIndex])+1,
"");
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);
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)
378 switch ($gap->getType())
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);
387 $gaptemplate =
new ilTemplate(
"tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE,
"Modules/TestQuestionPool");
388 foreach ($gap->getItems() as $item)
390 $gaptemplate->setCurrentBlock(
"select_gap_option");
391 $gaptemplate->setVariable(
"SELECT_GAP_VALUE", $item->getOrder());
393 $gaptemplate->parseCurrentBlock();
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);
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);
407 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
408 $questionoutput = $template->get();
409 if (!$show_question_only)
414 return $questionoutput;
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
442 $user_solution = array();
446 $user_solution =& $this->
object->getSolutionValues($active_id,
$pass);
447 if (!is_array($user_solution))
449 $user_solution = array();
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)
458 $gaptemplate =
new ilTemplate(
"tpl.il_as_qpl_cloze_question_output_solution_gap.html", TRUE, TRUE,
"Modules/TestQuestionPool");
460 foreach ($user_solution as $solutionarray)
462 if ($solutionarray[
"value1"] == $gap_index) $found = $solutionarray;
467 if ($graphicalOutput)
470 $details = $this->
object->calculateReachedPoints($active_id,
$pass, TRUE);
471 $check = $details[$gap_index];
474 $gaptemplate->setCurrentBlock(
"icon_ok");
476 $gaptemplate->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
477 $gaptemplate->parseCurrentBlock();
481 $gaptemplate->setCurrentBlock(
"icon_not_ok");
482 if ($check[
"positive"])
485 $gaptemplate->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
490 $gaptemplate->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
492 $gaptemplate->parseCurrentBlock();
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();
504 switch ($gap->getType())
508 if (($active_id > 0) && (!$show_correct_solution))
510 if ((count($found) == 0) || (strlen(trim($found[
"value2"])) == 0))
512 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
514 $solutiontext .=
" ";
526 $gaptemplate->setVariable(
"SOLUTION", $solutiontext);
527 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
531 if (($active_id > 0) && (!$show_correct_solution))
533 if ((count($found) == 0) || (strlen(trim($found[
"value2"])) == 0))
535 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
537 $solutiontext .=
" ";
542 $item = $gap->getItem($found[
"value2"]);
543 if (is_object($item))
549 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
551 $solutiontext .=
" ";
560 $gaptemplate->setVariable(
"SOLUTION", $solutiontext);
561 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
565 if (($active_id > 0) && (!$show_correct_solution))
567 if ((count($found) == 0) || (strlen(trim($found[
"value2"])) == 0))
569 for ($chars = 0; $chars < $gap->getMaxWidth(); $chars++)
571 $solutiontext .=
" ";
583 $gaptemplate->setVariable(
"SOLUTION", $solutiontext);
584 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
588 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
591 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
592 $questionoutput = $template->get();
594 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
595 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
597 $solutionoutput = $solutiontemplate->get();
598 if (!$show_question_only)
603 return $solutionoutput;
609 $user_solution = array();
612 include_once
"./Modules/Test/classes/class.ilObjTest.php";
617 $user_solution =& $this->
object->getSolutionValues($active_id,
$pass);
618 if (!is_array($user_solution))
620 $user_solution = array();
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)
630 switch ($gap->getType())
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)
638 if (strcmp($solution[
"value1"], $gap_index) == 0)
643 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
646 $gaptemplate =
new ilTemplate(
"tpl.il_as_qpl_cloze_question_gap_select.html", TRUE, TRUE,
"Modules/TestQuestionPool");
647 foreach ($gap->getItems() as $item)
649 $gaptemplate->setCurrentBlock(
"select_gap_option");
650 $gaptemplate->setVariable(
"SELECT_GAP_VALUE", $item->getOrder());
652 foreach ($user_solution as $solution)
654 if (strcmp($solution[
"value1"], $gap_index) == 0)
656 if (strcmp($solution[
"value2"], $item->getOrder()) == 0)
658 $gaptemplate->setVariable(
"SELECT_GAP_SELECTED",
" selected=\"selected\"");
662 $gaptemplate->parseCurrentBlock();
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);
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)
674 if (strcmp($solution[
"value1"], $gap_index) == 0)
679 $output = preg_replace(
"/\[gap\].*?\[\/gap\]/", $gaptemplate->get(), $output, 1);
683 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($output, TRUE));
684 $questionoutput = $template->get();
685 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
696 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
698 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
699 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
700 $this->
object->cleanupMediaObjectUsage();
711 global $rbacsystem, $ilTabs;
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();
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"]);
726 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
729 $ilTabs->addTarget(
"edit_content",
730 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
731 array(
"edit",
"insert",
"exec_pg"),
732 "",
"", $force_active);
736 $ilTabs->addTarget(
"preview",
737 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
739 "ilPageObjectGUI",
"", $force_active);
742 $force_active =
false;
743 $commands =
$_POST[
"cmd"];
744 if (is_array($commands))
746 foreach ($commands as
$key => $value)
748 if (preg_match(
"/^removegap_.*/",
$key, $matches) ||
749 preg_match(
"/^addgap_.*/",
$key, $matches)
752 $force_active =
true;
756 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
759 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
761 $ilTabs->addTarget(
"edit_properties",
763 array(
"editQuestion",
"originalSyncForm",
"save",
"createGaps",
"saveEdit"),
764 $classname,
"", $force_active);
769 $ilTabs->addTarget(
"feedback",
770 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
771 array(
"feedback",
"saveFeedback"),
777 $ilTabs->addTarget(
"solution_hint",
778 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
779 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
780 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
790 $ilTabs->addTarget(
"statistics",
791 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
796 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
800 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
804 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));