ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
Form.php
Go to the documentation of this file.
1<?php
2
4
8
12class Form
13{
14 private \ilLanguage $language;
16 private \ILIAS\Refinery\Factory $refinery;
17
18 public function __construct(
19 private General $settings,
20 private bool $write_access
21 ) {
22 global $DIC;
23 $this->language = $DIC->language();
24 $this->language->loadLanguageModule("bgtask");
25 $this->field_factory = $DIC->ui()->factory()->input()->field();
26 $this->refinery = $DIC->refinery();
27 }
28
29 public function asFormSection(): Section
30 {
31 return $this->field_factory->section(
32 [$this->asFormGroup()],
33 $this->language->txt('obj_file')
34 );
35 }
36
37 public function asFormGroup(): Group
38 {
39 $download_limit = $this->field_factory
40 ->numeric(
41 $this->language->txt('bgtask_setting_limit'),
42 $this->language->txt('bgtask_setting_limit_info')
43 )
44 ->withValue($this->settings->getDownloadLimitinMB())
45 ->withRequired(true)
46 ->withDisabled(!$this->write_access)
47 ->withAdditionalTransformation(
48 $this->refinery->custom()->transformation(function (int $value): int {
49 $this->settings->setDownloadLimitInMB($value);
50 return $value;
51 })
52 );
53
54 $inline_file_extensions = $this->field_factory
55 ->tag(
56 $this->language->txt('inline_file_extensions'),
57 [],
58 $this->language->txt('inline_file_extensions_info')
59 )
60 ->withValue($this->settings->getInlineFileExtensions())
61 ->withDisabled(!$this->write_access)
62 ->withAdditionalTransformation(
63 $this->refinery->custom()->transformation(function (array $value): array {
64 $this->settings->setInlineFileExtensions($value);
65 return $value;
66 })
67 );
68
69 $show_amount_of_downloads = $this->field_factory
70 ->checkbox(
71 $this->language->txt('show_amount_of_downloads'),
72 $this->language->txt('show_amount_of_downloads_info')
73 )
74 ->withValue($this->settings->isShowAmountOfDownloads())
75 ->withDisabled(!$this->write_access)
76 ->withAdditionalTransformation(
77 $this->refinery->custom()->transformation(
78 function (bool $value): bool {
79 $this->settings->setShowAmountOfDownloads($value);
80 return $value;
81 }
82 )
83 );
84
85 $ascii_filename = $this->field_factory
86 ->checkbox(
87 $this->language->txt('download_ascii_filename'),
88 $this->language->txt('download_ascii_filename_info')
89 )
90 ->withValue($this->settings->isDownloadWithAsciiFileName())
91 ->withDisabled(!$this->write_access)
92 ->withAdditionalTransformation(
93 $this->refinery->custom()->transformation(function (bool $value): bool {
94 $this->settings->setDownloadWithAsciiFileName($value);
95 return $value;
96 })
97 );
98
99 return $this->field_factory->group(
100 [
101 $ascii_filename,
102 $download_limit,
103 $inline_file_extensions,
104 $show_amount_of_downloads,
105 ]
106 );
107 }
108}
ILIAS Refinery Factory $refinery
Definition: Form.php:16
__construct(private General $settings, private bool $write_access)
Definition: Form.php:18
This is what a factory for input fields looks like.
Definition: Factory.php:31
Describes the monoid operation of grouping form inputs.
Definition: Group.php:32
This describes section inputs.
Definition: Section.php:29
withValue($value)
Get an input like this with another value displayed on the client side.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:3
global $DIC
Definition: shib_login.php:26