ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
Form.php
Go to the documentation of this file.
1 <?php
2 
20 
23 
27 class Form
28 {
29  private \ilLanguage $language;
30  private \ILIAS\UI\Component\Input\Field\Factory $field_factory;
31  private \ILIAS\Refinery\Factory $refinery;
32 
33  public function __construct(private General $settings)
34  {
35  global $DIC;
36  $this->language = $DIC->language();
37  $this->language->loadLanguageModule("bgtask");
38  $this->field_factory = $DIC->ui()->factory()->input()->field();
39  $this->refinery = $DIC->refinery();
40  }
41 
42  public function asFormSection(): Section
43  {
44  return $this->field_factory->section(
45  [$this->asFormGroup()],
46  $this->language->txt('obj_file')
47  );
48  }
49 
50  public function asFormGroup(): Group
51  {
52  $download_limit = $this->field_factory
53  ->numeric(
54  $this->language->txt('bgtask_setting_limit'),
55  $this->language->txt('bgtask_setting_limit_info')
56  )
57  ->withValue($this->settings->getDownloadLimitinMB())
58  ->withRequired(true)
59  ->withAdditionalTransformation(
60  $this->refinery->custom()->transformation(function ($value): void {
61  $this->settings->setDownloadLimitInMB($value);
62  })
63  );
64 
65  $inline_file_extensions = $this->field_factory
66  ->tag(
67  $this->language->txt('inline_file_extensions'),
68  [],
69  $this->language->txt('inline_file_extensions_info')
70  )
71  ->withValue($this->settings->getInlineFileExtensions())
73  $this->refinery->custom()->transformation(function ($value): void {
74  $this->settings->setInlineFileExtensions($value);
75  })
76  );
77 
78  $show_amount_of_downloads = $this->field_factory
79  ->checkbox(
80  $this->language->txt('show_amount_of_downloads'),
81  $this->language->txt('show_amount_of_downloads_info')
82  )
83  ->withValue($this->settings->isShowAmountOfDownloads())
85  $this->refinery->custom()->transformation(
86  function ($value): void {
87  $this->settings->setShowAmountOfDownloads($value);
88  }
89  )
90  );
91 
92  $ascii_filename = $this->field_factory
93  ->checkbox(
94  $this->language->txt('download_ascii_filename'),
95  $this->language->txt('download_ascii_filename_info')
96  )
97  ->withValue($this->settings->isDownloadWithAsciiFileName())
99  $this->refinery->custom()->transformation(function ($value): void {
100  $this->settings->setDownloadWithAsciiFileName($value);
101  })
102  );
103 
104  return $this->field_factory->group(
105  [
106  $ascii_filename,
107  $download_limit,
108  $inline_file_extensions,
109  $show_amount_of_downloads,
110  ]
111  );
112  }
113 }
ILIAS UI Component Input Field Factory $field_factory
Definition: Form.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Form.php:19
__construct(private General $settings)
Definition: Form.php:33
ILIAS Refinery Factory $refinery
Definition: Form.php:31
global $DIC
Definition: shib_login.php:25
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:59
language()
description: > Example for rendring a language glyph.
Definition: language.php:25