ILIAS  release_8 Revision v8.24
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 global $DIC;
45 $lng = $DIC['lng'];
46
47 $foundvalues = $_POST[$this->getPostVar()];
48
49 if (is_array($foundvalues)) {
50 if (!isset($foundvalues['correctness']) || count($foundvalues['correctness']) < count($this->values)) {
51 $this->setAlert($lng->txt("msg_input_is_required"));
52 return false;
53 }
54 } else {
55 $this->setAlert($lng->txt("msg_input_is_required"));
56 return false;
57 }
58
59 return $this->checkSubItemsInput();
60 }
61
62 public function insert(ilTemplate $a_tpl): void
63 {
64 $tpl = new ilTemplate("tpl.prop_kprimchoicecorrection_input.html", true, true, "Modules/TestQuestionPool");
65
66 foreach ($this->values as $value) {
71 if (strlen($value->getImageFile())) {
72 $imagename = $value->getImageWebPath();
73
74 if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
75 if (@file_exists($value->getThumbFsPath())) {
76 $imagename = $value->getThumbWebPath();
77 }
78 }
79
80 $tpl->setCurrentBlock('image');
81 $tpl->setVariable('SRC_IMAGE', $imagename);
82 $tpl->setVariable('IMAGE_NAME', $value->getImageFile());
83 $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext()));
84 $tpl->parseCurrentBlock();
85 }
86
87 $tpl->setCurrentBlock("row");
88
89 $tpl->setVariable("ANSWER", $value->getAnswertext());
90
91 $tpl->setVariable("POST_VAR", $this->getPostVar());
92 $tpl->setVariable("ROW_NUMBER", $value->getPosition());
93 $tpl->setVariable("ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
94
95 $tpl->setVariable(
96 "CORRECTNESS_TRUE_ID",
97 $this->getPostVar() . "[correctness][{$value->getPosition()}][true]"
98 );
99 $tpl->setVariable(
100 "CORRECTNESS_FALSE_ID",
101 $this->getPostVar() . "[correctness][{$value->getPosition()}][false]"
102 );
103 $tpl->setVariable("CORRECTNESS_TRUE_VALUE", 1);
104 $tpl->setVariable("CORRECTNESS_FALSE_VALUE", 0);
105
106 if ($value->getCorrectness() !== null) {
107 if ($value->getCorrectness()) {
108 $tpl->setVariable('CORRECTNESS_TRUE_SELECTED', ' checked="checked"');
109 } else {
110 $tpl->setVariable('CORRECTNESS_FALSE_SELECTED', ' checked="checked"');
111 }
112 }
113
114 if ($this->getDisabled()) {
115 $tpl->setVariable("DISABLED_CORRECTNESS", " disabled=\"disabled\"");
116 }
117
118 $tpl->parseCurrentBlock();
119 }
120
121 $tpl->setVariable("TRUE_TEXT", $this->qstObject->getTrueOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
122 $tpl->setVariable("FALSE_TEXT", $this->qstObject->getFalseOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
123
124 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
125 $tpl->setVariable("DELETE_IMAGE_HEADER", $this->lng->txt('delete_image_header'));
126 $tpl->setVariable("DELETE_IMAGE_QUESTION", $this->lng->txt('delete_image_question'));
127 $tpl->setVariable("ANSWER_TEXT", $this->lng->txt('answer'));
128
129 $tpl->setVariable("OPTIONS_TEXT", $this->lng->txt('options'));
130
131 $a_tpl->setCurrentBlock("prop_generic");
132 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
133 $a_tpl->parseCurrentBlock();
134 }
135}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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)
global $DIC
Definition: feed.php:28
$index
Definition: metadata.php:145