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');
296 if ((
string) $user_solution === (string) $answer_id) {
298 $template->setVariable(
'SOLUTION_ALT', $this->
lng->txt(
'checked'));
301 $template->setVariable(
'SOLUTION_ALT', $this->
lng->txt(
'unchecked'));
304 $template->setVariable(
'QID', $this->
object->getId());
305 $template->setVariable(
'SUFFIX', $show_correct_solution ?
'bestsolution' :
'usersolution');
306 $template->setVariable(
'SOLUTION_VALUE', $answer_id);
307 if ((
string) $user_solution === (
string) $answer_id) {
308 $template->setVariable(
'SOLUTION_CHECKED',
'checked');
312 if ($result_output) {
313 $points = $this->
object->answers[$answer_id]->getPoints();
314 $resulttext = ($points == 1) ?
"(%s {$this->lng->txt('point')})" :
"(%s {$this->lng->txt('points')})";
315 $template->setVariable(
'RESULT_OUTPUT', sprintf($resulttext, $points));
317 $template->parseCurrentBlock();
320 $questiontext = $this->
object->getQuestionForHTMLOutput();
324 if ($show_question_text ===
true) {
327 $questionoutput = $template->get();
329 if ($feedback !==
'') {
335 $solutiontemplate->setVariable(
'ILC_FB_CSS_CLASS', $cssClass);
338 $solutiontemplate->setVariable(
'SOLUTION_OUTPUT', $questionoutput);
340 $solutionoutput = $solutiontemplate->get();
342 if (!$show_question_only) {
346 return $solutionoutput;
350 string $user_solution,
352 float $answer_points,
353 float $maximum_points
355 if ($user_solution === $answer_id
356 && $answer_points === $maximum_points
357 || $user_solution !== $answer_id
358 && $answer_points === 0.0
360 return self::CORRECTNESS_OK;
363 if ($user_solution === $answer_id
364 && $answer_points > 0.0) {
365 return self::CORRECTNESS_MOSTLY_OK;
368 return self::CORRECTNESS_NOT_OK;
372 bool $show_question_only =
false,
373 bool $show_inline_feedback =
false 377 $template =
new ilTemplate(
'tpl.il_as_qpl_mc_sr_output.html',
true,
true,
'components/ILIAS/TestQuestionPool');
378 foreach ($keys as $answer_id) {
379 $answer = $this->
object->answers[$answer_id];
380 if ($answer->hasImage()) {
381 if ($this->
object->getThumbSize()) {
382 $template->setCurrentBlock(
'preview');
383 $template->setVariable(
'URL_PREVIEW', $this->
object->getImagePathWeb() . $answer->getImage());
384 $template->setVariable(
'TEXT_PREVIEW', $this->
lng->txt(
'preview'));
386 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
387 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
388 $alt = $answer->getImage();
389 if (strlen($answer->getAnswertext())) {
390 $alt = $answer->getAnswertext();
392 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
395 $template->parseCurrentBlock();
397 $template->setCurrentBlock(
'answer_image');
398 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $answer->getImage());
399 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
400 $alt = $answer->getImage();
401 if (strlen($answer->getAnswertext())) {
402 $alt = $answer->getAnswertext();
404 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
405 $template->setVariable(
'ATTR', $attr);
408 $template->parseCurrentBlock();
414 $template->setCurrentBlock(
'answer_row');
415 $template->setVariable(
'QID', $this->
object->getId() .
'ID');
416 $template->setVariable(
'ANSWER_ID', $answer_id);
421 if ((
string) $user_solution === (
string) $answer_id) {
422 $template->setVariable(
'CHECKED_ANSWER',
' checked="checked"');
426 $template->parseCurrentBlock();
428 $questiontext = $this->
object->getQuestionForHTMLOutput();
433 $questionoutput = $template->get();
434 if (!$show_question_only) {
438 return $questionoutput;
444 bool $is_question_postponed =
false,
445 array|
bool $user_post_solutions =
false,
446 bool $show_specific_inline_feedback =
false 451 if ($active_id !== 0) {
452 $solutions = $this->
object->getTestOutputSolutions($active_id, $pass);
453 foreach ($solutions as $solution_value) {
454 $user_solution = $solution_value[
'value1'];
458 $template =
new ilTemplate(
'tpl.il_as_qpl_mc_sr_output.html',
true,
true,
'components/ILIAS/TestQuestionPool');
459 foreach ($keys as $answer_id) {
460 $answer = $this->
object->answers[$answer_id];
461 if ($answer->hasImage()) {
462 if ($this->
object->getThumbSize()) {
463 $template->setCurrentBlock(
'preview');
464 $template->setVariable(
'URL_PREVIEW', $this->
object->getImagePathWeb() . $answer->getImage());
465 $template->setVariable(
'TEXT_PREVIEW', $this->
lng->txt(
'preview'));
467 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
468 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
469 $alt = $answer->getImage();
470 if (strlen($answer->getAnswertext())) {
471 $alt = $answer->getAnswertext();
473 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
476 $template->parseCurrentBlock();
478 $template->setCurrentBlock(
'answer_image');
479 $template->setVariable(
'ANSWER_IMAGE_URL', $this->
object->getImagePathWeb() . $answer->getImage());
480 list($width, $height, $type, $attr) = getimagesize($this->
object->getImagePath() . $answer->getImage());
481 $alt = $answer->getImage();
482 if (strlen($answer->getAnswertext())) {
483 $alt = $answer->getAnswertext();
485 $alt = preg_replace(
'/<[^>]*?>/',
'', $alt);
486 $template->setVariable(
'ATTR', $attr);
489 $template->parseCurrentBlock();
493 if ($show_specific_inline_feedback) {
496 $template->setCurrentBlock(
'answer_row');
497 $template->setVariable(
'ANSWER_ID', $answer_id);
499 if ($user_solution === (
string) $answer_id) {
500 $template->setVariable(
'CHECKED_ANSWER',
' checked="checked"');
502 $template->parseCurrentBlock();
504 $template->setVariable(
'QUESTIONTEXT', $this->
object->getQuestionForHTMLOutput());
505 $questionoutput = $template->get();
506 $pageoutput = $this->
outQuestionPage(
'', $is_question_postponed, $active_id, $questionoutput, $show_specific_inline_feedback);
517 $choice_keys = array_keys($this->
object->answers);
519 if ($this->
object->getShuffle()) {
520 $choice_keys = $this->
object->getShuffler()->transform($choice_keys);
535 $is_multi_line = $this->request_data_collector->string(
'types');
536 if ($is_multi_line ===
'') {
537 $is_multi_line =
'0';
539 $this->
object->setMultilineAnswerSetting($is_multi_line);
540 $this->
object->setShuffle($this->request_data_collector->bool(
'shuffle') ??
false);
542 $choice = $this->request_data_collector->raw(
'choice');
543 if (isset($choice[
'imagename']) && is_array($choice[
'imagename']) && $is_multi_line ===
'1') {
544 $this->
object->setIsSingleline(
true);
545 $this->tpl->setOnScreenMessage(
'info', $this->
lng->txt(
'info_answer_type_change'),
true);
547 $this->
object->setIsSingleline($is_multi_line ===
'0');
550 $object_thumb_size = $this->
object->getThumbSize();
551 $thumb_size = $this->request_data_collector->int(
'thumb_size') ?? $object_thumb_size;
552 if ($thumb_size !== $object_thumb_size) {
553 $this->
object->setThumbSize($thumb_size);
554 $this->rebuild_thumbnails =
true;
562 $shuffle->setValue(1);
563 $shuffle->setChecked($this->
object->getShuffle());
564 $shuffle->setRequired(
false);
567 if (!$this->
object->getSelfAssessmentEditingMode()) {
573 0 => $this->
lng->txt(
'answers_singleline'),
574 1 => $this->
lng->txt(
'answers_multiline'),
577 $types->setValue($is_singleline ? 0 : 1);
581 if ($is_singleline) {
584 $thumb_size->setSuffix($this->
lng->txt(
'thumb_size_unit_pixel'));
585 $thumb_size->setMinValue($this->
object->getMinimumThumbSize());
586 $thumb_size->setMaxValue($this->
object->getMaximumThumbSize());
587 $thumb_size->setDecimals(0);
588 $thumb_size->setSize(6);
589 $thumb_size->setInfo($this->
lng->txt(
'thumb_size_info'));
590 $thumb_size->setValue($this->
object->getThumbSize());
591 $thumb_size->setRequired(
true);
594 $thumb_size->setValue($this->
object->getThumbSize());
618 $this->
object->flushAnswers();
620 $this->request_data_collector->raw(
'choice') ?? [],
621 $this->
object->isSingleline() === false
624 if ($choice === []) {
628 if (!$this->
object->isSingleline()) {
629 foreach ($choice[
'answer'] as $index => $answer) {
630 $answertext = $answer;
631 $this->
object->addAnswer(
633 $this->
refinery->kindlyTo()->float()->transform($choice[
'points'][$index]),
636 $choice[
'answer_id'][$index]
643 foreach ($choice[
'answer'] as $index => $answertext) {
644 $answertext = htmlentities($answertext);
645 $picturefile = $choice[
'imagename'][$index] ?? null;
646 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][$index] ??
'';
647 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][$index] ??
'';
649 if ($file_temp_name !==
'') {
651 $file_name_parts = explode(
'.', $file_org_name);
652 $suffix = strtolower(array_pop($file_name_parts));
653 if (in_array($suffix, [
'jpg',
'jpeg',
'png',
'gif'])) {
655 $filename = $this->
object->buildHashedImageFilename($file_org_name);
662 $points = (float) str_replace(
',',
'.', $choice[
'points'][$index]);
663 $this->
object->addAnswer(
668 $choice[
'answer_id'][$index]
672 if ($this->rebuild_thumbnails) {
673 $this->
object->setAnswers(
674 $this->
object->rebuildThumbnails(
675 $this->object->isSingleline(),
676 $this->
object->getThumbSize(),
677 $this->
object->getImagePath(),
678 $this->
object->getAnswers()
688 $choices->setQuestionObject($this->
object);
689 $choices->setSingleline($is_singleline);
690 $choices->setAllowMove(
false);
691 if ($this->
object->getSelfAssessmentEditingMode()) {
692 $choices->setSize(40);
694 if ($this->
object->getAnswerCount() == 0) {
695 $this->
object->addAnswer(
'', 0, 0);
699 $value->setAnswerText(html_entity_decode($value->getAnswerText()));
702 $this->
object->getAnswers()
722 private function aggregateAnswers($relevant_answers_chosen, $answers_defined_on_question): array
725 foreach ($answers_defined_on_question as $answer) {
726 $aggregated_info_for_answer = [];
727 $aggregated_info_for_answer[
'answertext'] = $answer->getAnswerText();
728 $aggregated_info_for_answer[
'count_checked'] = 0;
730 foreach ($relevant_answers_chosen as $relevant_answer) {
731 if ($relevant_answer[
'value1'] == $answer->getOrder()) {
732 $aggregated_info_for_answer[
'count_checked']++;
735 $aggregated_info_for_answer[
'count_unchecked'] =
736 ceil(count($relevant_answers_chosen) / count($answers_defined_on_question))
737 - $aggregated_info_for_answer[
'count_checked'];
739 $aggregate[] = $aggregated_info_for_answer;
751 $tpl =
new ilTemplate(
'tpl.il_as_aggregated_answers_table.html',
true,
true,
'components/ILIAS/TestQuestionPool');
761 foreach ($aggregate as $line_data) {
772 $feedbackOutputRequired =
false;
774 switch ($this->
object->getSpecificFeedbackSetting()) {
776 $feedbackOutputRequired =
true;
780 if ((
string) $user_solution === (string) $answer_id) {
781 $feedbackOutputRequired =
true;
786 if ($this->
object->getAnswer($answer_id)->getPoints() > 0) {
787 $feedbackOutputRequired =
true;
792 if ($feedbackOutputRequired) {
793 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->
object->getId(), 0, $answer_id);
795 $template->setCurrentBlock(
'feedback');
797 $template->parseCurrentBlock();
808 foreach ($agg as $ans) {
810 'answer' => $ans[
'answertext'],
811 'frequency' => $ans[
'count_checked']
822 $choices->setQuestionObject($this->
object);
823 $choices->setValues($this->
object->getAnswers());
833 $values = $input->getValues();
835 foreach ($this->
object->getAnswers() as $index => $answer) {
837 $points = (float) str_replace(
',',
'.', $values[$index]->getPoints());
838 $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.
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)
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)