ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilWOPISettingsForm.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
28 use ILIAS\Data\URI;
29 
34 {
35  private Standard $form;
39  private ilLanguage $lng;
40  private \ILIAS\Refinery\Factory $refinery;
41 
42  public function __construct(
43  private Setting $settings,
44  private bool $write_access
45  ) {
46  global $DIC;
47  $this->ui_factory = $DIC->ui()->factory();
48  $this->ui_renderer = $DIC->ui()->renderer();
49  $this->ctrl = $DIC->ctrl();
50  $this->lng = $DIC->language();
51  $this->refinery = $DIC->refinery();
52 
53  $this->form = $this->initForm();
54  }
55 
56  private function initForm(): Standard
57  {
58  return $this->ui_factory->input()->container()->form()->standard(
59  $this->ctrl->getFormActionByClass(ilWOPIAdministrationGUI::class, ilWOPIAdministrationGUI::CMD_STORE),
60  $this->getSection()->getInputs()
61  );
62  }
63 
64  private function getSection(): Section
65  {
66  $wopi_discovery_url = $this->settings->get("wopi_discovery_url");
67  $saving_interval_value = (int) $this->settings->get("saving_interval", '0');
68  $saving_interval_value = $saving_interval_value === 0 ? null : $saving_interval_value;
69 
70  $wopi_url = $this->ui_factory
71  ->input()
72  ->field()
73  ->text(
74  $this->lng->txt("wopi_url"),
75  $this->lng->txt("wopi_url_byline")
76  )
77  ->withDisabled(!$this->write_access)
78  ->withAdditionalTransformation(
79  $this->refinery->custom()->transformation(fn($v) => $v === '' ? null : $v)
81  $this->refinery->custom()->constraint(function ($v): bool {
82  if ($v === null) {
83  return false;
84  }
85  return (new Crawler())->validate(new URI($v));
86  }, $this->lng->txt('msg_error_wopi_invalid_discorvery_url'))
87  )->withAdditionalTransformation(
88  $this->refinery->custom()->transformation(function ($v): true {
89  $this->settings->set("wopi_discovery_url", $v);
90 
91  return true;
92  })
93  )->withValue(
94  $wopi_discovery_url ?? ''
95  );
96 
97  $saving_interval = $this->ui_factory->input()->field()->optionalGroup(
98  [
99  $this->ui_factory
100  ->input()
101  ->field()
102  ->numeric(
103  $this->lng->txt("saving_interval"),
104  $this->lng->txt("saving_interval_byline")
105  )
106  ->withDisabled(!$this->write_access)
107  ->withAdditionalTransformation(
108  $this->refinery->custom()->transformation(fn($v) => $v === '' ? null : $v)
110  $this->refinery->custom()->transformation(function ($v): true {
111  if ($v === null || $v === 0) {
112  $this->settings->delete("saving_interval");
113  return true;
114  }
115 
116  $this->settings->set("saving_interval", (string) $v);
117 
118  return true;
119  })
120  )->withValue(
121  $saving_interval_value
122  )
123  ],
124  $this->lng->txt("activate_saving_interval")
125  )->withValue(
126  $saving_interval_value === null ? null : [$saving_interval_value]
127  )->withAdditionalTransformation(
128  $this->refinery->custom()->transformation(function ($v) {
129  if ($v === null || $v === [null]) {
130  $this->settings->delete("saving_interval");
131  }
132  return $v;
133  })
134  );
135 
136  return $this->ui_factory
137  ->input()
138  ->field()
139  ->section(
140  [
141  $this->ui_factory
142  ->input()
143  ->field()
144  ->optionalGroup(
145  [$wopi_url, $saving_interval],
146  $this->lng->txt("activate_wopi")
147  )
148  ->withDisabled(!$this->write_access)
149  ->withValue(
150  $wopi_discovery_url === null ? null : [
151  $wopi_discovery_url,
152  $saving_interval_value === null ? null : [$saving_interval_value]
153  ]
154  )->withAdditionalTransformation(
155  $this->refinery->custom()->transformation(function ($v) {
156  if ($v === null || $v === [null]) {
157  $this->settings->set("wopi_activated", '0');
158  $this->settings->delete("wopi_discovery_url");
159  } else {
160  $this->settings->set("wopi_activated", "1");
161  }
162  return $v;
163  })
164  )
165  ],
166  $this->lng->txt("wopi_settings"),
167  );
168  }
169 
170  public function proceed(RequestInterface $request): bool
171  {
172  $this->form = $this->form->withRequest($request);
173 
174  return $this->form->getData() !== null;
175  }
176 
177  public function getHTML(): string
178  {
179  return $this->ui_renderer->render($this->form);
180  }
181 }
proceed(RequestInterface $request)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This is how the factory for UI elements looks.
Definition: Factory.php:37
__construct(private Setting $settings, private bool $write_access)
global $DIC
Definition: shib_login.php:26
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
This describes a standard form.
Definition: Standard.php:28
form( $class_path, string $cmd, string $submit_caption="")
ILIAS Refinery Factory $refinery