ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUploadLimitsOverviewGUI.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;
24use ILIAS\UI\Renderer as UIRenderer;
25
32{
33 public const CMD_INDEX = 'index';
34 public const CMD_ADD_UPLOAD_POLICY = 'addUploadPolicy';
35 public const CMD_EDIT_UPLOAD_POLICY = 'editUploadPolicy';
36 public const CMD_SAVE_UPLOAD_POLICY = 'saveUploadPolicy';
37 public const CMD_DELETE_UPLOAD_POLICY = 'deleteUploadPolicy';
38 protected int $ref_id;
42 protected ilDBInterface $db;
43 protected HttpServices $http;
47 protected RefineryFactory $refinery;
49 protected UIFactory $ui_factory;
50 protected UIRenderer $ui_renderer;
52 protected ilTabsGUI $tabs;
53
54 public function __construct()
55 {
56 global $DIC;
57
58 $this->ctrl = $DIC->ctrl();
59 $this->current_user = $DIC->user();
60 $this->db = $DIC->database();
61 $this->http = $DIC->http();
62 $this->language = $DIC->language();
63 $this->main_tpl = $DIC->ui()->mainTemplate();
64 $this->rbac_review = $DIC->rbac()->review();
65 $this->access = $DIC->access();
66 $this->refinery = $DIC->refinery();
67 $this->toolbar = $DIC->toolbar();
68 $this->ui_factory = $DIC->ui()->factory();
69 $this->ui_renderer = $DIC->ui()->renderer();
70 $this->tabs = $DIC->tabs();
71 $this->ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
72
73 $this->upload_policy_db_repository = new UploadPolicyDBRepository($this->db);
74 }
75
76 public function executeCommand(): void
77 {
78 switch ($this->ctrl->getCmd(self::CMD_INDEX)) {
81 $this->gotoUploadPolicyForm();
82 break;
85 $this->gotoUploadPolicyForm(true);
86 break;
89 $this->saveUploadPolicy();
90 break;
93 $this->deleteUploadPolicy();
94 break;
95 case self::CMD_INDEX:
96 default:
97 $this->index();
98 break;
99 }
100 }
101
102 private function hasWriteAccessOrRedirect(): void
103 {
104 if (!$this->hasWriteAccess()) {
105 $this->main_tpl->setOnScreenMessage(
106 'failure',
107 $this->language->txt("permission_denied"),
108 true
109 );
110 $this->ctrl->redirect($this);
111 }
112 }
113
114 private function hasWriteAccess(): bool
115 {
116 return $this->access->checkAccess("write", "", $this->ref_id);
117 }
118
119 protected function index(): void
120 {
121 if ($this->hasWriteAccess()) {
122 $this->toolbar->addComponent(
123 $this->ui_factory->button()->primary(
124 $this->language->txt("add_upload_policy"),
125 $this->ctrl->getLinkTargetByClass(self::class, self::CMD_ADD_UPLOAD_POLICY)
126 )
127 );
128 }
129
130 $policies_table = new UploadPoliciesTableUI(
131 $this->upload_policy_db_repository,
132 $this->ctrl,
133 $this->http,
134 $this->language,
135 $this->main_tpl,
136 $this->rbac_review,
137 $this->refinery,
138 $this->ui_factory,
139 $this->ui_renderer,
140 $this->hasWriteAccess()
141 );
142 $this->main_tpl->setContent(
143 $this->ui_renderer->render($policies_table->getComponents())
144 );
145 }
146
147 protected function gotoUploadPolicyForm(bool $is_update = false): void
148 {
149 $this->tabs->clearTargets();
150 $this->tabs->setBackTarget(
151 $this->language->txt('back'),
152 $this->ctrl->getLinkTargetByClass(self::class, self::CMD_INDEX)
153 );
154
155 $policy_form_ui = new UploadPolicyFormUI(
156 $this->upload_policy_db_repository,
157 $this->ctrl,
158 $this->http,
159 $this->language,
160 $this->rbac_review,
161 $this->refinery,
162 $this->ui_factory
163 );
164
165 $form_panel_title = ($is_update) ?
166 $this->language->txt('edit_upload_policy') :
167 $this->language->txt('add_upload_policy');
168
169 $this->main_tpl->setContent(
170 $this->ui_renderer->render(
171 $this->ui_factory->panel()->standard(
172 $form_panel_title,
173 [$policy_form_ui->getForm()]
174 )
175 )
176 );
177 }
178
179 protected function saveUploadPolicy(): void
180 {
181 $policy_form_ui = new UploadPolicyFormUI(
182 $this->upload_policy_db_repository,
183 $this->ctrl,
184 $this->http,
185 $this->language,
186 $this->rbac_review,
187 $this->refinery,
188 $this->ui_factory
189 );
190 $policy_form = $policy_form_ui->getForm();
191 $policy_form = $policy_form->withRequest($this->http->request());
192 $data = $policy_form->getData();
193
194 if ($data !== null) {
195 $date_now = new DateTimeImmutable();
196 $policy_id = null;
199 }
200
201 $upload_policy = new UploadPolicy(
202 $policy_id,
209 $date_now,
211 $this->current_user->getId(),
212 $date_now,
213 $date_now
214 );
215 $this->upload_policy_db_repository->store($upload_policy);
216
217 $this->ctrl->redirectByClass(self::class, self::CMD_INDEX);
218 }
219
220 $this->main_tpl->setContent($this->ui_renderer->render($policy_form));
221 }
222
223 protected function deleteUploadPolicy(): void
224 {
225 $deletion_successful = false;
226
227 if ($this->http->wrapper()->query()->has(UploadPolicy::POLICY_ID)) {
228 $policy_id = $this->http->wrapper()->query()->retrieve(
230 $this->refinery->kindlyTo()->int()
231 );
232 $policy = $this->upload_policy_db_repository->get($policy_id);
233 if ($policy !== null) {
234 $this->upload_policy_db_repository->delete($policy);
235 $deletion_successful = true;
236 }
237 }
238
239 if ($deletion_successful) {
240 $this->main_tpl->setOnScreenMessage(
242 $this->language->txt('policy_deletion_successful'),
243 true
244 );
245 } else {
246 $this->main_tpl->setOnScreenMessage(
248 $this->language->txt('policy_deletion_failure_not_found'),
249 true
250 );
251 }
252
253 $this->ctrl->redirectByClass(self::class, self::CMD_INDEX);
254 }
255}
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
const SCOPE_DEFINITION_GLOBAL
language handling
User class.
class ilRbacReview Contains Review functions of core Rbac.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
UploadPolicyDBRepository $upload_policy_db_repository
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26