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();
77 $this->rbac_review = $DIC->rbac()->review();
81 protected function txt(
string $var): string
83 return $this->
lng->txt(
'msg_' . $var);
86 protected function infoTxt(
string $var): string
88 return $this->
txt($var .
'_info');
105 return $this->renderer->render($this->
form);
108 public function initForm():
void 110 $field = $this->
ui->input()->field();
111 $custom_trafo = fn (callable
$c) => $this->
refinery->custom()->transformation($c);
112 $custom_constraint = fn (callable $c,
string $error) => $this->
refinery->custom()->constraint($c, $error);
116 $denotation = $field->select($this->
txt(self::F_TYPE), $types, $this->
infoTxt(self::F_TYPE))
120 $custom_trafo(
function ($v):
void {
126 $title = $field->text($this->
txt(self::F_TITLE), $this->
infoTxt(self::F_TITLE))
130 $custom_trafo(
function ($v):
void {
136 $body = $field->textarea($this->
txt(self::F_BODY), $this->
infoTxt(self::F_BODY))
139 $custom_trafo(
function ($v):
void {
146 $str =
$format->toString() .
' H:i:s';
148 $display_date_start = $field->dateTime($this->
txt(self::F_DISPLAY_DATE_START))
151 ->withValue($this->
notification->getDisplayStart()->format($str))
158 $display_date_end = $field->dateTime($this->
txt(self::F_DISPLAY_DATE_END))
161 ->withValue($this->
notification->getDisplayEnd()->format($str))
168 $event_date_start = $field->dateTime($this->
txt(self::F_EVENT_DATE_START))
171 ->withValue($this->
notification->getEventStart()->format($str))
178 $event_date_end = $field->dateTime($this->
txt(self::F_EVENT_DATE_END))
181 ->withValue($this->
notification->getEventEnd()->format($str))
189 $type_during_event = $field->select($this->
txt(self::F_TYPE_DURING_EVENT), $types)
193 $custom_trafo(
function ($v):
void {
198 $permanent = $field->switchableGroup([
199 self::F_PERMANENT .
'_yes' => $field->group([], $this->txt(self::F_PERMANENT .
'_yes')),
200 self::F_PERMANENT .
'_no' => $field->group(
202 self::F_DISPLAY_DATE_START => $display_date_start,
203 self::F_DISPLAY_DATE_END => $display_date_end,
204 self::F_EVENT_DATE_START => $event_date_start,
205 self::F_EVENT_DATE_END => $event_date_end,
206 self::F_TYPE_DURING_EVENT => $type_during_event
208 $this->txt(self::F_PERMANENT .
'_no')
210 ], $this->
txt(self::F_PERMANENT), $this->
infoTxt(self::F_PERMANENT))
213 ) ? self::F_PERMANENT .
'_yes' : self::F_PERMANENT .
'_no' 216 $custom_trafo(
function ($v) {
217 $permanent = isset($v[0]) && $v[0] === self::F_PERMANENT .
'_yes';
219 return $permanent ? null : $v[1];
222 ->withAdditionalTransformation(
223 $custom_constraint(
static function ($v):
bool {
230 $display_start = $v[self::F_DISPLAY_DATE_START];
231 $display_end = $v[self::F_DISPLAY_DATE_END];
232 $event_start = $v[self::F_EVENT_DATE_START];
233 $event_end = $v[self::F_EVENT_DATE_END];
235 if ($display_start >= $display_end) {
238 if ($event_start >= $event_end) {
241 if ($event_start < $display_start) {
244 return $event_end <= $display_end;
245 }, $this->
txt(
'error_false_date_configuration'))
249 $dismissable = $field->checkbox($this->
txt(self::F_DISMISSABLE), $this->
infoTxt(self::F_DISMISSABLE))
252 $custom_trafo(
function ($v):
void {
259 $limited_to_role_ids = $field->multiSelect(
'', $available_roles)
260 ->withValue($this->
notification->getLimitedToRoleIds());
263 ? self::F_LIMIT_TO_ROLES
264 : self::F_SHOW_TO_ALL_ROLES;
266 $roles = $field->switchableGroup([
267 self::F_SHOW_TO_ALL_ROLES => $field->group(
269 $this->txt(self::F_SHOW_TO_ALL_ROLES)
270 )->withByline($this->
infoTxt(self::F_SHOW_TO_ALL_ROLES)),
271 self::F_LIMIT_TO_ROLES => $field->group(
272 [$limited_to_role_ids],
273 $this->txt(self::F_LIMIT_TO_ROLES)
274 )->withByline($this->
infoTxt(self::F_LIMIT_TO_ROLES))
275 ], $this->
txt(self::F_PRESENTATION))
277 ->withAdditionalTransformation(
278 $custom_trafo(
function ($v):
void {
279 $limit_to_roles = ($v[0] ?? null) === self::F_LIMIT_TO_ROLES;
280 $limited_to_role_ids = (array) ($v[1][0] ?? []);
282 $this->
notification->setLimitedToRoleIds($limited_to_role_ids);
287 $section = $field->section([
288 self::F_TYPE => $denotation,
289 self::F_TITLE => $title,
290 self::F_BODY => $body,
291 self::F_PERMANENT => $permanent,
292 self::F_DISMISSABLE => $dismissable,
293 self::F_LIMIT_TO_ROLES => $roles,
294 ], $this->
txt(
'form_title'))->withAdditionalTransformation(
300 $this->
form = $this->
ui->input()->container()->form()->standard(
303 )->withAdditionalTransformation(
304 $this->
refinery->custom()->transformation(
function ($v) {
305 return array_shift($v);
312 $this->
form = $this->
form->withRequest($this->
http->request());
345 foreach ($this->rbac_review->getRolesByFilter($filter) as $role) {
346 $opt[(
int) $role[
'obj_id']] = $role[
'title'] .
' (' . $role[
'obj_id'] .
')';
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd)
__construct(Container $dic, ilPlugin $plugin)