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