ILIAS  release_8 Revision v8.24
class.ilTextWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
29 protected array $values = array();
30 protected bool $allowMove = false;
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 $this->validationRegexp = "";
42 }
43
44 public function setValues(array $a_values): void
45 {
46 $this->values = $a_values;
47 }
48
52 public function setValue($a_value): void
53 {
54 $this->values = (array) $a_value;
55 }
56
57 public function getValues(): array
58 {
59 return $this->values;
60 }
61
62 public function setAllowMove(bool $a_allow_move): void
63 {
64 $this->allowMove = $a_allow_move;
65 }
66
67 public function getAllowMove(): bool
68 {
69 return $this->allowMove;
70 }
71
72 public function checkInput(): bool
73 {
75
76 $foundvalues = $this->getInput();
77 if (count($foundvalues) > 0) {
78 foreach ($foundvalues as $value) {
79 if ($this->getRequired() && trim($value) == "") {
80 $this->setAlert($lng->txt("msg_input_is_required"));
81 return false;
82 } elseif (strlen($this->getValidationRegexp())) {
83 if (!preg_match($this->getValidationRegexp(), $value)) {
84 $this->setAlert($lng->txt("msg_wrong_format"));
85 return false;
86 }
87 } elseif ($this->getMaxLength() && mb_strlen($value) > $this->getMaxLength()) {
88 $this->setAlert($lng->txt("msg_input_char_limit_max"));
89 return false;
90 }
91 }
92 } elseif ($this->getRequired()) {
93 $this->setAlert($lng->txt("msg_input_is_required"));
94 return false;
95 }
96
97 return $this->checkSubItemsInput();
98 }
99
100 public function getInput(): array
101 {
102 return $this->strArray($this->getPostVar());
103 }
104
105 public function insert(ilTemplate $a_tpl): void
106 {
107 $a_tpl->setCurrentBlock("prop_generic");
108 $a_tpl->setVariable("PROP_GENERIC", $this->render());
109 $a_tpl->parseCurrentBlock();
110 }
111
112 public function render(string $a_mode = ""): string
113 {
114 $tpl = new ilTemplate("tpl.prop_textwizardinput.html", true, true, "Services/Form");
115 $i = 0;
116 foreach ($this->values as $value) {
117 if (strlen($value)) {
118 $tpl->setCurrentBlock("prop_text_propval");
121 }
122 if ($this->getAllowMove()) {
123 $tpl->setCurrentBlock("move");
124 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
125 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
126 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
127 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
130 }
131 $tpl->setCurrentBlock("row");
132 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
133 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
134 $tpl->setVariable("SIZE", $this->getSize());
135 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
136
137 if ($this->getDisabled()) {
138 $tpl->setVariable(
139 "DISABLED",
140 " disabled=\"disabled\""
141 );
142 } else {
143 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
144 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
145 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
147 }
148
150 $i++;
151 }
152
153 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
154
155 if (!$this->getDisabled()) {
156 $this->tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
157 $this->tpl->addJavascript("./Services/Form/templates/default/textwizard.js");
158 }
159
160 return $tpl->get();
161 }
162}
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)
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilGlobalTemplateInterface $tpl
setAllowMove(bool $a_allow_move)
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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