ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMatchingPairWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
28  protected $pairs = [];
29  protected $allowMove = false;
30  protected $terms = [];
31  protected $definitions = [];
32 
39  public function __construct($a_title = "", $a_postvar = "")
40  {
41  parent::__construct($a_title, $a_postvar);
42  }
43 
44  public function setValue($a_value): void
45  {
46  $this->pairs = array();
47  $this->terms = array();
48  $this->definitions = array();
49  if (is_array($a_value)) {
50  if (isset($a_value['term']) && is_array($a_value['term'])) {
51  foreach ($a_value['term'] as $idx => $term) {
52  $this->pairs[] = new assAnswerMatchingPair(
53  new assAnswerMatchingTerm('', '', $term),
54  new assAnswerMatchingDefinition('', '', $a_value['definition'][$idx]),
55  (float) $a_value['points'][$idx]
56  );
57  }
58  }
59  $term_ids = explode(",", $a_value['term_id']);
60  foreach ($term_ids as $id) {
61  $this->terms[] = new assAnswerMatchingTerm('', '', $id);
62  }
63  $definition_ids = explode(",", $a_value['definition_id']);
64  foreach ($definition_ids as $id) {
65  $this->definitions[] = new assAnswerMatchingDefinition('', '', $id);
66  }
67  }
68  }
69 
75  public function setTerms($a_terms): void
76  {
77  $this->terms = $a_terms;
78  }
79 
85  public function setDefinitions($a_definitions): void
86  {
87  $this->definitions = $a_definitions;
88  }
89 
95  public function setPairs($a_pairs): void
96  {
97  $this->pairs = $a_pairs;
98  }
99 
105  public function setAllowMove($a_allow_move): void
106  {
107  $this->allowMove = $a_allow_move;
108  }
109 
115  public function getAllowMove(): bool
116  {
117  return $this->allowMove;
118  }
119 
124  public function checkInput(): bool
125  {
126  global $DIC;
127  $lng = $DIC['lng'];
128 
129  if (is_array($_POST[$this->getPostVar()])) {
130  $foundvalues = ilArrayUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
131  } else {
132  $foundvalues = $_POST[$this->getPostVar()];
133  }
134  if (is_array($foundvalues)) {
135  // check answers
136  if (isset($foundvalues['term']) && is_array($foundvalues['term'])) {
137  foreach ($foundvalues['term'] as $val) {
138  if ($this->getRequired() && $val < 1) {
139  $this->setAlert($lng->txt("msg_input_is_required"));
140  return false;
141  }
142  }
143  foreach ($foundvalues['definition'] as $val) {
144  if ($this->getRequired() && $val < 1) {
145  $this->setAlert($lng->txt("msg_input_is_required"));
146  return false;
147  }
148  }
149  $max = 0;
150  foreach ($foundvalues['points'] as $val) {
151  if ($this->getRequired() && (strlen($val)) === 0) {
152  $this->setAlert($lng->txt("msg_input_is_required"));
153  return false;
154  }
155  $val = str_replace(",", ".", $val);
156  if (!is_numeric($val)) {
157  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
158  return false;
159  }
160 
161  $val = (float) $val;
162  if ($val > 0) {
163  $max += $val;
164  }
165  }
166  if ($max <= 0) {
167  $this->setAlert($lng->txt("enter_enough_positive_points"));
168  return false;
169  }
170  } else {
171  if ($this->getRequired()) {
172  $this->setAlert($lng->txt("msg_input_is_required"));
173  return false;
174  }
175  }
176  } else {
177  if ($this->getRequired()) {
178  $this->setAlert($lng->txt("msg_input_is_required"));
179  return false;
180  }
181  }
182  return $this->checkSubItemsInput();
183  }
184 
189  public function insert(ilTemplate $a_tpl): void
190  {
191  global $DIC;
192  $lng = $DIC['lng'];
193  $global_tpl = $DIC['tpl'];
194  $global_tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
195  $global_tpl->addJavascript("./Modules/TestQuestionPool/templates/default/matchingpairwizard.js");
196 
197  $tpl = new ilTemplate("tpl.prop_matchingpairinput.html", true, true, "Modules/TestQuestionPool");
198  $i = 0;
199 
200  foreach ($this->pairs as $pair) {
201  $counter = 1;
202  $tpl->setCurrentBlock("option_term");
203  $tpl->setVariable("TEXT_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($lng->txt('please_select')));
204  $tpl->setVariable("VALUE_OPTION", 0);
205  $tpl->parseCurrentBlock();
206  foreach ($this->terms as $term) {
207  $tpl->setCurrentBlock("option_term");
208  $tpl->setVariable("VALUE_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($term->getIdentifier()));
209  $tpl->setVariable("TEXT_OPTION", $lng->txt('term') . " " . $counter);
210  if ($pair->getTerm()->getIdentifier() == $term->getIdentifier()) {
211  $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
212  }
213  $tpl->parseCurrentBlock();
214  $counter++;
215  }
216  $counter = 1;
217  $tpl->setCurrentBlock("option_definition");
218  $tpl->setVariable("TEXT_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($lng->txt('please_select')));
219  $tpl->setVariable("VALUE_OPTION", 0);
220  $tpl->parseCurrentBlock();
221  foreach ($this->definitions as $definition) {
222  $tpl->setCurrentBlock("option_definition");
223  $tpl->setVariable("VALUE_OPTION", ilLegacyFormElementsUtil::prepareFormOutput($definition->getIdentifier()));
224  $tpl->setVariable("TEXT_OPTION", $lng->txt('definition') . " " . $counter);
225  if ($pair->getDefinition()->getIdentifier() == $definition->getIdentifier()) {
226  $tpl->setVariable('SELECTED_OPTION', ' selected="selected"');
227  }
228  $tpl->parseCurrentBlock();
229  $counter++;
230  }
231 
232 
233  $tpl->setCurrentBlock('points_value');
234  $tpl->setVariable('POINTS_VALUE', $pair->getPoints());
235  $tpl->parseCurrentBlock();
236 
237  if ($this->getAllowMove()) {
238  $tpl->setCurrentBlock("move");
239  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
240  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
241  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
242  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
243  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
244  $tpl->parseCurrentBlock();
245  }
246 
247  $tpl->setCurrentBlock("row");
248  $tpl->setVariable("ROW_NUMBER", $i);
249 
250  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
251  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
252  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
253  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
254  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
255 
256  $tpl->setVariable("POST_VAR", $this->getPostVar());
257 
258  $tpl->parseCurrentBlock();
259 
260  $i++;
261  }
262 
263  $tpl->setCurrentBlock('term_ids');
264  $ids = array();
265  foreach ($this->terms as $term) {
266  array_push($ids, $term->getIdentifier());
267  }
268  $tpl->setVariable("POST_VAR", $this->getPostVar());
269  $tpl->setVariable("TERM_IDS", join(",", $ids));
270  $tpl->parseCurrentBlock();
271 
272  $tpl->setCurrentBlock('definition_ids');
273  $ids = array();
274  foreach ($this->definitions as $definition) {
275  array_push($ids, $definition->getIdentifier());
276  }
277  $tpl->setVariable("POST_VAR", $this->getPostVar());
278  $tpl->setVariable("DEFINITION_IDS", join(",", $ids));
279  $tpl->parseCurrentBlock();
280 
281  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
282  $tpl->setVariable("TEXT_POINTS", $lng->txt('points'));
283  $tpl->setVariable("TEXT_DEFINITION", $lng->txt('definition'));
284  $tpl->setVariable("TEXT_TERM", $lng->txt('term'));
285  $tpl->setVariable("TEXT_ACTIONS", $lng->txt('actions'));
286 
287  $a_tpl->setCurrentBlock("prop_generic");
288  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
289  $a_tpl->parseCurrentBlock();
290  }
291 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDefinitions($a_definitions)
Set definitions.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
static get(string $a_glyph, string $a_text="")
static prepareFormOutput($a_str, bool $a_strip=false)
checkInput()
Check input, strip slashes etc.
global $DIC
Definition: feed.php:28
insert(ilTemplate $a_tpl)
Insert property html.
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
ilGlobalTemplateInterface $global_tpl
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$i
Definition: metadata.php:41
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct($a_title="", $a_postvar="")
Constructor.