19 declare(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" => []]];
62 protected string $cmd = self::DEFAULT_SECTION;
78 string $submit_caption =
"" 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();
92 self::initJavascript();
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) {
114 $main_tpl = $DIC->ui()->mainTemplate();
117 $main_tpl->addJavaScript(
"../components/ILIAS/Repository/resources/repository.js");
119 $main_tpl->addJavaScript(
"assets/js/repository.js");
126 $d[] =
$f->input()->field()->text(
"");
128 self::$initialised =
true;
134 $this->async_mode = self::ASYNC_MODAL;
140 $this->async_mode = self::ASYNC_ON;
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);
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);
211 $this->values[$key] = $value;
212 $field = $this->
ui->factory()->input()->field()->hidden();
213 $field = $field->withValue($value);
222 $field = $field->withRequired(
true,
new NotEmpty(
227 $field = $field->withRequired(
true);
237 $field = $field->withDisabled(
true);
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);
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);
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(
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)
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]);
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
429 $field = $field->withOption($value, $title, $description);
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
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
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;
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;
550 string $id_parameter,
551 string $description =
"",
552 ?
int $max_files =
null,
553 array $mime_types = [],
554 array $ctrl_path = [],
555 string $logger_id =
"" 557 $this->upload_handler[$key] = new \ilRepoStandardUploadHandlerGUI(
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) {
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;
631 $field_path[] = $key;
639 if (!$supress_0_key) {
644 $this->fields[$key] = $field;
646 $this->last_key = $key;
652 if (!isset($this->fields[$key])) {
653 throw new \ilException(
"Unknown Key: " . $key);
655 return $this->fields[$key];
665 if ($this->last_key !==
"") {
674 if (is_null($this->
form)) {
675 $async = ($this->async_mode !== self::ASYNC_NONE);
677 if (!is_null($this->class_path)) {
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) {
686 } elseif (count($this->sections[$sec_key][
"fields"]) > 0) {
688 foreach ($this->sections[$sec_key][
"fields"] as $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];
745 foreach ($this->field_path[$key] as $path_key) {
746 if (!isset($value[$path_key])) {
749 $value = $value[$path_key];
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>";
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="")