ILIAS  release_8 Revision v8.23
ilSelectInputGUI Class Reference

This class represents a selection list property in a property form. More...

+ Inheritance diagram for ilSelectInputGUI:
+ Collaboration diagram for ilSelectInputGUI:

Public Member Functions

 __construct (string $a_title="", string $a_postvar="")
 
 setOptions (array $a_options)
 
 getOptions ()
 
 setValue ($a_value)
 Set Value. More...
 
 getValue ()
 Get Value. More...
 
 setValueByArray (array $a_values)
 
 checkInput ()
 
 getInput ()
 
 addCustomAttribute (string $a_attr)
 
 getCustomAttributes ()
 
 render ($a_mode="")
 
 insert (ilTemplate $a_tpl)
 
 getTableFilterHTML ()
 Get input item HTML to be inserted into table filters. More...
 
 getToolbarHTML ()
 Get input item HTML to be inserted into ilToolbarGUI. More...
 
 setHideSubForm (bool $a_value, ?string $a_condition=null)
 Set initial sub form visibility, optionally add dynamic value-based condition. More...
 
 hideSubForm ()
 
- Public Member Functions inherited from ilSubEnabledFormPropertyGUI
 addSubItem (ilFormPropertyGUI $a_item)
 
 getSubItems ()
 
 getSubInputItemsRecursive ()
 returns a flat array of possibly existing subitems recursively More...
 
 checkSubItemsInput ()
 Check SubItems. More...
 
 getSubForm ()
 
 getItemByPostVar (string $a_post_var)
 
- Public Member Functions inherited from ilFormPropertyGUI
 __construct (string $a_title="", string $a_postvar="")
 
 executeCommand ()
 
 getType ()
 
 setTitle (string $a_title)
 
 getTitle ()
 
 setPostVar (string $a_postvar)
 
 getPostVar ()
 
 getFieldId ()
 
 setInfo (string $a_info)
 
 getInfo ()
 
 setAlert (string $a_alert)
 
 getAlert ()
 
 setRequired (bool $a_required)
 
 getRequired ()
 
 setDisabled (bool $a_disabled)
 
 getDisabled ()
 
 checkInput ()
 Check input, strip slashes etc. More...
 
 setParentForm (ilPropertyFormGUI $a_parentform)
 
 getParentForm ()
 
 setParent (ilFormPropertyGUI $a_val)
 
 getParent ()
 
 getSubForm ()
 
 hideSubForm ()
 
 setHiddenTitle (string $a_val)
 
 getHiddenTitle ()
 
 getItemByPostVar (string $a_post_var)
 Get item by post var. More...
 
 serializeData ()
 
 unserializeData (string $a_data)
 
 setParentTable ($a_val)
 Set parent table. More...
 
 getParentTable ()
 Get parent table. More...
 
 writeToSession ()
 
 clearFromSession ()
 
 readFromSession ()
 
 getHiddenTag (string $a_post_var, string $a_value)
 
 setMulti (bool $a_multi, bool $a_sortable=false, bool $a_addremove=true)
 
 getMulti ()
 
 setMultiValues (array $a_values)
 
 getMultiValues ()
 
 getContentOutsideFormTag ()
 Get content that has to reside outside of the parent form tag, e.g. More...
 
 stripSlashesAddSpaceFallback (string $a_str)
 Strip slashes with add space fallback, see https://www.ilias.de/mantis/view.php?id=19727. More...
 
 getTableFilterLabelFor ()
 Get label "for" attribute value for filter. More...
 
 getFormLabelFor ()
 Get label "for" attribute value for form. More...
 
 setRequestParam (string $key, $val)
 This writes the request (aka post) values. More...
 
- Public Member Functions inherited from ilTableFilterItem
 getTableFilterLabelFor ()
 Get label "for" attribute value. More...
 

Protected Attributes

array $cust_attr = array()
 
array $options = array()
 
 $value
 
bool $hide_sub = false
 
- Protected Attributes inherited from ilSubEnabledFormPropertyGUI
array $sub_items = array()
 
- Protected Attributes inherited from ilFormPropertyGUI
array $set_params = []
 
ilTable2GUI $parent_table = null
 
ilFormPropertyGUI $parent_gui = null
 
ilCtrl $ctrl
 
ilLanguage $lng
 
string $type = ""
 
string $title = ""
 
string $postvar = ""
 
string $info = ""
 
string $alert = ""
 
bool $required = false
 
ilPropertyFormGUI $parentform = null
 
string $hidden_title = ""
 
bool $multi = false
 
bool $multi_sortable = false
 
bool $multi_addremove = true
 
array $multi_values = []
 
RequestInterface $request
 
HTTP Services $http
 
Refinery Factory $refinery = null
 
bool $disabled = false
 
ilGlobalTemplateInterface $global_tpl = null
 

Additional Inherited Members

- Static Public Member Functions inherited from ilFormPropertyGUI
static removeProhibitedCharacters (string $a_text)
 Remove prohibited characters see #19159. More...
 
- Protected Member Functions inherited from ilFormPropertyGUI
 setType (string $a_type)
 
 checkParentFormTable ()
 
 getSessionKey ()
 
 getMultiIconsHTML ()
 
 int ($key)
 
 intArray ($key)
 
 str ($key)
 
 raw ($key)
 
 strArray ($key)
 
 arrayArray ($key)
 
 isRequestParamArray (string $key)
 
 getRequestParam (string $key, Refinery\Transformation $t)
 

Detailed Description

This class represents a selection list property in a property form.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 26 of file class.ilSelectInputGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilSelectInputGUI::__construct ( string  $a_title = "",
string  $a_postvar = "" 
)

Definition at line 36 of file class.ilSelectInputGUI.php.

References $DIC, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Repository\lng(), and ilFormPropertyGUI\setType().

39  {
40  global $DIC;
41 
42  $this->lng = $DIC->language();
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("select");
45  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ addCustomAttribute()

ilSelectInputGUI::addCustomAttribute ( string  $a_attr)

Definition at line 132 of file class.ilSelectInputGUI.php.

Referenced by setHideSubForm().

132  : void
133  {
134  $this->cust_attr[] = $a_attr;
135  }
+ Here is the caller graph for this function:

◆ checkInput()

ilSelectInputGUI::checkInput ( )

Definition at line 90 of file class.ilSelectInputGUI.php.

References ilFormPropertyGUI\$lng, $valid, $value, ilSubEnabledFormPropertyGUI\checkSubItemsInput(), ilFormPropertyGUI\getMulti(), getOptions(), ilFormPropertyGUI\getPostVar(), ilFormPropertyGUI\getRequired(), ilFormPropertyGUI\setAlert(), ilFormPropertyGUI\str(), ilFormPropertyGUI\strArray(), and ilLanguage\txt().

90  : bool
91  {
92  $lng = $this->lng;
93 
94  $valid = true;
95  if (!$this->getMulti()) {
96  if ($this->getRequired() && trim($this->str($this->getPostVar())) == "") {
97  $valid = false;
98  } elseif (!array_key_exists($this->str($this->getPostVar()), $this->getOptions())) {
99  $this->setAlert($lng->txt('msg_invalid_post_input'));
100  return false;
101  }
102  } else {
103  $values = $this->strArray($this->getPostVar());
104  foreach ($values as $value) {
105  if (!array_key_exists($value, $this->getOptions())) {
106  $this->setAlert($lng->txt('msg_invalid_post_input'));
107  return false;
108  }
109  }
110  if ($this->getRequired() && !trim(implode("", $values))) {
111  $valid = false;
112  }
113  }
114  if (!$valid) {
115  $this->setAlert($lng->txt("msg_input_is_required"));
116  return false;
117  }
118  return $this->checkSubItemsInput();
119  }
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...
$valid
+ Here is the call graph for this function:

◆ getCustomAttributes()

ilSelectInputGUI::getCustomAttributes ( )

Definition at line 137 of file class.ilSelectInputGUI.php.

References $cust_attr.

Referenced by render().

137  : array
138  {
139  return $this->cust_attr;
140  }
+ Here is the caller graph for this function:

◆ getInput()

ilSelectInputGUI::getInput ( )
Returns
string|string[]

Definition at line 124 of file class.ilSelectInputGUI.php.

References ilFormPropertyGUI\getMulti(), ilFormPropertyGUI\getPostVar(), ilFormPropertyGUI\str(), and ilFormPropertyGUI\strArray().

125  {
126  if (!$this->getMulti()) {
127  return $this->str($this->getPostVar());
128  }
129  return $this->strArray($this->getPostVar());
130  }
+ Here is the call graph for this function:

◆ getOptions()

ilSelectInputGUI::getOptions ( )

Definition at line 52 of file class.ilSelectInputGUI.php.

Referenced by checkInput(), and render().

52  : array
53  {
54  return $this->options ?: array();
55  }
+ Here is the caller graph for this function:

◆ getTableFilterHTML()

ilSelectInputGUI::getTableFilterHTML ( )

Get input item HTML to be inserted into table filters.

Implements ilTableFilterItem.

Definition at line 227 of file class.ilSelectInputGUI.php.

References render().

227  : string
228  {
229  $html = $this->render();
230  return $html;
231  }
+ Here is the call graph for this function:

◆ getToolbarHTML()

ilSelectInputGUI::getToolbarHTML ( )

Get input item HTML to be inserted into ilToolbarGUI.

Implements ilToolbarItem.

Definition at line 233 of file class.ilSelectInputGUI.php.

References render().

233  : string
234  {
235  $html = $this->render("toolbar");
236  return $html;
237  }
+ Here is the call graph for this function:

◆ getValue()

ilSelectInputGUI::getValue ( )

Get Value.

Returns
string|array Value

Definition at line 76 of file class.ilSelectInputGUI.php.

References $value.

Referenced by render().

77  {
78  return $this->value;
79  }
+ Here is the caller graph for this function:

◆ hideSubForm()

ilSelectInputGUI::hideSubForm ( )

Definition at line 255 of file class.ilSelectInputGUI.php.

255  : bool
256  {
257  return $this->hide_sub;
258  }

◆ insert()

ilSelectInputGUI::insert ( ilTemplate  $a_tpl)

Definition at line 220 of file class.ilSelectInputGUI.php.

References ilTemplate\parseCurrentBlock(), render(), ilTemplate\setCurrentBlock(), and HTML_Template_IT\setVariable().

220  : void
221  {
222  $a_tpl->setCurrentBlock("prop_generic");
223  $a_tpl->setVariable("PROP_GENERIC", $this->render());
224  $a_tpl->parseCurrentBlock();
225  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
+ Here is the call graph for this function:

◆ render()

ilSelectInputGUI::render (   $a_mode = "")

Definition at line 142 of file class.ilSelectInputGUI.php.

References ilFormPropertyGUI\$postvar, $tpl, $value, getCustomAttributes(), ilFormPropertyGUI\getDisabled(), ilFormPropertyGUI\getFieldId(), ilFormPropertyGUI\getHiddenTag(), ilFormPropertyGUI\getMulti(), ilFormPropertyGUI\getMultiIconsHTML(), ilFormPropertyGUI\getMultiValues(), getOptions(), ilFormPropertyGUI\getPostVar(), ilFormPropertyGUI\getRequired(), ilFormPropertyGUI\getTitle(), getValue(), and ilLegacyFormElementsUtil\prepareFormOutput().

Referenced by getTableFilterHTML(), getToolbarHTML(), and insert().

142  : string
143  {
144  $sel_value = "";
145  $tpl = new ilTemplate("tpl.prop_select.html", true, true, "Services/Form");
146 
147  foreach ($this->getCustomAttributes() as $attr) {
148  $tpl->setCurrentBlock('cust_attr');
149  $tpl->setVariable('CUSTOM_ATTR', $attr);
150  $tpl->parseCurrentBlock();
151  }
152 
153  if ($this->getRequired()) {
154  $tpl->setCurrentBlock('required_attribute');
155  $tpl->setVariable('REQUIRED', 'required');
156  $tpl->parseCurrentBlock();
157  }
158 
159  // determine value to select. Due to accessibility reasons we
160  // should always select a value (per default the first one)
161  $first = true;
162  foreach ($this->getOptions() as $option_value => $option_text) {
163  if ($first) {
164  $sel_value = $option_value;
165  }
166  $first = false;
167  if ((string) $option_value == (string) $this->getValue()) {
168  $sel_value = $option_value;
169  }
170  }
171  foreach ($this->getOptions() as $option_value => $option_text) {
172  $tpl->setCurrentBlock("prop_select_option");
173  $tpl->setVariable("VAL_SELECT_OPTION", ilLegacyFormElementsUtil::prepareFormOutput((string) $option_value));
174  if ((string) $sel_value == (string) $option_value) {
175  $tpl->setVariable(
176  "CHK_SEL_OPTION",
177  'selected="selected"'
178  );
179  }
180  $tpl->setVariable("TXT_SELECT_OPTION", $option_text);
181  $tpl->parseCurrentBlock();
182  }
183  $tpl->setVariable("ID", $this->getFieldId());
184 
185  $postvar = $this->getPostVar();
186  if ($this->getMulti() && substr($postvar, -2) != "[]") {
187  $postvar .= "[]";
188  }
189 
190  $tpl->setVariable("POST_VAR", $postvar);
191  if ($this->getDisabled()) {
192  if ($this->getMulti()) {
193  $value = $this->getMultiValues();
194  $hidden = "";
195  if (is_array($value)) {
196  foreach ($value as $item) {
197  $hidden .= $this->getHiddenTag($postvar, $item);
198  }
199  }
200  } else {
201  $hidden = $this->getHiddenTag($postvar, (string) $this->getValue());
202  }
203  if ($hidden) {
204  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
205  $tpl->setVariable("HIDDEN_INPUT", $hidden);
206  }
207  }
208 
209  // multi icons
210  if ($this->getMulti() && !$a_mode && !$this->getDisabled()) {
211  $tpl->touchBlock("inline_in_bl");
212  $tpl->setVariable("MULTI_ICONS", $this->getMultiIconsHTML());
213  }
214 
215  $tpl->setVariable("ARIA_LABEL", ilLegacyFormElementsUtil::prepareFormOutput($this->getTitle()));
216 
217  return $tpl->get();
218  }
static prepareFormOutput($a_str, bool $a_strip=false)
getHiddenTag(string $a_post_var, string $a_value)
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setHideSubForm()

ilSelectInputGUI::setHideSubForm ( bool  $a_value,
?string  $a_condition = null 
)

Set initial sub form visibility, optionally add dynamic value-based condition.

Definition at line 242 of file class.ilSelectInputGUI.php.

References addCustomAttribute(), and ilFormPropertyGUI\getFieldId().

245  : void {
246  $this->hide_sub = $a_value;
247 
248  if ($a_condition) {
249  $this->addCustomAttribute('onchange="if(this.value ' . $a_condition . ')' .
250  ' { il.Form.showSubForm(\'subform_' . $this->getFieldId() . '\', \'il_prop_cont_' . $this->getFieldId() . '\'); }' .
251  ' else { il.Form.hideSubForm(\'subform_' . $this->getFieldId() . '\'); };"');
252  }
253  }
addCustomAttribute(string $a_attr)
+ Here is the call graph for this function:

◆ setOptions()

◆ setValue()

ilSelectInputGUI::setValue (   $a_value)

Set Value.

Parameters
string | array$a_valueValue

Definition at line 62 of file class.ilSelectInputGUI.php.

References ilFormPropertyGUI\getMulti(), and ilFormPropertyGUI\setMultiValues().

Referenced by ilUserProfile\addStandardFieldsToForm(), ilGlossaryPresentationGUI\initPrintViewSelectionForm(), ilTaxAssignInputGUI\setCurrentValues(), and setValueByArray().

62  : void
63  {
64  if ($this->getMulti() && is_array($a_value)) {
65  $this->setMultiValues($a_value);
66  $a_value = array_shift($a_value);
67  }
68  $this->value = $a_value;
69  }
setMultiValues(array $a_values)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setValueByArray()

ilSelectInputGUI::setValueByArray ( array  $a_values)

Definition at line 82 of file class.ilSelectInputGUI.php.

References ilFormPropertyGUI\getPostVar(), ilSubEnabledFormPropertyGUI\getSubItems(), and setValue().

82  : void
83  {
84  $this->setValue($a_values[$this->getPostVar()] ?? "");
85  foreach ($this->getSubItems() as $item) {
86  $item->setValueByArray($a_values);
87  }
88  }
setValue($a_value)
Set Value.
+ Here is the call graph for this function:

Field Documentation

◆ $cust_attr

array ilSelectInputGUI::$cust_attr = array()
protected

Definition at line 28 of file class.ilSelectInputGUI.php.

Referenced by getCustomAttributes().

◆ $hide_sub

bool ilSelectInputGUI::$hide_sub = false
protected

Definition at line 34 of file class.ilSelectInputGUI.php.

◆ $options

array ilSelectInputGUI::$options = array()
protected

◆ $value

ilSelectInputGUI::$value
protected

Definition at line 33 of file class.ilSelectInputGUI.php.

Referenced by checkInput(), getValue(), and render().


The documentation for this class was generated from the following file: