19declare(strict_types=1);
36 protected \ilLanguage
$lng;
40 protected \ILIAS\Data\Factory
$data;
53 protected \ILIAS\HTTP\Services
$http;
54 protected \ilCtrlInterface
$ctrl;
55 protected \ILIAS\DI\UIServices
$ui;
58 protected array
$sections = [self::DEFAULT_SECTION => [
"title" =>
"",
"description" =>
"",
"fields" => []]];
63 protected ?Form\Standard
$form =
null;
83 $this->
ui = $DIC->ui();
84 $this->
ctrl = $DIC->ctrl();
85 $this->
http = $DIC->http();
86 $this->
lng = $DIC->language();
88 $this->main_tpl =
$DIC->ui()->mainTemplate();
89 $this->
user = $DIC->user();
90 $this->data = new \ILIAS\Data\Factory();
94 $this->
lng->loadLanguageModule(
"rep");
99 return "il.repository.ui.init();\n" .
100 "il.repository.core.init('" . ILIAS_HTTP_PATH .
"')";
107 if (!isset(
$DIC[
"ui.factory"])) {
111 $f =
$DIC->ui()->factory();
112 $r =
$DIC->ui()->renderer();
113 if (!self::$initialised) {
126 $d[] =
$f->input()->field()->text(
"");
128 self::$initialised =
true;
151 return ($this->async_mode !== self::ASYNC_NONE);
162 string $description =
""
164 if ($this->title ==
"") {
168 $this->sections[$key] = [
170 "description" => $description,
173 $this->current_section = $key;
180 string $description =
"",
181 ?
string $value =
null
183 $this->values[$key] = $value;
184 $field = $this->
ui->factory()->input()->field()->text($title, $description);
185 if (!is_null($value)) {
186 $field = $field->withValue($value);
188 $this->addField($key, $field);
195 string $description =
"",
198 $this->values[$key] = $value;
199 $field = $this->
ui->factory()->input()->field()->checkbox($title, $description);
200 if (!is_null($value)) {
201 $field = $field->withValue($value);
203 $this->addField($key, $field);
211 $this->values[$key] = $value;
212 $field = $this->
ui->factory()->input()->field()->hidden();
213 $field = $field->withValue($value);
214 $this->addField($key, $field);
220 if ($required && ($field = $this->getLastField())) {
222 $field = $field->withRequired(
true,
new NotEmpty(
227 $field = $field->withRequired(
true);
229 $this->replaceLastField($field);
236 if ($disabled && ($field = $this->getLastField())) {
237 $field = $field->withDisabled(
true);
238 $this->disable[$this->last_key] =
true;
239 $this->replaceLastField($field);
247 string $description =
"",
248 ?
string $value =
null
250 $this->values[$key] = $value;
251 $field = $this->
ui->factory()->input()->field()->textarea($title, $description);
252 if (!is_null($value)) {
253 $field = $field->withValue($value);
255 $this->addField($key, $field);
262 string $description =
"",
264 ?
int $min_value =
null,
265 ?
int $max_value =
null
267 $this->values[$key] = $value;
269 if (!is_null($min_value)) {
270 $trans[] = $this->
refinery->int()->isGreaterThanOrEqual($min_value);
272 if (!is_null($max_value)) {
273 $trans[] = $this->
refinery->int()->isLessThanOrEqual($max_value);
275 $field = $this->
ui->factory()->input()->field()->numeric($title, $description);
276 if (count($trans) > 0) {
277 $field = $field->withAdditionalTransformation($this->
refinery->logical()->parallel($trans));
279 if (!is_null($value)) {
280 $field = $field->withValue($value);
282 $this->addField($key, $field);
289 string $description =
"",
292 $this->values[$key] = $value;
293 $field = $this->
ui->factory()->input()->field()->dateTime($title, $description);
295 $format = $this->
user->getDateFormat();
296 $dt_format = (string) $format;
298 $field = $field->withFormat($format);
299 if (!is_null($value)) {
300 $field = $field->withValue(
301 (
new \DateTime($value->get(
IL_CAL_DATE)))->format($dt_format)
304 $this->addField($key, $field);
311 string $description =
"",
314 $this->values[$key] = $value;
315 $field = $this->
ui->factory()->input()->field()->dateTime($title, $description)->withUseTime(
true);
318 $dt_format = $this->data->dateFormat()->withTime12($this->
user->getDateFormat());
320 $dt_format = $this->data->dateFormat()->withTime24($this->
user->getDateFormat());
322 $field = $field->withFormat($dt_format);
324 $field = $field->withValue(
326 ((
string) $dt_format)
330 $this->addField($key, $field);
337 string $description =
"",
340 string $label_from =
"",
341 string $label_to =
""
343 $this->values[$key] = [$from, $to];
344 if ($label_from ===
"") {
345 $label_from = $this->
lng->txt(
"rep_activation_limited_start");
347 if ($label_to ===
"") {
348 $label_to = $this->
lng->txt(
"rep_activation_limited_end");
350 $field = $this->
ui->factory()->input()->field()->duration($title, $description)->withUseTime(
true)->withLabels($label_from, $label_to);
353 $dt_format = $this->data->dateFormat()->withTime12($this->
user->getDateFormat());
355 $dt_format = $this->data->dateFormat()->withTime24($this->
user->getDateFormat());
357 $field = $field->withFormat($dt_format);
358 $val_from = $val_to =
null;
360 $val_from = (new \DateTime(
362 ))->format((
string) $dt_format);
365 $val_to = (new \DateTime(
367 ))->format((
string) $dt_format);
369 $field = $field->withValue([$val_from, $val_to]);
370 $this->addField($key, $field);
379 if (is_null($value)) {
383 return new \ilDateTime($value->format(
"Y-m-d H:i:s"),
IL_CAL_DATETIME);
385 return new \ilDate($value->format(
"Y-m-d"),
IL_CAL_DATE);
392 string $description =
"",
393 ?
string $value =
null
395 $this->values[$key] = $value;
396 $field = $this->
ui->factory()->input()->field()->select($title, $options, $description);
397 if (!is_null($value)) {
398 $field = $field->withValue($value);
410 string $description =
"",
411 ?
string $value =
null
413 $this->values[$key] = $value;
414 $field = $this->
ui->factory()->input()->field()->radio($title, $description);
415 if (!is_null($value)) {
416 $field = $field->withOption($value,
"");
417 $field = $field->withValue($value);
426 public function radioOption(
string $value,
string $title,
string $description =
""): self
428 if ($field = $this->getLastField()) {
429 $field = $field->withOption($value, $title, $description);
430 $this->replaceLastField($field);
435 public function switch(
438 string $description =
"",
439 ?
string $value =
null
441 $this->values[$key] = $value;
442 $this->current_switch = [
445 "description" => $description,
455 string $description =
"",
458 $this->values[$key] = $value;
459 $this->current_optional = [
462 "description" => $description,
469 public function group(
string $key,
string $title,
string $description =
"", $disabled =
false): self
471 $this->endCurrentGroup();
472 $this->current_group = [
475 "description" => $description,
476 "disabled" => $disabled,
484 if (!is_null($this->current_group)) {
485 if (!is_null($this->current_switch)) {
487 foreach ($this->current_group[
"fields"] as $key) {
488 $fields[$key] = $this->fields[$key];
490 $this->current_switch[
"groups"][$this->current_group[
"key"]] =
491 $this->
ui->factory()->input()->field()->group(
493 $this->current_group[
"title"]
494 )->withByline($this->current_group[
"description"]);
495 if ($this->current_group[
"disabled"]) {
496 $this->current_switch[
"groups"][$this->current_group[
"key"]] =
497 $this->current_switch[
"groups"][$this->current_group[
"key"]]
498 ->withDisabled(
true);
502 $this->current_group =
null;
505 public function end(): self
507 $this->endCurrentGroup();
508 if (!is_null($this->current_switch)) {
509 $field = $this->
ui->factory()->input()->field()->switchableGroup(
510 $this->current_switch[
"groups"],
511 $this->current_switch[
"title"],
512 $this->current_switch[
"description"]
514 if (!is_null($this->current_switch[
"value"])) {
515 $cvalue = $this->current_switch[
"value"];
516 if (isset($this->current_switch[
"groups"][$cvalue])) {
517 $field = $field->withValue($cvalue);
520 $key = $this->current_switch[
"key"];
521 $this->current_switch =
null;
522 $this->addField($key, $field);
524 if (!is_null($this->current_optional)) {
525 $field = $this->
ui->factory()->input()->field()->optionalGroup(
526 $this->current_optional[
"fields"],
527 $this->current_optional[
"title"],
528 $this->current_optional[
"description"]
530 if ($this->current_optional[
"value"]) {
532 foreach ($this->current_optional[
"fields"] as $key => $input) {
533 $value[$key] = $input->getValue();
535 $field = $field->withValue($value);
537 $field = $field->withValue(
null);
539 $key = $this->current_optional[
"key"];
540 $this->current_optional =
null;
541 $this->addField($key, $field);
549 \Closure $result_handler,
550 string $id_parameter,
551 string $description =
"",
552 ?
int $max_files =
null,
553 array $mime_types = [],
554 array $ctrl_path = [],
555 string $logger_id =
""
564 foreach ([
"application/x-compressed",
"application/x-zip-compressed"] as $zipmime) {
565 if (in_array(
"application/zip", $mime_types) &&
566 !in_array($zipmime, $mime_types)) {
567 $mime_types[] = $zipmime;
571 if (count($mime_types) > 0) {
572 $description .= $this->
lng->txt(
"rep_allowed_types") .
": " .
573 implode(
", ", $mime_types);
576 $field = $this->
ui->factory()->input()->field()->file(
577 $this->upload_handler[$key],
583 if (!is_null($max_files)) {
584 $field = $field->withMaxFiles($max_files);
586 if (count($mime_types) > 0) {
587 $field = $field->withAcceptedMimeTypes($mime_types);
599 if (!isset($this->upload_handler[$key])) {
600 throw new \ilException(
"Unknown file upload field: " . $key);
602 return $this->upload_handler[$key];
609 throw new \ilException(
"Missing Input Key: " . $key);
611 if (isset($this->field[$key])) {
612 throw new \ilException(
"Duplicate Input Key: " . $key);
615 if ($this->current_section !== self::DEFAULT_SECTION) {
616 $field_path[] = $this->current_section;
618 if (!is_null($this->current_group)) {
619 $this->current_group[
"fields"][] = $key;
620 if (!is_null($this->current_switch)) {
621 $field_path[] = $this->current_switch[
"key"];
623 $field_path[] = $key;
625 } elseif (!is_null($this->current_optional)) {
626 $field_path[] = $this->current_optional[
"key"];
627 $this->current_optional[
"fields"][$key] = $field;
628 $field_path[] = $key;
630 $this->sections[$this->current_section][
"fields"][] = $key;
631 $field_path[] = $key;
639 if (!$supress_0_key) {
644 $this->fields[$key] = $field;
645 $this->field_path[$key] = $field_path;
646 $this->last_key = $key;
652 if (!isset($this->fields[$key])) {
653 throw new \ilException(
"Unknown Key: " . $key);
655 return $this->fields[$key];
660 return $this->fields[$this->last_key] ??
null;
665 if ($this->last_key !==
"") {
666 $this->fields[$this->last_key] = $field;
674 if (is_null($this->
form)) {
675 $async = ($this->async_mode !== self::ASYNC_NONE);
677 if (!is_null($this->class_path)) {
678 $action = $ctrl->getLinkTargetByClass($this->class_path, $this->cmd,
"", $async);
681 foreach ($this->sections as $sec_key => $section) {
682 if ($sec_key === self::DEFAULT_SECTION) {
683 foreach ($this->sections[$sec_key][
"fields"] as $f_key) {
684 $inputs[$f_key] = $this->getFieldForKey($f_key);
686 } elseif (count($this->sections[$sec_key][
"fields"]) > 0) {
688 foreach ($this->sections[$sec_key][
"fields"] as $f_key) {
689 $sec_inputs[$f_key] = $this->getFieldForKey($f_key);
691 $inputs[$sec_key] = $this->
ui->factory()->input()->field()->section(
694 $section[
"description"]
698 $this->
form = $this->
ui->factory()->input()->container()->form()->standard(
702 if ($this->submit_caption !==
"") {
703 $this->
form = $this->
form->withSubmitLabel($this->submit_caption);
711 return $this->getForm()->getSubmitLabel() ?? $this->
lng->txt(
"save");
716 if (is_null($this->raw_data)) {
717 $request = $this->
http->request();
718 $this->
form = $this->getForm()->withRequest($request);
719 $this->raw_data = $this->
form->getData();
726 return !(is_null($this->raw_data));
732 public function getData(
string $key)
736 if (!isset($this->fields[$key])) {
740 if (isset($this->disable[$key])) {
741 return $this->values[$key];
744 $value = $this->raw_data;
745 foreach ($this->field_path[$key] as $path_key) {
746 if (!isset($value[$path_key])) {
749 $value = $value[$path_key];
752 $field = $this->getFieldForKey($key);
756 $value = $this->getDateTimeData($value, $field->getUseTime());
762 $this->getDateTimeData($value[
"start"], $field->getUseTime()),
763 $this->getDateTimeData($value[
"end"], $field->getUseTime()),
767 if ($field instanceof \
ILIAS\UI\
Component\Input\Field\OptionalGroup) {
768 $value = is_array($value);
776 if ($this->async_mode === self::ASYNC_NONE && !$this->
ctrl->isAsynch()) {
777 $html = $this->
ui->renderer()->render($this->getForm());
779 $html = $this->
ui->renderer()->renderAsync($this->getForm()) .
"<script>" . $this->
getOnLoadCode() .
"</script>";
@classDescription Date and time handling
addJavaScript(string $a_js_file, bool $a_add_version_parameter=true, int $a_batch=2)
Add a javascript file that should be included in the header.
addOnLoadCode(string $a_code, int $a_batch=2)
Add on load code.
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
if(!file_exists('../ilias.ini.php'))