ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExplorerSelectInputGUI.php
Go to the documentation of this file.
1 <?php
2 
25 {
29  protected $value;
30  protected bool $multi_nodes;
32  protected bool $disabled = false;
33 
34  public function __construct(
35  string $a_title,
36  string $a_postvar,
37  ilExplorerBaseGUI $a_explorer_gui,
38  bool $a_multi = false
39  ) {
40  global $DIC;
41 
42  $this->lng = $DIC->language();
43  $this->multi_nodes = $a_multi;
44  $this->explorer_gui = $a_explorer_gui;
45  $this->global_template = $DIC['tpl'];
46 
47  parent::__construct($a_title, $a_postvar);
48  $this->setType("exp_select");
49  }
50 
54  public function getExplHandleCmd(): string
55  {
56  return "handleExplorerCommand";
57  }
58 
62  public function handleExplorerCommand(): void
63  {
64  $val = $this->getValue();
65  if (is_array($val)) {
66  foreach ($val as $v) {
67  $this->explorer_gui->setNodeOpen($v);
68  $this->explorer_gui->setNodeSelected($v);
69  }
70  } elseif ($val != "") {
71  $this->explorer_gui->setNodeOpen($val);
72  $this->explorer_gui->setNodeSelected($val);
73  }
74  $this->explorer_gui->handleCommand();
75  }
76 
80  abstract public function getTitleForNodeId($a_id): string;
81 
85  public function setValue($a_value): void
86  {
87  if ($this->multi_nodes && !is_array($a_value)) {
88  if ($a_value !== false) {
89  $this->value = array($a_value);
90  } else {
91  $this->value = array();
92  }
93  } else {
94  $this->value = $a_value;
95  }
96  }
97 
101  public function getValue()
102  {
103  return $this->value;
104  }
105 
109  public function setValueByArray(array $a_values): void
110  {
111  $this->setValue($a_values[$this->getPostVar()] ?? "");
112  }
113 
118  public function checkInput(): bool
119  {
120  $lng = $this->lng;
121 
122  // check required
123  if ($this->getRequired()) {
124  if ((!$this->multi_nodes && trim($this->getInput()) === "") ||
125  ($this->multi_nodes && count($this->getInput()) === 0)) {
126  $this->setAlert($lng->txt("msg_input_is_required"));
127  return false;
128  }
129  }
130  return true;
131  }
132 
136  public function getInput()
137  {
138  if ($this->multi_nodes) {
139  return $this->strArray($this->getPostVar());
140  } else {
141  return $this->str($this->getPostVar());
142  }
143  }
144 
148  public function render(string $a_mode = "property_form"): string
149  {
150  $lng = $this->lng;
151 
152  $this->global_tpl->addJavascript("./Services/UIComponent/Explorer2/js/Explorer2.js");
153  $this->global_tpl->addJavascript("./Services/UIComponent/Modal/js/Modal.js");
154  $this->global_tpl->addOnLoadCode(
155  "il.Explorer2.initSelect('" . $this->getFieldId() . "');"
156  );
157 
158  $tpl = new ilTemplate("tpl.prop_expl_select.html", true, true, "Services/UIComponent/Explorer2");
159 
160  if ($a_mode !== "property_form") {
161  $tpl->touchBlock("tiny_presentation");
162  }
163 
164  // set values
165  $val = $this->getValue();
166  if (is_array($val)) {
167  $val_txt = $sep = "";
168  foreach ($val as $v) {
169  $tpl->setCurrentBlock("node_hid");
170  $tpl->setVariable("HID_NAME", $this->getPostVar() . "[]");
171  $tpl->setVariable("HID_VAL", $v);
172  $tpl->parseCurrentBlock();
173  $val_txt .= $sep . $this->getTitleForNodeId($v);
174  $sep = ", ";
175  $this->explorer_gui->setNodeOpen($v);
176  $this->explorer_gui->setNodeSelected($v);
177  }
178  $tpl->setVariable("VAL_TXT", $val_txt);
179  } elseif ($val != "") {
180  $tpl->setCurrentBlock("node_hid");
181  $tpl->setVariable("HID_NAME", $this->getPostVar());
182  $tpl->setVariable("HID_VAL", $val);
183  $tpl->parseCurrentBlock();
184  $tpl->setVariable("VAL_TXT", $this->getTitleForNodeId($val));
185  $this->explorer_gui->setNodeOpen($val);
186  $this->explorer_gui->setNodeSelected($val);
187  }
188 
189  $tpl->setVariable("POST_VAR", $this->getPostVar());
190  $tpl->setVariable("ID", $this->getFieldId());
191  $ol_js = "il.Explorer2.initSelect('" . $this->getFieldId() . "');";
192  $this->global_template->addOnLoadCode($ol_js);
193 
194  // $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->getValue()));
195 
196  //added disabled
197  if (!$this->disabled) {
198  $tpl->setCurrentBlock("txt_select");
199  $tpl->setVariable("TXT_SELECT", $lng->txt("select"));
200  $tpl->setVariable("ID_TXT_SELECT", $this->getFieldId());
201  $tpl->parseCurrentBlock();
202 
203  $tpl->setCurrentBlock("txt_reset");
204  $tpl->setVariable("TXT_RESET", $lng->txt("reset"));
205  $tpl->setVariable("ID_TXT_RESET", $this->getFieldId());
206  $tpl->parseCurrentBlock();
207  }
208 
209  $tpl->setVariable("EXPL", $this->explorer_gui->getHTML());
210 
211  $top_tb = new ilToolbarGUI();
212 
213  $button = ilLinkButton::getInstance();
214  $button->setCaption("select");
215  $button->addCSSClass("ilExplSelectInputButS");
216  $button->setOmitPreventDoubleSubmission(true);
217  $top_tb->addStickyItem($button);
218 
219  $button = ilLinkButton::getInstance();
220  $button->setCaption("cancel");
221  $button->addCSSClass("ilExplSelectInputButC");
222  $button->setOmitPreventDoubleSubmission(true);
223  $top_tb->addStickyItem($button);
224 
225  // :TODO: we should probably clone the buttons properly
226  $tpl->setVariable("TOP_TB", $top_tb->getHTML());
227  $tpl->setVariable("BOT_TB", $top_tb->getHTML());
228 
229  return $tpl->get();
230  }
231 
235  public function insert(ilTemplate $a_tpl): void
236  {
237  $a_tpl->setCurrentBlock("prop_generic");
238  $a_tpl->setVariable("PROP_GENERIC", $this->render());
239  $a_tpl->parseCurrentBlock();
240  }
241 
245  public function getTableFilterHTML(): string
246  {
247  $html = $this->render("table_filter");
248  return $html;
249  }
250 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
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.
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a property in a property form.
setValueByArray(array $a_values)
Set value by array.
__construct(Container $dic, ilPlugin $plugin)
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
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
insert(ilTemplate $a_tpl)
Insert property html.