ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 
70  public function editQuestion(
71  bool $checkonly = false,
72  ?bool $is_save_cmd = null
73  ): bool {
74  $save = $is_save_cmd ?? $this->isSaveCommand();
75 
76  $form = new ilPropertyFormGUI();
77  $this->editForm = $form;
78 
79  $form->setFormAction($this->ctrl->getFormAction($this));
80  $form->setTitle($this->outQuestionType());
81  $form->setMultipart(true);
82  $form->setTableWidth("100%");
83  $form->setId("asstextquestion");
84 
85  $this->addBasicQuestionFormProperties($form);
87  $this->populateAnswerSpecificFormPart($form);
88 
89 
90  $this->populateTaxonomyFormSection($form);
91 
92  $this->addQuestionFormCommandButtons($form);
93 
94  $errors = false;
95 
96  if ($save) {
97  $form->setValuesByPost();
98  $errors = !$form->checkInput();
99  $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
100  if ($errors) {
101  $checkonly = false;
102  }
103  }
104 
105  if (!$checkonly) {
106  $this->renderEditForm($form);
107  }
108  return $errors;
109  }
110 
111  private static function buildAnswerTextOnlyArray($answers): array
112  {
113  $answerTexts = [];
114 
115  foreach ($answers as $answer) {
116  $answerTexts[] = $answer->getAnswertext();
117  }
118 
119  return $answerTexts;
120  }
121 
122  public function magicAfterTestOutput(): void
123  {
124  // TODO - BEGIN: what exactly is done here? cant we use the parent method?
125  $rtestring = ilRTE::_getRTEClassname();
126  $rte = new $rtestring();
127  $rte->addUserTextEditor('textarea.textinput');
128 
129  // TODO - END: what exactly is done here? cant we use the parent method?
130  }
131 
132  public function getSolutionOutput(
133  int $active_id,
134  ?int $pass = null,
135  bool $graphical_output = false,
136  bool $result_output = false,
137  bool $show_question_only = true,
138  bool $show_feedback = false,
139  bool $show_correct_solution = false,
140  bool $show_manual_scoring = false,
141  bool $show_question_text = true,
142  bool $show_inline_feedback = true
143  ): string {
144  if (($active_id > 0) && (!$show_correct_solution)) {
145  $solution = $this->getUserAnswer($active_id, $pass);
146  } else {
147  $solution = $this->getBestAnswer($this->renderPurposeSupportsFormHtml());
148  }
149 
150  return $this->renderSolutionOutput(
151  $solution,
152  $active_id,
153  $pass,
154  $graphical_output,
155  $result_output,
156  $show_question_only,
157  $show_feedback,
158  $show_correct_solution,
159  $show_manual_scoring,
160  $show_question_text,
161  false,
162  false,
163  );
164  }
165 
166  public function renderSolutionOutput(
167  mixed $user_solutions,
168  int $active_id,
169  ?int $pass,
170  bool $graphical_output = false,
171  bool $result_output = false,
172  bool $show_question_only = true,
173  bool $show_feedback = false,
174  bool $show_correct_solution = false,
175  bool $show_manual_scoring = false,
176  bool $show_question_text = true,
177  bool $show_autosave_title = false,
178  bool $show_inline_feedback = false,
179  ): ?string {
180 
181  $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", true, true, "components/ILIAS/TestQuestionPool");
182  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "components/ILIAS/TestQuestionPool");
183 
184  $solution = $this->object->getHtmlUserSolutionPurifier()->purify($user_solutions);
185  if ($this->renderPurposeSupportsFormHtml()) {
186  $template->setCurrentBlock('essay_div');
187  $template->setVariable("DIV_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true));
188  } else {
189  $template->setCurrentBlock('essay_textarea');
190  $template->setVariable("TA_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true, true));
191  }
192  $template->parseCurrentBlock();
193 
194  if (!$show_correct_solution) {
195  $max_no_of_chars = $this->object->getMaxNumOfChars();
196 
197  if ($max_no_of_chars == 0) {
198  $max_no_of_chars = ucfirst($this->lng->txt('unlimited'));
199  }
200 
201  $act_no_of_chars = $this->object->countLetters($solution);
202  $template->setVariable("CHARACTER_INFO", '<b>' . $max_no_of_chars . '</b>' .
203  $this->lng->txt('answer_characters') . ' <b>' . $act_no_of_chars . '</b>');
204 
205  if ($this->object->isWordCounterEnabled()) {
206  $template->setCurrentBlock('word_count');
207  $template->setVariable(
208  'WORD_COUNT',
209  $this->lng->txt('qst_essay_written_words') .
210  ' <b>' . $this->object->countWords($solution) . '</b>'
211  );
212  $template->parseCurrentBlock();
213  }
214  }
215  if (($active_id > 0) && (!$show_correct_solution)) {
216  if ($graphical_output) {
217  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_NOT_OK);
218  $reached_points = $this->object->getReachedPoints($active_id, $pass);
219  if ($reached_points == $this->object->getMaximumPoints()) {
220  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_OK);
221  } elseif ($reached_points > 0) {
222  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_MOSTLY_OK);
223  }
224  $template->setCurrentBlock("icon_ok");
225  $template->setVariable("ICON_OK", $correctness_icon);
226  $template->parseCurrentBlock();
227  }
228  }
229  if ($show_question_text == true) {
230  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
231  }
232  $questionoutput = $template->get();
233 
234  $feedback = '';
235  if ($show_feedback) {
236  if (!$this->isTestPresentationContext()) {
237  $fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
238  $feedback .= strlen($fb) ? $fb : '';
239  }
240  }
241  if (strlen($feedback)) {
242  $cssClass = (
243  $this->hasCorrectSolution($active_id, $pass) ?
245  );
246 
247  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
248  $solutiontemplate->setVariable("FEEDBACK", ilLegacyFormElementsUtil::prepareTextareaOutput($feedback, true));
249  }
250 
251  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
252 
253  $solutionoutput = $solutiontemplate->get();
254  if (!$show_question_only) {
255  // get page object output
256  $solutionoutput = $this->getILIASPage($solutionoutput);
257  }
258  return $solutionoutput;
259  }
260 
261  public function getAutoSavedSolutionOutput(
262  int $active_id,
263  ?int $pass = null,
264  bool $graphical_output = false,
265  bool $result_output = false,
266  bool $show_question_only = true,
267  bool $show_feedback = false,
268  bool $show_correct_solution = false,
269  bool $show_manual_scoring = false,
270  bool $show_question_text = true,
271  bool $show_autosave_title = false,
272  bool $show_inline_feedback = false,
273  ): string {
274  $user_solution = $this->getUserAnswer($active_id, $pass);
275 
276  if (($active_id > 0) && (!$show_correct_solution)) {
277  $solution = $user_solution;
278  } else {
279  $solution = $this->getBestAnswer($this->renderPurposeSupportsFormHtml());
280  }
281 
282  $template = new ilTemplate("tpl.il_as_qpl_text_question_output_solution.html", true, true, "components/ILIAS/TestQuestionPool");
283  $solutiontemplate = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "components/ILIAS/TestQuestionPool");
284 
285  $solution = '';
286  $autosaved_solution = $this->object->getLatestAutosaveContent($active_id, $pass);
287  if ($autosaved_solution !== null) {
288  if ($show_autosave_title) {
289  $template->setCurrentBlock('autosave_title');
290  $template->setVariable('AUTOSAVE_TITLE', $this->lng->txt('autosavecontent'));
291  $template->parseCurrentBlock();
292  }
293  $solution = $this->object->getHtmlUserSolutionPurifier()->purify($autosaved_solution);
294  if ($this->renderPurposeSupportsFormHtml()) {
295  $template->setCurrentBlock('essay_div');
296  $template->setVariable("DIV_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true));
297  } else {
298  $template->setCurrentBlock('essay_textarea');
299  $template->setVariable("TA_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true, true));
300  }
301  $template->parseCurrentBlock();
302  }
303 
304  if (!$show_correct_solution) {
305  $max_no_of_chars = $this->object->getMaxNumOfChars();
306 
307  if ($max_no_of_chars == 0) {
308  $max_no_of_chars = ucfirst($this->lng->txt('unlimited'));
309  }
310 
311  $act_no_of_chars = $this->object->countLetters($solution);
312  $template->setVariable("CHARACTER_INFO", '<b>' . $max_no_of_chars . '</b>' .
313  $this->lng->txt('answer_characters') . ' <b>' . $act_no_of_chars . '</b>');
314 
315  if ($this->object->isWordCounterEnabled()) {
316  $template->setCurrentBlock('word_count');
317  $template->setVariable(
318  'WORD_COUNT',
319  $this->lng->txt('qst_essay_written_words') .
320  ' <b>' . $this->object->countWords($solution) . '</b>'
321  );
322  $template->parseCurrentBlock();
323  }
324  }
325  if ($show_question_text == true) {
326  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
327  }
328  $questionoutput = $template->get();
329 
330  $feedback = '';
331  if ($show_feedback) {
332  if (!$this->isTestPresentationContext()) {
333  $fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
334  $feedback .= strlen($fb) ? $fb : '';
335  }
336  }
337  if (strlen($feedback)) {
338  $cssClass = (
339  $this->hasCorrectSolution($active_id, $pass) ?
341  );
342 
343  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
344  $solutiontemplate->setVariable("FEEDBACK", ilLegacyFormElementsUtil::prepareTextareaOutput($feedback, true));
345  }
346 
347  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
348 
349  $solutionoutput = $solutiontemplate->get();
350  if (!$show_question_only) {
351  // get page object output
352  $solutionoutput = $this->getILIASPage($solutionoutput);
353  }
354  return $solutionoutput;
355  }
356 
357  private function getBestAnswer($asHtml): string
358  {
359  $answers = $this->object->getAnswers();
360  if (!count($answers)) {
361  return '';
362  }
363 
364  if ($asHtml) {
365  $tplFile = 'tpl.il_as_qpl_text_question_best_solution_html.html';
366  } else {
367  $tplFile = 'tpl.il_as_qpl_text_question_best_solution_ta.html';
368  }
369 
370  $tpl = new ilTemplate($tplFile, true, true, 'components/ILIAS/TestQuestionPool');
371 
372  foreach ($answers as $answer) {
373  $keywordString = '';
374  if (in_array($this->object->getKeywordRelation(), assTextQuestion::getScoringModesWithPointsByKeyword())) {
375  $keywordString .= (string) $answer->getPoints() . ' ';
376  if ($answer->getPoints() === 1.0 || $answer->getPoints() === -1.0) {
377  $keywordString .= $this->lng->txt('point');
378  } else {
379  $keywordString .= $this->lng->txt('points');
380  }
381  $keywordString .= ' ' . $this->lng->txt('for') . ' ';
382  }
383  $keywordString .= $answer->getAnswertext();
384 
385  $tpl->setCurrentBlock('keyword');
386  $tpl->setVariable('KEYWORD', $keywordString);
388  }
389 
390  $tpl->setVariable('KEYWORD_HEADER', $this->lng->txt('solution_contain_keywords'));
391  $tpl->setVariable('SCORING_LABEL', $this->lng->txt('essay_scoring_mode') . ': ');
392 
393  switch ($this->object->getKeywordRelation()) {
395  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_any'));
396  break;
398  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_all'));
399  break;
401  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_one'));
402  break;
403  }
404 
405  return $tpl->get();
406  }
407 
408  private function getUserAnswer($active_id, $pass)
409  {
410  $user_solution = "";
411  $solutions = $this->object->getSolutionValues($active_id, $pass);
412  foreach ($solutions as $idx => $solution_value) {
413  $user_solution = $solution_value["value1"];
414  }
415  return $user_solution;
416  }
417 
418  public function getPreview(
419  bool $show_question_only = false,
420  bool $show_inline_feedback = false
421  ): string {
422  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", true, true, "components/ILIAS/TestQuestionPool");
423  if ($this->object->getMaxNumOfChars()) {
424  $template->setCurrentBlock("maximum_char_hint");
425  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
426  $template->parseCurrentBlock();
427  #mbecker: No such block. $template->setCurrentBlock("has_maxchars");
428  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
429  $template->parseCurrentBlock();
430  $template->setCurrentBlock("maxchars_counter");
431  $template->setVariable("QID", $this->object->getId());
432  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
433  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
434  $template->setVariable("CHARACTERS", $this->lng->txt("qst_essay_chars_remaining"));
435  $template->parseCurrentBlock();
436  }
437 
438  if ($this->object->isWordCounterEnabled()) {
439  $template->setCurrentBlock("word_counter");
440  $template->setVariable("QID", $this->object->getId());
441  $template->setVariable("WORDCOUNTER", $this->lng->txt("qst_essay_allready_written_words"));
442  $template->parseCurrentBlock();
443  }
444 
445  if (is_object($this->getPreviewSession())) {
446  $template->setVariable(
447  "ESSAY",
449  (string) $this->getPreviewSession()->getParticipantsSolution()
450  )
451  );
452  }
453 
454  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
455  $template->setVariable("QID", $this->object->getId());
456 
457  $questionoutput = $template->get();
458 
459  $questionoutput .= $this->getJsCode();
460 
461  if (!$show_question_only) {
462  // get page object output
463  $questionoutput = $this->getILIASPage($questionoutput);
464  }
465  return $questionoutput;
466  }
467 
468  public function getTestOutput(
469  int $active_id,
470  int $pass,
471  bool $is_question_postponed = false,
472  array|bool $user_post_solutions = false,
473  bool $show_specific_inline_feedback = false
474  ): string {
475  // get the solution of the user for the active pass or from the last pass if allowed
476  $user_solution = "";
477  if ($active_id) {
478  $solutions = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
479  foreach ($solutions as $solution_value) {
480  $user_solution = $solution_value["value1"];
481  }
482 
483  if ($this->tiny_mce_enabled) {
484  $user_solution = htmlentities($user_solution);
485  }
486 
487  $user_solution = str_replace(['{', '}', '\\'], ['&#123;', '&#125;', '&#92;'], $user_solution);
488  }
489 
490  $template = new ilTemplate("tpl.il_as_qpl_text_question_output.html", true, true, "components/ILIAS/TestQuestionPool");
491  if ($this->object->getMaxNumOfChars()) {
492  $template->setCurrentBlock("maximum_char_hint");
493  $template->setVariable("MAXIMUM_CHAR_HINT", sprintf($this->lng->txt("text_maximum_chars_allowed"), $this->object->getMaxNumOfChars()));
494  $template->parseCurrentBlock();
495  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
496  $template->parseCurrentBlock();
497  $template->setCurrentBlock("maxchars_counter");
498  $template->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
499  $template->setVariable("QID", $this->object->getId());
500  $template->setVariable("TEXTBOXSIZE", strlen($this->object->getMaxNumOfChars()));
501  $template->setVariable("CHARACTERS", $this->lng->txt("qst_essay_chars_remaining"));
502  $template->parseCurrentBlock();
503  }
504 
505  if ($this->object->isWordCounterEnabled()) {
506  $template->setCurrentBlock("word_counter");
507  $template->setVariable("QID", $this->object->getId());
508  $template->setVariable("WORDCOUNTER", $this->lng->txt("qst_essay_allready_written_words"));
509  $template->parseCurrentBlock();
510  }
511 
512  $template->setVariable("QID", $this->object->getId());
513  $template->setVariable("ESSAY", $user_solution);
514  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
515  $questionoutput = $template->get();
516 
517  $questionoutput .= $this->getJsCode();
518 
519  $pageoutput = $this->outQuestionPage("", $is_question_postponed, $active_id, $questionoutput);
520  return $pageoutput;
521  }
522 
523  protected function getJsCode(): string
524  {
525  $tpl = new ilTemplate('tpl.charcounter.html', true, true, 'components/ILIAS/TestQuestionPool');
526 
527  $tpl->setCurrentBlock('tinymce_handler');
528  $tpl->touchBlock('tinymce_handler');
530 
531  if ($this->object->getMaxNumOfChars() > 0) {
532  $tpl->setCurrentBlock('letter_counter_js');
533  $tpl->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
535  }
536 
537  if ($this->object->isWordCounterEnabled()) {
538  $tpl->setCurrentBlock('word_counter_js');
539  $tpl->touchBlock('word_counter_js');
541  }
542 
543  $tpl->setCurrentBlock('counter_js');
544  $tpl->setVariable("QID", $this->object->getId());
546 
547  $this->tpl->addOnLoadCode('mcQuestionCharCounterInit();');
548  return $tpl->get();
549  }
550 
551  public function addSuggestedSolution(): void
552  {
554  ilSession::set('subquestion_index', 0);
555  $cmd = $this->request_data_collector->rawArray('cmd');
556 
557  if ($cmd['addSuggestedSolution'] && $this->writePostData()) {
558  $this->tpl->setOnScreenMessage('info', $this->getErrorMessage());
559  $this->editQuestion();
560  return;
561  }
562  $this->object->saveToDb();
563  $this->ctrl->setParameter($this, 'q_id', $this->object->getId());
564  $this->tpl->setVariable('HEADER', $this->object->getTitleForHTMLOutput());
565  $this->getQuestionTemplate();
566  }
567 
568  public function getSpecificFeedbackOutput(array $userSolution): string
569  {
570  return '';
571  }
572 
574  {
575  $this->object->setWordCounterEnabled($this->request_data_collector->bool('wordcounter') ?? false);
576  $this->object->setMaxNumOfChars($this->request_data_collector->int('maxchars'));
577  $this->object->setTextRating($this->request_data_collector->string('text_rating'));
578  $this->object->setKeywordRelation($this->request_data_collector->string('scoring_mode'));
579  }
580 
581  public function writeAnswerSpecificPostData(ilPropertyFormGUI $form): void
582  {
583  $points = 0;
584  switch ($this->object->getKeywordRelation()) {
586  $this->object->setAnswers([]);
587  $points = $this->request_data_collector->float('non_keyword_points');
588  break;
590  $this->object->setAnswers($this->request_data_collector->raw('any_keyword'));
591  $points = $this->object->getMaximumPoints();
592  break;
594  $this->object->setAnswers($this->request_data_collector->raw('all_keyword'));
595  $points = $this->request_data_collector->float('all_keyword_points');
596  break;
598  $this->object->setAnswers($this->request_data_collector->raw('one_keyword'));
599  $points = $this->request_data_collector->float('one_keyword_points');
600  break;
601  }
602  $this->object->setPoints((float) $points);
603  }
604 
606  {
607  // wordcounter
608  $wordcounter = new ilCheckboxInputGUI($this->lng->txt('qst_essay_wordcounter_enabled'), 'wordcounter');
609  $wordcounter->setInfo($this->lng->txt('qst_essay_wordcounter_enabled_info'));
610  $wordcounter->setChecked($this->object->isWordCounterEnabled());
611  $form->addItem($wordcounter);
612 
613  // maxchars
614  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
615  $maxchars->setSize(5);
616  $maxchars->setMinValue(1);
617  if ($this->object->getMaxNumOfChars() > 0) {
618  $maxchars->setValue($this->object->getMaxNumOfChars());
619  }
620  $maxchars->setInfo($this->lng->txt("description_maxchars"));
621  $form->addItem($maxchars);
622 
623  // text rating
624  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "text_rating");
625  $text_options = [
626  "ci" => $this->lng->txt("cloze_textgap_case_insensitive"),
627  "cs" => $this->lng->txt("cloze_textgap_case_sensitive"),
628  "l1" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "1"),
629  "l2" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "2"),
630  "l3" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "3"),
631  "l4" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "4"),
632  "l5" => sprintf($this->lng->txt("cloze_textgap_levenshtein_of"), "5")
633  ];
634  $textrating->setOptions($text_options);
635  $textrating->setValue($this->object->getTextRating());
636  $form->addItem($textrating);
637 
638  return $form;
639  }
640 
642  {
643  $scoringMode = new ilRadioGroupInputGUI(
644  $this->lng->txt('essay_scoring_mode'),
645  'scoring_mode'
646  );
647 
648  $scoringOptionNone = new ilRadioOption(
649  $this->lng->txt('essay_scoring_mode_without_keywords'),
651  $this->lng->txt(
652  'essay_scoring_mode_without_keywords_desc'
653  )
654  );
655  $scoringOptionAnyKeyword = new ilRadioOption(
656  $this->lng->txt('essay_scoring_mode_keyword_relation_any'),
658  $this->lng->txt(
659  'essay_scoring_mode_keyword_relation_any_desc'
660  )
661  );
662  $scoringOptionAllKeyword = new ilRadioOption(
663  $this->lng->txt('essay_scoring_mode_keyword_relation_all'),
665  $this->lng->txt(
666  'essay_scoring_mode_keyword_relation_all_desc'
667  )
668  );
669  $scoringOptionOneKeyword = new ilRadioOption(
670  $this->lng->txt('essay_scoring_mode_keyword_relation_one'),
672  $this->lng->txt(
673  'essay_scoring_mode_keyword_relation_one_desc'
674  )
675  );
676 
677  $scoringMode->addOption($scoringOptionNone);
678  $scoringMode->addOption($scoringOptionAnyKeyword);
679  $scoringMode->addOption($scoringOptionAllKeyword);
680  $scoringMode->addOption($scoringOptionOneKeyword);
681  $scoringMode->setRequired(true);
682  $scoringMode->setValue($this->object->getKeywordRelation());
683 
684  if ($this->object->getAnswerCount() == 0) {
685  $this->object->addAnswer("", 1, 0, 0);
686  }
687 
688  // Without Keywords
689  $nonKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "non_keyword_points");
690  $nonKeywordPoints->allowDecimals(true);
691  $nonKeywordPoints->setValue($this->object->getPoints());
692  $nonKeywordPoints->setRequired(true);
693  $nonKeywordPoints->setSize(3);
694  $nonKeywordPoints->setMinValue(0.0);
695  $nonKeywordPoints->setMinvalueShouldBeGreater(true);
696  $scoringOptionNone->addSubItem($nonKeywordPoints);
697 
698  // Any Keyword
699  $anyKeyword = new ilEssayKeywordWizardInputGUI($this->lng->txt("answers"), "any_keyword");
700  $anyKeyword->setRequired(true);
701  $anyKeyword->setQuestionObject($this->object);
702  $anyKeyword->setSingleline(true);
703  $anyKeyword->setValues($this->object->getAnswers());
704  $scoringOptionAnyKeyword->addSubItem($anyKeyword);
705 
706  // All Keywords
707  $allKeyword = new ilTextWizardInputGUI($this->lng->txt("answers"), "all_keyword");
708  $allKeyword->setRequired(true);
709  //$allKeyword->setQuestionObject($this->object);
710  //$allKeyword->setSingleline(TRUE);
711  $allKeyword->setValues(self::buildAnswerTextOnlyArray($this->object->getAnswers()));
712  $allKeyword->setMaxLength($anyKeyword->getMaxLength());
713  $scoringOptionAllKeyword->addSubItem($allKeyword);
714  $allKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "all_keyword_points");
715  $allKeywordPoints->allowDecimals(true);
716  $allKeywordPoints->setValue($this->object->getPoints());
717  $allKeywordPoints->setRequired(true);
718  $allKeywordPoints->setSize(3);
719  $allKeywordPoints->setMinValue(0.0);
720  $allKeywordPoints->setMinvalueShouldBeGreater(true);
721  $scoringOptionAllKeyword->addSubItem($allKeywordPoints);
722 
723  // One Keywords
724  $oneKeyword = new ilTextWizardInputGUI($this->lng->txt("answers"), "one_keyword");
725  $oneKeyword->setRequired(true);
726  //$oneKeyword->setQuestionObject($this->object);
727  //$oneKeyword->setSingleline(TRUE);
728  $oneKeyword->setValues(self::buildAnswerTextOnlyArray($this->object->getAnswers()));
729  $oneKeyword->setMaxLength($anyKeyword->getMaxLength());
730  $scoringOptionOneKeyword->addSubItem($oneKeyword);
731  $oneKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "one_keyword_points");
732  $oneKeywordPoints->allowDecimals(true);
733  $oneKeywordPoints->setValue($this->object->getPoints());
734  $oneKeywordPoints->setRequired(true);
735  $oneKeywordPoints->setSize(3);
736  $oneKeywordPoints->setMinValue(0.0);
737  $oneKeywordPoints->setMinvalueShouldBeGreater(true);
738  $scoringOptionOneKeyword->addSubItem($oneKeywordPoints);
739 
740  $form->addItem($scoringMode);
741  return $form;
742  }
743 
754  {
755  return [];
756  }
757 
768  {
769  return [];
770  }
771 
772  public function isAnswerFreuqencyStatisticSupported(): bool
773  {
774  return false;
775  }
776 
777  public function getAnswersFrequency($relevantAnswers, $questionIndex): array
778  {
779  return [];
780  }
781 
783  {
784  $this->populateQuestionSpecificFormPart($form);
785  $this->populateAnswerSpecificFormPart($form);
786 
787  $form->removeItemByPostVar('maxchars');
788  }
789 
794  {
795  $this->writeQuestionSpecificPostData($form);
796  $this->writeAnswerSpecificPostData($form);
797  }
798 }
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)
generateCorrectnessIconsForCorrectness(int $correctness)
static getScoringModesWithPointsByKeyword()
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
getSolutionOutput(int $active_id, ?int $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_inline_feedback=true)
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)
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from the request and applies them to the data object...
setOptions(array $a_options)
ilGlobalPageTemplate $tpl
static prepareFormOutput($a_str, bool $a_strip=false)
editQuestion(bool $checkonly=false, ?bool $is_save_cmd=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
getTestOutput(int $active_id, int $pass, bool $is_question_postponed=false, array|bool $user_post_solutions=false, bool $show_specific_inline_feedback=false)
This class represents a property in a property form.
Class for text questions.
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)
{}
getAutoSavedSolutionOutput(int $active_id, ?int $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,)
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,)
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 the request 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:24
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPreview(bool $show_question_only=false, bool $show_inline_feedback=false)
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...
const SCORING_MODE_KEYWORD_RELATION_NONE
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)
renderEditForm(ilPropertyFormGUI $form)
getGenericFeedbackOutput(int $active_id, ?int $pass)