24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
52 include_once
"./Modules/TestQuestionPool/classes/class.assTextSubset.php";
56 $this->
object->loadFromDb($id);
74 $this->tpl->addJavascript(
"./Services/JavaScript/js/Basic.js");
75 $javascript =
"<script type=\"text/javascript\">ilAddOnLoad(initialSelect);\n".
76 "function initialSelect() {\n%s\n}</script>";
79 $this->tpl->addBlockFile(
"QUESTION_DATA",
"question_data",
"tpl.il_as_qpl_textsubset.html",
"Modules/TestQuestionPool");
81 for ($i = 0; $i < $this->
object->getAnswerCount(); $i++)
83 $this->tpl->setCurrentBlock(
"answers");
84 $answer = $this->
object->getAnswer($i);
85 $this->tpl->setVariable(
"VALUE_ANSWER_COUNTER", $answer->getOrder() + 1);
86 $this->tpl->setVariable(
"ANSWER_ORDER", $answer->getOrder());
89 $this->tpl->parseCurrentBlock();
91 if ($this->object->getAnswerCount() > 0)
93 $this->tpl->setCurrentBlock(
"answersheading");
94 $this->tpl->setVariable(
"TEXT_ANSWER_TEXT", $this->lng->txt(
"answer_text"));
95 $this->tpl->setVariable(
"TEXT_POINTS", $this->lng->txt(
"points"));
96 $this->tpl->parseCurrentBlock();
99 $internallinks = array(
100 "lm" => $this->lng->txt(
"obj_lm"),
101 "st" => $this->lng->txt(
"obj_st"),
102 "pg" => $this->lng->txt(
"obj_pg"),
103 "glo" => $this->lng->txt(
"glossary_term")
105 foreach ($internallinks as $key => $value)
107 $this->tpl->setCurrentBlock(
"internallink");
108 $this->tpl->setVariable(
"TYPE_INTERNAL_LINK", $key);
109 $this->tpl->setVariable(
"TEXT_INTERNAL_LINK", $value);
110 $this->tpl->parseCurrentBlock();
113 $this->tpl->setCurrentBlock(
"HeadContent");
114 if ($this->object->getAnswerCount() == 0)
116 $this->tpl->setVariable(
"CONTENT_BLOCK", sprintf($javascript,
"document.frm_textsubset.title.focus();"));
120 switch ($this->ctrl->getCmd())
123 $this->tpl->setVariable(
"CONTENT_BLOCK", sprintf($javascript,
"document.frm_textsubset.answer_".($this->object->getAnswerCount() - $_POST[
"nrOfAnswers"]).
".focus(); document.getElementById('answer_".($this->object->getAnswerCount() - $_POST[
"nrOfAnswers"]).
"').scrollIntoView(\"true\");"));
126 if ($this->object->getAnswerCount() == 0)
128 $this->tpl->setVariable(
"CONTENT_BLOCK", sprintf($javascript,
"document.frm_textsubset.title.focus();"));
132 $this->tpl->setVariable(
"CONTENT_BLOCK", sprintf($javascript,
"document.frm_textsubset.answer_".($this->object->getAnswerCount() - 1).
".focus(); document.getElementById('answer_".($this->object->getAnswerCount() - 1).
"').scrollIntoView(\"true\");"));
136 $this->tpl->setVariable(
"CONTENT_BLOCK", sprintf($javascript,
"document.frm_textsubset.title.focus();"));
140 $this->tpl->parseCurrentBlock();
143 $text_options = array(
144 array(
"ci", $this->lng->txt(
"cloze_textgap_case_insensitive")),
145 array(
"cs", $this->lng->txt(
"cloze_textgap_case_sensitive")),
146 array(
"l1", sprintf($this->lng->txt(
"cloze_textgap_levenshtein_of"),
"1")),
147 array(
"l2", sprintf($this->lng->txt(
"cloze_textgap_levenshtein_of"),
"2")),
148 array(
"l3", sprintf($this->lng->txt(
"cloze_textgap_levenshtein_of"),
"3")),
149 array(
"l4", sprintf($this->lng->txt(
"cloze_textgap_levenshtein_of"),
"4")),
150 array(
"l5", sprintf($this->lng->txt(
"cloze_textgap_levenshtein_of"),
"5"))
152 $text_rating = $this->
object->getTextRating();
153 foreach ($text_options as $text_option)
155 $this->tpl->setCurrentBlock(
"text_rating");
156 $this->tpl->setVariable(
"RATING_VALUE", $text_option[0]);
157 $this->tpl->setVariable(
"RATING_TEXT", $text_option[1]);
158 if (strcmp($text_rating, $text_option[0]) == 0)
160 $this->tpl->setVariable(
"SELECTED_RATING_VALUE",
" selected=\"selected\"");
162 $this->tpl->parseCurrentBlock();
165 if ($this->object->getAnswerCount() > 0)
167 $this->tpl->setCurrentBlock(
"selectall");
168 $this->tpl->setVariable(
"SELECT_ALL", $this->lng->txt(
"select_all"));
169 $this->tpl->parseCurrentBlock();
170 $this->tpl->setCurrentBlock(
"existinganswers");
171 $this->tpl->setVariable(
"DELETE", $this->lng->txt(
"delete"));
172 $this->tpl->setVariable(
"MOVE", $this->lng->txt(
"move"));
173 $this->tpl->setVariable(
"ARROW",
"<img src=\"" .
ilUtil::getImagePath(
"arrow_downright.gif") .
"\" alt=\"".$this->lng->txt(
"arrow_downright").
"\">");
174 $this->tpl->parseCurrentBlock();
177 for ($i = 1; $i < 10; $i++)
179 $this->tpl->setCurrentBlock(
"numbers");
180 $this->tpl->setVariable(
"VALUE_NUMBER", $i);
183 $this->tpl->setVariable(
"TEXT_NUMBER", $i .
" " . $this->lng->txt(
"answer"));
187 $this->tpl->setVariable(
"TEXT_NUMBER", $i .
" " . $this->lng->txt(
"answers"));
189 $this->tpl->parseCurrentBlock();
192 $this->tpl->setCurrentBlock(
"question_data");
193 $this->tpl->setVariable(
"TEXTSUBSET_ID", $this->object->getId());
197 $this->tpl->setVariable(
"VALUE_CORRECTANSWERS", $this->object->getCorrectAnswers());
198 $this->tpl->setVariable(
"VALUE_POINTS", $this->object->getMaximumPoints());
199 $questiontext = $this->
object->getQuestion();
200 $this->tpl->setVariable(
"VALUE_QUESTION",
ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($questiontext)));
201 $this->tpl->setVariable(
"VALUE_ADD_ANSWER", $this->lng->txt(
"add"));
202 $this->tpl->setVariable(
"TEXT_TITLE", $this->lng->txt(
"title"));
203 $this->tpl->setVariable(
"TEXT_AUTHOR", $this->lng->txt(
"author"));
204 $this->tpl->setVariable(
"TEXT_COMMENT", $this->lng->txt(
"description"));
205 $this->tpl->setVariable(
"TEXT_QUESTION", $this->lng->txt(
"question"));
206 $this->tpl->setVariable(
"TEXT_SOLUTION_HINT", $this->lng->txt(
"solution_hint"));
207 $this->tpl->setVariable(
"TEXT_RATING", $this->lng->txt(
"text_rating"));
208 $this->tpl->setVariable(
"TEXT_POINTS", $this->lng->txt(
"maximum_points"));
209 $this->tpl->setVariable(
"TEXT_CORRECTANSWERS", $this->lng->txt(
"nr_of_correct_answers"));
212 $est_working_time = $this->
object->getEstimatedWorkingTime();
213 $this->tpl->setVariable(
"TEXT_WORKING_TIME", $this->lng->txt(
"working_time"));
214 $this->tpl->setVariable(
"TIME_FORMAT", $this->lng->txt(
"time_format"));
215 $this->tpl->setVariable(
"VALUE_WORKING_TIME",
ilUtil::makeTimeSelect(
"Estimated",
false, $est_working_time[h], $est_working_time[m], $est_working_time[s]));
217 if (count($this->object->suggested_solutions))
219 $solution_array = $this->
object->getSuggestedSolution(0);
220 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
222 $this->tpl->setVariable(
"TEXT_VALUE_SOLUTION_HINT",
" <a href=\"$href\" target=\"content\">" . $this->lng->txt(
"solution_hint").
"</a> ");
223 $this->tpl->setVariable(
"BUTTON_REMOVE_SOLUTION", $this->lng->txt(
"remove"));
224 $this->tpl->setVariable(
"BUTTON_ADD_SOLUTION", $this->lng->txt(
"change"));
225 $this->tpl->setVariable(
"VALUE_SOLUTION_HINT", $solution_array[
"internal_link"]);
229 $this->tpl->setVariable(
"BUTTON_ADD_SOLUTION", $this->lng->txt(
"add"));
231 $this->tpl->setVariable(
"SAVE",$this->lng->txt(
"save"));
232 $this->tpl->setVariable(
"SAVE_EDIT", $this->lng->txt(
"save_edit"));
233 $this->tpl->setVariable(
"CANCEL",$this->lng->txt(
"cancel"));
234 $this->tpl->setVariable(
"TXT_REQUIRED_FLD", $this->lng->txt(
"required_field"));
235 $this->ctrl->setParameter($this,
"sel_question_types",
"assTextSubset");
236 $this->tpl->setVariable(
"ACTION_TEXTSUBSET_TEST", $this->ctrl->getFormAction($this));
237 $this->tpl->setVariable(
"TEXT_QUESTION_TYPE", $this->
outQuestionType());
240 $this->tpl->parseCurrentBlock();
241 include_once
"./Services/RTE/classes/class.ilRTE.php";
243 include_once
"./Services/RTE/classes/class.$rtestring.php";
244 $rte =
new $rtestring();
245 $rte->addPlugin(
"latex");
246 $rte->addButton(
"latex"); $rte->addButton(
"pastelatex");
247 include_once
"./classes/class.ilObject.php";
248 $obj_id =
$_GET[
"q_id"];
250 $rte->addRTESupport($obj_id, $obj_type,
"assessment");
252 $this->tpl->setCurrentBlock(
"adm_content");
254 $this->tpl->parseCurrentBlock();
263 $answers = $_POST[
"chb_answers"];
264 if (is_array($answers))
267 foreach ($answers as $answer)
269 $this->
object->deleteAnswer($answer);
283 for ($i = 0; $i < $_POST[
"nrOfAnswers"]; $i++)
285 $this->
object->addAnswer(
288 count($this->object->answers)
297 $unfilled_answer =
false;
298 foreach ($_POST as $key => $value)
300 if (preg_match(
"/answer_(\d+)/", $key, $matches))
304 $unfilled_answer =
true;
308 if ($unfilled_answer)
322 $unfilled_answer =
false;
323 foreach ($_POST as $key => $value)
325 if (preg_match(
"/answer_(\d+)/", $key, $matches))
329 $unfilled_answer =
true;
333 if ($unfilled_answer)
350 $cmd = $this->ctrl->getCmd();
352 if ((!$_POST[
"title"]) or (!$_POST[
"author"]) or (!$_POST[
"question"]) or (!$_POST[
"correctanswers"]))
377 if ((
$result) and (strcmp($this->ctrl->getCmd(),
"add") == 0))
380 ilUtil::sendInfo($this->lng->txt(
"fill_out_all_required_fields_add_answer"));
386 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
388 $this->
object->setQuestion($questiontext);
389 $this->
object->setSuggestedSolution($_POST[
"solution_hint"], 0);
390 $this->
object->setCorrectAnswers($_POST[
"correctanswers"]);
391 $this->
object->setTextRating($_POST[
"text_rating"]);
396 $this->
object->flushAnswers();
399 foreach ($_POST as $key => $value)
401 if (preg_match(
"/answer_(\d+)/", $key, $matches))
403 $this->
object->addAnswer(
412 if ($_POST[
"textsubset_id"] > 0)
414 $this->
object->setId($_POST[
"textsubset_id"]);
417 $maximum_points = $this->
object->getMaximumPoints();
418 if (($maximum_points <= 0) && (count($this->object->answers) > 0))
421 $this->
setErrorMessage($this->lng->txt(
"enter_enough_positive_points"));
423 $this->
object->setPoints($maximum_points);
431 $this->
object->saveToDb();
432 $this->ctrl->setParameter($this,
"q_id", $this->object->getId());
440 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions);
441 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
442 $this->tpl->setVariable(
"FORMACTION", $formaction);
445 function getSolutionOutput($active_id,
$pass = NULL, $graphicalOutput = FALSE, $result_output = FALSE, $show_question_only = TRUE, $show_feedback = FALSE, $show_correct_solution = FALSE)
448 $solutions = array();
449 if (($active_id > 0) && (!$show_correct_solution))
451 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
456 foreach ($this->object->answers as $answer)
458 if ($answer->getPoints() > 0)
460 if (!is_array($rank[$answer->getPoints()]))
462 $rank[$answer->getPoints()] = array();
464 array_push($rank[$answer->getPoints()], $answer->getAnswertext());
467 krsort($rank, SORT_NUMERIC);
468 foreach ($rank as $index => $bestsolutions)
470 array_push($solutions, array(
"value1" => join(
",", $bestsolutions),
"points" => $index));
475 include_once
"./classes/class.ilTemplate.php";
476 $template =
new ilTemplate(
"tpl.il_as_qpl_textsubset_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
477 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
478 $available_answers =& $this->
object->getAvailableAnswers();
479 for ($i = 0; $i < $this->
object->getCorrectAnswers(); $i++)
481 if ((!$test_id) && (strcmp($solutions[$i][
"value1"],
"") == 0))
486 if (($active_id > 0) && (!$show_correct_solution))
488 if ($graphicalOutput)
491 $index = $this->
object->isAnswerCorrect($available_answers, $solutions[$i][
"value1"]);
493 if ($index !== FALSE)
495 unset($available_answers[$index]);
500 $template->setCurrentBlock(
"icon_ok");
502 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
503 $template->parseCurrentBlock();
507 $template->setCurrentBlock(
"icon_ok");
509 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
510 $template->parseCurrentBlock();
514 $template->setCurrentBlock(
"textsubset_row");
515 $template->setVariable(
"SOLUTION", $solutions[$i][
"value1"]);
516 $template->setVariable(
"COUNTER", $i+1);
519 $points = $solutions[$i][
"points"];
520 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
521 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
523 $template->parseCurrentBlock();
526 $questiontext = $this->
object->getQuestion();
527 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
528 $questionoutput = $template->get();
530 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
531 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
533 $solutionoutput = $solutiontemplate->get();
534 if (!$show_question_only)
539 return $solutionoutput;
545 include_once
"./classes/class.ilTemplate.php";
546 $template =
new ilTemplate(
"tpl.il_as_qpl_textsubset_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
547 $width = $this->
object->getMaxTextboxWidth();
548 for ($i = 0; $i < $this->
object->getCorrectAnswers(); $i++)
550 $template->setCurrentBlock(
"textsubset_row");
551 $template->setVariable(
"COUNTER", $i+1);
552 $template->setVariable(
"TEXTFIELD_ID", sprintf(
"%02d", $i+1));
553 $template->setVariable(
"TEXTFIELD_SIZE", $width);
554 $template->parseCurrentBlock();
556 $questiontext = $this->
object->getQuestion();
557 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
558 $questionoutput = $template->get();
559 if (!$show_question_only)
564 return $questionoutput;
574 include_once
"./Modules/Test/classes/class.ilObjTest.php";
579 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
583 include_once
"./classes/class.ilTemplate.php";
584 $template =
new ilTemplate(
"tpl.il_as_qpl_textsubset_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
585 $width = $this->
object->getMaxTextboxWidth();
586 for ($i = 0; $i < $this->
object->getCorrectAnswers(); $i++)
588 $template->setCurrentBlock(
"textsubset_row");
589 foreach ($solutions as $idx => $solution_value)
593 $template->setVariable(
"TEXTFIELD_VALUE",
" value=\"" . $solution_value[
"value1"].
"\"");
596 $template->setVariable(
"COUNTER", $i+1);
597 $template->setVariable(
"TEXTFIELD_ID", sprintf(
"%02d", $i+1));
598 $template->setVariable(
"TEXTFIELD_SIZE", $width);
599 $template->parseCurrentBlock();
601 $questiontext = $this->
object->getQuestion();
602 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
603 $questionoutput = $template->get();
604 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
611 if ($_POST[
"cmd"][
"addSuggestedSolution"])
621 ilUtil::sendInfo($this->lng->txt(
"fill_out_all_required_fields_add_answer"));
626 $this->
object->saveToDb();
627 $this->ctrl->setParameter($this,
"q_id", $this->object->getId());
628 $this->tpl->setVariable(
"HEADER", $this->object->getTitle());
642 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
645 $this->
object->cleanupMediaObjectUsage();
658 $this->tpl->addBlockFile(
"ADM_CONTENT",
"feedback",
"tpl.il_as_qpl_textsubset_feedback.html",
"Modules/TestQuestionPool");
659 $this->tpl->setVariable(
"FEEDBACK_TEXT", $this->lng->txt(
"feedback"));
660 $this->tpl->setVariable(
"FEEDBACK_COMPLETE", $this->lng->txt(
"feedback_complete_solution"));
661 $this->tpl->setVariable(
"VALUE_FEEDBACK_COMPLETE",
ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)), FALSE));
662 $this->tpl->setVariable(
"FEEDBACK_INCOMPLETE", $this->lng->txt(
"feedback_incomplete_solution"));
663 $this->tpl->setVariable(
"VALUE_FEEDBACK_INCOMPLETE",
ilUtil::prepareFormOutput($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)), FALSE));
665 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
667 $this->tpl->setVariable(
"SAVE", $this->lng->txt(
"save"));
669 $this->tpl->setVariable(
"FORMACTION", $this->ctrl->getFormAction($this));
671 include_once
"./Services/RTE/classes/class.ilRTE.php";
673 include_once
"./Services/RTE/classes/class.$rtestring.php";
674 $rte =
new $rtestring();
675 $rte->addPlugin(
"latex");
676 $rte->addButton(
"latex"); $rte->addButton(
"pastelatex");
677 include_once
"./classes/class.ilObject.php";
678 $obj_id =
$_GET[
"q_id"];
680 $rte->addRTESupport($obj_id, $obj_type,
"assessment");
692 global $rbacsystem, $ilTabs;
694 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
695 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
696 $q_type = $this->
object->getQuestionType();
700 $classname = $q_type .
"GUI";
701 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
702 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
707 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
710 $ilTabs->addTarget(
"edit_content",
711 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
712 array(
"edit",
"insert",
"exec_pg"),
713 "",
"", $force_active);
717 $ilTabs->addTarget(
"preview",
718 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
720 "ilPageObjectGUI",
"", $force_active);
723 $force_active =
false;
724 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
727 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
729 $ilTabs->addTarget(
"edit_properties",
731 array(
"editQuestion",
"save",
"cancel",
"addSuggestedSolution",
732 "cancelExplorer",
"linkChilds",
"removeSuggestedSolution",
"add",
"deleteAnswer",
734 $classname,
"", $force_active);
739 $ilTabs->addTarget(
"feedback",
740 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
741 array(
"feedback",
"saveFeedback"),
748 $ilTabs->addTarget(
"statistics",
749 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
754 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
758 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
762 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));