ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExplorerSelectInputGUI.php
Go to the documentation of this file.
1<?php
2
20
29{
31 protected UIServices $ui;
32
36 protected $value;
37 protected bool $multi_nodes;
39 protected bool $disabled = false;
40
48 protected $on_load_code;
49
50 public function __construct(
51 string $a_title,
52 string $a_postvar,
53 ilExplorerBaseGUI $a_explorer_gui,
54 bool $a_multi = false
55 ) {
56 global $DIC;
57
58 $this->lng = $DIC->language();
59 $this->multi_nodes = $a_multi;
60 $this->explorer_gui = $a_explorer_gui;
61 $this->global_template = $DIC->ui()->mainTemplate();
62
63 $this->ui = $DIC->ui();
64
65 parent::__construct($a_title, $a_postvar);
66 $this->setType("exp_select");
67 }
68
72 public function getExplHandleCmd(): string
73 {
74 return "handleExplorerCommand";
75 }
76
80 public function handleExplorerCommand(): void
81 {
82 $val = $this->getValue();
83 if (is_array($val)) {
84 foreach ($val as $v) {
85 $this->explorer_gui->setNodeOpen($v);
86 $this->explorer_gui->setNodeSelected($v);
87 }
88 } elseif ($val != "") {
89 $this->explorer_gui->setNodeOpen($val);
90 $this->explorer_gui->setNodeSelected($val);
91 }
92 $this->explorer_gui->handleCommand();
93 }
94
98 abstract public function getTitleForNodeId($a_id): string;
99
103 public function setValue($a_value): void
104 {
105 if ($this->multi_nodes && !is_array($a_value)) {
106 if ($a_value !== false) {
107 $this->value = array($a_value);
108 } else {
109 $this->value = array();
110 }
111 } else {
112 $this->value = $a_value;
113 }
114 }
115
119 public function getValue()
120 {
121 return $this->value;
122 }
123
127 public function setValueByArray(array $a_values): void
128 {
129 $this->setValue($a_values[$this->getPostVar()] ?? "");
130 }
131
136 public function checkInput(): bool
137 {
139
140 // check required
141 if ($this->getRequired()) {
142 if ((!$this->multi_nodes && trim($this->getInput()) === "") ||
143 ($this->multi_nodes && count($this->getInput()) === 0)) {
144 $this->setAlert($lng->txt("msg_input_is_required"));
145 return false;
146 }
147 }
148 return true;
149 }
150
154 public function getInput()
155 {
156 if ($this->multi_nodes) {
157 return $this->strArray($this->getPostVar());
158 } else {
159 return $this->str($this->getPostVar());
160 }
161 }
162
166 public function render(string $a_mode = "property_form"): string
167 {
169
171
172 $this->global_tpl->addJavascript("assets/js/Explorer2.js");
173 $this->global_tpl->addJavascript("asserts/js/LegacyModal.js");
174 $this->global_tpl->addOnLoadCode($on_load_code);
175
176 $tpl = new ilTemplate("tpl.prop_expl_select.html", true, true, "components/ILIAS/UIComponent/Explorer2");
177
178 if ($a_mode !== "property_form") {
179 $tpl->touchBlock("tiny_presentation");
180 }
181
182 // set values
183 $val = $this->getValue();
184 if (is_array($val)) {
185 $val_txt = $sep = "";
186 foreach ($val as $v) {
187 $tpl->setCurrentBlock("node_hid");
188 $tpl->setVariable("HID_NAME", $this->getPostVar() . "[]");
189 $tpl->setVariable("HID_VAL", $v);
190 $tpl->parseCurrentBlock();
191 $val_txt .= $sep . $this->getTitleForNodeId($v);
192 $sep = ", ";
193 $this->explorer_gui->setNodeOpen($v);
194 $this->explorer_gui->setNodeSelected($v);
195 }
196 $tpl->setVariable("VAL_TXT", $val_txt);
197 } elseif ($val != "") {
198 $tpl->setCurrentBlock("node_hid");
199 $tpl->setVariable("HID_NAME", $this->getPostVar());
200 $tpl->setVariable("HID_VAL", $val);
201 $tpl->parseCurrentBlock();
202 $tpl->setVariable("VAL_TXT", $this->getTitleForNodeId($val));
203 $this->explorer_gui->setNodeOpen($val);
204 $this->explorer_gui->setNodeSelected($val);
205 }
206
207 $tpl->setVariable("POST_VAR", $this->getPostVar());
208 $tpl->setVariable("ID", $this->getFieldId());
209 $this->global_template->addOnLoadCode($on_load_code);
210
211 // $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
212
213 //added disabled
214 if (!$this->disabled) {
215 $tpl->setCurrentBlock("txt_select");
216 $tpl->setVariable("TXT_SELECT", $lng->txt("select"));
217 $tpl->setVariable("ID_TXT_SELECT", $this->getFieldId());
218 $tpl->parseCurrentBlock();
219
220 $tpl->setCurrentBlock("txt_reset");
221 $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
222 $tpl->setVariable("ID_TXT_RESET", $this->getFieldId());
223 $tpl->parseCurrentBlock();
224 }
225
226 $tpl->setVariable("EXPL", $this->explorer_gui->getHTML());
227
228 $top_tb = new ilToolbarGUI();
229
230 $button = ilLinkButton::getInstance();
231 $button->setCaption("select");
232 $button->addCSSClass("ilExplSelectInputButS");
233 $button->setOmitPreventDoubleSubmission(true);
234 $top_tb->addStickyItem($button);
235
236 $button = ilLinkButton::getInstance();
237 $button->setCaption("cancel");
238 $button->addCSSClass("ilExplSelectInputButC");
239 $button->setOmitPreventDoubleSubmission(true);
240 $top_tb->addStickyItem($button);
241
242 // :TODO: we should probably clone the buttons properly
243 $tpl->setVariable("TOP_TB", $top_tb->getHTML());
244 $tpl->setVariable("BOT_TB", $top_tb->getHTML());
245
246 return $tpl->get();
247 }
248
252 public function insert(ilTemplate $a_tpl): void
253 {
254 $a_tpl->setCurrentBlock("prop_generic");
255 $a_tpl->setVariable("PROP_GENERIC", $this->render());
256 $a_tpl->parseCurrentBlock();
257 }
258
262 public function getTableFilterHTML(): string
263 {
264 $html = $this->render("table_filter");
265 return $html;
266 }
267
268 protected function getInitializationOnLoadCode(): string
269 {
270 if (isset($this->on_load_code)) {
271 return $this->on_load_code;
272 }
273
274 $modal = $this->ui->factory()->modal()->roundtrip(
275 'placeholder',
276 $this->ui->factory()->legacy()->content('<div id="' . $this->getFieldId() . '_expl_marker"></div>')
277 );
278 $rendered_modal = str_replace(
279 ["\r\n", "\n", "\r"],
280 ' ',
281 addslashes(json_encode($this->ui->renderer()->renderAsync($modal)))
282 );
283 return $this->on_load_code = 'il.Explorer2.initSelect(\'' . $this->getFieldId() . '\',"' .
284 $rendered_modal . '",\'' .
285 $modal->getShowSignal() . '\',\'' .
286 $modal->getCloseSignal() . '\');';
287 }
288}
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:544
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Select explorer tree nodes input GUI.
render(string $a_mode="property_form")
Render item.
$on_load_code
The on load code sould only be added once, otherwise the select link opens two modals and stuff break...
ilGlobalTemplateInterface $global_template
handleExplorerCommand()
Handle explorer command.
getTableFilterHTML()
Get HTML for table filter.
__construct(string $a_title, string $a_postvar, ilExplorerBaseGUI $a_explorer_gui, bool $a_multi=false)
setValueByArray(array $a_values)
Set value by array.
getTitleForNodeId($a_id)
Get title for node id (needs to be overwritten, if explorer is not a tree eplorer.
getExplHandleCmd()
Get explorer handle command function.
insert(ilTemplate $a_tpl)
Insert property html.
checkInput()
Check input, strip slashes etc.
This class represents a property in a property form.
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...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26