ILIAS  release_7 Revision v7.30-3-g800a261c036
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
8use ILIAS\Data\Factory as DataFactory;
10
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}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $options, $byline)
Definition: MultiSelect.php:34
This describes commonalities between all inputs.
Definition: Input.php:32
This describes a multi-select input.
Definition: MultiSelect.php:11
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Class ChatMainBarProvider \MainMenu\Provider.