ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilForumNotificationEventsFormGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24{
26 private array $events = [
27 'notify_modified' => ilForumNotificationEvents::UPDATED,
28 'notify_censored' => ilForumNotificationEvents::CENSORED,
29 'notify_uncensored' => ilForumNotificationEvents::UNCENSORED,
30 'notify_post_deleted' => ilForumNotificationEvents::POST_DELETED,
31 'notify_thread_deleted' => ilForumNotificationEvents::THREAD_DELETED,
32 ];
33
34 public function __construct(
35 private readonly string $action,
36 private ?array $predefined_values,
37 private readonly \ILIAS\UI\Factory $ui_factory,
38 private readonly ilLanguage $lng
39 ) {
40 }
41
42 public function getValueForEvent(string $event): int
43 {
44 if (isset($this->events[$event])) {
45 return $this->events[$event];
46 }
47
48 throw new InvalidArgumentException(sprintf('Event "%s" is not supported.', $event));
49 }
50
54 public function getValidEvents(): array
55 {
56 return array_keys($this->events);
57 }
58
59 public function build(): \ILIAS\UI\Component\Input\Container\Form\Form
60 {
61 return $this->ui_factory->input()->container()->form()->standard(
62 $this->action,
63 $this->getInputs()
64 );
65 }
66
70 public function getInputs(): array
71 {
72 $items = [];
73
74 foreach (array_keys($this->events) as $key) {
75 $checkbox = $this->ui_factory->input()->field()->checkbox($this->lng->txt($key));
76 if ($this->predefined_values !== null && isset($this->predefined_values[$key])) {
77 $checkbox = $checkbox->withValue($this->predefined_values[$key]);
78 }
79
80 $items[$key] = $checkbox;
81 }
82
83 $hidden = $this->ui_factory->input()->field()->hidden();
84 if ($this->predefined_values !== null && isset($this->predefined_values['hidden_value'])) {
85 $hidden = $hidden->withValue((string) $this->predefined_values['hidden_value']);
86 }
87 $items['hidden_value'] = $hidden;
88
89 return $items;
90 }
91}
__construct(private readonly string $action, private ?array $predefined_values, private readonly \ILIAS\UI\Factory $ui_factory, private readonly ilLanguage $lng)
language handling
This describes inputs that can be used in forms.
Definition: FormInput.php:33
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:31