48 $this->
object->loadFromDb(
$id);
57 return $this->
object->feedbackOBJ->isSpecificAnswerFeedbackAvailable($this->
object->getId());
84 if ($this->
object->getSelfAssessmentEditingMode()) {
85 return $this->
object->isSingleline();
89 return $this->request_data_collector->int(
'types') === 0;
92 if (empty($this->
object->getLastChange())
93 && !$this->request_data_collector->isset(
'types')) {
95 return $this->
object->getMultilineAnswerSetting() === 0;
98 return $this->
object->isSingleline();
102 bool $checkonly =
false,
103 ?
bool $is_save_cmd =
null 108 $this->editForm = $form;
110 $form->setFormAction($this->
ctrl->getFormAction($this));
113 if ($is_singleline) {
114 $form->setMultipart(
true);
116 $form->setMultipart(
false);
118 $form->setTableWidth(
'100%');
119 $form->setId(
'asssinglechoice');
132 foreach ($this->request_data_collector->getParsedBody() as $key => $value) {
133 $item = $form->getItemByPostVar($key);
134 if ($item ===
null) {
137 switch (get_class($item)) {
138 case 'ilDurationInputGUI':
139 $item->setHours($value[
'hh']);
140 $item->setMinutes($value[
'mm']);
141 $item->setSeconds($value[
'ss']);
144 $item->setValue($value);
148 $errors = !$form->checkInput();
171 $position = key($this->request_data_collector->raw(
'cmd')[
'removeimagechoice']);
172 $this->
object->removeAnswerImage($position);
179 $position = key($this->request_data_collector->raw(
'cmd')[
'addchoice']);
180 $this->
object->addAnswer(
'', 0, $position + 1);
187 $position = key($this->request_data_collector->raw(
'cmd')[
'removechoice']);
188 $this->
object->deleteAnswer($position);
195 bool $graphical_output =
false,
196 bool $result_output =
false,
197 bool $show_question_only =
true,
198 bool $show_feedback =
false,
199 bool $show_correct_solution =
false,
200 bool $show_manual_scoring =
false,
201 bool $show_question_text =
true,
202 bool $show_inline_feedback =
true 205 if (($active_id > 0) && (!$show_correct_solution)) {
206 $user_solutions = $this->
object->getSolutionValues($active_id, $pass);
211 foreach ($this->
object->answers as $index => $answer) {
212 if ($answer->getPoints() > $max_points) {
213 $max_points = $answer->getPoints();
214 $found_index = $index;
217 $user_solutions = [[
'value1' => $found_index]];
228 $show_correct_solution,
229 $show_manual_scoring,
232 $show_inline_feedback,
237 mixed $user_solutions,
240 bool $graphical_output =
false,
241 bool $result_output =
false,
242 bool $show_question_only =
true,
243 bool $show_feedback =
false,
244 bool $show_correct_solution =
false,
245 bool $show_manual_scoring =
false,
246 bool $show_question_text =
true,
247 bool $show_autosave_title =
false,
248 bool $show_inline_feedback =
false,
251 foreach ($user_solutions as $idx => $solution_value) {
252 $user_solution = $solution_value[
'value1'];
255 $template =
new ilTemplate(
'tpl.il_as_qpl_mc_sr_output_solution.html',
true,
true,
'components/ILIAS/TestQuestionPool');
256 $solutiontemplate =
new ilTemplate(
'tpl.il_as_tst_solution_output.html',
true,
true,
'components/ILIAS/TestQuestionPool');
259 foreach ($keys as $answer_id) {
260 $answer = $this->
object->answers[$answer_id];
261 if ($active_id > 0 && !$show_correct_solution && $graphical_output) {
263 (
string) $user_solution,
265 $answer->getPoints(),
266 $this->
object->getMaximumPoints()
268 $template->setCurrentBlock(
'icon_ok');
270 $template->parseCurrentBlock();
272 if ($answer->hasImage()) {
273 $template->setCurrentBlock(
'answer_image');
274 if ($this->
object->getThumbSize()) {
275 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
277 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $answer->getImage());
279 $alt = $answer->getImage();
280 if (strlen($answer->getAnswertext())) {
281 $alt = $answer->getAnswertext();
283 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
286 $template->parseCurrentBlock();
292 $template->setCurrentBlock(
'answer_row');
293 $template->setVariable(
'ANSWER_TEXT', $this->
renderLatex(
298 if ((
string) $user_solution === (string) $answer_id) {
300 $template->setVariable(
'SOLUTION_ALT', $this->
lng->txt(
'checked'));
303 $template->setVariable(
'SOLUTION_ALT', $this->
lng->txt(
'unchecked'));
306 $template->setVariable(
'QID', $this->
object->getId());
307 $template->setVariable(
'SUFFIX', $show_correct_solution ?
'bestsolution' :
'usersolution');
308 $template->setVariable(
'SOLUTION_VALUE', $answer_id);
309 if ((
string) $user_solution === (
string) $answer_id) {
310 $template->setVariable(
'SOLUTION_CHECKED',
'checked');
314 if ($result_output) {
315 $points = $this->
object->answers[$answer_id]->getPoints();
316 $resulttext = ($points == 1) ?
"(%s {$this->lng->txt('point')})" :
"(%s {$this->lng->txt('points')})";
317 $template->setVariable(
'RESULT_OUTPUT', sprintf($resulttext, $points));
319 $template->parseCurrentBlock();
322 $questiontext = $this->
object->getQuestionForHTMLOutput();
326 if ($show_question_text ===
true) {
327 $template->setVariable(
'QUESTIONTEXT', $this->
renderLatex(
331 $questionoutput = $template->get();
333 if ($feedback !==
'') {
339 $solutiontemplate->setVariable(
'ILC_FB_CSS_CLASS', $cssClass);
342 $solutiontemplate->setVariable(
'SOLUTION_OUTPUT', $questionoutput);
344 $solutionoutput = $solutiontemplate->get();
346 if (!$show_question_only) {
350 return $solutionoutput;
354 string $user_solution,
356 float $answer_points,
357 float $maximum_points
359 if ($user_solution === $answer_id
360 && $answer_points === $maximum_points
361 || $user_solution !== $answer_id
362 && $answer_points === 0.0
364 return self::CORRECTNESS_OK;
367 if ($user_solution === $answer_id
368 && $answer_points > 0.0) {
369 return self::CORRECTNESS_MOSTLY_OK;
372 return self::CORRECTNESS_NOT_OK;
376 bool $show_question_only =
false,
377 bool $show_inline_feedback =
false 381 $template =
new ilTemplate(
'tpl.il_as_qpl_mc_sr_output.html',
true,
true,
'components/ILIAS/TestQuestionPool');
382 foreach ($keys as $answer_id) {
383 $answer = $this->
object->answers[$answer_id];
384 if ($answer->hasImage()) {
385 if ($this->
object->getThumbSize()) {
386 $template->setCurrentBlock(
'preview');
387 $template->setVariable(
'URL_PREVIEW', $this->
object->getImagePathWeb() . $answer->getImage());
388 $template->setVariable(
'TEXT_PREVIEW', $this->
lng->txt(
'preview'));
390 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
391 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
392 $alt = $answer->getImage();
393 if (strlen($answer->getAnswertext())) {
394 $alt = $answer->getAnswertext();
396 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
399 $template->parseCurrentBlock();
401 $template->setCurrentBlock(
'answer_image');
402 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $answer->getImage());
403 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
404 $alt = $answer->getImage();
405 if (strlen($answer->getAnswertext())) {
406 $alt = $answer->getAnswertext();
408 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
409 $template->setVariable(
'ATTR', $attr);
412 $template->parseCurrentBlock();
418 $template->setCurrentBlock(
'answer_row');
419 $template->setVariable(
'QID', $this->
object->getId() .
'ID');
420 $template->setVariable(
'ANSWER_ID', $answer_id);
421 $template->setVariable(
'ANSWER_TEXT', $this->
renderLatex(
427 if ((
string) $user_solution === (
string) $answer_id) {
428 $template->setVariable(
'CHECKED_ANSWER',
' checked="checked"');
432 $template->parseCurrentBlock();
434 $questiontext = $this->
object->getQuestionForHTMLOutput();
438 $template->setVariable(
'QUESTIONTEXT', $this->
renderLatex(
441 $questionoutput = $template->get();
442 if (!$show_question_only) {
446 return $questionoutput;
452 bool $is_question_postponed =
false,
453 array|
bool $user_post_solutions =
false,
454 bool $show_specific_inline_feedback =
false 459 if ($active_id !== 0) {
460 $solutions = $this->
object->getTestOutputSolutions($active_id, $pass);
461 foreach ($solutions as $solution_value) {
462 $user_solution = $solution_value[
'value1'];
466 $template =
new ilTemplate(
'tpl.il_as_qpl_mc_sr_output.html',
true,
true,
'components/ILIAS/TestQuestionPool');
467 foreach ($keys as $answer_id) {
468 $answer = $this->
object->answers[$answer_id];
469 if ($answer->hasImage()) {
470 if ($this->
object->getThumbSize()) {
471 $template->setCurrentBlock(
'preview');
472 $template->setVariable(
'URL_PREVIEW', $this->
object->getImagePathWeb() . $answer->getImage());
473 $template->setVariable(
'TEXT_PREVIEW', $this->
lng->txt(
'preview'));
475 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
476 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
477 $alt = $answer->getImage();
478 if (strlen($answer->getAnswertext())) {
479 $alt = $answer->getAnswertext();
481 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
484 $template->parseCurrentBlock();
486 $template->setCurrentBlock(
'answer_image');
487 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $answer->getImage());
488 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
489 $alt = $answer->getImage();
490 if (strlen($answer->getAnswertext())) {
491 $alt = $answer->getAnswertext();
493 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
494 $template->setVariable(
'ATTR', $attr);
497 $template->parseCurrentBlock();
501 if ($show_specific_inline_feedback) {
504 $template->setCurrentBlock(
'answer_row');
505 $template->setVariable(
'ANSWER_ID', $answer_id);
506 $template->setVariable(
'ANSWER_TEXT', $this->
renderLatex(
509 if ($user_solution === (
string) $answer_id) {
510 $template->setVariable(
'CHECKED_ANSWER',
' checked="checked"');
512 $template->parseCurrentBlock();
514 $template->setVariable(
'QUESTIONTEXT', $this->
renderLatex(
515 $this->
object->getQuestionForHTMLOutput()
517 $questionoutput = $template->get();
518 $pageoutput = $this->
outQuestionPage(
'', $is_question_postponed, $active_id, $questionoutput, $show_specific_inline_feedback);
529 $choice_keys = array_keys($this->
object->answers);
531 if ($this->
object->getShuffle()) {
532 $choice_keys = $this->
object->getShuffler()->transform($choice_keys);
547 $is_multi_line = $this->request_data_collector->string(
'types');
548 if ($is_multi_line ===
'') {
549 $is_multi_line =
'0';
551 $this->
object->setMultilineAnswerSetting($is_multi_line);
552 $this->
object->setShuffle($this->request_data_collector->bool(
'shuffle') ??
false);
554 $choice = $this->request_data_collector->raw(
'choice');
555 if (isset($choice[
'imagename']) && is_array($choice[
'imagename']) && $is_multi_line ===
'1') {
556 $this->
object->setIsSingleline(
true);
557 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'info_answer_type_change'),
true);
559 $this->
object->setIsSingleline($is_multi_line ===
'0');
562 $object_thumb_size = $this->
object->getThumbSize();
563 $thumb_size = $this->request_data_collector->int(
'thumb_size') ?? $object_thumb_size;
564 if ($thumb_size !== $object_thumb_size) {
565 $this->
object->setThumbSize($thumb_size);
566 $this->rebuild_thumbnails =
true;
574 $shuffle->setValue(1);
575 $shuffle->setChecked($this->
object->getShuffle());
576 $shuffle->setRequired(
false);
579 if (!$this->
object->getSelfAssessmentEditingMode()) {
585 0 => $this->
lng->txt(
'answers_singleline'),
586 1 => $this->
lng->txt(
'answers_multiline'),
589 $types->setValue($is_singleline ? 0 : 1);
593 if ($is_singleline) {
596 $thumb_size->
setSuffix($this->
lng->txt(
'thumb_size_unit_pixel'));
597 $thumb_size->setMinValue($this->
object->getMinimumThumbSize());
598 $thumb_size->setMaxValue($this->
object->getMaximumThumbSize());
599 $thumb_size->setDecimals(0);
600 $thumb_size->setSize(6);
601 $thumb_size->setInfo($this->
lng->txt(
'thumb_size_info'));
602 $thumb_size->setValue($this->
object->getThumbSize());
603 $thumb_size->setRequired(
true);
606 $thumb_size->setValue($this->
object->getThumbSize());
630 $this->
object->flushAnswers();
632 $this->request_data_collector->raw(
'choice') ?? [],
633 $this->
object->isSingleline() === false
636 if ($choice === []) {
640 if (!$this->
object->isSingleline()) {
641 foreach ($choice[
'answer'] as $index => $answer) {
642 $answertext = $answer;
643 $this->
object->addAnswer(
645 $this->
refinery->kindlyTo()->float()->transform($choice[
'points'][$index]),
648 $choice[
'answer_id'][$index]
655 foreach ($choice[
'answer'] as $index => $answertext) {
656 $answertext = htmlentities($answertext);
657 $picturefile = $choice[
'imagename'][$index] ??
null;
658 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][$index] ??
'';
659 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][$index] ??
'';
661 if ($file_temp_name !==
'') {
663 $file_name_parts = explode(
'.', $file_org_name);
664 $suffix = strtolower(array_pop($file_name_parts));
665 if (in_array($suffix, [
'jpg',
'jpeg',
'png',
'gif'])) {
667 $filename = $this->
object->buildHashedImageFilename($file_org_name);
674 $points = (float) str_replace(
',',
'.', $choice[
'points'][$index]);
675 $this->
object->addAnswer(
680 $choice[
'answer_id'][$index]
684 if ($this->rebuild_thumbnails) {
685 $this->
object->setAnswers(
686 $this->
object->rebuildThumbnails(
687 $this->object->isSingleline(),
688 $this->
object->getThumbSize(),
689 $this->
object->getImagePath(),
690 $this->
object->getAnswers()
700 $choices->setQuestionObject($this->
object);
701 $choices->setSingleline($is_singleline);
702 $choices->setAllowMove(
false);
703 if ($this->
object->getSelfAssessmentEditingMode()) {
704 $choices->setSize(40);
706 if ($this->
object->getAnswerCount() == 0) {
707 $this->
object->addAnswer(
'', 0, 0);
711 $value->setAnswerText(html_entity_decode($value->getAnswerText()));
714 $this->
object->getAnswers()
716 $choices->setInfo($choices->getInfo() .
' ' . $this->
lng->txt(
'latex_edit_info'));
735 private function aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question): array
738 foreach ($answers_defined_on_question as $answer) {
739 $aggregated_info_for_answer = [];
740 $aggregated_info_for_answer[
'answertext'] = $answer->getAnswerText();
741 $aggregated_info_for_answer[
'count_checked'] = 0;
743 foreach ($relevant_answers_chosen as $relevant_answer) {
744 if ($relevant_answer[
'value1'] == $answer->getOrder()) {
745 $aggregated_info_for_answer[
'count_checked']++;
748 $aggregated_info_for_answer[
'count_unchecked'] =
749 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
750 - $aggregated_info_for_answer[
'count_checked'];
752 $aggregate[] = $aggregated_info_for_answer;
764 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
'components/ILIAS/TestQuestionPool');
774 foreach ($aggregate as $line_data) {
785 $feedbackOutputRequired =
false;
787 switch ($this->
object->getSpecificFeedbackSetting()) {
789 $feedbackOutputRequired =
true;
793 if ((
string) $user_solution === (string) $answer_id) {
794 $feedbackOutputRequired =
true;
799 if ($this->
object->getAnswer($answer_id)->getPoints() > 0) {
800 $feedbackOutputRequired =
true;
805 if ($feedbackOutputRequired) {
806 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->
object->getId(), 0, $answer_id);
808 $template->setCurrentBlock(
'feedback');
809 $template->setVariable(
'FEEDBACK', $this->
renderLatex(
812 $template->parseCurrentBlock();
823 foreach ($agg as $ans) {
825 'answer' => $ans[
'answertext'],
826 'frequency' => $ans[
'count_checked']
837 $choices->setQuestionObject($this->
object);
838 $choices->setValues($this->
object->getAnswers());
848 $values = $input->getValues();
850 foreach ($this->
object->getAnswers() as $index => $answer) {
852 $points = (float) str_replace(
',',
'.', $values[$index]->getPoints());
853 $answer->setPoints($points);
isTestPresentationContext()
setAdditionalContentEditingModeFromPost()
hasCorrectSolution($activeId, $passIndex)
__construct(int $id=-1)
assSingleChoiceGUI constructor
populateQuestionSpecificFormPart(\ilPropertyFormGUI $form, bool $is_singleline=false)
generateCorrectnessIconsForCorrectness(int $correctness)
aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question)
setCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Sets the template to the given block.
editQuestion(bool $checkonly=false, ?bool $is_save_cmd=null)
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
Extracts the answer specific values from the request and applies them to the data object...
Class for answers with a binary state indicator.
renderLatex($content)
Wrap content with latex in a LatexContent UI component and render it to be processed by MathJax in th...
getTestOutput(int $active_id, int $pass, bool $is_question_postponed=false, array|bool $user_post_solutions=false, bool $show_specific_inline_feedback=false)
populateInlineFeedback($template, $answer_id, $user_solution)
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
renderAggregateView($aggregate)
parseCurrentBlock(string $blockname=self::DEFAULT_BLOCK)
Parses the given block.
const CSS_CLASS_FEEDBACK_CORRECT
ilGlobalPageTemplate $tpl
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)
getSpecificFeedbackOutput(array $user_solution)
getAnswersFrequency($relevantAnswers, $questionIndex)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
generateCorrectness(string $user_solution, string $answer_id, float $answer_points, float $maximum_points)
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
writeQuestionGenericPostData()
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
Class for single choice questions.
writePostData(bool $always=false)
{}
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
populateAnswerSpecificFormPart(\ilPropertyFormGUI $form, bool $is_singleline=false)
static getHtmlPath(string $relative_path)
get url of path
const CSS_CLASS_FEEDBACK_WRONG
getEditAnswersSingleLine(bool $checkonly=false)
Get the single/multiline editing of answers.
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
saveTaxonomyAssignments()
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
__construct(Container $dic, ilPlugin $plugin)
cleanupAnswerText(array $answer_text, bool $is_rte)
sk - 12.05.2023: This is one more of those that we need, but don't want.
isRenderPurposePrintPdf()
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...
setVariable(string $variable, $value='')
Sets the given variable to the given value.
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,)
getPreview(bool $show_question_only=false, bool $show_inline_feedback=false)
renderEditForm(ilPropertyFormGUI $form)
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
Extracts the question specific values from the request and applies them to the data object...
renderPurposeSupportsFormHtml()
getGenericFeedbackOutput(int $active_id, ?int $pass)