ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExplorerSelectInputGUI.php
Go to the documentation of this file.
1 <?php
2 
27 {
32  protected $value;
33  protected bool $multi_nodes;
35  protected bool $disabled = false;
36 
37  public function __construct(
38  string $a_title,
39  string $a_postvar,
40  ilExplorerBaseGUI $a_explorer_gui,
41  bool $a_multi = false
42  ) {
43  global $DIC;
44 
45  $this->lng = $DIC->language();
46  $this->multi_nodes = $a_multi;
47  $this->explorer_gui = $a_explorer_gui;
48  $this->global_template = $DIC->ui()->mainTemplate();
49 
50  parent::__construct($a_title, $a_postvar);
51  $this->setType("exp_select");
52  }
53 
57  public function getExplHandleCmd(): string
58  {
59  return "handleExplorerCommand";
60  }
61 
65  public function handleExplorerCommand(): void
66  {
67  $val = $this->getValue();
68  if (is_array($val)) {
69  foreach ($val as $v) {
70  $this->explorer_gui->setNodeOpen($v);
71  $this->explorer_gui->setNodeSelected($v);
72  }
73  } elseif ($val != "") {
74  $this->explorer_gui->setNodeOpen($val);
75  $this->explorer_gui->setNodeSelected($val);
76  }
77  $this->explorer_gui->handleCommand();
78  }
79 
83  abstract public function getTitleForNodeId($a_id): string;
84 
88  public function setValue($a_value): void
89  {
90  if ($this->multi_nodes && !is_array($a_value)) {
91  if ($a_value !== false) {
92  $this->value = array($a_value);
93  } else {
94  $this->value = array();
95  }
96  } else {
97  $this->value = $a_value;
98  }
99  }
100 
104  public function getValue()
105  {
106  return $this->value;
107  }
108 
112  public function setValueByArray(array $a_values): void
113  {
114  $this->setValue($a_values[$this->getPostVar()] ?? "");
115  }
116 
121  public function checkInput(): bool
122  {
123  $lng = $this->lng;
124 
125  // check required
126  if ($this->getRequired()) {
127  if ((!$this->multi_nodes && trim($this->getInput()) === "") ||
128  ($this->multi_nodes && count($this->getInput()) === 0)) {
129  $this->setAlert($lng->txt("msg_input_is_required"));
130  return false;
131  }
132  }
133  return true;
134  }
135 
139  public function getInput()
140  {
141  if ($this->multi_nodes) {
142  return $this->strArray($this->getPostVar());
143  } else {
144  return $this->str($this->getPostVar());
145  }
146  }
147 
151  public function render(string $a_mode = "property_form"): string
152  {
153  $lng = $this->lng;
154 
155  $this->global_tpl->addJavascript("./Services/UIComponent/Explorer2/js/Explorer2.js");
156  $this->global_tpl->addJavascript("./Services/UIComponent/Modal/js/Modal.js");
157  $this->global_tpl->addOnLoadCode(
158  "il.Explorer2.initSelect('" . $this->getFieldId() . "');"
159  );
160 
161  $tpl = new ilTemplate("tpl.prop_expl_select.html", true, true, "Services/UIComponent/Explorer2");
162 
163  if ($a_mode !== "property_form") {
164  $tpl->touchBlock("tiny_presentation");
165  }
166 
167  // set values
168  $val = $this->getValue();
169  if (is_array($val)) {
170  $val_txt = $sep = "";
171  foreach ($val as $v) {
172  $tpl->setCurrentBlock("node_hid");
173  $tpl->setVariable("HID_NAME", $this->getPostVar() . "[]");
174  $tpl->setVariable("HID_VAL", $v);
175  $tpl->parseCurrentBlock();
176  $val_txt .= $sep . $this->getTitleForNodeId($v);
177  $sep = ", ";
178  $this->explorer_gui->setNodeOpen($v);
179  $this->explorer_gui->setNodeSelected($v);
180  }
181  $tpl->setVariable("VAL_TXT", $val_txt);
182  } elseif ($val != "") {
183  $tpl->setCurrentBlock("node_hid");
184  $tpl->setVariable("HID_NAME", $this->getPostVar());
185  $tpl->setVariable("HID_VAL", $val);
186  $tpl->parseCurrentBlock();
187  $tpl->setVariable("VAL_TXT", $this->getTitleForNodeId($val));
188  $this->explorer_gui->setNodeOpen($val);
189  $this->explorer_gui->setNodeSelected($val);
190  }
191 
192  $tpl->setVariable("POST_VAR", $this->getPostVar());
193  $tpl->setVariable("ID", $this->getFieldId());
194  $ol_js = "il.Explorer2.initSelect('" . $this->getFieldId() . "');";
195  $this->global_template->addOnLoadCode($ol_js);
196 
197  // $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
198 
199  //added disabled
200  if (!$this->disabled) {
201  $tpl->setCurrentBlock("txt_select");
202  $tpl->setVariable("TXT_SELECT", $lng->txt("select"));
203  $tpl->setVariable("ID_TXT_SELECT", $this->getFieldId());
204  $tpl->parseCurrentBlock();
205 
206  $tpl->setCurrentBlock("txt_reset");
207  $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
208  $tpl->setVariable("ID_TXT_RESET", $this->getFieldId());
209  $tpl->parseCurrentBlock();
210  }
211 
212  $tpl->setVariable("EXPL", $this->explorer_gui->getHTML());
213 
214  $top_tb = new ilToolbarGUI();
215 
216  $button = ilLinkButton::getInstance();
217  $button->setCaption("select");
218  $button->addCSSClass("ilExplSelectInputButS");
219  $button->setOmitPreventDoubleSubmission(true);
220  $top_tb->addStickyItem($button);
221 
222  $button = ilLinkButton::getInstance();
223  $button->setCaption("cancel");
224  $button->addCSSClass("ilExplSelectInputButC");
225  $button->setOmitPreventDoubleSubmission(true);
226  $top_tb->addStickyItem($button);
227 
228  // :TODO: we should probably clone the buttons properly
229  $tpl->setVariable("TOP_TB", $top_tb->getHTML());
230  $tpl->setVariable("BOT_TB", $top_tb->getHTML());
231 
232  return $tpl->get();
233  }
234 
238  public function insert(ilTemplate $a_tpl): void
239  {
240  $a_tpl->setCurrentBlock("prop_generic");
241  $a_tpl->setVariable("PROP_GENERIC", $this->render());
242  $a_tpl->parseCurrentBlock();
243  }
244 
248  public function getTableFilterHTML(): string
249  {
250  $html = $this->render("table_filter");
251  return $html;
252  }
253 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_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...
render(string $a_mode="property_form")
Render item.
getTableFilterHTML()
Get HTML for table filter.
checkInput()
Check input, strip slashes etc.
__construct(string $a_title, string $a_postvar, ilExplorerBaseGUI $a_explorer_gui, bool $a_multi=false)
global $DIC
Definition: feed.php:28
__construct(VocabulariesInterface $vocabularies)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:546
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getExplHandleCmd()
Get explorer handle command function.
getTitleForNodeId($a_id)
Get title for node id (needs to be overwritten, if explorer is not a tree eplorer.
handleExplorerCommand()
Handle explorer command.
ilGlobalTemplateInterface $global_template
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setValueByArray(array $a_values)
Set value by array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
disabled()
Example showing how to plug a disabled checkbox into a form.
Definition: disabled.php:10
insert(ilTemplate $a_tpl)
Insert property html.