ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilAdvSelectInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
29 {
30  protected array $options = array();
31  protected string $value = "";
32 
33  public function __construct(
34  string $a_title = "",
35  string $a_postvar = ""
36  ) {
37  global $DIC;
38 
39  $this->lng = $DIC->language();
40  parent::__construct($a_title, $a_postvar);
41  $this->setType("advselect");
42  }
43 
44  public function addOption(
45  string $a_value,
46  string $a_text,
47  string $a_html = ""
48  ): void {
49  $this->options[$a_value] = array("value" => $a_value,
50  "txt" => $a_text, "html" => $a_html);
51  }
52 
53  public function getOptions(): array
54  {
55  return $this->options;
56  }
57 
58  public function setValue(string $a_value): void
59  {
60  $this->value = $a_value;
61  }
62 
63  public function getValue(): string
64  {
65  return $this->value;
66  }
67 
68  public function setValueByArray(array $a_values): void
69  {
70  $this->setValue($a_values[$this->getPostVar()] ?? "");
71  }
72 
73  public function checkInput(): bool
74  {
75  $lng = $this->lng;
76 
77  if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
78  $this->setAlert($lng->txt("msg_input_is_required"));
79  return false;
80  }
81  return true;
82  }
83 
84  public function getInput(): string
85  {
86  return $this->str($this->getPostVar());
87  }
88 
90  {
91  $selection = new ilAdvancedSelectionListGUI();
92  $selection->setFormSelectMode(
93  $this->getPostVar(),
94  "",
95  false,
96  "",
97  "",
98  "",
99  ""
100  );
101  $selection->setId($this->getPostVar());
102  $selection->setHeaderIcon(ilAdvancedSelectionListGUI::DOWN_ARROW_DARK);
103  $selection->setSelectedValue($this->getValue());
104  $selection->setUseImages(false);
105  $selection->setOnClickMode(ilAdvancedSelectionListGUI::ON_ITEM_CLICK_FORM_SELECT);
106 
107  foreach ($this->getOptions() as $option) {
108  $selection->addItem(
109  $option["txt"],
110  $option["value"],
111  "",
112  "",
113  $option["value"],
114  "",
115  $option["html"]
116  );
117  if ($this->getValue() == $option["value"]) {
118  $selection->setListTitle($option["txt"]);
119  }
120  }
121  return $selection;
122  }
123 
124  public function insert(ilTemplate $a_tpl): void
125  {
126  $selection = $this->getAdvSelection();
127  $a_tpl->setCurrentBlock("prop_generic");
128  $a_tpl->setVariable("PROP_GENERIC", $selection->getHTML());
129  $a_tpl->parseCurrentBlock();
130  }
131 
132  public function getOnloadCode(): array
133  {
134  return $this->getAdvSelection()->getOnloadCode();
135  }
136 }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(string $a_title="", string $a_postvar="")
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...
global $DIC
Definition: feed.php:28
addOption(string $a_value, string $a_text, string $a_html="")
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
This class represents a property in a property form.
__construct(Container $dic, ilPlugin $plugin)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...