ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.assTextQuestionGUI.php
Go to the documentation of this file.
1 <?php
2 
34 {
35  protected bool $tiny_mce_enabled;
43  public function __construct($id = -1)
44  {
45  $this->tiny_mce_enabled = (new ilSetting('advanced_editing'))->get('advanced_editing_javascript_editor')
46  === 'tinymce' ? true : false;
48  $this->object = new assTextQuestion();
49  if ($id >= 0) {
50  $this->object->loadFromDb($id);
51  }
52  }
53 
57  protected function writePostData(bool $always = false): int
58  {
59  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
60  if (!$hasErrors) {
64  $this->saveTaxonomyAssignments();
65  return 0;
66  }
67  return 1;
68  }
69 
75  public function editQuestion($checkonly = false): bool
76  {
77  $save = $this->isSaveCommand();
78  $this->getQuestionTemplate();
79 
80  $form = new ilPropertyFormGUI();
81  $this->editForm = $form;
82 
83  $form->setFormAction($this->ctrl->getFormAction($this));
84  $form->setTitle($this->outQuestionType());
85  $form->setMultipart(true);
86  $form->setTableWidth("100%");
87  $form->setId("asstextquestion");
88 
89  $this->addBasicQuestionFormProperties($form);
91  $this->populateAnswerSpecificFormPart($form);
92 
93 
94  $this->populateTaxonomyFormSection($form);
95 
96  $this->addQuestionFormCommandButtons($form);
97 
98  $errors = false;
99 
100  if ($save) {
101  $form->setValuesByPost();
102  $errors = !$form->checkInput();
103  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
104  if ($errors) {
105  $checkonly = false;
106  }
107  }
108 
109  if (!$checkonly) {
110  $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
111  }
112  return $errors;
113  }
114 
115  private static function buildAnswerTextOnlyArray($answers): array
116  {
117  $answerTexts = [];
118 
119  foreach ($answers as $answer) {
120  $answerTexts[] = $answer->getAnswertext();
121  }
122 
123  return $answerTexts;
124  }
125 
126  public function magicAfterTestOutput(): void
127  {
128  // TODO - BEGIN: what exactly is done here? cant we use the parent method?
129  $rtestring = ilRTE::_getRTEClassname();
130  $rte = new $rtestring();
131  $rte->addUserTextEditor("textinput");
132  $this->outAdditionalOutput();
133 
134  // TODO - END: what exactly is done here? cant we use the parent method?
135  }
136 
149  public function getSolutionOutput(
150  $active_id,
151  $pass = null,
152  $graphicalOutput = false,
153  $result_output = false,
154  $show_question_only = true,
155  $show_feedback = false,
156  $show_correct_solution = false,
157  $show_manual_scoring = false,
158  $show_question_text = true,
159  ): string {
160  // get the solution of the user for the active pass or from the last pass if allowed
161  if (($active_id > 0) && (!$show_correct_solution)) {
162  $solution = $this->getUserAnswer($active_id, $pass);
163  } else {
164  $solution = $this->getBestAnswer($this->renderPurposeSupportsFormHtml());
165  }
166 
167  return $this->renderSolutionOutput(
168  $solution,
169  $active_id,
170  $pass,
171  $graphicalOutput,
172  $result_output,
173  $show_question_only,
174  $show_feedback,
175  $show_correct_solution,
176  $show_manual_scoring,
177  $show_question_text,
178  false,
179  false,
180  );
181  }
182 
183  public function renderSolutionOutput(
184  mixed $user_solutions,
185  int $active_id,
186  ?int $pass,
187  bool $graphical_output = false,
188  bool $result_output = false,
189  bool $show_question_only = true,
190  bool $show_feedback = false,
191  bool $show_correct_solution = false,
192  bool $show_manual_scoring = false,
193  bool $show_question_text = true,
194  bool $show_autosave_title = false,
195  bool $show_inline_feedback = false,
196  ): ?string {
197 
198  $solution = $user_solutions;
199  $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", true, true, "Modules/TestQuestionPool");
200  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
201 
202  $solution = $this->object->getHtmlUserSolutionPurifier()->purify($solution);
203  if ($this->renderPurposeSupportsFormHtml()) {
204  $template->setCurrentBlock('essay_div');
205  $template->setVariable("DIV_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true));
206  } else {
207  $template->setCurrentBlock('essay_textarea');
208  $template->setVariable("TA_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true, true));
209  }
210  $template->parseCurrentBlock();
211 
212  if (!$show_correct_solution) {
213  $max_no_of_chars = $this->object->getMaxNumOfChars();
214 
215  if ($max_no_of_chars == 0) {
216  $max_no_of_chars = ucfirst($this->lng->txt('unlimited'));
217  }
218 
219  $act_no_of_chars = $this->object->countLetters($solution);
220  $template->setVariable("CHARACTER_INFO", '<b>' . $max_no_of_chars . '</b>' .
221  $this->lng->txt('answer_characters') . ' <b>' . $act_no_of_chars . '</b>');
222 
223  if ($this->object->isWordCounterEnabled()) {
224  $template->setCurrentBlock('word_count');
225  $template->setVariable(
226  'WORD_COUNT',
227  $this->lng->txt('qst_essay_written_words') .
228  ' <b>' . $this->object->countWords($solution) . '</b>'
229  );
230  $template->parseCurrentBlock();
231  }
232  }
233  if (($active_id > 0) && (!$show_correct_solution)) {
234  if ($graphical_output) {
235  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_NOT_OK);
236  $reached_points = $this->object->getReachedPoints($active_id, $pass);
237  if ($reached_points == $this->object->getMaximumPoints()) {
238  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_OK);
239  } elseif ($reached_points > 0) {
240  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_MOSTLY_OK);
241  }
242  $template->setCurrentBlock("icon_ok");
243  $template->setVariable("ICON_OK", $correctness_icon);
244  $template->parseCurrentBlock();
245  }
246  }
247  if ($show_question_text == true) {
248  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
249  }
250  $questionoutput = $template->get();
251 
252  $feedback = '';
253  if ($show_feedback) {
254  if (!$this->isTestPresentationContext()) {
255  $fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
256  $feedback .= strlen($fb) ? $fb : '';
257  }
258  }
259  if (strlen($feedback)) {
260  $cssClass = (
261  $this->hasCorrectSolution($active_id, $pass) ?
263  );
264 
265  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
266  $solutiontemplate->setVariable("FEEDBACK", ilLegacyFormElementsUtil::prepareTextareaOutput($feedback, true));
267  }
268 
269  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
270 
271  $solutionoutput = $solutiontemplate->get();
272  if (!$show_question_only) {
273  // get page object output
274  $solutionoutput = $this->getILIASPage($solutionoutput);
275  }
276  return $solutionoutput;
277  }
278 
292  public function getAutoSavedSolutionOutput(
293  $active_id,
294  $pass = null,
295  bool $graphical_output = false,
296  bool $result_output = false,
297  bool $show_question_only = true,
298  bool $show_feedback = false,
299  bool $show_correct_solution = false,
300  bool $show_manual_scoring = false,
301  bool $show_question_text = true,
302  bool $show_autosave_title = false,
303  bool $show_inline_feedback = false,
304  ): string {
305  // get the solution of the user for the active pass or from the last pass if allowed
306 
307  $user_solution = $this->getUserAnswer($active_id, $pass);
308 
309  if (($active_id > 0) && (!$show_correct_solution)) {
310  $solution = $user_solution;
311  } else {
312  $solution = $this->getBestAnswer($this->renderPurposeSupportsFormHtml());
313  }
314 
315  $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", true, true, "Modules/TestQuestionPool");
316  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
317 
318  $solution = '';
319  $autosaved_solution = $this->object->getLatestAutosaveContent($active_id, $pass);
320  if ($autosaved_solution !== null) {
321  if ($show_autosave_title) {
322  $template->setCurrentBlock('autosave_title');
323  $template->setVariable('AUTOSAVE_TITLE', $this->lng->txt('autosavecontent'));
324  $template->parseCurrentBlock();
325  }
326  $solution = $this->object->getHtmlUserSolutionPurifier()->purify($autosaved_solution);
327  if ($this->renderPurposeSupportsFormHtml()) {
328  $template->setCurrentBlock('essay_div');
329  $template->setVariable("DIV_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true));
330  } else {
331  $template->setCurrentBlock('essay_textarea');
332  $template->setVariable("TA_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true, true));
333  }
334  $template->parseCurrentBlock();
335  }
336 
337  if (!$show_correct_solution) {
338  $max_no_of_chars = $this->object->getMaxNumOfChars();
339 
340  if ($max_no_of_chars == 0) {
341  $max_no_of_chars = ucfirst($this->lng->txt('unlimited'));
342  }
343 
344  $act_no_of_chars = $this->object->countLetters($solution);
345  $template->setVariable("CHARACTER_INFO", '<b>' . $max_no_of_chars . '</b>' .
346  $this->lng->txt('answer_characters') . ' <b>' . $act_no_of_chars . '</b>');
347 
348  if ($this->object->isWordCounterEnabled()) {
349  $template->setCurrentBlock('word_count');
350  $template->setVariable(
351  'WORD_COUNT',
352  $this->lng->txt('qst_essay_written_words') .
353  ' <b>' . $this->object->countWords($solution) . '</b>'
354  );
355  $template->parseCurrentBlock();
356  }
357  }
358  if ($show_question_text == true) {
359  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
360  }
361  $questionoutput = $template->get();
362 
363  $feedback = '';
364  if ($show_feedback) {
365  if (!$this->isTestPresentationContext()) {
366  $fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
367  $feedback .= strlen($fb) ? $fb : '';
368  }
369  }
370  if (strlen($feedback)) {
371  $cssClass = (
372  $this->hasCorrectSolution($active_id, $pass) ?
374  );
375 
376  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
377  $solutiontemplate->setVariable("FEEDBACK", ilLegacyFormElementsUtil::prepareTextareaOutput($feedback, true));
378  }
379 
380  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
381 
382  $solutionoutput = $solutiontemplate->get();
383  if (!$show_question_only) {
384  // get page object output
385  $solutionoutput = $this->getILIASPage($solutionoutput);
386  }
387  return $solutionoutput;
388  }
389 
390  private function getBestAnswer($asHtml): string
391  {
392  $answers = $this->object->getAnswers();
393  if (!count($answers)) {
394  return '';
395  }
396 
397  if ($asHtml) {
398  $tplFile = 'tpl.il_as_qpl_text_question_best_solution_html.html';
399  } else {
400  $tplFile = 'tpl.il_as_qpl_text_question_best_solution_ta.html';
401  }
402 
403  $tpl = new ilTemplate($tplFile, true, true, 'Modules/TestQuestionPool');
404 
405  foreach ($answers as $answer) {
406  $keywordString = '';
407  if (in_array($this->object->getKeywordRelation(), assTextQuestion::getScoringModesWithPointsByKeyword())) {
408  $keywordString .= (string) $answer->getPoints() . ' ';
409  if ($answer->getPoints() === 1.0 || $answer->getPoints() === -1.0) {
410  $keywordString .= $this->lng->txt('point');
411  } else {
412  $keywordString .= $this->lng->txt('points');
413  }
414  $keywordString .= ' ' . $this->lng->txt('for') . ' ';
415  }
416  $keywordString .= $answer->getAnswertext();
417 
418  $tpl->setCurrentBlock('keyword');
419  $tpl->setVariable('KEYWORD', $keywordString);
421  }
422 
423  $tpl->setVariable('KEYWORD_HEADER', $this->lng->txt('solution_contain_keywords'));
424  $tpl->setVariable('SCORING_LABEL', $this->lng->txt('essay_scoring_mode') . ': ');
425 
426  switch ($this->object->getKeywordRelation()) {
427  case 'any':
428  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_any'));
429  break;
430  case 'all':
431  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_all'));
432  break;
433  case 'one':
434  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_one'));
435  break;
436  }
437 
438  return $tpl->get();
439  }
440 
441  private function getUserAnswer($active_id, $pass)
442  {
443  $user_solution = "";
444  $solutions = $this->object->getSolutionValues($active_id, $pass);
445  foreach ($solutions as $idx => $solution_value) {
446  $user_solution = $solution_value['value1'];
447  }
448  return $user_solution;
449  }
450 
451  public function getPreview($show_question_only = false, $showInlineFeedback = false): string
452  {
453  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", true, true, "Modules/TestQuestionPool");
454  if ($this->object->getMaxNumOfChars()) {
455  $template->setCurrentBlock("maximum_char_hint");
456  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
457  $template->parseCurrentBlock();
458  #mbecker: No such block. $template->setCurrentBlock("has_maxchars");
459  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
460  $template->parseCurrentBlock();
461  $template->setCurrentBlock("maxchars_counter");
462  $template->setVariable("QID", $this->object->getId());
463  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
464  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
465  $template->setVariable("CHARACTERS", $this->lng->txt("qst_essay_chars_remaining"));
466  $template->parseCurrentBlock();
467  }
468 
469  if ($this->object->isWordCounterEnabled()) {
470  $template->setCurrentBlock("word_counter");
471  $template->setVariable("QID", $this->object->getId());
472  $template->setVariable("WORDCOUNTER", $this->lng->txt("qst_essay_allready_written_words"));
473  $template->parseCurrentBlock();
474  }
475 
476  if (is_object($this->getPreviewSession())) {
477  $template->setVariable(
478  "ESSAY",
480  (string) $this->getPreviewSession()->getParticipantsSolution()
481  )
482  );
483  }
484 
485  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
486  $template->setVariable("QID", $this->object->getId());
487 
488  $questionoutput = $template->get();
489 
490  $questionoutput .= $this->getJsCode();
491 
492  if (!$show_question_only) {
493  // get page object output
494  $questionoutput = $this->getILIASPage($questionoutput);
495  }
496  return $questionoutput;
497  }
498 
499  public function getTestOutput($active_id, $pass = null, $is_postponed = false, $use_post_solutions = false, $inlineFeedback = false): string
500  {
501  // get the solution of the user for the active pass or from the last pass if allowed
502  $user_solution = "";
503  if ($active_id) {
504  $solutions = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
505  foreach ($solutions as $idx => $solution_value) {
506  $user_solution = $solution_value['value1'];
507  }
508 
509  if ($this->tiny_mce_enabled) {
510  $user_solution = htmlentities($user_solution);
511  }
512 
513  $user_solution = str_replace(['{', '}', '\\'], ['&#123;', '&#125;', '&#92;'], $user_solution);
514  }
515 
516  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", true, true, "Modules/TestQuestionPool");
517  if ($this->object->getMaxNumOfChars()) {
518  $template->setCurrentBlock("maximum_char_hint");
519  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
520  $template->parseCurrentBlock();
521  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
522  $template->parseCurrentBlock();
523  $template->setCurrentBlock("maxchars_counter");
524  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
525  $template->setVariable("QID", $this->object->getId());
526  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
527  $template->setVariable("CHARACTERS", $this->lng->txt("qst_essay_chars_remaining"));
528  $template->parseCurrentBlock();
529  }
530 
531  if ($this->object->isWordCounterEnabled()) {
532  $template->setCurrentBlock("word_counter");
533  $template->setVariable("QID", $this->object->getId());
534  $template->setVariable("WORDCOUNTER", $this->lng->txt("qst_essay_allready_written_words"));
535  $template->parseCurrentBlock();
536  }
537 
538  $template->setVariable("QID", $this->object->getId());
539  $template->setVariable("ESSAY", $user_solution);
540  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
541  $questionoutput = $template->get();
542 
543  $questionoutput .= $this->getJsCode();
544 
545  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
547  return $pageoutput;
548  }
549 
550  protected function getJsCode(): string
551  {
552  $tpl = new ilTemplate('tpl.charcounter.html', true, true, 'Modules/TestQuestionPool');
553 
554  $tpl->setCurrentBlock('tinymce_handler');
555  $tpl->touchBlock('tinymce_handler');
557 
558  if ($this->object->getMaxNumOfChars() > 0) {
559  $tpl->setCurrentBlock('letter_counter_js');
560  $tpl->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
562  }
563 
564  if ($this->object->isWordCounterEnabled()) {
565  $tpl->setCurrentBlock('word_counter_js');
566  $tpl->touchBlock('word_counter_js');
568  }
569 
570  $tpl->setCurrentBlock('counter_js');
571  $tpl->setVariable("QID", $this->object->getId());
573 
574  $this->tpl->addOnLoadCode('mcQuestionCharCounterInit();');
575  return $tpl->get();
576  }
577 
578  public function addSuggestedSolution(): void
579  {
580  ilSession::set("subquestion_index", 0);
581  if ($_POST["cmd"]["addSuggestedSolution"]) {
582  if ($this->writePostData()) {
583  $this->tpl->setOnScreenMessage('info', $this->getErrorMessage());
584  $this->editQuestion();
585  return;
586  }
587  // @MBECKER: Check this in running test
588  if (!$this->checkInput()) {
589  $this->tpl->setOnScreenMessage('info', $this->lng->txt("fill_out_all_required_fields_add_answer"));
590  $this->editQuestion();
591  return;
592  }
593  }
594  $this->object->saveToDb();
595  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
596  $this->tpl->setVariable("HEADER", $this->object->getTitleForHTMLOutput());
597  $this->getQuestionTemplate();
598  }
599 
600  public function getSpecificFeedbackOutput(array $userSolution): string
601  {
602  return '';
603  }
604 
606  {
607  $this->object->setWordCounterEnabled(isset($_POST['wordcounter']) && $_POST['wordcounter']);
608  $this->object->setMaxNumOfChars((int) ($_POST["maxchars"] ?? 0));
609  $this->object->setTextRating($_POST["text_rating"]);
610  $this->object->setKeywordRelation($_POST['scoring_mode']);
611  }
612 
613  public function writeAnswerSpecificPostData(ilPropertyFormGUI $form): void
614  {
615  $points = 0;
616  switch ($this->object->getKeywordRelation()) {
617  case 'non':
618  $this->object->setAnswers([]);
619  $points = str_replace(',', '.', $_POST['non_keyword_points'] ?? '');
620  break;
621  case 'any':
622  $this->object->setAnswers($_POST['any_keyword']);
623  $points = $this->object->getMaximumPoints();
624  break;
625  case 'all':
626  $this->object->setAnswers($_POST['all_keyword']);
627  $points = str_replace(',', '.', $_POST['all_keyword_points'] ?? '');
628  break;
629  case 'one':
630  $this->object->setAnswers($_POST['one_keyword']);
631  $points = (float) str_replace(',', '.', $_POST['one_keyword_points'] ?? '');
632  break;
633  }
634  $this->object->setPoints((float) $points);
635  }
636 
638  {
639  // wordcounter
640  $wordcounter = new ilCheckboxInputGUI($this->lng->txt('qst_essay_wordcounter_enabled'), 'wordcounter');
641  $wordcounter->setInfo($this->lng->txt('qst_essay_wordcounter_enabled_info'));
642  $wordcounter->setChecked($this->object->isWordCounterEnabled());
643  $form->addItem($wordcounter);
644 
645  // maxchars
646  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
647  $maxchars->setSize(5);
648  $maxchars->setMinValue(1);
649  if ($this->object->getMaxNumOfChars() > 0) {
650  $maxchars->setValue($this->object->getMaxNumOfChars());
651  }
652  $maxchars->setInfo($this->lng->txt("description_maxchars"));
653  $form->addItem($maxchars);
654 
655  // text rating
656  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "text_rating");
657  $text_options = [
658  "ci" => $this->lng->txt("cloze_textgap_case_insensitive"),
659  "cs" => $this->lng->txt("cloze_textgap_case_sensitive"),
660  "l1" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1"),
661  "l2" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2"),
662  "l3" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3"),
663  "l4" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4"),
664  "l5" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5")
665  ];
666  $textrating->setOptions($text_options);
667  $textrating->setValue($this->object->getTextRating());
668  $form->addItem($textrating);
669 
670  return $form;
671  }
672 
674  {
675  $scoringMode = new ilRadioGroupInputGUI(
676  $this->lng->txt('essay_scoring_mode'),
677  'scoring_mode'
678  );
679 
680  $scoringOptionNone = new ilRadioOption(
681  $this->lng->txt('essay_scoring_mode_without_keywords'),
682  'non',
683  $this->lng->txt(
684  'essay_scoring_mode_without_keywords_desc'
685  )
686  );
687  $scoringOptionAnyKeyword = new ilRadioOption(
688  $this->lng->txt('essay_scoring_mode_keyword_relation_any'),
689  'any',
690  $this->lng->txt(
691  'essay_scoring_mode_keyword_relation_any_desc'
692  )
693  );
694  $scoringOptionAllKeyword = new ilRadioOption(
695  $this->lng->txt('essay_scoring_mode_keyword_relation_all'),
696  'all',
697  $this->lng->txt(
698  'essay_scoring_mode_keyword_relation_all_desc'
699  )
700  );
701  $scoringOptionOneKeyword = new ilRadioOption(
702  $this->lng->txt('essay_scoring_mode_keyword_relation_one'),
703  'one',
704  $this->lng->txt(
705  'essay_scoring_mode_keyword_relation_one_desc'
706  )
707  );
708 
709  $scoringMode->addOption($scoringOptionNone);
710  $scoringMode->addOption($scoringOptionAnyKeyword);
711  $scoringMode->addOption($scoringOptionAllKeyword);
712  $scoringMode->addOption($scoringOptionOneKeyword);
713  $scoringMode->setRequired(true);
714  $scoringMode->setValue($this->object->getKeywordRelation());
715 
716  if ($this->object->getAnswerCount() == 0) {
717  $this->object->addAnswer("", 1, 0, 0);
718  }
719 
720  // Without Keywords
721  $nonKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "non_keyword_points");
722  $nonKeywordPoints->allowDecimals(true);
723  $nonKeywordPoints->setValue($this->object->getPoints());
724  $nonKeywordPoints->setRequired(true);
725  $nonKeywordPoints->setSize(3);
726  $nonKeywordPoints->setMinValue(0.0);
727  $nonKeywordPoints->setMinvalueShouldBeGreater(true);
728  $scoringOptionNone->addSubItem($nonKeywordPoints);
729 
730  // Any Keyword
731  $anyKeyword = new ilEssayKeywordWizardInputGUI($this->lng->txt("answers"), "any_keyword");
732  $anyKeyword->setRequired(true);
733  $anyKeyword->setQuestionObject($this->object);
734  $anyKeyword->setSingleline(true);
735  $anyKeyword->setValues($this->object->getAnswers());
736  $scoringOptionAnyKeyword->addSubItem($anyKeyword);
737 
738  // All Keywords
739  $allKeyword = new ilTextWizardInputGUI($this->lng->txt("answers"), "all_keyword");
740  $allKeyword->setRequired(true);
741  //$allKeyword->setQuestionObject($this->object);
742  //$allKeyword->setSingleline(TRUE);
743  $allKeyword->setValues(self::buildAnswerTextOnlyArray($this->object->getAnswers()));
744  $allKeyword->setMaxLength($anyKeyword->getMaxLength());
745  $scoringOptionAllKeyword->addSubItem($allKeyword);
746  $allKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "all_keyword_points");
747  $allKeywordPoints->allowDecimals(true);
748  $allKeywordPoints->setValue($this->object->getPoints());
749  $allKeywordPoints->setRequired(true);
750  $allKeywordPoints->setSize(3);
751  $allKeywordPoints->setMinValue(0.0);
752  $allKeywordPoints->setMinvalueShouldBeGreater(true);
753  $scoringOptionAllKeyword->addSubItem($allKeywordPoints);
754 
755  // One Keywords
756  $oneKeyword = new ilTextWizardInputGUI($this->lng->txt("answers"), "one_keyword");
757  $oneKeyword->setRequired(true);
758  //$oneKeyword->setQuestionObject($this->object);
759  //$oneKeyword->setSingleline(TRUE);
760  $oneKeyword->setValues(self::buildAnswerTextOnlyArray($this->object->getAnswers()));
761  $oneKeyword->setMaxLength($anyKeyword->getMaxLength());
762  $scoringOptionOneKeyword->addSubItem($oneKeyword);
763  $oneKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "one_keyword_points");
764  $oneKeywordPoints->allowDecimals(true);
765  $oneKeywordPoints->setValue($this->object->getPoints());
766  $oneKeywordPoints->setRequired(true);
767  $oneKeywordPoints->setSize(3);
768  $oneKeywordPoints->setMinValue(0.0);
769  $oneKeywordPoints->setMinvalueShouldBeGreater(true);
770  $scoringOptionOneKeyword->addSubItem($oneKeywordPoints);
771 
772  $form->addItem($scoringMode);
773  return $form;
774  }
775 
786  {
787  return [];
788  }
789 
800  {
801  return [];
802  }
803 
810  public function getAggregatedAnswersView(array $relevant_answers): string
811  {
812  return ''; //print_r($relevant_answers,true);
813  }
814 
815  public function isAnswerFreuqencyStatisticSupported(): bool
816  {
817  return false;
818  }
819 
820  public function getAnswersFrequency($relevantAnswers, $questionIndex): array
821  {
822  return [];
823  }
824 
826  {
827  $this->populateQuestionSpecificFormPart($form);
828  $this->populateAnswerSpecificFormPart($form);
829 
830  $form->removeItemByPostVar('maxchars');
831  }
832 
837  {
838  $this->writeQuestionSpecificPostData($form);
839  $this->writeAnswerSpecificPostData($form);
840  }
841 }
static _getRTEClassname()
hasCorrectSolution($activeId, $passIndex)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getAnswersFrequency($relevantAnswers, $questionIndex)
getAutoSavedSolutionOutput( $active_id, $pass=null, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_autosave_title=false, bool $show_inline_feedback=false,)
Get the question solution output.
generateCorrectnessIconsForCorrectness(int $correctness)
static getScoringModesWithPointsByKeyword()
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
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.
This class represents a selection list property in a property form.
removeItemByPostVar(string $a_post_var, bool $a_remove_unused_headers=false)
__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.
setOptions(array $a_options)
ilGlobalPageTemplate $tpl
static prepareFormOutput($a_str, bool $a_strip=false)
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)
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
writePostData(bool $always=false)
{}
Basic GUI class for assessment questions.
setRequired(bool $a_required)
renderSolutionOutput(mixed $user_solutions, int $active_id, ?int $pass, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_autosave_title=false, bool $show_inline_feedback=false,)
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...
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.
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a text wizard property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free...
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.
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form)
getGenericFeedbackOutput(int $active_id, ?int $pass)