41 protected static $tags = [
'a',
'strong',
'ol',
'ul',
'li',
'p'];
83 $this->
ui = $DIC->ui()->factory();
84 $this->renderer =
$DIC->ui()->renderer();
85 $this->request =
$DIC->http()->request();
86 $this->ctrl =
$DIC->ctrl();
87 $this->lng =
$DIC->language();
90 $this->refinery =
$DIC->refinery();
100 protected function txt(
string $var) : string
102 return $this->lng->txt(
'msg_' . $var);
109 protected function infoTxt(
string $var) : ?string
111 return $this->
txt($var .
'_info');
128 return $this->renderer->render($this->form);
131 public function initForm() : void
133 $field = $this->
ui->input()->field();
134 $custom_trafo =
function (callable
$c) {
135 return $this->refinery->custom()->transformation(
$c);
137 $custom_constraint =
function (callable
$c,
string $error) {
138 return $this->refinery->custom()->constraint(
$c, $error);
143 $denotation = $field->select($this->
txt(self::F_TYPE), $types, $this->
infoTxt(self::F_TYPE))
146 ->withAdditionalTransformation(
147 $custom_trafo(
function ($v) :
void {
153 $title = $field->text($this->
txt(self::F_TITLE), $this->
infoTxt(self::F_TITLE))
156 ->withAdditionalTransformation(
157 $custom_trafo(
function ($v) :
void {
163 $body = $field->textarea($this->
txt(self::F_BODY), $this->
infoTxt(self::F_BODY))
165 ->withAdditionalTransformation(
166 $custom_trafo(
function ($v) :
void {
173 $str =
$format->toString() .
' H:i:s';
175 $display_date_start = $field->dateTime($this->
txt(self::F_DISPLAY_DATE_START))
178 ->withValue($this->
notification->getDisplayStart()->format($str))
179 ->withAdditionalTransformation(
180 $custom_trafo(
function (?DateTimeImmutable $v) : ?\DateTimeImmutable {
181 $this->
notification->setDisplayStart($v ??
new DateTimeImmutable());
185 $display_date_end = $field->dateTime($this->
txt(self::F_DISPLAY_DATE_END))
188 ->withValue($this->
notification->getDisplayEnd()->format($str))
189 ->withAdditionalTransformation(
190 $custom_trafo(
function (?DateTimeImmutable $v) : ?\DateTimeImmutable {
191 $this->
notification->setDisplayEnd($v ??
new DateTimeImmutable());
195 $event_date_start = $field->dateTime($this->
txt(self::F_EVENT_DATE_START))
198 ->withValue($this->
notification->getEventStart()->format($str))
199 ->withAdditionalTransformation(
200 $custom_trafo(
function (?DateTimeImmutable $v) : ?\DateTimeImmutable {
201 $this->
notification->setEventStart($v ??
new DateTimeImmutable());
205 $event_date_end = $field->dateTime($this->
txt(self::F_EVENT_DATE_END))
208 ->withValue($this->
notification->getEventEnd()->format($str))
209 ->withAdditionalTransformation(
210 $custom_trafo(
function (?DateTimeImmutable $v) : ?\DateTimeImmutable {
211 $this->
notification->setEventEnd($v ??
new DateTimeImmutable());
216 $type_during_event = $field->select($this->
txt(self::F_TYPE_DURING_EVENT), $types)
219 ->withAdditionalTransformation(
220 $custom_trafo(
function ($v) :
void {
225 $permanent = $field->switchableGroup([
226 self::F_PERMANENT .
'_yes' => $field->group([], $this->txt(self::F_PERMANENT .
'_yes')),
227 self::F_PERMANENT .
'_no' => $field->group(
229 self::F_DISPLAY_DATE_START => $display_date_start,
230 self::F_DISPLAY_DATE_END => $display_date_end,
231 self::F_EVENT_DATE_START => $event_date_start,
232 self::F_EVENT_DATE_END => $event_date_end,
233 self::F_TYPE_DURING_EVENT => $type_during_event
235 $this->
txt(self::F_PERMANENT .
'_no')
237 ], $this->
txt(self::F_PERMANENT), $this->
infoTxt(self::F_PERMANENT))
240 ) ? self::F_PERMANENT .
'_yes' : self::F_PERMANENT .
'_no'
242 ->withAdditionalTransformation(
243 $custom_trafo(
function ($v) {
244 $permanent = isset($v[0]) && $v[0] === self::F_PERMANENT .
'_yes';
246 return $permanent ? null : $v[1];
249 ->withAdditionalTransformation(
250 $custom_constraint(
static function ($v) :
bool {
262 if ($display_start >= $display_end) {
265 if ($event_start >= $event_end) {
268 if ($event_start < $display_start) {
271 return $event_end <= $display_end;
272 }, $this->
txt(
'error_false_date_configuration'))
276 $dismissable = $field->checkbox($this->
txt(self::F_DISMISSABLE), $this->
infoTxt(self::F_DISMISSABLE))
278 ->withAdditionalTransformation(
279 $custom_trafo(
function ($v) :
void {
286 $limited_to_role_ids = $field->multiSelect(
'', $available_roles)
287 ->withValue($this->
notification->getLimitedToRoleIds());
293 $roles = $field->switchableGroup([
294 self::F_SHOW_TO_ALL_ROLES => $field->group(
296 $this->txt(self::F_SHOW_TO_ALL_ROLES)
297 )->withByline($this->infoTxt(self::F_SHOW_TO_ALL_ROLES)),
298 self::F_LIMIT_TO_ROLES => $field->group(
299 [$limited_to_role_ids],
300 $this->txt(self::F_LIMIT_TO_ROLES)
301 )->withByline($this->infoTxt(self::F_LIMIT_TO_ROLES))
302 ], $this->txt(self::F_PRESENTATION))
304 ->withAdditionalTransformation(
305 $custom_trafo(
function ($v) :
void {
306 $limit_to_roles = ($v[0] ??
null) === self::F_LIMIT_TO_ROLES;
307 $limited_to_role_ids = (array) $v[1][0] ?? [];
309 $this->
notification->setLimitedToRoleIds($limited_to_role_ids);
315 self::F_TYPE => $denotation,
316 self::F_TITLE => $title,
317 self::F_BODY => $body,
318 self::F_PERMANENT => $permanent,
319 self::F_DISMISSABLE => $dismissable,
320 self::F_LIMIT_TO_ROLES => $roles,
321 ], $this->
txt(
'form_title'))->withAdditionalTransformation(
327 $this->form = $this->
ui->input()->container()->form()->standard(
330 )->withAdditionalTransformation(
331 $this->refinery->custom()->transformation(
function ($v) {
332 return array_shift($v);
340 $this->form = $this->form->withRequest(
$DIC->http()->request());
378 foreach (
$DIC->rbac()->review()->getRolesByFilter($filter) as $role) {
379 $opt[$role[
'obj_id']] = $role[
'title'] .
' (' . $role[
'obj_id'] .
')';
An exception for terminatinating execution or to throw for unit testing.
Customizing of pimple-DIC for ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc