19 declare(strict_types=1);
37 protected \ilLanguage
$lng;
41 protected \ILIAS\Data\Factory
$data;
54 protected \ILIAS\HTTP\Services
$http;
55 protected \ilCtrlInterface
$ctrl;
56 protected \ILIAS\DI\UIServices
$ui;
59 protected array
$sections = [self::DEFAULT_SECTION => [
"title" =>
"",
"description" =>
"",
"fields" => []]];
63 protected string $cmd = self::DEFAULT_SECTION;
79 string $submit_caption =
"" 84 $this->
ui = $DIC->ui();
85 $this->
ctrl = $DIC->ctrl();
86 $this->
http = $DIC->http();
87 $this->
lng = $DIC->language();
89 $this->main_tpl = $DIC->ui()->mainTemplate();
90 $this->
user = $DIC->user();
91 $this->data = new \ILIAS\Data\Factory();
93 self::initJavascript();
95 $this->
lng->loadLanguageModule(
"rep");
100 return "il.repository.ui.init();\n" .
101 "il.repository.core.init('" . ILIAS_HTTP_PATH .
"')";
108 if (!isset($DIC[
"ui.factory"])) {
112 $f = $DIC->ui()->factory();
113 $r = $DIC->ui()->renderer();
114 if (!self::$initialised) {
115 $main_tpl = $DIC->ui()->mainTemplate();
116 $main_tpl->addJavaScript(
"assets/js/repository.js");
121 $d[] =
$f->input()->field()->text(
"");
123 self::$initialised =
true;
129 $this->async_mode = self::ASYNC_MODAL;
130 $this->in_modal =
true;
136 $this->async_mode = self::ASYNC_ON;
142 $this->in_modal =
true;
148 return ($this->async_mode !== self::ASYNC_NONE);
159 string $description =
"" 161 if ($this->title ==
"") {
165 $this->sections[$key] = [
167 "description" => $description,
170 $this->current_section = $key;
177 string $description =
"",
178 ?
string $value =
null 180 $this->values[$key] = $value;
181 $field = $this->
ui->factory()->input()->field()->text($title, $description);
182 if (!is_null($value)) {
183 $field = $field->withValue($value);
192 string $description =
"",
195 $this->values[$key] = $value;
196 $field = $this->
ui->factory()->input()->field()->checkbox($title, $description);
197 if (!is_null($value)) {
198 $field = $field->withValue($value);
208 $this->values[$key] = $value;
209 $field = $this->
ui->factory()->input()->field()->hidden();
210 $field = $field->withValue($value);
219 $field = $field->withRequired(
true,
new NotEmpty(
224 $field = $field->withRequired(
true);
234 $field = $field->withDisabled(
true);
244 string $description =
"",
245 ?
string $value =
null 247 $this->values[$key] = $value;
248 $field = $this->
ui->factory()->input()->field()->textarea($title, $description);
249 if (!is_null($value)) {
250 $field = $field->withValue($value);
259 string $description =
"",
261 ?
int $min_value =
null,
262 ?
int $max_value =
null 264 $this->values[$key] = $value;
266 if (!is_null($min_value)) {
267 $trans[] = $this->
refinery->int()->isGreaterThanOrEqual($min_value);
269 if (!is_null($max_value)) {
270 $trans[] = $this->
refinery->int()->isLessThanOrEqual($max_value);
272 $field = $this->
ui->factory()->input()->field()->numeric($title, $description);
273 if (count($trans) > 0) {
274 $field = $field->withAdditionalTransformation($this->
refinery->logical()->parallel($trans));
276 if (!is_null($value)) {
277 $field = $field->withValue($value);
286 string $description =
"",
289 $this->values[$key] = $value;
290 $field = $this->
ui->factory()->input()->field()->dateTime($title, $description);
292 $format = $this->
user->getDateFormat();
293 $dt_format = (string) $format;
295 $field = $field->withFormat($format);
296 if (!is_null($value)) {
297 $field = $field->withValue(
308 string $description =
"",
311 $this->values[$key] = $value;
312 $field = $this->
ui->factory()->input()->field()->dateTime($title, $description)->withUseTime(
true);
315 $dt_format = $this->data->dateFormat()->withTime12($this->
user->getDateFormat());
317 $dt_format = $this->data->dateFormat()->withTime24($this->
user->getDateFormat());
319 $field = $field->withFormat($dt_format);
321 $field = $field->withValue(
323 ((
string) $dt_format)
334 string $description =
"",
337 string $label_from =
"",
338 string $label_to =
"" 340 $this->values[$key] = [$from, $to];
341 if ($label_from ===
"") {
342 $label_from = $this->
lng->txt(
"rep_activation_limited_start");
344 if ($label_to ===
"") {
345 $label_to = $this->
lng->txt(
"rep_activation_limited_end");
347 $field = $this->
ui->factory()->input()->field()->duration($title, $description)->withUseTime(
true)->withLabels($label_from, $label_to);
350 $dt_format = $this->data->dateFormat()->withTime12($this->
user->getDateFormat());
352 $dt_format = $this->data->dateFormat()->withTime24($this->
user->getDateFormat());
354 $field = $field->withFormat($dt_format);
355 $val_from = $val_to =
null;
357 $val_from = (new \DateTime(
359 ))->format((
string) $dt_format);
362 $val_to = (new \DateTime(
364 ))->format((
string) $dt_format);
366 $field = $field->withValue([$val_from, $val_to]);
376 if (is_null($value)) {
380 return new \ilDateTime($value->format(
"Y-m-d H:i:s"),
IL_CAL_DATETIME);
382 return new \ilDate($value->format(
"Y-m-d"),
IL_CAL_DATE);
389 string $description =
"",
390 ?
string $value =
null 392 $this->values[$key] = $value;
393 $field = $this->
ui->factory()->input()->field()->select($title, $options, $description);
394 if (!is_null($value)) {
395 $field = $field->withValue($value);
407 string $description =
"",
408 ?
string $value =
null 410 $this->values[$key] = $value;
411 $field = $this->
ui->factory()->input()->field()->radio($title, $description);
412 if (!is_null($value)) {
413 $field = $field->withOption($value,
"");
414 $field = $field->withValue($value);
423 public function radioOption(
string $value,
string $title,
string $description =
""): self
426 $field = $field->withOption($value, $title, $description);
432 public function switch(
435 string $description =
"",
436 ?
string $value =
null 438 $this->values[$key] = $value;
439 $this->current_switch = [
442 "description" => $description,
452 string $description =
"",
455 $this->values[$key] = $value;
456 $this->current_optional = [
459 "description" => $description,
466 public function group(
string $key,
string $title,
string $description =
"", $disabled =
false): self
469 $this->current_group = [
472 "description" => $description,
473 "disabled" => $disabled,
481 if (!is_null($this->current_group)) {
482 if (!is_null($this->current_switch)) {
484 foreach ($this->current_group[
"fields"] as $key) {
485 $fields[$key] = $this->fields[$key];
487 $this->current_switch[
"groups"][$this->current_group[
"key"]] =
488 $this->
ui->factory()->input()->field()->group(
490 $this->current_group[
"title"]
491 )->withByline($this->current_group[
"description"]);
492 if ($this->current_group[
"disabled"]) {
493 $this->current_switch[
"groups"][$this->current_group[
"key"]] =
494 $this->current_switch[
"groups"][$this->current_group[
"key"]]
495 ->withDisabled(
true);
499 $this->current_group =
null;
502 public function end(): self
505 if (!is_null($this->current_switch)) {
506 $field = $this->
ui->factory()->input()->field()->switchableGroup(
507 $this->current_switch[
"groups"],
508 $this->current_switch[
"title"],
509 $this->current_switch[
"description"]
511 if (!is_null($this->current_switch[
"value"])) {
512 $cvalue = $this->current_switch[
"value"];
513 if (isset($this->current_switch[
"groups"][$cvalue])) {
514 $field = $field->withValue($cvalue);
517 $key = $this->current_switch[
"key"];
518 $this->current_switch =
null;
521 if (!is_null($this->current_optional)) {
522 $field = $this->
ui->factory()->input()->field()->optionalGroup(
523 $this->current_optional[
"fields"],
524 $this->current_optional[
"title"],
525 $this->current_optional[
"description"]
527 if ($this->current_optional[
"value"]) {
529 foreach ($this->current_optional[
"fields"] as $key => $input) {
530 $value[$key] = $input->getValue();
532 $field = $field->withValue($value);
534 $field = $field->withValue(
null);
536 $key = $this->current_optional[
"key"];
537 $this->current_optional =
null;
547 string $id_parameter,
548 string $description =
"",
549 ?
int $max_files =
null,
550 array $mime_types = [],
551 array $ctrl_path = [],
552 string $logger_id =
"" 554 $this->upload_handler[$key] = new \ilRepoStandardUploadHandlerGUI(
561 foreach ([
"application/x-compressed",
"application/x-zip-compressed"] as $zipmime) {
562 if (in_array(
"application/zip", $mime_types) &&
563 !in_array($zipmime, $mime_types)) {
564 $mime_types[] = $zipmime;
568 if (count($mime_types) > 0) {
569 $description .= $this->
lng->txt(
"rep_allowed_types") .
": " .
570 implode(
", ", $mime_types);
573 $field = $this->
ui->factory()->input()->field()->file(
574 $this->upload_handler[$key],
579 if (!is_null($max_files)) {
580 $field = $field->withMaxFiles($max_files);
582 if (count($mime_types) > 0) {
583 $field = $field->withAcceptedMimeTypes($mime_types);
595 if (!isset($this->upload_handler[$key])) {
596 throw new \ilException(
"Unknown file upload field: " . $key);
598 return $this->upload_handler[$key];
605 throw new \ilException(
"Missing Input Key: " . $key);
607 if (isset($this->field[$key])) {
608 throw new \ilException(
"Duplicate Input Key: " . $key);
611 if ($this->current_section !== self::DEFAULT_SECTION) {
614 if (!is_null($this->current_group)) {
615 $this->current_group[
"fields"][] = $key;
616 if (!is_null($this->current_switch)) {
617 $field_path[] = $this->current_switch[
"key"];
619 $field_path[] = $key;
621 } elseif (!is_null($this->current_optional)) {
622 $field_path[] = $this->current_optional[
"key"];
623 $this->current_optional[
"fields"][$key] = $field;
624 $field_path[] = $key;
627 $field_path[] = $key;
635 if (!$supress_0_key) {
640 $this->fields[$key] = $field;
642 $this->last_key = $key;
648 if (!isset($this->fields[$key])) {
649 throw new \ilException(
"Unknown Key: " . $key);
651 return $this->fields[$key];
661 if ($this->last_key !==
"") {
670 if (is_null($this->
form)) {
671 $async = ($this->async_mode !== self::ASYNC_NONE);
673 if (!is_null($this->class_path)) {
677 foreach ($this->sections as $sec_key => $section) {
678 if ($sec_key === self::DEFAULT_SECTION) {
679 foreach ($this->sections[$sec_key][
"fields"] as $f_key) {
682 } elseif (count($this->sections[$sec_key][
"fields"]) > 0) {
684 foreach ($this->sections[$sec_key][
"fields"] as $f_key) {
687 $inputs[$sec_key] = $this->
ui->factory()->input()->field()->section(
690 $section[
"description"]
694 $this->
form = $this->
ui->factory()->input()->container()->form()->standard(
698 if ($this->submit_caption !==
"") {
699 $this->
form = $this->
form->withSubmitLabel($this->submit_caption);
707 return $this->
getForm()->getSubmitLabel() ?? $this->
lng->txt(
"save");
712 if (is_null($this->raw_data)) {
713 $request = $this->
http->request();
714 $this->
form = $this->
getForm()->withRequest($request);
715 $this->raw_data = $this->
form->getData();
722 return !(is_null($this->raw_data));
728 public function getData(
string $key)
732 if (!isset($this->fields[$key])) {
736 if (isset($this->disable[$key])) {
737 return $this->values[$key];
741 foreach ($this->field_path[$key] as $path_key) {
742 if (!isset($value[$path_key])) {
745 $value = $value[$path_key];
764 $value = is_array($value);
772 if ($this->async_mode === self::ASYNC_NONE && !$this->
ctrl->isAsynch()) {
773 $html = $this->
ui->renderer()->render($this->
getForm());
775 $html = $this->
ui->renderer()->renderAsync($this->
getForm()) .
"<script>" . $this->
getOnLoadCode() .
"</script>";
777 if ($this->in_modal) {
778 if ($this->async_mode === self::ASYNC_MODAL) {
779 $html = str_replace(
"<form ",
"<form data-rep-modal-form='async' ", $html);
781 $html = str_replace(
"<form ",
"<form data-rep-modal-form='sync' ", $html);
getLinkTargetByClass( $a_class, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
Returns a link target for the given information.
Interface Observer Contains several chained tasks and infos about them.
Builds a Color from either hex- or rgb values.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
form( $class_path, string $cmd, string $submit_caption="")
static getPhpUploadSizeLimitInBytes()