ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
SelectSpecificDataImplementation.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
27{
31 protected array $options;
32
33 public function __construct(
34 ?int $field_id = null,
36 ) {
38
39 usort($options, function (Option $a, Option $b) {
40 return $a->getPosition() <=> $b->getPosition();
41 });
42 $this->options = $options;
43 }
44
45 public function isTypeSupported(Type $type): bool
46 {
47 return $type === Type::SELECT || $type === Type::SELECT_MULTI;
48 }
49
50 protected function getSubData(): \Generator
51 {
52 yield from $this->getOptions();
53 }
54
55 public function hasOptions(): bool
56 {
57 return !empty($this->options);
58 }
59
60 public function getOptions(): \Generator
61 {
62 yield from $this->options;
63 }
64
65 public function getOption(int $option_id): ?Option
66 {
67 foreach ($this->options as $option) {
68 if ($option->optionID() === $option_id) {
69 return $option;
70 }
71 }
72 return null;
73 }
74
75 public function removeOption(int $option_id): void
76 {
77 foreach ($this->options as $key => $option) {
78 if ($option->optionID() !== $option_id) {
79 continue;
80 }
81 unset($this->options[$key]);
82 $this->markAsChanged();
83 }
84 }
85
86 public function addOption(): Option
87 {
88 $option = new OptionImplementation(0);
89 $this->options[] = $option;
90 return $option;
91 }
92}
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples