ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
9 use ILIAS\Transformation\Factory as TransformationFactory;
10 use ILIAS\Validation\Factory as ValidationFactory;
11 
15 class MultiSelect extends Input implements C\Input\Field\MultiSelect
16 {
17 
21  protected $options = [];
22 
31  public function __construct(
32  DataFactory $data_factory,
33  ValidationFactory $validation_factory,
34  TransformationFactory $transformation_factory,
35  $label,
36  $options,
37  $byline
38  ) {
39  parent::__construct($data_factory, $validation_factory, $transformation_factory, $label, $byline);
40  $this->options = $options;
41  }
42 
46  public function getOptions() : array
47  {
48  return $this->options;
49  }
50 
54  protected function isClientSideValueOk($value)
55  {
56  if (is_null($value)) {
57  return true;
58  }
59  if (is_array($value)) {
60  foreach ($value as $v) {
61  if (!array_key_exists($v, $this->options)) {
62  return false;
63  }
64  }
65  return true;
66  }
67  return false;
68  }
69 
73  protected function getConstraintForRequirement()
74  {
75  $constraint = $this->validation_factory->custom(
76  function ($value) {
77  return (is_array($value) && count($value) > 0);
78  },
79  "Empty"
80  );
81  return $constraint;
82  }
83 }
This describes commonalities between all inputs.
Definition: Input.php:30
__construct(DataFactory $data_factory, ValidationFactory $validation_factory, TransformationFactory $transformation_factory, $label, $options, $byline)
Definition: MultiSelect.php:31
Factory for basic transformations.
Definition: Factory.php:11
This describes a multi-select input.
Definition: MultiSelect.php:10
Builds data types.
Definition: Factory.php:14