45 $this->tiny_mce_enabled = (
new ilSetting(
'advanced_editing'))->
get(
'advanced_editing_javascript_editor')
46 ===
'tinymce' ? true :
false;
48 include_once
"./Modules/TestQuestionPool/classes/class.assTextQuestion.php";
51 $this->
object->loadFromDb(
$id);
60 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
62 require_once
'Services/Form/classes/class.ilPropertyFormGUI.php';
82 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
84 $this->editForm = $form;
86 $form->setFormAction($this->
ctrl->getFormAction($this));
88 $form->setMultipart(
true);
89 $form->setTableWidth(
"100%");
90 $form->setId(
"asstextquestion");
104 $form->setValuesByPost();
105 $errors = !$form->checkInput();
106 $form->setValuesByPost();
113 $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
120 $answerTexts = array();
122 foreach ($answers as $answer) {
123 $answerTexts[] = $answer->getAnswertext();
133 include_once
"./Services/RTE/classes/class.ilRTE.php";
135 include_once
"./Services/RTE/classes/class.$rtestring.php";
136 $rte =
new $rtestring();
137 $rte->addUserTextEditor(
"textinput");
158 $graphicalOutput =
false,
159 $result_output =
false,
160 $show_question_only =
true,
161 $show_feedback =
false,
162 $show_correct_solution =
false,
163 $show_manual_scoring =
false,
164 $show_question_text =
true 169 if (($active_id > 0) && (!$show_correct_solution)) {
171 $solution = $user_solution;
177 include_once
"./Services/UICore/classes/class.ilTemplate.php";
178 $template =
new ilTemplate(
"tpl.il_as_qpl_text_question_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
179 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
181 $solution = $this->
object->getHtmlUserSolutionPurifier()->purify($solution);
183 $template->setCurrentBlock(
'essay_div');
184 $template->setVariable(
"DIV_ESSAY", $this->
object->prepareTextareaOutput($solution,
true));
186 $template->setCurrentBlock(
'essay_textarea');
187 $template->setVariable(
"TA_ESSAY", $this->
object->prepareTextareaOutput($solution,
true,
true));
189 $template->parseCurrentBlock();
191 if (!$show_correct_solution) {
192 $max_no_of_chars = $this->
object->getMaxNumOfChars();
194 if ($max_no_of_chars == 0) {
195 $max_no_of_chars = ucfirst($this->
lng->txt(
'unlimited'));
198 $act_no_of_chars = $this->
object->countLetters($solution);
199 $template->setVariable(
"CHARACTER_INFO",
'<b>' . $max_no_of_chars .
'</b>' .
200 $this->
lng->txt(
'answer_characters') .
' <b>' . $act_no_of_chars .
'</b>');
202 if ($this->
object->isWordCounterEnabled()) {
203 $template->setCurrentBlock(
'word_count');
204 $template->setVariable(
206 $this->
lng->txt(
'qst_essay_written_words') .
207 ' <b>' . $this->
object->countWords($solution) .
'</b>' 209 $template->parseCurrentBlock();
212 if (($active_id > 0) && (!$show_correct_solution)) {
213 if ($graphicalOutput) {
215 $reached_points = $this->
object->getReachedPoints($active_id, $pass);
216 if ($reached_points == $this->
object->getMaximumPoints()) {
218 } elseif ($reached_points > 0) {
221 $template->setCurrentBlock(
"icon_ok");
222 $template->setVariable(
"ICON_OK", $correctness_icon);
223 $template->parseCurrentBlock();
226 if ($show_question_text ==
true) {
227 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
229 $questionoutput = $template->get();
232 if ($show_feedback) {
235 $feedback .= strlen($fb) ? $fb :
'';
238 if (strlen($feedback)) {
244 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
245 $solutiontemplate->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($feedback,
true));
248 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
250 $solutionoutput = $solutiontemplate->get();
251 if (!$show_question_only) {
255 return $solutionoutput;
274 $graphicalOutput =
false,
275 $result_output =
false,
276 $show_question_only =
true,
277 $show_feedback =
false,
278 $show_correct_solution =
false,
279 $show_manual_scoring =
false,
280 $show_question_text =
true,
281 $show_autosave_title =
false 287 if (($active_id > 0) && (!$show_correct_solution)) {
288 $solution = $user_solution;
294 include_once
"./Services/UICore/classes/class.ilTemplate.php";
295 $template =
new ilTemplate(
"tpl.il_as_qpl_text_question_output_solution.html",
true,
true,
"Modules/TestQuestionPool");
296 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"Modules/TestQuestionPool");
299 $autosaved_solution = $this->
object->getLatestAutosaveContent($active_id, $pass);
300 if (!is_null($autosaved_solution)) {
301 if ($show_autosave_title) {
302 $template->setCurrentBlock(
'autosave_title');
303 $template->setVariable(
'AUTOSAVE_TITLE', $this->
lng->txt(
'autosavecontent'));
304 $template->parseCurrentBlock();
306 $solution = $this->
object->getHtmlUserSolutionPurifier()->purify($autosaved_solution);
308 $template->setCurrentBlock(
'essay_div');
311 $template->setCurrentBlock(
'essay_textarea');
314 $template->parseCurrentBlock();
317 if (!$show_correct_solution) {
318 $max_no_of_chars = $this->
object->getMaxNumOfChars();
320 if ($max_no_of_chars == 0) {
321 $max_no_of_chars = ucfirst($this->
lng->txt(
'unlimited'));
324 $act_no_of_chars = $this->
object->countLetters($solution);
325 $template->setVariable(
"CHARACTER_INFO",
'<b>' . $max_no_of_chars .
'</b>' .
326 $this->
lng->txt(
'answer_characters') .
' <b>' . $act_no_of_chars .
'</b>');
328 if ($this->
object->isWordCounterEnabled()) {
329 $template->setCurrentBlock(
'word_count');
330 $template->setVariable(
332 $this->
lng->txt(
'qst_essay_written_words') .
333 ' <b>' . $this->
object->countWords($solution) .
'</b>' 335 $template->parseCurrentBlock();
338 if ($show_question_text ==
true) {
339 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
341 $questionoutput = $template->get();
344 if ($show_feedback) {
347 $feedback .= strlen($fb) ? $fb :
'';
350 if (strlen($feedback)) {
356 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
357 $solutiontemplate->setVariable(
"FEEDBACK", $this->
object->prepareTextareaOutput($feedback,
true));
360 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
362 $solutionoutput = $solutiontemplate->get();
363 if (!$show_question_only) {
367 return $solutionoutput;
372 $answers = $this->
object->getAnswers();
373 if (!count($answers)) {
378 $tplFile =
'tpl.il_as_qpl_text_question_best_solution_html.html';
380 $tplFile =
'tpl.il_as_qpl_text_question_best_solution_ta.html';
383 $tpl =
new ilTemplate($tplFile,
true,
true,
'Modules/TestQuestionPool');
385 foreach ($answers as $answer) {
388 $keywordString .= (string) $answer->getPoints() .
' ';
389 if ($answer->getPoints() === 1.0 || $answer->getPoints() === -1.0) {
390 $keywordString .= $this->
lng->txt(
'point');
392 $keywordString .= $this->
lng->txt(
'points');
394 $keywordString .=
' ' . $this->
lng->txt(
'for') .
' ';
396 $keywordString .= $answer->getAnswertext();
406 switch ($this->
object->getKeywordRelation()) {
408 $tpl->
setVariable(
'SCORING_MODE', $this->
lng->txt(
'essay_scoring_mode_keyword_relation_any'));
411 $tpl->
setVariable(
'SCORING_MODE', $this->
lng->txt(
'essay_scoring_mode_keyword_relation_all'));
414 $tpl->
setVariable(
'SCORING_MODE', $this->
lng->txt(
'essay_scoring_mode_keyword_relation_one'));
424 $solutions = $this->
object->getSolutionValues($active_id, $pass);
425 foreach ($solutions as $idx => $solution_value) {
426 $user_solution = $solution_value[
"value1"];
428 return $user_solution;
431 public function getPreview($show_question_only =
false, $showInlineFeedback =
false): string
434 include_once
"./Services/UICore/classes/class.ilTemplate.php";
435 $template =
new ilTemplate(
"tpl.il_as_qpl_text_question_output.html",
true,
true,
"Modules/TestQuestionPool");
436 if ($this->
object->getMaxNumOfChars()) {
437 $template->setCurrentBlock(
"maximum_char_hint");
438 $template->setVariable(
"MAXIMUM_CHAR_HINT", sprintf($this->
lng->txt(
"text_maximum_chars_allowed"), $this->
object->getMaxNumOfChars()));
439 $template->parseCurrentBlock();
440 #mbecker: No such block. $template->setCurrentBlock("has_maxchars"); 441 $template->setVariable(
"MAXCHARS", $this->
object->getMaxNumOfChars());
442 $template->parseCurrentBlock();
443 $template->setCurrentBlock(
"maxchars_counter");
444 $template->setVariable(
"QID", $this->
object->getId());
445 $template->setVariable(
"MAXCHARS", $this->
object->getMaxNumOfChars());
446 $template->setVariable(
"TEXTBOXSIZE", strlen($this->
object->getMaxNumOfChars()));
447 $template->setVariable(
"CHARACTERS", $this->
lng->txt(
"qst_essay_chars_remaining"));
448 $template->parseCurrentBlock();
451 if ($this->
object->isWordCounterEnabled()) {
452 $template->setCurrentBlock(
"word_counter");
453 $template->setVariable(
"QID", $this->
object->getId());
454 $template->setVariable(
"WORDCOUNTER", $this->
lng->txt(
"qst_essay_allready_written_words"));
455 $template->parseCurrentBlock();
459 $template->setVariable(
467 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
468 $template->setVariable(
"QID", $this->
object->getId());
470 $questionoutput = $template->get();
474 if (!$show_question_only) {
478 return $questionoutput;
481 public function getTestOutput($active_id, $pass = null, $is_postponed =
false, $use_post_solutions =
false, $inlineFeedback =
false): string
486 $solutions = $this->
object->getUserSolutionPreferingIntermediate($active_id, $pass);
487 foreach ($solutions as $idx => $solution_value) {
488 $user_solution = $solution_value[
"value1"];
491 if ($this->tiny_mce_enabled) {
492 $user_solution = htmlentities($user_solution);
495 $user_solution = str_replace([
'{',
'}',
'\\'], [
'{',
'}',
'\'], $user_solution);
499 include_once
"./Services/UICore/classes/class.ilTemplate.php";
500 $template =
new ilTemplate(
"tpl.il_as_qpl_text_question_output.html",
true,
true,
"Modules/TestQuestionPool");
501 if ($this->
object->getMaxNumOfChars()) {
502 $template->setCurrentBlock(
"maximum_char_hint");
503 $template->setVariable(
"MAXIMUM_CHAR_HINT", sprintf($this->
lng->txt(
"text_maximum_chars_allowed"), $this->
object->getMaxNumOfChars()));
504 $template->parseCurrentBlock();
505 #mbecker: No such block. $template->setCurrentBlock("has_maxchars"); 506 $template->setVariable(
"MAXCHARS", $this->
object->getMaxNumOfChars());
507 $template->parseCurrentBlock();
508 $template->setCurrentBlock(
"maxchars_counter");
509 $template->setVariable(
"MAXCHARS", $this->
object->getMaxNumOfChars());
510 $template->setVariable(
"QID", $this->
object->getId());
511 $template->setVariable(
"TEXTBOXSIZE", strlen($this->
object->getMaxNumOfChars()));
512 $template->setVariable(
"CHARACTERS", $this->
lng->txt(
"qst_essay_chars_remaining"));
513 $template->parseCurrentBlock();
516 if ($this->
object->isWordCounterEnabled()) {
517 $template->setCurrentBlock(
"word_counter");
518 $template->setVariable(
"QID", $this->
object->getId());
519 $template->setVariable(
"WORDCOUNTER", $this->
lng->txt(
"qst_essay_allready_written_words"));
520 $template->parseCurrentBlock();
523 $template->setVariable(
"QID", $this->
object->getId());
524 $template->setVariable(
"ESSAY", $user_solution);
525 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
526 $questionoutput = $template->get();
530 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
531 include_once
"./Services/YUI/classes/class.ilYuiUtil.php";
538 $tpl =
new ilTemplate(
'tpl.charcounter.html',
true,
true,
'Modules/TestQuestionPool');
544 if ($this->
object->getMaxNumOfChars() > 0) {
550 if ($this->
object->isWordCounterEnabled()) {
560 $this->tpl->addOnLoadCode(
'mcQuestionCharCounterInit();');
567 if ($_POST[
"cmd"][
"addSuggestedSolution"]) {
574 if (!$this->checkInput()) {
575 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
"fill_out_all_required_fields_add_answer"));
580 $this->
object->saveToDb();
581 $this->
ctrl->setParameter($this,
"q_id", $this->
object->getId());
582 $this->tpl->setVariable(
"HEADER", $this->
object->getTitleForHTMLOutput());
593 $this->
object->setWordCounterEnabled(isset($_POST[
'wordcounter']) && $_POST[
'wordcounter']);
594 $this->
object->setMaxNumOfChars($_POST[
"maxchars"] ?? 0);
595 $this->
object->setTextRating($_POST[
"text_rating"]);
596 $this->
object->setKeywordRelation($_POST[
'scoring_mode']);
602 switch ($this->
object->getKeywordRelation()) {
604 $this->
object->setAnswers(array());
605 $points = str_replace(
',',
'.', $_POST[
'non_keyword_points'] ??
'');
608 $this->
object->setAnswers($_POST[
'any_keyword']);
609 $points = $this->
object->getMaximumPoints();
612 $this->
object->setAnswers($_POST[
'all_keyword']);
613 $points = str_replace(
',',
'.', $_POST[
'all_keyword_points'] ??
'');
616 $this->
object->setAnswers($_POST[
'one_keyword']);
617 $points = (float) str_replace(
',',
'.', $_POST[
'one_keyword_points'] ??
'');
620 $this->
object->setPoints((
float) $points);
626 $wordcounter =
new ilCheckboxInputGUI($this->
lng->txt(
'qst_essay_wordcounter_enabled'),
'wordcounter');
627 $wordcounter->
setInfo($this->
lng->txt(
'qst_essay_wordcounter_enabled_info'));
628 $wordcounter->setChecked($this->
object->isWordCounterEnabled());
634 $maxchars->setMinValue(1);
635 if ($this->
object->getMaxNumOfChars() > 0) {
636 $maxchars->setValue($this->
object->getMaxNumOfChars());
638 $maxchars->setInfo($this->
lng->txt(
"description_maxchars"));
643 $text_options = array(
644 "ci" => $this->
lng->txt(
"cloze_textgap_case_insensitive"),
645 "cs" => $this->
lng->txt(
"cloze_textgap_case_sensitive"),
646 "l1" => sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"1"),
647 "l2" => sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"2"),
648 "l3" => sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"3"),
649 "l4" => sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"4"),
650 "l5" => sprintf($this->
lng->txt(
"cloze_textgap_levenshtein_of"),
"5")
652 $textrating->setOptions($text_options);
653 $textrating->setValue($this->
object->getTextRating());
662 $this->
lng->txt(
'essay_scoring_mode'),
667 $this->
lng->txt(
'essay_scoring_mode_without_keywords'),
670 'essay_scoring_mode_without_keywords_desc' 674 $this->
lng->txt(
'essay_scoring_mode_keyword_relation_any'),
677 'essay_scoring_mode_keyword_relation_any_desc' 681 $this->
lng->txt(
'essay_scoring_mode_keyword_relation_all'),
684 'essay_scoring_mode_keyword_relation_all_desc' 688 $this->
lng->txt(
'essay_scoring_mode_keyword_relation_one'),
691 'essay_scoring_mode_keyword_relation_one_desc' 695 $scoringMode->addOption($scoringOptionNone);
696 $scoringMode->addOption($scoringOptionAnyKeyword);
697 $scoringMode->addOption($scoringOptionAllKeyword);
698 $scoringMode->addOption($scoringOptionOneKeyword);
699 $scoringMode->setRequired(
true);
701 strlen($this->
object->getKeywordRelation()) ? $this->
object->getKeywordRelation(
705 if ($this->
object->getAnswerCount() == 0) {
706 $this->
object->addAnswer(
"", 1, 0, 0);
708 require_once
"./Modules/TestQuestionPool/classes/class.ilEssayKeywordWizardInputGUI.php";
713 $nonKeywordPoints->setValue($this->
object->getPoints());
714 $nonKeywordPoints->setRequired(
true);
715 $nonKeywordPoints->setSize(3);
716 $nonKeywordPoints->setMinValue(0.0);
717 $nonKeywordPoints->setMinvalueShouldBeGreater(
true);
718 $scoringOptionNone->
addSubItem($nonKeywordPoints);
723 $anyKeyword->setQuestionObject($this->
object);
724 $anyKeyword->setSingleline(
true);
725 $anyKeyword->setValues($this->
object->getAnswers());
726 $scoringOptionAnyKeyword->
addSubItem($anyKeyword);
733 $allKeyword->setValues(self::buildAnswerTextOnlyArray($this->
object->getAnswers()));
734 $allKeyword->setMaxLength($anyKeyword->getMaxLength());
735 $scoringOptionAllKeyword->
addSubItem($allKeyword);
738 $allKeywordPoints->setValue($this->
object->getPoints());
739 $allKeywordPoints->setRequired(
true);
740 $allKeywordPoints->setSize(3);
741 $allKeywordPoints->setMinValue(0.0);
742 $allKeywordPoints->setMinvalueShouldBeGreater(
true);
743 $scoringOptionAllKeyword->
addSubItem($allKeywordPoints);
750 $oneKeyword->setValues(self::buildAnswerTextOnlyArray($this->
object->getAnswers()));
751 $oneKeyword->setMaxLength($anyKeyword->getMaxLength());
752 $scoringOptionOneKeyword->
addSubItem($oneKeyword);
755 $oneKeywordPoints->setValue($this->
object->getPoints());
756 $oneKeywordPoints->setRequired(
true);
757 $oneKeywordPoints->setSize(3);
758 $oneKeywordPoints->setMinValue(0.0);
759 $oneKeywordPoints->setMinvalueShouldBeGreater(
true);
760 $scoringOptionOneKeyword->
addSubItem($oneKeywordPoints);
static _getRTEClassname()
isTestPresentationContext()
hasCorrectSolution($activeId, $passIndex)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAnswersFrequency($relevantAnswers, $questionIndex)
generateCorrectnessIconsForCorrectness(int $correctness)
static getScoringModesWithPointsByKeyword()
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
__construct($id=-1)
assTextQuestionGUI constructor
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
static initDomEvent(?ilGlobalTemplateInterface $a_main_tpl=null)
Init YUI DomEvent used in Services/Calendar, Modules/Session, Modules/Test (Jan 2022) ...
getPreview($show_question_only=false, $showInlineFeedback=false)
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
const CSS_CLASS_FEEDBACK_CORRECT
ilGlobalPageTemplate $tpl
getAggregatedAnswersView(array $relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
editQuestion($checkonly=false)
Creates an output of the edit form for the question.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
getAutoSavedSolutionOutput( $active_id, $pass=null, $graphicalOutput=false, $result_output=false, $show_question_only=true, $show_feedback=false, $show_correct_solution=false, $show_manual_scoring=false, $show_question_text=true, $show_autosave_title=false)
Get the question solution output.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
writeQuestionGenericPostData()
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
getUserAnswer($active_id, $pass)
setValue(string $a_value)
getSpecificFeedbackOutput(array $userSolution)
const CSS_CLASS_FEEDBACK_WRONG
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
writePostData(bool $always=false)
{}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getTestOutput($active_id, $pass=null, $is_postponed=false, $use_post_solutions=false, $inlineFeedback=false)
touchBlock(string $blockname)
overwrites ITX::touchBlock.
static buildAnswerTextOnlyArray($answers)
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
saveTaxonomyAssignments()
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
getSolutionOutput( $active_id, $pass=null, $graphicalOutput=false, $result_output=false, $show_question_only=true, $show_feedback=false, $show_correct_solution=false, $show_manual_scoring=false, $show_question_text=true)
Get the question solution output.
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
outAdditionalOutput()
Why are you here? Some magic for plugins?
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
static set(string $a_var, $a_val)
Set a value.
isAnswerFreuqencyStatisticSupported()
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
renderPurposeSupportsFormHtml()
getGenericFeedbackOutput(int $active_id, ?int $pass)