ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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  ) {
45  global $DIC;
46  $this->ui_factory = $DIC->ui()->factory();
47  $this->ui_renderer = $DIC->ui()->renderer();
48  $this->ctrl = $DIC->ctrl();
49  $this->lng = $DIC->language();
50  $this->refinery = $DIC->refinery();
51 
52  $this->form = $this->initForm();
53  }
54 
55  private function initForm(): Standard
56  {
57  return $this->ui_factory->input()->container()->form()->standard(
58  $this->ctrl->getFormActionByClass(ilWOPIAdministrationGUI::class, ilWOPIAdministrationGUI::CMD_STORE),
59  $this->getSection()->getInputs()
60  );
61  }
62 
63  private function getSection(): Section
64  {
65  $wopi_activated = (bool) $this->settings->get("wopi_activated", '0');
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->input()->field()->text(
71  $this->lng->txt("wopi_url"),
72  $this->lng->txt("wopi_url_byline")
73  /*. $this->renderLink(
74  " ➜︎ Wikipedia",
75  "https://en.wikipedia.org/wiki/Web_Application_Open_Platform_Interface",
76  true
77  )*/
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  )
107  $this->refinery->custom()->transformation(fn($v) => $v === '' ? null : $v)
109  $this->refinery->custom()->transformation(function ($v): true {
110  if ($v === null || $v === 0) {
111  $this->settings->delete("saving_interval");
112  return true;
113  }
114 
115  $this->settings->set("saving_interval", (string) $v);
116 
117  return true;
118  })
119  )->withValue(
120  $saving_interval_value
121  )
122  ],
123  $this->lng->txt("activate_saving_interval")
124  )->withValue(
125  $saving_interval_value === null ? null : [$saving_interval_value]
126  )->withAdditionalTransformation(
127  $this->refinery->custom()->transformation(function ($v) {
128  if ($v === null || $v === [null]) {
129  $this->settings->delete("saving_interval");
130  }
131  return $v;
132  })
133  );
134 
135  return $this->ui_factory->input()->field()->section(
136  [
137  $this->ui_factory->input()->field()->optionalGroup(
138  [$wopi_url, $saving_interval],
139  $this->lng->txt("activate_wopi")
140  )->withValue(
141  $wopi_discovery_url === null ? null : [
142  $wopi_discovery_url,
143  $saving_interval_value === null ? null : [$saving_interval_value]
144  ]
145  )->withAdditionalTransformation(
146  $this->refinery->custom()->transformation(function ($v) {
147  if ($v === null || $v === [null]) {
148  $this->settings->set("wopi_activated", '0');
149  $this->settings->delete("wopi_discovery_url");
150  } else {
151  $this->settings->set("wopi_activated", "1");
152  }
153  return $v;
154  })
155  )
156  ],
157  $this->lng->txt("wopi_settings"),
158  );
159  }
160 
161  public function proceed(RequestInterface $request): bool
162  {
163  $this->form = $this->form->withRequest($request);
164 
165  return $this->form->getData() !== null;
166  }
167 
168  public function getHTML(): string
169  {
170  return $this->ui_renderer->render($this->form);
171  }
172 
173  private function renderLink(string $translation, string $url, bool $new_tab = true): string
174  {
175  $link = $this->ui_factory->link()->standard(
176  $translation,
177  $url
178  )->withOpenInNewViewport($new_tab);
179  return $this->ui_renderer->render($link);
180  }
181 }
proceed(RequestInterface $request)
$url
Definition: shib_logout.php:66
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This is how the factory for UI elements looks.
Definition: Factory.php:37
global $DIC
Definition: shib_login.php:22
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="")
renderLink(string $translation, string $url, bool $new_tab=true)
__construct(private Setting $settings,)
ILIAS Refinery Factory $refinery