ILIAS  release_7 Revision v7.30-3-g800a261c036
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 
25  private $complex = true;
26 
34  public function __construct(
35  DataFactory $data_factory,
36  \ILIAS\Refinery\Factory $refinery,
37  $label,
38  $options,
39  $byline
40  ) {
41  parent::__construct($data_factory, $refinery, $label, $byline);
42  $this->options = $options;
43  }
44 
48  public function getOptions() : array
49  {
50  return $this->options;
51  }
52 
56  protected function isClientSideValueOk($value) : bool
57  {
58  if (is_null($value)) {
59  return true;
60  }
61  if (is_array($value)) {
62  foreach ($value as $v) {
63  if (!array_key_exists($v, $this->options)) {
64  return false;
65  }
66  }
67  return true;
68  }
69  return false;
70  }
71 
75  protected function getConstraintForRequirement()
76  {
77  $constraint = $this->refinery->custom()->constraint(
78  function ($value) {
79  return (is_array($value) && count($value) > 0);
80  },
81  "Empty"
82  );
83  return $constraint;
84  }
85 
89  public function getUpdateOnLoadCode() : \Closure
90  {
91  return function ($id) {
92  $code = "var checkedBoxes = function() {
93  var options = [];
94  $('#$id').find('li').each(function() {
95  if ($(this).find('input').prop('checked')) {
96  options.push($(this).find('span').text());
97  }
98  });
99  return options.join(', ');
100  }
101  $('#$id').on('input', function(event) {
102  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
103  });
104  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
105  ";
106  return $code;
107  };
108  }
109 
113  public function isComplex() : bool
114  {
115  return $this->complex;
116  }
117 }
Class ChatMainBarProvider .
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $options, $byline)
Definition: MultiSelect.php:34
This describes a multi-select input.
Definition: MultiSelect.php:10
Builds data types.
Definition: Factory.php:19
__construct(Container $dic, ilPlugin $plugin)