ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTextWizardInputGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
30 protected array $values = array();
31 protected bool $allowMove = false;
32
33 public function __construct(
34 string $a_title = "",
35 string $a_postvar = ""
36 ) {
37 global $DIC;
38
39 $this->lng = $DIC->language();
40 $this->tpl = $DIC["tpl"];
41 parent::__construct($a_title, $a_postvar);
42 $this->validationRegexp = "";
43 }
44
45 public function setValues(array $a_values): void
46 {
47 $this->values = $a_values;
48 }
49
53 public function setValue($a_value): void
54 {
55 $this->values = (array) $a_value;
56 }
57
58 public function getValues(): array
59 {
60 return $this->values;
61 }
62
63 public function setAllowMove(bool $a_allow_move): void
64 {
65 $this->allowMove = $a_allow_move;
66 }
67
68 public function getAllowMove(): bool
69 {
70 return $this->allowMove;
71 }
72
73 public function checkInput(): bool
74 {
76
77 $foundvalues = $this->getInput();
78 if (count($foundvalues) > 0) {
79 foreach ($foundvalues as $value) {
80 if ($this->getRequired() && trim($value) == "") {
81 $this->setAlert($lng->txt("msg_input_is_required"));
82 return false;
83 } elseif (strlen($this->getValidationRegexp())) {
84 if (!preg_match($this->getValidationRegexp(), $value)) {
85 $this->setAlert($lng->txt("msg_wrong_format"));
86 return false;
87 }
88 } elseif ($this->getMaxLength() && mb_strlen($value) > $this->getMaxLength()) {
89 $this->setAlert($lng->txt("msg_input_char_limit_max"));
90 return false;
91 }
92 }
93 } elseif ($this->getRequired()) {
94 $this->setAlert($lng->txt("msg_input_is_required"));
95 return false;
96 }
97
98 return $this->checkSubItemsInput();
99 }
100
101 public function getInput(): array
102 {
103 return $this->strArray($this->getPostVar());
104 }
105
106 public function insert(ilTemplate $a_tpl): void
107 {
108 $a_tpl->setCurrentBlock("prop_generic");
109 $a_tpl->setVariable("PROP_GENERIC", $this->render());
110 $a_tpl->parseCurrentBlock();
111 }
112
113 public function render(string $a_mode = ""): string
114 {
115 $tpl = new ilTemplate("tpl.prop_textwizardinput.html", true, true, "components/ILIAS/Form");
116 $i = 0;
117 foreach ($this->values as $value) {
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]");
128 $tpl->setVariable("UP_BUTTON", $this->symbol()->glyph("up")->render());
129 $tpl->setVariable("DOWN_BUTTON", $this->symbol()->glyph("down")->render());
131 }
132 $tpl->setCurrentBlock("row");
133 $tpl->setVariable("POST_VAR", $this->getPostVar() . "[$i]");
134 $tpl->setVariable("ID", $this->getFieldId() . "[$i]");
135 $tpl->setVariable("SIZE", $this->getSize());
136 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
137
138 if ($this->getDisabled()) {
139 $tpl->setVariable(
140 "DISABLED",
141 " disabled=\"disabled\""
142 );
143 } else {
144 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
145 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
146 $tpl->setVariable("ADD_BUTTON", $this->symbol()->glyph("add")->render());
147 $tpl->setVariable("REMOVE_BUTTON", $this->symbol()->glyph("remove")->render());
148 }
149
151 $i++;
152 }
153
154 $tpl->setVariable("ELEMENT_ID", $this->getFieldId());
155
156 if (!$this->getDisabled()) {
157 $this->tpl->addJavascript("assets/js/ServiceFormWizardInput.js");
158 $this->tpl->addJavascript("assets/js/textwizard.js");
159 }
160
161 return $tpl->get();
162 }
163}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
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 class represents a text wizard property in a property form.
ilGlobalTemplateInterface $tpl
setAllowMove(bool $a_allow_move)
__construct(string $a_title="", string $a_postvar="")
checkInput()
Check input, strip slashes etc.
setVariable(string $variable, $value='')
Sets the given variable to the given value.
parseCurrentBlock(string $block_name=self::DEFAULT_BLOCK)
Parses the given block.
setCurrentBlock(string $part=self::DEFAULT_BLOCK)
Sets the template to the given block.
get(string $part=self::DEFAULT_BLOCK)
Renders the given block and returns the html string.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26