ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 ($value->getImageFile() !== null
72  && $value->getImageFile() !== '') {
73  $imagename = $value->getImageWebPath();
74 
75  if (($this->getSingleline()) && ($this->qstObject->getThumbSize())) {
76  if (@file_exists($value->getThumbFsPath())) {
77  $imagename = $value->getThumbWebPath();
78  }
79  }
80 
81  $tpl->setCurrentBlock('image');
82  $tpl->setVariable('SRC_IMAGE', $imagename);
83  $tpl->setVariable('IMAGE_NAME', $value->getImageFile());
84  $tpl->setVariable('ALT_IMAGE', ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext()));
85  $tpl->parseCurrentBlock();
86  }
87 
88  $tpl->setCurrentBlock("row");
89 
90  $tpl->setVariable("ANSWER", $value->getAnswertext());
91 
92  $tpl->setVariable("POST_VAR", $this->getPostVar());
93  $tpl->setVariable("ROW_NUMBER", $value->getPosition());
94  $tpl->setVariable("ID", $this->getPostVar() . "[answer][{$value->getPosition()}]");
95 
96  $tpl->setVariable(
97  "CORRECTNESS_TRUE_ID",
98  $this->getPostVar() . "[correctness][{$value->getPosition()}][true]"
99  );
100  $tpl->setVariable(
101  "CORRECTNESS_FALSE_ID",
102  $this->getPostVar() . "[correctness][{$value->getPosition()}][false]"
103  );
104  $tpl->setVariable("CORRECTNESS_TRUE_VALUE", 1);
105  $tpl->setVariable("CORRECTNESS_FALSE_VALUE", 0);
106 
107  if ($value->getCorrectness() !== null) {
108  if ($value->getCorrectness()) {
109  $tpl->setVariable('CORRECTNESS_TRUE_SELECTED', ' checked="checked"');
110  } else {
111  $tpl->setVariable('CORRECTNESS_FALSE_SELECTED', ' checked="checked"');
112  }
113  }
114 
115  if ($this->getDisabled()) {
116  $tpl->setVariable("DISABLED_CORRECTNESS", " disabled=\"disabled\"");
117  }
118 
119  $tpl->parseCurrentBlock();
120  }
121 
122  $tpl->setVariable("TRUE_TEXT", $this->qstObject->getTrueOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
123  $tpl->setVariable("FALSE_TEXT", $this->qstObject->getFalseOptionLabelTranslation($this->lng, $this->qstObject->getOptionLabel()));
124 
125  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
126  $tpl->setVariable("DELETE_IMAGE_HEADER", $this->lng->txt('delete_image_header'));
127  $tpl->setVariable("DELETE_IMAGE_QUESTION", $this->lng->txt('delete_image_question'));
128  $tpl->setVariable("ANSWER_TEXT", $this->lng->txt('answer'));
129 
130  $tpl->setVariable("OPTIONS_TEXT", $this->lng->txt('options'));
131 
132  $a_tpl->setCurrentBlock("prop_generic");
133  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
134  $a_tpl->parseCurrentBlock();
135  }
136 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
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)
global $DIC
Definition: feed.php:28
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)