ILIAS  release_8 Revision v8.24
class.ilSelectBuilderInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
28{
29 protected array $open_answer_indexes = array();
30
31 public function __construct(
32 string $a_title = "",
33 string $a_postvar = ""
34 ) {
35 global $DIC;
36
37 $this->lng = $DIC->language();
38 $this->tpl = $DIC["tpl"];
39 parent::__construct($a_title, $a_postvar);
40 }
41
42 public function getOpenAnswerIndexes(): array
43 {
45 }
46
47 public function setOpenAnswerIndexes(array $a_indexes): void
48 {
49 $this->open_answer_indexes = $a_indexes;
50 }
51
52 // Mark an index as open answer
53 public function addOpenAnswerIndex(string $a_idx): void
54 {
55 $this->open_answer_indexes[] = $a_idx;
56 }
57
58 public function isOpenAnswerIndex(string $a_idx): bool
59 {
60 return in_array($a_idx, $this->open_answer_indexes);
61 }
62
63 public function checkInput(): bool
64 {
66
67 $foundvalues = $this->getInput();
68 $this->setOpenAnswerIndexes(array());
69 if (is_array($foundvalues)) {
70 foreach ($foundvalues as $value) {
71 if ($this->getRequired() && trim($value) == "") {
72 $this->setAlert($lng->txt("msg_input_is_required"));
73 return false;
74 } elseif (strlen($this->getValidationRegexp())) {
75 if (!preg_match($this->getValidationRegexp(), $value)) {
76 $this->setAlert($lng->txt("msg_wrong_format"));
77 return false;
78 }
79 }
80 }
81 } else {
82 $this->setAlert($lng->txt("msg_input_is_required"));
83 return false;
84 }
85
86 foreach ($this->strArray($this->getPostVar() . '_open') as $oindex => $ovalue) {
87 $this->addOpenAnswerIndex((string) $oindex);
88 }
89
90 return $this->checkSubItemsInput();
91 }
92
93 public function getInput(): array
94 {
95 return $this->strArray($this->getPostVar());
96 }
97
98 public function setValueByArray(array $a_values): void
99 {
100 parent::setValueByArray($a_values);
101
102 foreach ($this->strArray($this->getPostVar() . '_open') as $oindex => $ovalue) {
103 $this->addOpenAnswerIndex((string) $oindex);
104 }
105 }
106
107 public function insert(ilTemplate $a_tpl): void
108 {
110
111 $tpl = new ilTemplate("tpl.prop_selectbuilder.html", true, true, "Services/Form");
112 $i = 0;
113 foreach ($this->values as $value) {
114 if (!is_string($value)) {
115 continue;
116 }
117
118 if (strlen($value)) {
119 $tpl->setCurrentBlock("prop_text_propval");
122 }
123 if ($this->getAllowMove()) {
124 $tpl->setCurrentBlock("move");
125 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
126 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
127 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
130
132 }
133 $tpl->setCurrentBlock("row");
134 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
135 #$tpl->setVariable('POST_VAR_OPEN',$this->getPostVar().'[open]'.'['.$i.']');
136 $tpl->setVariable('POST_VAR_OPEN', $this->getPostVar() . '_open' . '[' . $i . ']');
137 $tpl->setVariable('POST_VAR_OPEN_ID', $this->getPostVar() . '_open[' . $i . ']');
138 $tpl->setVariable('TXT_OPEN', $lng->txt("form_open_answer"));
139
140 if ($this->isOpenAnswerIndex((string) $i)) {
141 $tpl->setVariable('PROP_OPEN_CHECKED', 'checked="checked"');
142 }
143 if ($this->getDisabled()) {
144 $tpl->setVariable('PROP_OPEN_DISABLED', 'disabled="disabled"');
145 }
146
147 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
148 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
149 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
150 $tpl->setVariable("SIZE", $this->getSize());
151 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
152 if ($this->getDisabled()) {
154 "DISABLED",
155 " disabled=\"disabled\""
156 );
157 }
161 $i++;
162 }
163 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
164
165 $a_tpl->setCurrentBlock("prop_generic");
166 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
167 $a_tpl->parseCurrentBlock();
168
170 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
171 $tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
172 }
173}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
static get(string $a_glyph, string $a_text="")
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkInput()
Check input, strip slashes etc.
__construct(string $a_title="", string $a_postvar="")
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
global $DIC
Definition: feed.php:28
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
$i
Definition: metadata.php:41
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc