55 protected \ILIAS\UI\Factory
$ui;
69 $this->
ui = $DIC->ui()->factory();
70 $this->renderer = $DIC->ui()->renderer();
71 $this->
http = $DIC->http();
72 $this->
ctrl = $DIC->ctrl();
73 $this->
lng = $DIC->language();
75 $this->rbac_review = $DIC->rbac()->review();
79 protected function txt(
string $var): string
81 return $this->
lng->txt(
'msg_' . $var);
84 protected function infoTxt(
string $var): string
86 return $this->
txt($var .
'_info');
103 return $this->renderer->render($this->
form);
106 public function initForm():
void 108 $field = $this->
ui->input()->field();
110 $custom_constraint = fn(callable $c,
string $error):
Transformation => $this->
refinery->custom()->constraint(
117 $denotation = $field->select($this->
txt(self::F_TYPE), $types, $this->
infoTxt(self::F_TYPE))
121 $custom_trafo(
function ($v):
void {
127 $title = $field->text($this->
txt(self::F_TITLE), $this->
infoTxt(self::F_TITLE))
131 $custom_trafo(
function ($v):
void {
137 $body = $field->markdown(
139 $this->
txt(self::F_BODY),
144 $custom_trafo(
function ($v):
void {
151 $str = $format->toString() .
' H:i:s';
153 $display_date_start = $field->dateTime($this->
txt(self::F_DISPLAY_DATE_START))
155 ->withFormat($format)
156 ->withValue($this->
notification->getDisplayStart()->format($str))
163 $display_date_end = $field->dateTime($this->
txt(self::F_DISPLAY_DATE_END))
165 ->withFormat($format)
166 ->withValue($this->
notification->getDisplayEnd()->format($str))
173 $event_date_start = $field->dateTime($this->
txt(self::F_EVENT_DATE_START))
175 ->withFormat($format)
176 ->withValue($this->
notification->getEventStart()->format($str))
183 $event_date_end = $field->dateTime($this->
txt(self::F_EVENT_DATE_END))
185 ->withFormat($format)
186 ->withValue($this->
notification->getEventEnd()->format($str))
194 $type_during_event = $field->select($this->
txt(self::F_TYPE_DURING_EVENT), $types)
198 $custom_trafo(
function ($v):
void {
203 $permanent = $field->switchableGroup([
204 self::F_PERMANENT .
'_yes' => $field->group([], $this->txt(self::F_PERMANENT .
'_yes')),
205 self::F_PERMANENT .
'_no' => $field->group(
207 self::F_DISPLAY_DATE_START => $display_date_start,
208 self::F_DISPLAY_DATE_END => $display_date_end,
209 self::F_EVENT_DATE_START => $event_date_start,
210 self::F_EVENT_DATE_END => $event_date_end,
211 self::F_TYPE_DURING_EVENT => $type_during_event
213 $this->txt(self::F_PERMANENT .
'_no')
215 ], $this->
txt(self::F_PERMANENT), $this->
infoTxt(self::F_PERMANENT))
218 ) ? self::F_PERMANENT .
'_yes' : self::F_PERMANENT .
'_no' 221 $custom_trafo(
function ($v) {
222 $permanent = isset($v[0]) && $v[0] === self::F_PERMANENT .
'_yes';
224 return $permanent ? null : $v[1];
227 ->withAdditionalTransformation(
228 $custom_constraint(
static function ($v):
bool {
233 $display_start = $v[self::F_DISPLAY_DATE_START] ?? null;
234 $display_end = $v[self::F_DISPLAY_DATE_END] ?? null;
235 $event_start = $v[self::F_EVENT_DATE_START] ?? null;
236 $event_end = $v[self::F_EVENT_DATE_END] ?? null;
238 if ($display_start >= $display_end) {
241 if ($event_start >= $event_end) {
244 if ($event_start < $display_start) {
247 return $event_end <= $display_end;
248 }, $this->
txt(
'error_false_date_configuration'))
252 $dismissable = $field->checkbox($this->
txt(self::F_DISMISSABLE), $this->
infoTxt(self::F_DISMISSABLE))
255 $custom_trafo(
function ($v):
void {
261 $installed_languages = $this->
lng->getInstalledLanguages();
263 $this->
lng->loadLanguageModule(
'meta');
264 foreach ($installed_languages as $installed_language) {
265 $lang_options[$installed_language] = $this->
lng->txt(
"meta_l_" . $installed_language);
268 $limited_to_languages = $field->multiSelect(
'', $lang_options)->withValue(
269 array_intersect($this->
notification->getLimitedToLanguages(), $installed_languages)
272 $lang_value = $this->
notification->hasLanguageLimitation()
273 ? self::F_HAS_LANGUAGE_LIMITATION
274 : self::F_SHOW_TO_ALL_LANGUAGES;
276 $languages = $field->switchableGroup([
277 self::F_SHOW_TO_ALL_LANGUAGES => $field->group(
279 $this->txt(self::F_SHOW_TO_ALL_LANGUAGES)
281 self::F_HAS_LANGUAGE_LIMITATION => $field->group(
282 [$limited_to_languages],
283 $this->txt(self::F_HAS_LANGUAGE_LIMITATION)
284 )->withByline($this->
infoTxt(self::F_HAS_LANGUAGE_LIMITATION))
285 ], $this->
txt(
"languages"))
287 ->withAdditionalTransformation(
288 $custom_trafo(
function ($v):
void {
289 $has_language_limitation = ($v[0] ?? null) === self::F_HAS_LANGUAGE_LIMITATION;
290 $limited_to_languages = (array) ($v[1][0] ?? []);
291 $this->
notification->setHasLanguageLimitation($has_language_limitation);
292 $this->
notification->setLimitedToLanguages($limited_to_languages);
298 $limited_to_role_ids = $field->multiSelect(
'', $available_roles)
299 ->withValue($this->
notification->getLimitedToRoleIds());
302 ? self::F_LIMIT_TO_ROLES
303 : self::F_SHOW_TO_ALL_ROLES;
305 $roles = $field->switchableGroup([
306 self::F_SHOW_TO_ALL_ROLES => $field->group(
308 $this->txt(self::F_SHOW_TO_ALL_ROLES)
309 )->withByline($this->
infoTxt(self::F_SHOW_TO_ALL_ROLES)),
310 self::F_LIMIT_TO_ROLES => $field->group(
311 [$limited_to_role_ids],
312 $this->txt(self::F_LIMIT_TO_ROLES)
313 )->withByline($this->
infoTxt(self::F_LIMIT_TO_ROLES))
314 ], $this->
txt(self::F_PRESENTATION))
316 ->withAdditionalTransformation(
317 $custom_trafo(
function ($v):
void {
318 $limit_to_roles = ($v[0] ?? null) === self::F_LIMIT_TO_ROLES;
319 $limited_to_role_ids = (array) ($v[1][0] ?? []);
321 $this->
notification->setLimitedToRoleIds($limited_to_role_ids);
326 $section = $field->section([
327 self::F_TYPE => $denotation,
328 self::F_TITLE => $title,
329 self::F_BODY => $body,
330 self::F_PERMANENT => $permanent,
331 self::F_DISMISSABLE => $dismissable,
332 self::F_HAS_LANGUAGE_LIMITATION => $languages,
333 self::F_LIMIT_TO_ROLES => $roles,
334 ], $this->
txt(
'form_title'))->withAdditionalTransformation(
336 return $this->notification;
340 $this->
form = $this->
ui->input()->container()->form()->standard(
343 )->withAdditionalTransformation(
344 $this->
refinery->custom()->transformation(
function ($v) {
345 return array_shift($v);
352 $this->
form = $this->
form->withRequest($this->
http->request());
385 foreach ($this->rbac_review->getRolesByFilter($filter) as $role) {
386 $opt[(
int) $role[
'obj_id']] = $role[
'title'] .
' (' . $role[
'obj_id'] .
')';
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")