ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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  include_once "./Modules/TestQuestionPool/classes/class.assTextQuestion.php";
49  $this->object = new assTextQuestion();
50  if ($id >= 0) {
51  $this->object->loadFromDb($id);
52  }
53  }
54 
58  protected function writePostData(bool $always = false): int
59  {
60  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
61  if (!$hasErrors) {
62  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
66  $this->saveTaxonomyAssignments();
67  return 0;
68  }
69  return 1;
70  }
71 
77  public function editQuestion($checkonly = false): bool
78  {
79  $save = $this->isSaveCommand();
80  $this->getQuestionTemplate();
81 
82  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
83  $form = new ilPropertyFormGUI();
84  $this->editForm = $form;
85 
86  $form->setFormAction($this->ctrl->getFormAction($this));
87  $form->setTitle($this->outQuestionType());
88  $form->setMultipart(true);
89  $form->setTableWidth("100%");
90  $form->setId("asstextquestion");
91 
92  $this->addBasicQuestionFormProperties($form);
94  $this->populateAnswerSpecificFormPart($form);
95 
96 
97  $this->populateTaxonomyFormSection($form);
98 
99  $this->addQuestionFormCommandButtons($form);
100 
101  $errors = false;
102 
103  if ($save) {
104  $form->setValuesByPost();
105  $errors = !$form->checkInput();
106  $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
107  if ($errors) {
108  $checkonly = false;
109  }
110  }
111 
112  if (!$checkonly) {
113  $this->tpl->setVariable("QUESTION_DATA", $form->getHTML());
114  }
115  return $errors;
116  }
117 
118  private static function buildAnswerTextOnlyArray($answers): array
119  {
120  $answerTexts = array();
121 
122  foreach ($answers as $answer) {
123  $answerTexts[] = $answer->getAnswertext();
124  }
125 
126  return $answerTexts;
127  }
128 
129  public function magicAfterTestOutput(): void
130  {
131  // TODO - BEGIN: what exactly is done here? cant we use the parent method?
132 
133  include_once "./Services/RTE/classes/class.ilRTE.php";
134  $rtestring = ilRTE::_getRTEClassname();
135  include_once "./Services/RTE/classes/class.$rtestring.php";
136  $rte = new $rtestring();
137  $rte->addUserTextEditor("textinput");
138  $this->outAdditionalOutput();
139 
140  // TODO - END: what exactly is done here? cant we use the parent method?
141  }
142 
155  public function getSolutionOutput(
156  $active_id,
157  $pass = null,
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
165  ): string {
166  // get the solution of the user for the active pass or from the last pass if allowed
167 
168 
169  if (($active_id > 0) && (!$show_correct_solution)) {
170  $user_solution = $this->getUserAnswer($active_id, $pass);
171  $solution = $user_solution;
172  } else {
173  $solution = $this->getBestAnswer($this->renderPurposeSupportsFormHtml());
174  }
175 
176  // generate the question output
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");
180 
181  $solution = $this->object->getHtmlUserSolutionPurifier()->purify($solution);
182  if ($this->renderPurposeSupportsFormHtml()) {
183  $template->setCurrentBlock('essay_div');
184  $template->setVariable("DIV_ESSAY", $this->object->prepareTextareaOutput($solution, true));
185  } else {
186  $template->setCurrentBlock('essay_textarea');
187  $template->setVariable("TA_ESSAY", $this->object->prepareTextareaOutput($solution, true, true));
188  }
189  $template->parseCurrentBlock();
190 
191  if (!$show_correct_solution) {
192  $max_no_of_chars = $this->object->getMaxNumOfChars();
193 
194  if ($max_no_of_chars == 0) {
195  $max_no_of_chars = ucfirst($this->lng->txt('unlimited'));
196  }
197 
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>');
201 
202  if ($this->object->isWordCounterEnabled()) {
203  $template->setCurrentBlock('word_count');
204  $template->setVariable(
205  'WORD_COUNT',
206  $this->lng->txt('qst_essay_written_words') .
207  ' <b>' . $this->object->countWords($solution) . '</b>'
208  );
209  $template->parseCurrentBlock();
210  }
211  }
212  if (($active_id > 0) && (!$show_correct_solution)) {
213  if ($graphicalOutput) {
214  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_NOT_OK);
215  $reached_points = $this->object->getReachedPoints($active_id, $pass);
216  if ($reached_points == $this->object->getMaximumPoints()) {
217  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_OK);
218  } elseif ($reached_points > 0) {
219  $correctness_icon = $this->generateCorrectnessIconsForCorrectness(self::CORRECTNESS_MOSTLY_OK);
220  }
221  $template->setCurrentBlock("icon_ok");
222  $template->setVariable("ICON_OK", $correctness_icon);
223  $template->parseCurrentBlock();
224  }
225  }
226  if ($show_question_text == true) {
227  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
228  }
229  $questionoutput = $template->get();
230 
231  $feedback = '';
232  if ($show_feedback) {
233  if (!$this->isTestPresentationContext()) {
234  $fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
235  $feedback .= strlen($fb) ? $fb : '';
236  }
237  }
238  if (strlen($feedback)) {
239  $cssClass = (
240  $this->hasCorrectSolution($active_id, $pass) ?
242  );
243 
244  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
245  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
246  }
247 
248  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
249 
250  $solutionoutput = $solutiontemplate->get();
251  if (!$show_question_only) {
252  // get page object output
253  $solutionoutput = $this->getILIASPage($solutionoutput);
254  }
255  return $solutionoutput;
256  }
257 
271  public function getAutoSavedSolutionOutput(
272  $active_id,
273  $pass = null,
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
282  ): string {
283  // get the solution of the user for the active pass or from the last pass if allowed
284 
285  $user_solution = $this->getUserAnswer($active_id, $pass);
286 
287  if (($active_id > 0) && (!$show_correct_solution)) {
288  $solution = $user_solution;
289  } else {
290  $solution = $this->getBestAnswer($this->renderPurposeSupportsFormHtml());
291  }
292 
293  // generate the question output
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");
297 
298  $solution = '';
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();
305  }
306  $solution = $this->object->getHtmlUserSolutionPurifier()->purify($autosaved_solution);
307  if ($this->renderPurposeSupportsFormHtml()) {
308  $template->setCurrentBlock('essay_div');
309  $template->setVariable("DIV_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true));
310  } else {
311  $template->setCurrentBlock('essay_textarea');
312  $template->setVariable("TA_ESSAY", ilLegacyFormElementsUtil::prepareTextareaOutput($solution, true, true));
313  }
314  $template->parseCurrentBlock();
315  }
316 
317  if (!$show_correct_solution) {
318  $max_no_of_chars = $this->object->getMaxNumOfChars();
319 
320  if ($max_no_of_chars == 0) {
321  $max_no_of_chars = ucfirst($this->lng->txt('unlimited'));
322  }
323 
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>');
327 
328  if ($this->object->isWordCounterEnabled()) {
329  $template->setCurrentBlock('word_count');
330  $template->setVariable(
331  'WORD_COUNT',
332  $this->lng->txt('qst_essay_written_words') .
333  ' <b>' . $this->object->countWords($solution) . '</b>'
334  );
335  $template->parseCurrentBlock();
336  }
337  }
338  if ($show_question_text == true) {
339  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
340  }
341  $questionoutput = $template->get();
342 
343  $feedback = '';
344  if ($show_feedback) {
345  if (!$this->isTestPresentationContext()) {
346  $fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
347  $feedback .= strlen($fb) ? $fb : '';
348  }
349  }
350  if (strlen($feedback)) {
351  $cssClass = (
352  $this->hasCorrectSolution($active_id, $pass) ?
354  );
355 
356  $solutiontemplate->setVariable("ILC_FB_CSS_CLASS", $cssClass);
357  $solutiontemplate->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
358  }
359 
360  $solutiontemplate->setVariable("SOLUTION_OUTPUT", $questionoutput);
361 
362  $solutionoutput = $solutiontemplate->get();
363  if (!$show_question_only) {
364  // get page object output
365  $solutionoutput = $this->getILIASPage($solutionoutput);
366  }
367  return $solutionoutput;
368  }
369 
370  private function getBestAnswer($asHtml): string
371  {
372  $answers = $this->object->getAnswers();
373  if (!count($answers)) {
374  return '';
375  }
376 
377  if ($asHtml) {
378  $tplFile = 'tpl.il_as_qpl_text_question_best_solution_html.html';
379  } else {
380  $tplFile = 'tpl.il_as_qpl_text_question_best_solution_ta.html';
381  }
382 
383  $tpl = new ilTemplate($tplFile, true, true, 'Modules/TestQuestionPool');
384 
385  foreach ($answers as $answer) {
386  $keywordString = '';
387  if (in_array($this->object->getKeywordRelation(), assTextQuestion::getScoringModesWithPointsByKeyword())) {
388  $keywordString .= (string) $answer->getPoints() . ' ';
389  if ($answer->getPoints() === 1.0 || $answer->getPoints() === -1.0) {
390  $keywordString .= $this->lng->txt('point');
391  } else {
392  $keywordString .= $this->lng->txt('points');
393  }
394  $keywordString .= ' ' . $this->lng->txt('for') . ' ';
395  }
396  $keywordString .= $answer->getAnswertext();
397 
398  $tpl->setCurrentBlock('keyword');
399  $tpl->setVariable('KEYWORD', $keywordString);
401  }
402 
403  $tpl->setVariable('KEYWORD_HEADER', $this->lng->txt('solution_contain_keywords'));
404  $tpl->setVariable('SCORING_LABEL', $this->lng->txt('essay_scoring_mode') . ': ');
405 
406  switch ($this->object->getKeywordRelation()) {
407  case 'any':
408  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_any'));
409  break;
410  case 'all':
411  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_all'));
412  break;
413  case 'one':
414  $tpl->setVariable('SCORING_MODE', $this->lng->txt('essay_scoring_mode_keyword_relation_one'));
415  break;
416  }
417 
418  return $tpl->get();
419  }
420 
421  private function getUserAnswer($active_id, $pass)
422  {
423  $user_solution = "";
424  $solutions = $this->object->getSolutionValues($active_id, $pass);
425  foreach ($solutions as $idx => $solution_value) {
426  $user_solution = $solution_value["value1"];
427  }
428  return $user_solution;
429  }
430 
431  public function getPreview($show_question_only = false, $showInlineFeedback = false): string
432  {
433  // generate the question output
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();
449  }
450 
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();
456  }
457 
458  if (is_object($this->getPreviewSession())) {
459  $template->setVariable(
460  "ESSAY",
462  (string) $this->getPreviewSession()->getParticipantsSolution()
463  )
464  );
465  }
466 
467  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
468  $template->setVariable("QID", $this->object->getId());
469 
470  $questionoutput = $template->get();
471 
472  $questionoutput .= $this->getJsCode();
473 
474  if (!$show_question_only) {
475  // get page object output
476  $questionoutput = $this->getILIASPage($questionoutput);
477  }
478  return $questionoutput;
479  }
480 
481  public function getTestOutput($active_id, $pass = null, $is_postponed = false, $use_post_solutions = false, $inlineFeedback = false): string
482  {
483  // get the solution of the user for the active pass or from the last pass if allowed
484  $user_solution = "";
485  if ($active_id) {
486  $solutions = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
487  foreach ($solutions as $idx => $solution_value) {
488  $user_solution = $solution_value["value1"];
489  }
490 
491  if ($this->tiny_mce_enabled) {
492  $user_solution = htmlentities($user_solution);
493  }
494 
495  $user_solution = str_replace(['{', '}', '\\'], ['&#123;', '&#125;', '&#92;'], $user_solution);
496  }
497 
498  // generate the question output
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();
514  }
515 
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();
521  }
522 
523  $template->setVariable("QID", $this->object->getId());
524  $template->setVariable("ESSAY", $user_solution);
525  $template->setVariable("QUESTIONTEXT", $this->object->getQuestionForHTMLOutput());
526  $questionoutput = $template->get();
527 
528  $questionoutput .= $this->getJsCode();
529 
530  $pageoutput = $this->outQuestionPage("", $is_postponed, $active_id, $questionoutput);
531  include_once "./Services/YUI/classes/class.ilYuiUtil.php";
533  return $pageoutput;
534  }
535 
536  protected function getJsCode(): string
537  {
538  $tpl = new ilTemplate('tpl.charcounter.html', true, true, 'Modules/TestQuestionPool');
539 
540  $tpl->setCurrentBlock('tinymce_handler');
541  $tpl->touchBlock('tinymce_handler');
543 
544  if ($this->object->getMaxNumOfChars() > 0) {
545  $tpl->setCurrentBlock('letter_counter_js');
546  $tpl->setVariable("MAXCHARS", $this->object->getMaxNumOfChars());
548  }
549 
550  if ($this->object->isWordCounterEnabled()) {
551  $tpl->setCurrentBlock('word_counter_js');
552  $tpl->touchBlock('word_counter_js');
554  }
555 
556  $tpl->setCurrentBlock('counter_js');
557  $tpl->setVariable("QID", $this->object->getId());
559 
560  $this->tpl->addOnLoadCode('mcQuestionCharCounterInit();');
561  return $tpl->get();
562  }
563 
564  public function addSuggestedSolution(): void
565  {
566  ilSession::set("subquestion_index", 0);
567  if ($_POST["cmd"]["addSuggestedSolution"]) {
568  if ($this->writePostData()) {
569  $this->tpl->setOnScreenMessage('info', $this->getErrorMessage());
570  $this->editQuestion();
571  return;
572  }
573  // @MBECKER: Check this in running test
574  if (!$this->checkInput()) {
575  $this->tpl->setOnScreenMessage('info', $this->lng->txt("fill_out_all_required_fields_add_answer"));
576  $this->editQuestion();
577  return;
578  }
579  }
580  $this->object->saveToDb();
581  $this->ctrl->setParameter($this, "q_id", $this->object->getId());
582  $this->tpl->setVariable("HEADER", $this->object->getTitleForHTMLOutput());
583  $this->getQuestionTemplate();
584  }
585 
586  public function getSpecificFeedbackOutput(array $userSolution): string
587  {
588  return '';
589  }
590 
592  {
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']);
597  }
598 
599  public function writeAnswerSpecificPostData(ilPropertyFormGUI $form): void
600  {
601  $points = 0;
602  switch ($this->object->getKeywordRelation()) {
603  case 'non':
604  $this->object->setAnswers(array());
605  $points = str_replace(',', '.', $_POST['non_keyword_points'] ?? '');
606  break;
607  case 'any':
608  $this->object->setAnswers($_POST['any_keyword']);
609  $points = $this->object->getMaximumPoints();
610  break;
611  case 'all':
612  $this->object->setAnswers($_POST['all_keyword']);
613  $points = str_replace(',', '.', $_POST['all_keyword_points'] ?? '');
614  break;
615  case 'one':
616  $this->object->setAnswers($_POST['one_keyword']);
617  $points = (float) str_replace(',', '.', $_POST['one_keyword_points'] ?? '');
618  break;
619  }
620  $this->object->setPoints((float) $points);
621  }
622 
624  {
625  // wordcounter
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());
629  $form->addItem($wordcounter);
630 
631  // maxchars
632  $maxchars = new ilNumberInputGUI($this->lng->txt("maxchars"), "maxchars");
633  $maxchars->setSize(5);
634  $maxchars->setMinValue(1);
635  if ($this->object->getMaxNumOfChars() > 0) {
636  $maxchars->setValue($this->object->getMaxNumOfChars());
637  }
638  $maxchars->setInfo($this->lng->txt("description_maxchars"));
639  $form->addItem($maxchars);
640 
641  // text rating
642  $textrating = new ilSelectInputGUI($this->lng->txt("text_rating"), "text_rating");
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")
651  );
652  $textrating->setOptions($text_options);
653  $textrating->setValue($this->object->getTextRating());
654  $form->addItem($textrating);
655 
656  return $form;
657  }
658 
660  {
661  $scoringMode = new ilRadioGroupInputGUI(
662  $this->lng->txt('essay_scoring_mode'),
663  'scoring_mode'
664  );
665 
666  $scoringOptionNone = new ilRadioOption(
667  $this->lng->txt('essay_scoring_mode_without_keywords'),
668  'non',
669  $this->lng->txt(
670  'essay_scoring_mode_without_keywords_desc'
671  )
672  );
673  $scoringOptionAnyKeyword = new ilRadioOption(
674  $this->lng->txt('essay_scoring_mode_keyword_relation_any'),
675  'any',
676  $this->lng->txt(
677  'essay_scoring_mode_keyword_relation_any_desc'
678  )
679  );
680  $scoringOptionAllKeyword = new ilRadioOption(
681  $this->lng->txt('essay_scoring_mode_keyword_relation_all'),
682  'all',
683  $this->lng->txt(
684  'essay_scoring_mode_keyword_relation_all_desc'
685  )
686  );
687  $scoringOptionOneKeyword = new ilRadioOption(
688  $this->lng->txt('essay_scoring_mode_keyword_relation_one'),
689  'one',
690  $this->lng->txt(
691  'essay_scoring_mode_keyword_relation_one_desc'
692  )
693  );
694 
695  $scoringMode->addOption($scoringOptionNone);
696  $scoringMode->addOption($scoringOptionAnyKeyword);
697  $scoringMode->addOption($scoringOptionAllKeyword);
698  $scoringMode->addOption($scoringOptionOneKeyword);
699  $scoringMode->setRequired(true);
700  $scoringMode->setValue(
701  strlen($this->object->getKeywordRelation()) ? $this->object->getKeywordRelation(
702  ) : 'non'
703  );
704 
705  if ($this->object->getAnswerCount() == 0) {
706  $this->object->addAnswer("", 1, 0, 0);
707  }
708  require_once "./Modules/TestQuestionPool/classes/class.ilEssayKeywordWizardInputGUI.php";
709 
710  // Without Keywords
711  $nonKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "non_keyword_points");
712  $nonKeywordPoints->allowDecimals(true);
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);
719 
720  // Any Keyword
721  $anyKeyword = new ilEssayKeywordWizardInputGUI($this->lng->txt("answers"), "any_keyword");
722  $anyKeyword->setRequired(true);
723  $anyKeyword->setQuestionObject($this->object);
724  $anyKeyword->setSingleline(true);
725  $anyKeyword->setValues($this->object->getAnswers());
726  $scoringOptionAnyKeyword->addSubItem($anyKeyword);
727 
728  // All Keywords
729  $allKeyword = new ilTextWizardInputGUI($this->lng->txt("answers"), "all_keyword");
730  $allKeyword->setRequired(true);
731  //$allKeyword->setQuestionObject($this->object);
732  //$allKeyword->setSingleline(TRUE);
733  $allKeyword->setValues(self::buildAnswerTextOnlyArray($this->object->getAnswers()));
734  $allKeyword->setMaxLength($anyKeyword->getMaxLength());
735  $scoringOptionAllKeyword->addSubItem($allKeyword);
736  $allKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "all_keyword_points");
737  $allKeywordPoints->allowDecimals(true);
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);
744 
745  // One Keywords
746  $oneKeyword = new ilTextWizardInputGUI($this->lng->txt("answers"), "one_keyword");
747  $oneKeyword->setRequired(true);
748  //$oneKeyword->setQuestionObject($this->object);
749  //$oneKeyword->setSingleline(TRUE);
750  $oneKeyword->setValues(self::buildAnswerTextOnlyArray($this->object->getAnswers()));
751  $oneKeyword->setMaxLength($anyKeyword->getMaxLength());
752  $scoringOptionOneKeyword->addSubItem($oneKeyword);
753  $oneKeywordPoints = new ilNumberInputGUI($this->lng->txt("points"), "one_keyword_points");
754  $oneKeywordPoints->allowDecimals(true);
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);
761 
762  $form->addItem($scoringMode);
763  return $form;
764  }
765 
776  {
777  return array();
778  }
779 
790  {
791  return array();
792  }
793 
800  public function getAggregatedAnswersView(array $relevant_answers): string
801  {
802  return ''; //print_r($relevant_answers,true);
803  }
804 
805  public function isAnswerFreuqencyStatisticSupported(): bool
806  {
807  return false;
808  }
809 
810  public function getAnswersFrequency($relevantAnswers, $questionIndex): array
811  {
812  return array();
813  }
814 
816  {
817  $this->populateQuestionSpecificFormPart($form);
818  $this->populateAnswerSpecificFormPart($form);
819 
820  $form->removeItemByPostVar('maxchars');
821  }
822 
827  {
828  $this->writeQuestionSpecificPostData($form);
829  $this->writeAnswerSpecificPostData($form);
830  }
831 }
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.
$errors
Definition: imgupload.php:65
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.
This class represents a checkbox property in a property form.
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from $_POST and applies them to the data object.
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)
allowDecimals(bool $a_value)
This class represents a property in a property 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...
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
This class represents a number property in a property form.
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)
{}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setRequired(bool $a_required)
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.
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
$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 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...
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)