22 require_once
'./Modules/Test/classes/inc.AssessmentConstants.php';
42 $this->
object->loadFromDb(
$id);
50 $this->glyph_factory = $DIC[
'ui.factory']->symbol()->glyph();
51 $this->renderer = $DIC[
'ui.renderer'];
66 $form->setValuesByPost();
75 $custom_check = $this->
object->checkQuestionCustomPart($form);
77 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
"form_input_not_valid"));
87 $min_auto_complete = (
int) $form->
getInput(
'min_auto_complete');
88 $longmenu_text = $this->request->raw(
'longmenu_text') ??
'';
89 $hidden_text_files = $this->request->raw(
'hidden_text_files') ??
'';
90 $hidden_correct_answers = $this->request->raw(
'hidden_correct_answers') ?? [];
91 $long_menu_type = $this->request->raw(
'long_menu_type') ?? [];
96 $this->
object->setQuestion($this->request->raw(
'question'));
97 $this->
object->setLongMenuTextValue($this->request->raw(
'longmenu_text'));
98 $this->
object->setMinAutoComplete($min_auto_complete);
99 $this->
object->setIdenticalScoring($this->request->int(
'identical_scoring'));
106 $longmenu_text = $this->request->raw(
'longmenu_text') ??
'';
107 $hidden_text_files = $this->request->raw(
'hidden_text_files') ??
'';
108 $answer_options_from_text = preg_split(
114 if (count($answer_options_from_text) - 1 !== count($answer_options_from_files)) {
115 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'longmenu_answeroptions_differ'));
119 $correct_answers = $this->
stripSlashesRecursive(json_decode($this->request->raw(
'hidden_correct_answers')));
120 foreach ($correct_answers as $answer) {
121 if (!is_numeric(str_replace(
',',
'.', $answer[1]))) {
122 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'points_non_numeric_or_negative_msg'));
132 function (
string|array $v):
string|array {
145 function (
string|array $v):
string|array {
157 if ($form === null) {
163 $this->tpl->setVariable(
"QUESTION_DATA", $this->
ctrl->getHTML($form));
192 $long_menu_text->setRows(10);
193 $long_menu_text->setCols(80);
194 if (!$this->
object->getSelfAssessmentEditingMode()) {
197 $long_menu_text->addPlugin(
"latex");
198 $long_menu_text->addButton(
"latex");
199 $long_menu_text->addButton(
"pastelatex");
200 $long_menu_text->setRTESupport($this->
object->getId(),
"qpl",
"assessment");
201 $long_menu_text->setUseRte(
true);
205 $long_menu_text->setUseTagsForRteOnly(
false);
208 $long_menu_text->setValue($this->
object->getLongMenuTextValue());
209 $form->
addItem($long_menu_text);
211 $tpl =
new ilTemplate(
"tpl.il_as_qpl_longmenu_question_gap_button_code.html",
true,
true,
"Modules/TestQuestionPool");
219 $modal->setHeading(
'');
220 $modal->setId(
"ilGapModal");
224 $min_auto_complete =
new ilNumberInputGUI($this->
lng->txt(
'min_auto_complete'),
'min_auto_complete');
226 $auto_complete = $this->
object->getMinAutoComplete();
227 if ($auto_complete === 0) {
230 $min_auto_complete->setDecimals(0);
231 $min_auto_complete->setValue($auto_complete);
232 $min_auto_complete->setMinValue(1);
233 $min_auto_complete->setMaxValue(99);
234 $min_auto_complete->setSize(5);
235 $form->
addItem($min_auto_complete);
237 $identical_scoring =
new ilCheckboxInputGUI($this->
lng->txt(
"identical_scoring"),
"identical_scoring");
238 $identical_scoring->setValue(1);
239 $identical_scoring->setChecked($this->
object->getIdenticalScoring());
240 $identical_scoring->setInfo($this->
lng->txt(
'identical_scoring_desc'));
241 $identical_scoring->setRequired(
false);
242 $form->
addItem($identical_scoring);
247 $form->
addItem($hidden_correct);
249 $long_menu_language = [
250 'edit' =>
'[' . $this->
lng->txt(
'edit') .
']',
251 'type' => $this->
lng->txt(
'type'),
252 'answers' => $this->
lng->txt(
'answers'),
253 'answer_options' => $this->
lng->txt(
'answer_options'),
254 'correct_answers' => $this->
lng->txt(
'correct_answers'),
255 'add_answers' =>
'[' . $this->
lng->txt(
'add_answers') .
']',
256 'manual_editing' => $this->
lng->txt(
'manual_editing')
260 'list' => json_decode($this->
object->getJsonStructure()),
262 'last_updated_element' => 0,
263 'replacement_word' =>
'',
264 'filereader_usable' =>
false,
267 $answers = $this->
object->getAnswersObject();
269 if ($this->request->isset(
'hidden_text_files')) {
270 $question_parts[
'list'] = json_decode($this->request->raw(
'hidden_correct_answers'));
271 $answers = $this->request->raw(
'hidden_text_files');
274 $this->tpl->addJavaScript(
'./Modules/TestQuestionPool/templates/default/longMenuQuestionGapBuilder.js');
275 $this->tpl->addJavaScript(
'./Modules/TestQuestionPool/templates/default/longMenuQuestion.js');
276 $tpl =
new ilTemplate(
"tpl.il_as_qpl_longmenu_question_gap.html",
true,
true,
"Modules/TestQuestionPool");
291 $this->glyph_factory->add()->withAction(
'#')
294 $this->glyph_factory->remove()->withAction(
'#')
297 $tag_input->setPostVar(
'taggable');
298 $tag_input->setJsSelfInit(
false);
299 $tag_input->setTypeAheadMinLength(1);
305 $this->tpl->addOnLoadCode(
'longMenuQuestion.Init(' .
306 json_encode($long_menu_language) .
', ' .
307 json_encode($question_parts) .
', ' .
339 $graphicalOutput =
false,
340 $result_output =
false,
341 $show_question_only =
true,
342 $show_feedback =
false,
343 $show_correct_solution =
false,
344 $show_manual_scoring =
false,
345 $show_question_text =
true 348 if (($active_id > 0) && (!$show_correct_solution)) {
349 $user_solutions = $this->
object->getSolutionValues($active_id, $pass,
true);
351 $user_solutions = [];
352 foreach ($this->
object->getCorrectAnswersForQuestionSolution($this->object->getId()) as $idx => $val) {
353 $user_solutions[] = [
368 $show_correct_solution,
369 $show_manual_scoring,
377 mixed $user_solutions,
380 bool $graphical_output =
false,
381 bool $result_output =
false,
382 bool $show_question_only =
true,
383 bool $show_feedback =
false,
384 bool $show_correct_solution =
false,
385 bool $show_manual_scoring =
false,
386 bool $show_question_text =
true,
387 bool $show_autosave_title =
false,
388 bool $show_inline_feedback =
false,
392 foreach ($user_solutions as $idx => $solution_value) {
393 $user_solution[$solution_value[
'value1']] = $solution_value[
'value2'];
397 $template =
new ilTemplate(
"tpl.il_as_qpl_longmenu_question_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
398 if ($show_question_text) {
399 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
402 $solution_template =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
403 $question_output = $template->get();
405 if ($show_feedback) {
408 $feedback .= strlen($fb) ? $fb :
'';
412 $feedback .= strlen($fb) ? $fb :
'';
414 if (strlen($feedback)) {
420 $solution_template->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
424 $solution_template->setVariable(
"SOLUTION_OUTPUT", $question_output);
426 $solution_output = $solution_template->get();
428 if (!$show_question_only) {
429 $solution_output = $this->
getILIASPage($solution_output);
432 return $solution_output;
435 public function getPreview($show_question_only =
false, $showInlineFeedback =
false): string
438 $user_solution = array_values($user_solution);
442 $question_output = $template->get();
443 if (!$show_question_only) {
444 $question_output = $this->
getILIASPage($question_output);
446 return $question_output;
454 $is_postponed =
false,
455 $use_post_solutions =
false,
456 $show_feedback =
false 460 $solutions = $this->
object->getUserSolutionPreferingIntermediate($active_id, $pass);
461 foreach ($solutions as $idx => $solution_value) {
462 $user_solution[$solution_value[
'value1']] = $solution_value[
'value2'];
468 $question_output = $template->get();
469 $page_output = $this->
outQuestionPage(
"", $is_postponed, $active_id, $question_output);
475 $template =
new ilTemplate(
"tpl.il_as_qpl_longmenu_question_output.html",
true,
true,
"Modules/TestQuestionPool");
476 $this->tpl->addJavaScript(
'./Modules/TestQuestionPool/templates/default/longMenuQuestionPlayer.js');
477 $this->tpl->addOnLoadCode(
'il.test.player.longmenu.init(' 478 . $this->
object->getMinAutoComplete() .
', ' 479 . json_encode($this->
object->getAvailableAnswerOptions())
482 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
489 if (!$this->
object->feedbackOBJ->specificAnswerFeedbackExists()) {
493 $feedback =
'<table class="test_specific_feedback"><tbody>';
494 $gaps = $this->
object->getCorrectAnswers();
495 foreach ($gaps as $index => $answer) {
497 $caption .= $index + 1 .
': ';
499 $feedback .=
'<tr><td>';
501 $feedback .= $caption .
'</td><td>';
502 $feedback .= $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
508 $feedback .=
'</tbody></table>';
536 $aggregation = array();
537 foreach ($relevant_answers as $answer) {
538 $overview[$answer[
'active_fi']][$answer[
'pass']][$answer[
'value1']] = $answer[
'value2'];
541 foreach ($overview as $active) {
542 foreach ($active as $answer) {
543 foreach ($answer as $option => $value) {
544 $aggregation[$option][$value] = $aggregation[$option][$value] + 1;
548 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_longmenu_question_answers_table.html',
true,
true,
"Modules/TestQuestionPool");
549 $json = json_decode($this->
object->getJsonStructure());
550 foreach ($json as
$key => $value) {
552 if (array_key_exists(
$key, $aggregation)) {
553 $aggregate = $aggregation[
$key];
554 foreach ($aggregate as $answer => $counts) {
569 $correct_answers = $this->
object->getCorrectAnswers();
570 $answers = $this->
object->getAnswers();
571 foreach ($text_array as
$key => $value) {
572 $answer_is_correct =
false;
575 if (
$key <
sizeof($text_array) - 1) {
576 if (!array_key_exists(
$key, $correct_answers)) {
577 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'longmenu_answeroptions_differ'));
581 if (array_key_exists(
$key, $user_solution)) {
582 $user_value = $user_solution[
$key];
583 if (in_array($user_value, $correct_answers[
$key][0])) {
584 $answer_is_correct =
true;
590 if (array_key_exists(
$key, $user_solution)) {
591 $user_value = $user_solution[
$key];
592 if (in_array($user_value, $correct_answers[
$key][0])) {
593 $answer_is_correct =
true;
600 return $return_value;
605 $tpl =
new ilTemplate(
"tpl.il_as_qpl_longmenu_question_text_gap.html",
true,
true,
"Modules/TestQuestionPool");
628 $tpl =
new ilTemplate(
"tpl.il_as_qpl_longmenu_question_select_gap.html",
true,
true,
"Modules/TestQuestionPool");
634 if ($user_value == -1) {
649 foreach ($answers as $value) {
652 if ($value == $user_value) {
663 return array_keys($this->
object->getAnswers());
670 foreach ($relevantAnswers as $row) {
671 if ($row[
'value1'] != $questionIndex) {
675 if (!isset($answers[$row[
'value2']])) {
678 $answers[$row[
'value2']] = array(
679 'answer' => $row[
'value2'],
'frequency' => 0
683 $answers[$row[
'value2']][
'frequency']++;
693 $table = parent::getAnswerFrequencyTableGUI(
702 $DIC->language()->txt(
'tst_corrections_answers_tbl_subindex'),
703 $DIC->language()->txt(
'longmenu') .
' ' . ($questionIndex + 1)
712 $correctAnswers = $this->
object->getCorrectAnswers();
714 foreach ($this->
object->getAnswers() as $lmIndex => $lm) {
716 'answers_all' => array(0 => $lm),
717 'answers_all_count' => count($lm),
718 'answers_correct' => $correctAnswers[$lmIndex][0]
721 $lmPoints = $correctAnswers[$lmIndex][1];
724 $section->setTitle($this->
lng->txt(
'longmenu') .
' ' . ($lmIndex + 1));
728 $this->
lng->txt(
'answers'),
729 'longmenu_' . $lmIndex
734 $lmInput->setValues($lmValues);
739 $pointsInp->setRequired(
true);
740 $pointsInp->allowDecimals(
true);
741 $pointsInp->setSize(4);
742 $pointsInp->setMinValue(0);
743 $pointsInp->setMinvalueShouldBeGreater(
false);
744 $pointsInp->setValue($lmPoints);
754 $correctAnswers = $this->
object->getCorrectAnswers();
756 foreach ($this->
object->getAnswers() as $lmIndex => $lm) {
757 $pointsInput = (float) str_replace(
',',
'.', $form->
getInput(
'points_' . $lmIndex));
758 $correctAnswersInput = (array) $form->
getInput(
'longmenu_' . $lmIndex .
'_tags');
760 foreach ($correctAnswersInput as $idx => $answer) {
761 if (in_array($answer, $lm)) {
765 unset($correctAnswersInput[$idx]);
768 $correctAnswersInput = array_values($correctAnswersInput);
770 $correctAnswers[$lmIndex][0] = $correctAnswersInput;
771 $correctAnswers[$lmIndex][1] = $pointsInput;
774 $this->
object->setCorrectAnswers($correctAnswers);
isTestPresentationContext()
hasCorrectSolution($activeId, $passIndex)
generateCorrectnessIconsForCorrectness(int $correctness)
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
buildBasicEditFormObject()
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
This is how a factory for glyphs looks like.
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
const CSS_CLASS_FEEDBACK_CORRECT
ilGlobalPageTemplate $tpl
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
writeQuestionGenericPostData()
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
const CSS_CLASS_FEEDBACK_WRONG
Basic GUI class for assessment questions.
saveTaxonomyAssignments()
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
This class represents a text area property in a property form.
const ADDITIONAL_CONTENT_EDITING_MODE_RTE
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static _getUsedHTMLTags(string $a_module="")
Returns an array of all allowed HTML tags for text editing.
getGenericFeedbackOutput(int $active_id, ?int $pass)