ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilEssayKeywordWizardInputGUI.php
Go to the documentation of this file.
1 <?php
19 {
20  public function setValue($a_value): void
21  {
22  $this->values = array();
23  if (is_array($a_value)) {
24  if (is_array($a_value['answer'])) {
25  foreach ($a_value['answer'] as $index => $value) {
26  if (isset($a_value['points'])) {
27  $pvalue = $a_value['points'][$index];
28  } else {
29  $value = 0.0;
30  }
31  if (isset($a_value['points_unchecked'])) {
32  $value_unchecked = $a_value['points_unchecked'][$index];
33  } else {
34  $value_unchecked = 0.0;
35  }
36  $answer = new ASS_AnswerMultipleResponseImage($value, (float) $pvalue, $index, $value_unchecked);
37  $this->values[] = $answer;
38  }
39  }
40  }
41  }
42 
47  public function checkInput(): bool
48  {
49  global $DIC;
50  $lng = $DIC['lng'];
51 
52  if (is_array($_POST[$this->getPostVar()])) {
54  $_POST[$this->getPostVar()],
55  false,
57  "assessment"
58  )
59  );
60  } else {
61  $foundvalues = $_POST[$this->getPostVar()];
62  }
63  if (is_array($foundvalues)) {
64  // check answers
65  if (is_array($foundvalues['answer'])) {
66  foreach ($foundvalues['answer'] as $aidx => $answervalue) {
67  if (((strlen($answervalue)) == 0) && (!isset($foundvalues['imagename']) || strlen($foundvalues['imagename'][$aidx]) == 0)) {
68  $this->setAlert($lng->txt("msg_input_is_required"));
69  return false;
70  }
71 
72  if (mb_strlen($answervalue) > $this->getMaxLength()) {
73  $this->setAlert($lng->txt("msg_input_char_limit_max"));
74  return false;
75  }
76  }
77  }
78  // check points
79  $max = 0;
80  if (is_array($foundvalues['points'])) {
81  foreach ($foundvalues['points'] as $points) {
82  if ($points > $max) {
83  $max = $points;
84  }
85  if (((strlen($points)) == 0) || (!is_numeric($points))) {
86  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
87  return false;
88  }
89  }
90  }
91  if ($max == 0) {
92  $this->setAlert($lng->txt("enter_enough_positive_points"));
93  return false;
94  }
95  } else {
96  $this->setAlert($lng->txt("msg_input_is_required"));
97  return false;
98  }
99 
100  return $this->checkSubItemsInput();
101  }
102 
107  public function insert(ilTemplate $a_tpl): void
108  {
109  global $DIC;
110  $lng = $DIC['lng'];
111 
112  $tpl = new ilTemplate("tpl.prop_essaykeywordswizardinput.html", true, true, "Modules/TestQuestionPool");
113  $i = 0;
114  foreach ($this->values as $value) {
115  if ($this->getSingleline()) {
116  if (is_object($value)) {
117  $tpl->setCurrentBlock("prop_text_propval");
118  $tpl->setVariable(
119  "PROPERTY_VALUE",
120  ilLegacyFormElementsUtil::prepareFormOutput($value->getAnswertext())
121  );
122  $tpl->parseCurrentBlock();
123  $tpl->setCurrentBlock("prop_points_propval");
124  $tpl->setVariable(
125  "PROPERTY_VALUE",
126  ilLegacyFormElementsUtil::prepareFormOutput($value->getPointsChecked())
127  );
128  $tpl->parseCurrentBlock();
129  }
130  $tpl->setCurrentBlock('singleline');
131  $tpl->setVariable("SIZE", $this->getSize());
132  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
133  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
134  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
135  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
136  if ($this->getDisabled()) {
137  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
138  }
139  $tpl->parseCurrentBlock();
140  } else {
141  if (!$this->getSingleline()) {
142  if (is_object($value)) {
143  $tpl->setCurrentBlock("prop_points_propval");
144  $tpl->setVariable(
145  "PROPERTY_VALUE",
147  );
148  $tpl->parseCurrentBlock();
149  }
150  }
151  }
152 
153  $tpl->setCurrentBlock("row");
154  $tpl->setVariable("POST_VAR", $this->getPostVar());
155  $tpl->setVariable("ROW_NUMBER", $i);
156  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
157  $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
158  if ($this->getDisabled()) {
159  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
160  }
161  $tpl->setVariable("ADD_BUTTON", $this->renderer->render(
162  $this->glyph_factory->add()->withAction('#')
163  ));
164  $tpl->setVariable("REMOVE_BUTTON", $this->renderer->render(
165  $this->glyph_factory->remove()->withAction('#')
166  ));
167  $tpl->parseCurrentBlock();
168  $i++;
169  }
170 
171  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
172  $tpl->setVariable("TEXT_YES", $lng->txt('yes'));
173  $tpl->setVariable("TEXT_NO", $lng->txt('no'));
174  $tpl->setVariable("DELETE_IMAGE_HEADER", $lng->txt('delete_image_header'));
175  $tpl->setVariable("DELETE_IMAGE_QUESTION", $lng->txt('delete_image_question'));
176  $tpl->setVariable("ANSWER_TEXT", $lng->txt('answer_text'));
177  $tpl->setVariable("POINTS_TEXT", $lng->txt('points'));
178  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
179  $tpl->setVariable("POINTS_CHECKED_TEXT", $lng->txt('checkbox_checked'));
180 
181  $a_tpl->setCurrentBlock("prop_generic");
182  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
183  $a_tpl->parseCurrentBlock();
184 
185  global $DIC;
186  $tpl = $DIC['tpl'];
187  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizardinput.js");
188  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/essaykeywordwizard.js");
189  }
190 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static stripSlashesRecursive($a_data, bool $a_strip_html=true, string $a_allow="")
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...
ASS_AnswerBinaryStateImage is a class for answers with a binary state indicator (checked/unchecked, set/unset) and an image file.
static prepareFormOutput($a_str, bool $a_strip=false)
checkInput()
Check input, strip slashes etc.
global $DIC
Definition: feed.php:28
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
static _getUsedHTMLTagsAsString(string $a_module="")
Returns a string of all allowed HTML tags for text editing.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a single choice wizard property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
insert(ilTemplate $a_tpl)
Insert property html.