ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilSelectBuilderInputGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
29 {
30  protected array $open_answer_indexes = array();
31 
32  public function __construct(
33  string $a_title = "",
34  string $a_postvar = ""
35  ) {
36  global $DIC;
37 
38  $this->lng = $DIC->language();
39  $this->tpl = $DIC["tpl"];
40  parent::__construct($a_title, $a_postvar);
41  }
42 
43  public function getOpenAnswerIndexes(): array
44  {
46  }
47 
48  public function setOpenAnswerIndexes(array $a_indexes): void
49  {
50  $this->open_answer_indexes = $a_indexes;
51  }
52 
53  // Mark an index as open answer
54  public function addOpenAnswerIndex(string $a_idx): void
55  {
56  $this->open_answer_indexes[] = $a_idx;
57  }
58 
59  public function isOpenAnswerIndex(string $a_idx): bool
60  {
61  return in_array($a_idx, $this->open_answer_indexes);
62  }
63 
64  public function checkInput(): bool
65  {
66  $lng = $this->lng;
67 
68  $foundvalues = $this->getInput();
69  $this->setOpenAnswerIndexes(array());
70  if (is_array($foundvalues)) {
71  foreach ($foundvalues as $value) {
72  if ($this->getRequired() && trim($value) == "") {
73  $this->setAlert($lng->txt("msg_input_is_required"));
74  return false;
75  } elseif (strlen($this->getValidationRegexp())) {
76  if (!preg_match($this->getValidationRegexp(), $value)) {
77  $this->setAlert($lng->txt("msg_wrong_format"));
78  return false;
79  }
80  }
81  }
82  } else {
83  $this->setAlert($lng->txt("msg_input_is_required"));
84  return false;
85  }
86 
87  foreach ($this->strArray($this->getPostVar() . '_open') as $oindex => $ovalue) {
88  $this->addOpenAnswerIndex((string) $oindex);
89  }
90 
91  return $this->checkSubItemsInput();
92  }
93 
94  public function getInput(): array
95  {
96  return $this->strArray($this->getPostVar());
97  }
98 
99  public function setValueByArray(array $a_values): void
100  {
101  parent::setValueByArray($a_values);
102 
103  foreach ($this->strArray($this->getPostVar() . '_open') as $oindex => $ovalue) {
104  $this->addOpenAnswerIndex((string) $oindex);
105  }
106  }
107 
108  public function insert(ilTemplate $a_tpl): void
109  {
110  $lng = $this->lng;
111 
112  $tpl = new ilTemplate("tpl.prop_selectbuilder.html", true, true, "components/ILIAS/Form");
113  $i = 0;
114  foreach ($this->values as $value) {
115  if (!is_string($value)) {
116  continue;
117  }
118 
119  if (strlen($value)) {
120  $tpl->setCurrentBlock("prop_text_propval");
123  }
124  if ($this->getAllowMove()) {
125  $tpl->setCurrentBlock("move");
126  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
127  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
128  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
129  $tpl->setVariable("UP_BUTTON", $this->symbol()->glyph("up")->render());
130  $tpl->setVariable("DOWN_BUTTON", $this->symbol()->glyph("down")->render());
131 
133  }
134  $tpl->setCurrentBlock("row");
135  $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
136  #$tpl->setVariable('POST_VAR_OPEN',$this->getPostVar().'[open]'.'['.$i.']');
137  $tpl->setVariable('POST_VAR_OPEN', $this->getPostVar() . '_open' . '[' . $i . ']');
138  $tpl->setVariable('POST_VAR_OPEN_ID', $this->getPostVar() . '_open[' . $i . ']');
139  $tpl->setVariable('TXT_OPEN', $lng->txt("form_open_answer"));
140 
141  if ($this->isOpenAnswerIndex((string) $i)) {
142  $tpl->setVariable('PROP_OPEN_CHECKED', 'checked="checked"');
143  }
144  if ($this->getDisabled()) {
145  $tpl->setVariable('PROP_OPEN_DISABLED', 'disabled="disabled"');
146  }
147 
148  $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
149  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
150  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
151  $tpl->setVariable("SIZE", $this->getSize());
152  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
153  if ($this->getDisabled()) {
154  $tpl->setVariable(
155  "DISABLED",
156  " disabled=\"disabled\""
157  );
158  }
159  $tpl->setVariable("ADD_BUTTON", $this->symbol()->glyph("add")->render());
160  $tpl->setVariable("REMOVE_BUTTON", $this->symbol()->glyph("remove")->render());
162  $i++;
163  }
164  $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
165 
166  $a_tpl->setCurrentBlock("prop_generic");
167  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
168  $a_tpl->parseCurrentBlock();
169 
170  $tpl = $this->tpl;
171  $tpl->addJavascript("assets/js/ServiceFormWizardInput.js");
172  $tpl->addJavascript("assets/js/textwizard.js");
173  }
174 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given 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...
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
ilGlobalTemplateInterface $tpl
static prepareFormOutput($a_str, bool $a_strip=false)
setVariable(string $variable, $value='')
Sets the given variable to the given value.
__construct(string $a_title="", string $a_postvar="")
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
global $DIC
Definition: shib_login.php:26
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
Input GUI for the configuration of select input elements.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
This class represents a text wizard property in a property form.