ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
MultiSelect.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
6 
7 use ILIAS\UI\Component as C;
10 
14 class MultiSelect extends Input implements C\Input\Field\MultiSelect
15 {
16 
20  protected $options = [];
21 
29  public function __construct(
30  DataFactory $data_factory,
31  \ILIAS\Refinery\Factory $refinery,
32  $label,
33  $options,
34  $byline
35  ) {
36  parent::__construct($data_factory, $refinery, $label, $byline);
37  $this->options = $options;
38  }
39 
43  public function getOptions() : array
44  {
45  return $this->options;
46  }
47 
51  protected function isClientSideValueOk($value) : bool
52  {
53  if (is_null($value)) {
54  return true;
55  }
56  if (is_array($value)) {
57  foreach ($value as $v) {
58  if (!array_key_exists($v, $this->options)) {
59  return false;
60  }
61  }
62  return true;
63  }
64  return false;
65  }
66 
70  protected function getConstraintForRequirement()
71  {
72  $constraint = $this->refinery->custom()->constraint(
73  function ($value) {
74  return (is_array($value) && count($value) > 0);
75  },
76  "Empty"
77  );
78  return $constraint;
79  }
80 
84  public function getUpdateOnLoadCode() : \Closure
85  {
86  return function ($id) {
87  $code = "var checkedBoxes = function() {
88  var options = {};
89  var options_combined = [];
90  $('#$id').find('input').each(function() {
91  options[$(this).val()] = $(this).prop('checked').toString();
92  });
93  for (let [key, value] of Object.entries(options)) {
94  options_combined.push(key + ': ' + value);
95  }
96  return options_combined.join(', ');
97  }
98  $('#$id').on('input', function(event) {
99  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
100  });
101  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
102  ";
103  return $code;
104  };
105  }
106 }
Class ChatMainBarProvider .
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $options, $byline)
Definition: MultiSelect.php:29
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event, &#39;$id&#39;, string_value);initially "onload" andon every input change. It must pass a readable string representation of its value in parameter &#39;string_value&#39;.string
Definition: MultiSelect.php:84
This describes a multi-select input.
Definition: MultiSelect.php:10
Builds data types.
Definition: Factory.php:19
__construct(Container $dic, ilPlugin $plugin)