ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.assLongMenuGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Modules/TestQuestionPool/classes/class.assQuestionGUI.php';
5require_once './Modules/TestQuestionPool/interfaces/interface.ilGuiQuestionScoringAdjustable.php';
6include_once './Modules/Test/classes/inc.AssessmentConstants.php';
7
16{
17 private $rbacsystem;
18 private $ilTabs;
19 public $lng;
20
21 public function __construct($id = -1)
22 {
24 include_once './Modules/TestQuestionPool/classes/class.assLongMenu.php';
25 $this->object = new assLongMenu();
26 if ($id >= 0) {
27 $this->object->loadFromDb($id);
28 }
29 global $DIC;
30 $rbacsystem = $DIC['rbacsystem'];
31 $ilTabs = $DIC['ilTabs'];
32 $lng = $DIC['lng'];
33 $this->rbacsystem = $rbacsystem;
34 $this->ilTabs = $ilTabs;
35 $this->lng = $lng;
36 }
37
43 protected function getUserSolution($active_id, $pass)
44 {
45 $user_solution = array();
46 if ($active_id) {
47 // hey: prevPassSolutions - obsolete due to central check
48 #$solutions = NULL;
49 #include_once "./Modules/Test/classes/class.ilObjTest.php";
50 #if (!ilObjTest::_getUsePreviousAnswers($active_id, true))
51 #{
52 # if (is_null($pass)) $pass = ilObjTest::_getPass($active_id);
53 #}
54 $solutions = $this->object->getSolutionValues($active_id, $pass, !$this->getUseIntermediateSolution());
55 //$solutions = $this->object->getTestOutputSolutions($active_id, $pass);
56 // hey.
57 foreach ($solutions as $idx => $solution_value) {
58 $user_solution[$solution_value["value1"]] = $solution_value["value2"];
59 }
60 return $user_solution;
61 }
62 return $user_solution;
63 }
64
65 public function getCommand($cmd)
66 {
67 return $cmd;
68 }
69
73 protected function writePostData($always = false)
74 {
75 $form = $this->buildEditForm();
76 $form->setValuesByPost();
77 $check = $form->checkInput();
80 $custom_check = $this->object->checkQuestionCustomPart($form);
81 if (!$check || !$custom_check) {
82 if (!$custom_check) {
83 ilUtil::sendFailure($this->lng->txt("form_input_not_valid"));
84 }
85 $this->editQuestion($form);
86 return 1;
87 }
89 return 0;
90 }
91
93 {
94 $this->object->setLongMenuTextValue(ilUtil::stripSlashesRecursive($_POST['longmenu_text']));
95 $this->object->setAnswers(json_decode(ilUtil::stripSlashesRecursive($_POST['hidden_text_files'])));
96 $this->object->setCorrectAnswers(json_decode(ilUtil::stripSlashesRecursive($_POST['hidden_correct_answers'])));
97 $this->object->setAnswerType(ilUtil::stripSlashesRecursive($_POST['long_menu_type']));
98 $this->object->setQuestion($_POST['question']);
99 $this->object->setLongMenuTextValue($_POST["longmenu_text"]);
100 $this->object->setMinAutoComplete((int) $_POST["min_auto_complete"]);
101 $this->object->setIdenticalScoring((int) $_POST["identical_scoring"]);
103 }
104
105 protected function editQuestion(ilPropertyFormGUI $form = null)
106 {
107 if ($form === null) {
108 $form = $this->buildEditForm();
109 }
110
111 $this->getQuestionTemplate();
112 $this->tpl->addCss('Modules/Test/templates/default/ta.css');
113
114 $this->tpl->setVariable("QUESTION_DATA", $this->ctrl->getHTML($form));
115 }
119 protected function buildEditForm()
120 {
121 $form = $this->buildBasicEditFormObject();
122
123 $this->addQuestionFormCommandButtons($form);
124
125 $this->addBasicQuestionFormProperties($form);
126
128 $this->populateAnswerSpecificFormPart($form);
129
130 $this->populateTaxonomyFormSection($form);
131
132 return $form;
133 }
139 {
140 $long_menu_text = new ilTextAreaInputGUI($this->lng->txt("longmenu_text"), 'longmenu_text');
141 $long_menu_text->setRequired(true);
142 //$long_menu_text->setInfo($this->lng->txt("longmenu_hint"));
143 $long_menu_text->setRows(10);
144 $long_menu_text->setCols(80);
145 if (!$this->object->getSelfAssessmentEditingMode()) {
146 if ($this->object->getAdditionalContentEditingMode() == assQuestion::ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT) {
147 include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
148 $long_menu_text->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("assessment"));
149 $long_menu_text->addPlugin("latex");
150 $long_menu_text->addButton("latex");
151 $long_menu_text->addButton("pastelatex");
152 $long_menu_text->setRTESupport($this->object->getId(), "qpl", "assessment");
153 $long_menu_text->setUseRte(true);
154 }
155 } else {
156 require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssSelfAssessmentQuestionFormatter.php';
158 $long_menu_text->setUseTagsForRteOnly(false);
159 }
160
161 $long_menu_text->setValue($this->object->prepareTextareaOutput($this->object->getLongMenuTextValue()));
162 $form->addItem($long_menu_text);
163
164 $tpl = new ilTemplate("tpl.il_as_qpl_long_menu_gap_button_code.html", true, true, "Modules/TestQuestionPool");
165 $tpl->setVariable('INSERT_GAP', $this->lng->txt('insert_gap'));
166 $tpl->parseCurrentBlock();
167 $button = new ilCustomInputGUI('&nbsp;', '');
168 $button->setHtml($tpl->get());
169 $form->addItem($button);
170
171 require_once("./Services/UIComponent/Modal/classes/class.ilModalGUI.php");
172 $modal = ilModalGUI::getInstance();
173 $modal->setHeading('');
174 $modal->setId("ilGapModal");
175 //$modal->setBackdrop(ilModalGUI::BACKDROP_OFF);
176 $modal->setBody('');
177
178 $min_auto_complete = new ilNumberInputGUI($this->lng->txt("min_auto_complete"), 'min_auto_complete');
179
180 $auto_complete = $this->object->getMinAutoComplete();
181 if ($auto_complete == 0) {
183 }
184 $min_auto_complete->setValue($auto_complete);
185 $min_auto_complete->setMinValue(1);
186 $min_auto_complete->setMaxValue(99);
187 $min_auto_complete->setSize(5);
188 $form->addItem($min_auto_complete);
189 // identical scoring
190 $identical_scoring = new ilCheckboxInputGUI($this->lng->txt("identical_scoring"), "identical_scoring");
191 $identical_scoring->setValue(1);
192 $identical_scoring->setChecked($this->object->getIdenticalScoring());
193 $identical_scoring->setInfo($this->lng->txt('identical_scoring_desc'));
194 $identical_scoring->setRequired(false);
195 $form->addItem($identical_scoring);
196 $hidden_text = new ilHiddenInputGUI('hidden_text_files');
197 $form->addItem($hidden_text);
198
199 $hidden_correct = new ilHiddenInputGUI('hidden_correct_answers');
200 $form->addItem($hidden_correct);
201
202 $tpl = new ilTemplate("tpl.il_as_qpl_long_menu_gap.html", true, true, "Modules/TestQuestionPool");
203 if (is_array($_POST) && array_key_exists('hidden_text_files', $_POST)) {
204 $tpl->setVariable('CORRECT_ANSWERS', $_POST['hidden_correct_answers']);
205 $tpl->setVariable('ALL_ANSWERS', $_POST['hidden_text_files']);
206 } else {
207 $tpl->setVariable('CORRECT_ANSWERS', $this->object->getJsonStructure());
208 $tpl->setVariable('ALL_ANSWERS', $this->object->getAnswersObject());
209 }
210 $tpl->setVariable('MAX_INPUT_FIELDS', assLongMenu::MAX_INPUT_FIELDS);
211 $tpl->setVariable('GAP_PLACEHOLDER', assLongMenu::GAP_PLACEHOLDER);
212 $tpl->setVariable('SELECT_BOX', $this->lng->txt('insert_gap'));
213 $tpl->setVariable("SELECT", $this->lng->txt('answers_select'));
214 $tpl->setVariable("TEXT", $this->lng->txt('answers_text_box'));
215 $tpl->setVariable("POINTS", $this->lng->txt('points'));
216 $tpl->setVariable("INFO_TEXT_UPLOAD", $this->lng->txt('info_text_upload'));
217 $tpl->setVariable("TXT_BROWSE", $this->lng->txt('select_file'));
218 $tpl->setVariable("MANUAL_EDITING", $this->lng->txt('manual_editing'));
219 $tpl->setVariable("CORRECT_ANSWER_TXT", $this->lng->txt('correct_answers'));
220 $tpl->setVariable("ANSWER_OPTIONS_TXT", $this->lng->txt('answer_options'));
221 $tpl->setVariable("ANSWERS_TXT", $this->lng->txt('answers'));
222 $tpl->setVariable("TYPE_TXT", $this->lng->txt('type'));
223 $tpl->setVariable("EDIT_TXT", $this->lng->txt('edit'));
224 $tpl->setVariable("ADD_ANSWER_TXT", $this->lng->txt('add_answers'));
225 $tpl->setVariable('POINTS_ERROR', $this->lng->txt('enter_enough_positive_points'));
226 $tpl->setVariable('AUTOCOMPLETE_ERROR', $this->lng->txt('autocomplete_error'));
227 $tpl->setVariable('MISSING_VALUE', $this->lng->txt('msg_input_is_required'));
228 $tpl->setVariable('SAVE', $this->lng->txt('save'));
229 $tpl->setVariable('CANCEL', $this->lng->txt('cancel'));
230 require_once("Services/Form/classes/class.ilTagInputGUI.php");
231 $tag_input = new ilTagInputGUI();
232 $tag_input->setTypeAhead(true);
233 $tag_input->setPostVar('taggable');
234 $tag_input->setJsSelfInit(false);
235 $tag_input->setTypeAheadMinLength(1);
236 $tpl->setVariable("TAGGING_PROTOTYPE", $tag_input->render(''));
237
238 $tpl->setVariable("MY_MODAL", $modal->getHTML());
239
240 $tpl->parseCurrentBlock();
241 $button = new ilCustomInputGUI('&nbsp;', '');
242 $button->setHtml($tpl->get());
243 $form->addItem($button);
244 return $form;
245 }
246
252 {
253 return $form;
254 }
255
262 {
263 return true;
264 }
265
279 public function getSolutionOutput(
280 $active_id,
281 $pass = null,
282 $graphicalOutput = false,
283 $result_output = false,
284 $show_question_only = true,
285 $show_feedback = false,
286 $show_correct_solution = false,
287 $show_manual_scoring = false,
288 $show_question_text = true
289 ) {
290 include_once "./Services/UICore/classes/class.ilTemplate.php";
291 $template = new ilTemplate("tpl.il_as_qpl_lome_question_output_solution.html", true, true, "Modules/TestQuestionPool");
292
293 if ($show_question_text) {
294 $question_text = $this->object->getQuestion();
295 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($question_text, true));
296 }
297 if (($active_id > 0) && (!$show_correct_solution)) {
298 $correct_solution = $this->getUserSolution($active_id, $pass);
299 } else {
300 $correct_solution = $this->object->getCorrectAnswersForQuestionSolution($this->object->getId());
301 }
302 $template->setVariable('LONGMENU_TEXT_SOLUTION', $this->getLongMenuTextWithInputFieldsInsteadOfGaps($correct_solution, true, $graphicalOutput));
303 $solution_template = new ilTemplate("tpl.il_as_tst_solution_output.html", true, true, "Modules/TestQuestionPool");
304 $question_output = $template->get();
305 $feedback = '';
306 if ($show_feedback) {
307 if (!$this->isTestPresentationContext()) {
308 $fb = $this->getGenericFeedbackOutput($active_id, $pass);
309 $feedback .= strlen($fb) ? $fb : '';
310 }
311
312 $fb = $this->getSpecificFeedbackOutput(array());
313 $feedback .= strlen($fb) ? $fb : '';
314 }
315 if (strlen($feedback)) {
316 $cssClass = (
317 $this->hasCorrectSolution($active_id, $pass) ?
319 );
320
321 $solution_template->setVariable("ILC_FB_CSS_CLASS", $cssClass);
322 $solution_template->setVariable("FEEDBACK", $this->object->prepareTextareaOutput($feedback, true));
323 }
324
325 $solution_template->setVariable("SOLUTION_OUTPUT", $question_output);
326
327 $solution_output = $solution_template->get();
328
329 if (!$show_question_only) {
330 $solution_output = $this->getILIASPage($solution_output);
331 }
332
333 return $solution_output;
334 }
335
336 public function getPreview($show_question_only = false, $showInlineFeedback = false)
337 {
338 $user_solution = is_object($this->getPreviewSession()) ? (array) $this->getPreviewSession()->getParticipantsSolution() : array();
339 $user_solution = array_values($user_solution);
340
341 include_once "./Services/UICore/classes/class.ilTemplate.php";
342 $template = new ilTemplate("tpl.il_as_qpl_longmenu_output.html", true, true, "Modules/TestQuestionPool");
343
344 $question_text = $this->object->getQuestion();
345 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($question_text, true));
346 $template->setVariable("ANSWER_OPTIONS_JSON", json_encode($this->object->getAvailableAnswerOptions()));
347 $template->setVariable('AUTOCOMPLETE_LENGTH', $this->object->getMinAutoComplete());
348 $template->setVariable('LONGMENU_TEXT', $this->getLongMenuTextWithInputFieldsInsteadOfGaps($user_solution));
349
350 $question_output = $template->get();
351 if (!$show_question_only) {
352 $question_output = $this->getILIASPage($question_output);
353 }
354 return $question_output;
355 }
356
357
358
359 public function getTestOutput(
360 $active_id,
361 // hey: prevPassSolutions - will be always available from now on
362 $pass,
363 // hey.
364 $is_postponed = false,
365 $use_post_solutions = false,
366 $show_feedback = false
367 ) {
368 $user_solution = array();
369 if ($active_id) {
370 $solutions = null;
371 include_once "./Modules/Test/classes/class.ilObjTest.php";
372 if (!ilObjTest::_getUsePreviousAnswers($active_id, true)) {
373 if (is_null($pass)) {
374 $pass = ilObjTest::_getPass($active_id);
375 }
376 }
377 $solutions = $this->object->getUserSolutionPreferingIntermediate($active_id, $pass);
378 foreach ($solutions as $idx => $solution_value) {
379 $user_solution[$solution_value["value1"]] = $solution_value["value2"];
380 }
381 }
382
383 // generate the question output
384 include_once "./Services/UICore/classes/class.ilTemplate.php";
385 $template = new ilTemplate("tpl.il_as_qpl_longmenu_output.html", true, true, "Modules/TestQuestionPool");
386
387 $question_text = $this->object->getQuestion();
388 $template->setVariable("QUESTIONTEXT", $this->object->prepareTextareaOutput($question_text, true));
389 $template->setVariable("ANSWER_OPTIONS_JSON", json_encode($this->object->getAvailableAnswerOptions()));
390 $template->setVariable('LONGMENU_TEXT', $this->getLongMenuTextWithInputFieldsInsteadOfGaps($user_solution));
391 $template->setVariable('AUTOCOMPLETE_LENGTH', $this->object->getMinAutoComplete());
392 $question_output = $template->get();
393 $page_output = $this->outQuestionPage("", $is_postponed, $active_id, $question_output);
394 return $page_output;
395 }
396
403 public function setQuestionTabs()
404 {
405 $this->ilTabs->clearTargets();
406
407 $this->ctrl->setParameterByClass("ilAssQuestionPageGUI", "q_id", $_GET["q_id"]);
408 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
409 $q_type = $this->object->getQuestionType();
410
411 if (strlen($q_type)) {
412 $classname = $q_type . "GUI";
413 $this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
414 $this->ctrl->setParameterByClass(strtolower($classname), "q_id", $_GET["q_id"]);
415 }
416
417 if ($_GET["q_id"]) {
418 if ($this->rbacsystem->checkAccess('write', $_GET["ref_id"])) {
419 // edit page
420 $this->ilTabs->addTarget(
421 "edit_page",
422 $this->ctrl->getLinkTargetByClass("ilAssQuestionPageGUI", "edit"),
423 array("edit", "insert", "exec_pg"),
424 "",
425 "",
426 $force_active
427 );
428 }
429
430 $this->addTab_QuestionPreview($this->ilTabs);
431 }
432
433 $force_active = false;
434 if ($this->rbacsystem->checkAccess('write', $_GET["ref_id"])) {
435 $url = "";
436 if ($classname) {
437 $url = $this->ctrl->getLinkTargetByClass($classname, "editQuestion");
438 }
439 $commands = $_POST["cmd"];
440 if (is_array($commands)) {
441 foreach ($commands as $key => $value) {
442 if (preg_match("/^delete_.*/", $key, $matches)) {
443 $force_active = true;
444 }
445 }
446 }
447 // edit question properties
448 $this->ilTabs->addTarget(
449 "edit_question",
450 $url,
451 array("editQuestion", "save", "saveEdit", "addkvp", "removekvp", "originalSyncForm"),
452 $classname,
453 "",
454 $force_active
455 );
456 }
457
458 // add tab for question feedback within common class assQuestionGUI
459 $this->addTab_QuestionFeedback($this->ilTabs);
460
461 // add tab for question hint within common class assQuestionGUI
462 $this->addTab_QuestionHints($this->ilTabs);
463
464 // add tab for question's suggested solution within common class assQuestionGUI
465 $this->addTab_SuggestedSolution($this->ilTabs, $classname);
466
467 // Assessment of questions sub menu entry
468 if ($_GET["q_id"]) {
469 $this->ilTabs->addTarget(
470 "statistics",
471 $this->ctrl->getLinkTargetByClass($classname, "assessment"),
472 array("assessment"),
473 $classname,
474 ""
475 );
476 }
477
478 $this->addBackTab($this->ilTabs);
479 }
480
481 public function getSpecificFeedbackOutput($userSolution)
482 {
483 if (!$this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->object->getId(), 0, 0)) {
484 return '';
485 }
486
487 $feedback = '<table class="test_specific_feedback"><tbody>';
488 $gaps = $this->object->getCorrectAnswers();
489 foreach ($gaps as $index => $answer) {
490 $caption = assLongMenu::GAP_PLACEHOLDER . ' ';
491 $caption .= $index + 1 . ': ';
492
493 $feedback .= '<tr><td>';
494
495 $feedback .= $caption . '</td><td>';
496 $feedback .= $this->object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation(
497 $this->object->getId(),
498 0,
499 $index
500 ) . '</td> </tr>';
501 }
502 $feedback .= '</tbody></table>';
503 return $this->object->prepareTextareaOutput($feedback, true);
504 }
505
506
517 {
518 return array();
519 }
520
529 public function getAggregatedAnswersView($relevant_answers)
530 {
531 $overview = array();
532 $aggregation = array();
533 foreach ($relevant_answers as $answer) {
534 $overview[$answer['active_fi']][$answer['pass']][$answer['value1']] = $answer['value2'];
535 }
536
537 foreach ($overview as $active) {
538 foreach ($active as $answer) {
539 foreach ($answer as $option => $value) {
540 $aggregation[$option][$value] = $aggregation[$option][$value] + 1;
541 }
542 }
543 }
544 $tpl = new ilTemplate('tpl.il_as_aggregated_long_menu_answers_table.html', true, true, "Modules/TestQuestionPool");
545 $json = json_decode($this->object->getJsonStructure());
546 foreach ($json as $key => $value) {
547 $tpl->setVariable('TITLE', 'Longmenu ' . ($key + 1));
548 if (array_key_exists($key, $aggregation)) {
549 $aggregate = $aggregation[$key];
550 foreach ($aggregate as $answer => $counts) {
551 $tpl->setVariable('OPTION', $answer);
552 $tpl->setVariable('COUNT', $counts);
553 $tpl->parseCurrentBlock();
554 }
555 }
556 }
557
558 return $tpl->get();
559 }
560
561 public function getLongMenuTextWithInputFieldsInsteadOfGaps($user_solution = array(), $solution = false, $graphical = false)
562 {
563 $return_value = '';
564 $text_array = preg_split("/\\[" . assLongMenu::GAP_PLACEHOLDER . " (\\d+)\\]/", $this->object->getLongMenuTextValue());
565 $correct_answers = $this->object->getCorrectAnswers();
566 $answers = $this->object->getAnswers();
567 foreach ($text_array as $key => $value) {
568 $answer_is_correct = false;
569 $user_value = '';
570 $return_value .= $value;
571 if ($key < sizeof($text_array) - 1) {
572 if ($correct_answers[$key][2] == assLongMenu::ANSWER_TYPE_TEXT_VAL) {
573 if (array_key_exists($key, $user_solution)) {
574 $user_value = $user_solution[$key];
575 if (in_array($user_value, $correct_answers[$key][0])) {
576 $answer_is_correct = true;
577 }
578 }
579
580 $return_value .= $this->getTextGapTemplate($key, $user_value, $solution, $answer_is_correct, $graphical);
581 } elseif ($correct_answers[$key][2] == assLongMenu::ANSWER_TYPE_SELECT_VAL) {
582 if (array_key_exists($key, $user_solution)) {
583 $user_value = $user_solution[$key];
584 if (in_array($user_value, $correct_answers[$key][0])) {
585 $answer_is_correct = true;
586 }
587 }
588 $return_value .= $this->getSelectGapTemplate($key, $answers[$key], $user_value, $solution, $answer_is_correct, $graphical);
589 }
590 }
591 }
592 return $return_value;
593 }
594
595 private function getTextGapTemplate($key, $value, $solution, $ok = false, $graphical = false)
596 {
597 $tpl = new ilTemplate("tpl.il_as_qpl_long_menu_text_gap.html", true, true, "Modules/TestQuestionPool");
598 if ($solution) {
599 $tpl->setVariable('DISABLED', 'disabled');
600 $tpl->setVariable('JS_IGNORE', '_ignore');
601 if ($graphical) {
602 if ($ok) {
603 $tpl->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
604 $tpl->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
605 } else {
606 $tpl->setVariable("ICON_OK", ilUtil::getImagePath("icon_not_ok.svg"));
607 $tpl->setVariable("TEXT_OK", $this->lng->txt("answer_is_wrong"));
608 }
609 }
610 }
611 $tpl->setVariable('VALUE', $value);
612 $tpl->setVariable('KEY', $key);
613
614 return $tpl->get();
615 }
616
617 private function getSelectGapTemplate($key, $answers, $user_value, $solution, $ok = false, $graphical = false)
618 {
619 $tpl = new ilTemplate("tpl.il_as_qpl_long_menu_select_gap.html", true, true, "Modules/TestQuestionPool");
620 $tpl->setVariable('KEY', $key);
621 if ($solution) {
622 $tpl->setVariable('DISABLED', 'disabled');
623 $tpl->setVariable('JS_IGNORE', '_ignore');
624 $tpl->setCurrentBlock('best_solution');
625 if ($user_value == -1) {
626 $tpl->setVariable("SOLUTION", $this->lng->txt("please_select"));
627 } else {
628 $tpl->setVariable('SOLUTION', $user_value);
629 }
630 if ($graphical) {
631 if ($ok) {
632 $tpl->setVariable("ICON_OK", ilUtil::getImagePath("icon_ok.svg"));
633 $tpl->setVariable("TEXT_OK", $this->lng->txt("answer_is_right"));
634 } else {
635 $tpl->setVariable("ICON_OK", ilUtil::getImagePath("icon_not_ok.svg"));
636 $tpl->setVariable("TEXT_OK", $this->lng->txt("answer_is_wrong"));
637 }
638 }
639 $tpl->parseCurrentBlock();
640 } else {
641 $tpl->setVariable("PLEASE_SELECT", $this->lng->txt("please_select"));
642 foreach ($answers as $value) {
643 $tpl->setCurrentBlock('select_option');
644 $tpl->setVariable('VALUE', $value);
645 if ($value == $user_value) {
646 $tpl->setVariable('SELECTED', 'selected');
647 }
648 $tpl->parseCurrentBlock();
649 }
650 }
651 return $tpl->get();
652 }
653
654 public function getSubQuestionsIndex()
655 {
656 return array_keys($this->object->getAnswers());
657 }
658
659 public function getAnswersFrequency($relevant_answers, $questionIndex)
660 {
661 $answers = array();
662
663 foreach ($relevant_answers as $row) {
664 if ($row['value1'] != $questionIndex) {
665 continue;
666 }
667
668 if (!isset($answers[$row['value2']])) {
669 //$label = $this->getAnswerTextLabel($row['value1'], $row['value2']);
670
671 $answers[$row['value2']] = array(
672 'answer' => $row['value2'], 'frequency' => 0
673 );
674 }
675
676 $answers[$row['value2']]['frequency']++;
677 }
678
679 return $answers;
680 }
681
682 public function getAnswerFrequencyTableGUI($parentGui, $parentCmd, $relevantAnswers, $questionIndex)
683 {
684 global $DIC; /* @var ILIAS\DI\Container $DIC */
685
686 $table = parent::getAnswerFrequencyTableGUI(
687 $parentGui,
688 $parentCmd,
689 $relevantAnswers,
690 $questionIndex
691 );
692
693 $table->setTitle(sprintf(
694 $DIC->language()->txt('tst_corrections_answers_tbl_subindex'),
695 $DIC->language()->txt('longmenu') . ' ' . ($questionIndex + 1)
696 ));
697
698 return $table;
699 }
700
702 {
703 $correctAnswers = $this->object->getCorrectAnswers();
704
705 foreach ($this->object->getAnswers() as $lmIndex => $lm) {
706 $lmValues = array(
707 'answers_all' => array(0 => $lm),
708 'answers_all_count' => count($lm),
709 'answers_correct' => $correctAnswers[$lmIndex][0]
710 );
711
712 $lmPoints = $correctAnswers[$lmIndex][1];
713
715 $section->setTitle($this->lng->txt('longmenu') . ' ' . ($lmIndex + 1));
716 $form->addItem($section);
717
719 $this->lng->txt('answers'),
720 'longmenu_' . $lmIndex
721 );
722
723 $lmInput->setRequired(true);
724
725 $lmInput->setValues($lmValues);
726
727 $form->addItem($lmInput);
728
729 $pointsInp = new ilNumberInputGUI($this->lng->txt("points"), 'points_' . $lmIndex);
730 $pointsInp->setRequired(true);
731 $pointsInp->allowDecimals(true);
732 $pointsInp->setSize(4);
733 $pointsInp->setMinValue(0);
734 $pointsInp->setMinvalueShouldBeGreater(false);
735 $pointsInp->setValue($lmPoints);
736 $form->addItem($pointsInp);
737 }
738 }
739
744 {
745 $correctAnswers = $this->object->getCorrectAnswers();
746
747 foreach ($this->object->getAnswers() as $lmIndex => $lm) {
748 $pointsInput = (float) $form->getInput('points_' . $lmIndex);
749 $correctAnswersInput = (array) $form->getInput('longmenu_' . $lmIndex . '_tags');
750
751 foreach ($correctAnswersInput as $idx => $answer) {
752 if (in_array($answer, $lm)) {
753 continue;
754 }
755
756 unset($correctAnswersInput[$idx]);
757 }
758
759 $correctAnswersInput = array_values($correctAnswersInput);
760
761 $correctAnswers[$lmIndex][0] = $correctAnswersInput;
762 $correctAnswers[$lmIndex][1] = $pointsInput;
763 }
764
765 $this->object->setCorrectAnswers($correctAnswers);
766 }
767}
$section
Definition: Utf8Test.php:83
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
getLongMenuTextWithInputFieldsInsteadOfGaps($user_solution=array(), $solution=false, $graphical=false)
setQuestionTabs()
Sets the ILIAS tabs for this question type.
getAnswersFrequency($relevant_answers, $questionIndex)
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.
getSelectGapTemplate($key, $answers, $user_value, $solution, $ok=false, $graphical=false)
getUserSolution($active_id, $pass)
getSpecificFeedbackOutput($userSolution)
Returns the answer specific feedback for the question.
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
getAnswerFrequencyTableGUI($parentGui, $parentCmd, $relevantAnswers, $questionIndex)
getTestOutput( $active_id, $pass, $is_postponed=false, $use_post_solutions=false, $show_feedback=false)
writePostData($always=false)
{Evaluates a posted edit form and writes the form data in the question object.integer A positive valu...
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
getAggregatedAnswersView($relevant_answers)
Returns an html string containing a question specific representation of the answers so far given in t...
editQuestion(ilPropertyFormGUI $form=null)
getTextGapTemplate($key, $value, $solution, $ok=false, $graphical=false)
supportsIntermediateSolutionOutput()
Question type specific support of intermediate solution output The function getSolutionOutput respect...
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from $_POST and applies them to the data object.
getPreview($show_question_only=false, $showInlineFeedback=false)
populateAnswerSpecificFormPart(ilPropertyFormGUI $form)
const MIN_LENGTH_AUTOCOMPLETE
const ANSWER_TYPE_TEXT_VAL
const ANSWER_TYPE_SELECT_VAL
Basic GUI class for assessment questions.
populateTaxonomyFormSection(ilPropertyFormGUI $form)
addTab_QuestionHints(ilTabsGUI $tabs)
adds the hints tab to ilTabsGUI
addQuestionFormCommandButtons($form)
Add the command buttons of a question properties form.
getILIASPage($html="")
Returns the ILIAS Page around a question.
getQuestionTemplate()
get question template
addTab_SuggestedSolution(ilTabsGUI $tabs, $classname)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
output question page
getUseIntermediateSolution()
Get if intermediate solution should be used for solution output.
addBackTab(ilTabsGUI $ilTabs)
hasCorrectSolution($activeId, $passIndex)
addTab_QuestionFeedback(ilTabsGUI $tabs)
adds the feedback tab to ilTabsGUI
addBasicQuestionFormProperties($form)
Add basic question form properties: assessment: title, author, description, question,...
addTab_QuestionPreview(ilTabsGUI $tabsGUI)
getGenericFeedbackOutput($active_id, $pass)
Returns the answer specific feedback for the question.
const ADDITIONAL_CONTENT_EDITING_MODE_DEFAULT
constant for additional content editing mode "default"
static getSelfAssessmentTags()
Get tags allowed in question tags in self assessment mode.
This class represents a checkbox property in a property form.
This class represents a custom property in a property form.
This class represents a section header in a property form.
This class represents a hidden form property in a property form.
static getInstance()
Get instance.
This class represents a number property in a property form.
static _getUsedHTMLTags($a_module="")
Returns an array of all allowed HTML tags for text editing.
static _getUsePreviousAnswers($active_id, $user_active_user_setting=false)
Returns if the previous results should be hidden for a learner.
static _getPass($active_id)
Retrieves the actual pass of a given user for a given test.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
This class represents a tag list property in a property form.
special template class to simplify handling of ITX/PEAR
This class represents a text area property in a property form.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
Interface ilGuiQuestionScoringAdjustable.
$index
Definition: metadata.php:128
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$url
$DIC
Definition: xapitoken.php:46