ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilKprimChoiceCorrectionsInputGUI.php
Go to the documentation of this file.
1<?php
2
28{
29 public function setValue($a_value): void
30 {
31 if (is_array($a_value) && is_array($a_value['correctness'])) {
32 foreach ($this->values as $index => $value) {
33 if (isset($a_value['correctness'][$index])) {
34 $this->values[$index]->setCorrectness((bool) $a_value['correctness'][$index]);
35 } else {
36 $this->values[$index]->setCorrectness(null);
37 }
38 }
39 }
40 }
41
42 public function checkInput(): bool
43 {
44 $data = $this->raw($this->getPostVar());
45
46 if (!is_array($data['correctness']) || count($data['correctness']) < count($this->values)) {
47 $this->setAlert($this->lng->txt("msg_input_is_required"));
48 return false;
49 }
50
51 return $this->checkSubItemsInput();
52 }
53
54 public function insert(ilTemplate $a_tpl): void
55 {
56 $tpl = new ilTemplate("tpl.prop_kprimchoicecorrection_input.html", true, true, "components/ILIAS/TestQuestionPool");
57
58 foreach ($this->values as $value) {
63 if ($value->getImageFile() !== null
64 && $value->getImageFile() !== '') {
65 $imagename = $value->getImageWebPath();
66
67 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
68 if (@file_exists($value->getThumbFsPath())) {
69 $imagename = $value->getThumbWebPath();
70 }
71 }
72
73 $tpl->setCurrentBlock('image');
74 $tpl->setVariable('SRC_IMAGE', $imagename);
75 $tpl->setVariable('IMAGE_NAME', $value->getImageFile());
76 $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext()));
77 $tpl->parseCurrentBlock();
78 }
79
80 $tpl->setCurrentBlock("row");
81
82 $tpl->setVariable("ANSWER", $value->getAnswertext());
83
84 $tpl->setVariable("POST_VAR", $this->getPostVar());
85 $tpl->setVariable("ROW_NUMBER", $value->getPosition());
86 $tpl->setVariable("ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
87
88 $tpl->setVariable(
89 "CORRECTNESS_TRUE_ID",
90 $this->getPostVar() . "[correctness][{$value->getPosition()}][true]"
91 );
92 $tpl->setVariable(
93 "CORRECTNESS_FALSE_ID",
94 $this->getPostVar() . "[correctness][{$value->getPosition()}][false]"
95 );
96 $tpl->setVariable("CORRECTNESS_TRUE_VALUE", 1);
97 $tpl->setVariable("CORRECTNESS_FALSE_VALUE", 0);
98
99 if ($value->getCorrectness() !== null) {
100 if ($value->getCorrectness()) {
101 $tpl->setVariable('CORRECTNESS_TRUE_SELECTED', ' checked="checked"');
102 } else {
103 $tpl->setVariable('CORRECTNESS_FALSE_SELECTED', ' checked="checked"');
104 }
105 }
106
107 if ($this->getDisabled()) {
108 $tpl->setVariable("DISABLED_CORRECTNESS", " disabled=\"disabled\"");
109 }
110
111 $tpl->parseCurrentBlock();
112 }
113
114 $tpl->setVariable("TRUE_TEXT", $this->qstObject->getTrueOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
115 $tpl->setVariable("FALSE_TEXT", $this->qstObject->getFalseOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
116
117 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
118 $tpl->setVariable("DELETE_IMAGE_HEADER", $this->lng->txt('delete_image_header'));
119 $tpl->setVariable("DELETE_IMAGE_QUESTION", $this->lng->txt('delete_image_question'));
120 $tpl->setVariable("ANSWER_TEXT", $this->lng->txt('answer'));
121
122 $tpl->setVariable("OPTIONS_TEXT", $this->lng->txt('options'));
123
124 $a_tpl->setCurrentBlock("prop_generic");
125 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
126 $a_tpl->parseCurrentBlock();
127 }
128}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
static prepareFormOutput($a_str, bool $a_strip=false)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)