ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UploadPolicyFormUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\HTTP\Services as HttpServices;
22use ILIAS\Refinery\Factory as RefineryFactory;
23use ILIAS\UI\Factory as UIFactory;
26
31{
32 public const INPUT_SECTION_GENERAL = "general_section";
33 public const INPUT_SECTION_AUDIENCE = "audience_section";
34 public const INPUT_SECTION_VALIDITY = "validity_section";
35
36 public const HIDDEN_INPUT_POLICY_ID = "policy_id";
37 public const INPUT_FIELD_TITLE = "title";
38 public const INPUT_FIELD_UPLOAD_LIMIT = "upload_limit";
39 public const INPUT_FIELD_AUDIENCE = "audience";
40 public const INPUT_FIELD_AUDIENCE_TYPE = "audience_type";
41 public const INPUT_FIELD_AUDIENCE_DATA = "audience_data";
42 public const INPUT_OPTION_ALL_USERS = "all_users";
43 public const INPUT_OPTION_GLOBAL_ROLES = "global_roles";
44 public const INPUT_FIELD_GLOBAL_ROLES = "global_roles";
45 public const INPUT_FIELD_VALID_UNTIL = "valid_until";
46 public const INPUT_FIELD_ACTIVE = "active";
47
48 protected const LABEL_INPUT_SECTION_GENERAL = "general";
49 protected const LABEL_INPUT_SECTION_AUDIENCE = "policy_audience";
50 protected const LABEL_INPUT_SECTION_VALIDITY = "policy_validity";
51
52 protected const LABEL_INPUT_FIELD_TITLE = "title";
53 protected const LABEL_INPUT_FIELD_UPLOAD_LIMIT = "policy_upload_limit";
54 protected const LABEL_INPUT_FIELD_AUDIENCE = "policy_audience";
55 protected const LABEL_INPUT_OPTION_ALL_USERS = "all_users";
56 protected const LABEL_INPUT_OPTION_GLOBAL_ROLES = "all_global_roles";
57 protected const LABEL_INPUT_FIELD_GLOBAL_ROLES = "all_global_roles";
58 protected const LABEL_INPUT_FIELD_VALID_UNTIL = "policy_valid_until";
59 protected const LABEL_INPUT_FIELD_ACTIVE = "active";
60
61 protected const BYLINE_INPUT_FIELD_TITLE = "policy_title_desc";
62 protected const BYLINE_INPUT_FIELD_UPLOAD_LIMIT = "policy_upload_limit_desc";
63 protected const BYLINE_INPUT_OPTION_ALL_USERS = "policy_audience_all_users_option_desc";
64 protected const BYLINE_INPUT_OPTION_GLOBAL_ROLES = "policy_audience_global_roles_option_desc";
65 protected const BYLINE_INPUT_FIELD_VALID_UNTIL = "policy_valid_until_desc";
66
67
68 protected StandardForm $form;
69
70
71 public function __construct(
72 protected UploadPolicyDBRepository $upload_policy_db_repository,
73 protected ilCtrlInterface $ctrl,
74 protected HttpServices $http,
75 protected ilLanguage $language,
76 protected ilRbacReview $rbac_review,
77 protected RefineryFactory $refinery,
78 protected UIFactory $ui_factory
79 ) {
80 $policy_id = null;
81 $upload_policy = null;
82
83 // Retrieve upload_policy if request contains policy_id
84 if ($this->http->wrapper()->query()->has(UploadPolicy::POLICY_ID)) {
85 $policy_id = $this->http->wrapper()->query()->retrieve(
87 $this->refinery->kindlyTo()->int()
88 );
89 $upload_policy = $this->upload_policy_db_repository->get($policy_id);
90 }
91
92 // Create hidden input (policy_id)
93 $policy_id_hidden_input = $this->ui_factory->input()->field()->hidden()->withValue((string) $policy_id);
94
95 // Create general section and its inputs (title and upload_limit)
96 $policy_title_input = $this->ui_factory->input()->field()->text(
97 $this->language->txt(self::LABEL_INPUT_FIELD_TITLE),
98 $this->language->txt(self::BYLINE_INPUT_FIELD_TITLE)
99 )->withValue(
100 $upload_policy?->getTitle() ?? ""
101 )->withRequired(true);
102 $upload_limit_input = $this->ui_factory->input()->field()->numeric(
103 $this->language->txt(self::LABEL_INPUT_FIELD_UPLOAD_LIMIT),
104 $this->language->txt(self::BYLINE_INPUT_FIELD_UPLOAD_LIMIT)
105 )->withValue(
106 $upload_policy?->getUploadLimitInMB()
107 )->withRequired(true);
108 $general_section = $this->ui_factory->input()->field()->section(
109 [
110 self::INPUT_FIELD_TITLE => $policy_title_input,
111 self::INPUT_FIELD_UPLOAD_LIMIT => $upload_limit_input
112 ],
113 $this->language->txt(self::LABEL_INPUT_SECTION_GENERAL)
114 );
115
116 // Create audience section and its input (audience)
117 $all_users_option = $this->ui_factory->input()->field()->group(
118 [],
119 $this->language->txt(self::LABEL_INPUT_OPTION_ALL_USERS),
120 $this->language->txt(self::BYLINE_INPUT_OPTION_ALL_USERS)
121 );
122 $global_role_input = $this->ui_factory->input()->field()->multiSelect(
123 $this->language->txt(self::LABEL_INPUT_FIELD_GLOBAL_ROLES) . ":",
124 $this->getGlobalRoles()
125 )->withValue(
126 $upload_policy?->getAudience()['global_roles'] ?? []
127 );
128 $global_roles_option = $this->ui_factory->input()->field()->group(
129 [
130 self::INPUT_FIELD_GLOBAL_ROLES => $global_role_input
131 ],
132 $this->language->txt(self::LABEL_INPUT_OPTION_GLOBAL_ROLES),
133 $this->language->txt(self::BYLINE_INPUT_OPTION_GLOBAL_ROLES)
134 );
135 $audience_input = $this->ui_factory->input()->field()->switchableGroup(
136 [
137 self::INPUT_OPTION_ALL_USERS => $all_users_option,
138 self::INPUT_OPTION_GLOBAL_ROLES => $global_roles_option
139 ],
140 $this->language->txt(self::LABEL_INPUT_FIELD_AUDIENCE)
141 )->withValue(
142 ($upload_policy?->getAudienceType() === UploadPolicy::AUDIENCE_TYPE_GLOBAL_ROLE) ? self::INPUT_OPTION_GLOBAL_ROLES : self::INPUT_OPTION_ALL_USERS
143 )->withRequired(true);
144 $audience_section = $this->ui_factory->input()->field()->section(
145 [
146 self::INPUT_FIELD_AUDIENCE => $audience_input
147 ],
148 $this->language->txt(self::LABEL_INPUT_SECTION_AUDIENCE)
149 )->withAdditionalTransformation(
151 );
152
153 // Create validity section and its inputs (valid_until and active)
154 $valid_until_input = $this->ui_factory->input()->field()->dateTime(
155 $this->language->txt(self::LABEL_INPUT_FIELD_VALID_UNTIL),
156 $this->language->txt(self::BYLINE_INPUT_FIELD_VALID_UNTIL)
157 )->withValue(
158 $upload_policy?->getValidUntil()
159 );
160 $active_input = $this->ui_factory->input()->field()->checkbox(
161 $this->language->txt(self::LABEL_INPUT_FIELD_ACTIVE)
162 )->withValue(
163 $upload_policy?->isActive()
164 );
165 $validity_section = $this->ui_factory->input()->field()->section(
166 [
167 self::INPUT_FIELD_VALID_UNTIL => $valid_until_input,
168 self::INPUT_FIELD_ACTIVE => $active_input
169 ],
170 $this->language->txt(self::LABEL_INPUT_SECTION_VALIDITY)
171 );
172
173 // Create form
174 $this->form = $this->ui_factory->input()->container()->form()->standard(
175 $this->ctrl->getLinkTargetByClass(ilUploadLimitsOverviewGUI::class, ilUploadLimitsOverviewGUI::CMD_SAVE_UPLOAD_POLICY),
176 [
177 self::INPUT_SECTION_GENERAL => $general_section,
178 self::INPUT_SECTION_AUDIENCE => $audience_section,
179 self::INPUT_SECTION_VALIDITY => $validity_section,
180 self::HIDDEN_INPUT_POLICY_ID => $policy_id_hidden_input,
181 ]
182 );
183 }
184
185
186 public function getForm(): StandardForm
187 {
188 return $this->form;
189 }
190
191
192 protected function getGlobalRoles(): array
193 {
194 $global_roles = $this->rbac_review->getRolesForIDs(
195 $this->rbac_review->getGlobalRoles(),
196 false
197 );
198
199 $roles = [];
200 foreach ($global_roles as $global_role) {
201 $roles[$global_role['rol_id']] = $global_role['title'];
202 }
203
204 return $roles;
205 }
206
208 {
209 return $this->refinery->custom()->transformation(function (array $audience_section): array {
210 $audience_type = match ($audience_section[self::INPUT_FIELD_AUDIENCE][0]) {
211 self::INPUT_OPTION_GLOBAL_ROLES => UploadPolicy::AUDIENCE_TYPE_GLOBAL_ROLE,
213 };
214
215 return [
216 self::INPUT_FIELD_AUDIENCE_TYPE => $audience_type,
217 self::INPUT_FIELD_AUDIENCE_DATA => $audience_section[self::INPUT_FIELD_AUDIENCE][1]
218 ];
219 });
220 }
221}
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
__construct(protected UploadPolicyDBRepository $upload_policy_db_repository, protected ilCtrlInterface $ctrl, protected HttpServices $http, protected ilLanguage $language, protected ilRbacReview $rbac_review, protected RefineryFactory $refinery, protected UIFactory $ui_factory)
const AUDIENCE_TYPE_GLOBAL_ROLE
const AUDIENCE_TYPE_ALL_USERS
language handling
class ilRbacReview Contains Review functions of core Rbac.
$http
Definition: deliver.php:30
A transformation is a function from one datatype to another.
This describes a standard form.
Definition: Standard.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
form( $class_path, string $cmd, string $submit_caption="")