ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
UploadPoliciesTableUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 
35 {
36  public const ACTIVE_FILTER_PARAM = "active_filter";
37  protected const ACTIVE_FILTER_ALL = "all";
38  protected const ACTIVE_FILTER_ACTIVE = "active";
39  protected const ACTIVE_FILTER_INACTIVE = "inactive";
40 
44  protected array $components = [];
45 
46  public function __construct(
47  protected UploadPolicyDBRepository $upload_policy_db_repository,
48  protected ilCtrlInterface $ctrl,
49  protected HttpServices $http,
50  protected ilLanguage $language,
51  protected ilGlobalTemplateInterface $main_tpl,
52  protected ilRbacReview $rbac_review,
53  protected RefineryFactory $refinery,
54  protected UIFactory $ui_factory,
55  protected Renderer $ui_renderer,
56  protected bool $write_access
57  ) {
58  $policies = $this->getPresentablePolicies();
59  $actions = $this->buildPolicyActions($policies);
60  $table = $this->ui_factory->table()->presentation(
61  $this->language->txt('upload_policies'),
62  [$this->getViewControl()],
63  function (
64  PresentationRow $row,
65  UploadPolicy $record,
66  UIFactory $ui_factory
67  ) use ($actions): PresentationRow {
68  // Create texts for better data presentation in table
69  $upload_limit_text = $record->getUploadLimitInMB() . " MB";
70  $active_text = ($record->isActive()) ? $this->language->txt('yes') : $this->language->txt('no');
71  $audience_text = $this->getAudienceText($record->getAudienceType(), $record->getAudience());
72  $scope_text = $record->getScopeDefinition();
73  $valid_until_text = $record->getValidUntil()?->format('d.m.Y') ?? $this->language->txt(
74  "policy_no_validity_limitation_set"
75  );
76 
77  // Create row with fields and actions
78  $row = $row
79  ->withHeadline($record->getTitle())
80  ->withImportantFields(
81  [
82  $this->language->txt('policy_upload_limit') => $upload_limit_text,
83  $this->language->txt('policy_audience') => $audience_text,
84  $this->language->txt('active') => $active_text
85  ]
86  )
87  ->withContent(
88  $ui_factory->listing()->descriptive(
89  [
90  $this->language->txt('policy_upload_limit') => $upload_limit_text,
91  $this->language->txt('policy_audience') => $audience_text,
92  $this->language->txt('active') => $active_text,
93  $this->language->txt('policy_scope') => $scope_text,
94  $this->language->txt('policy_valid_until') => $valid_until_text,
95  ]
96  )
97  );
98 
99  if (null !== ($dropdown = $actions[$record->getPolicyId()] ?? null)) {
100  return $row->withAction($dropdown);
101  }
102 
103  return $row;
104  }
105  )->withData($policies);
106 
107  $this->components[] = $table;
108  }
109 
113  public function getComponents(): array
114  {
115  return $this->components;
116  }
117 
122  protected function buildPolicyActions(array $policies): array
123  {
124  if (!$this->write_access) {
125  return [];
126  }
127  $dropdowns = [];
128  foreach ($policies as $policy) {
129  // Store policy_id for later use when the table's actions (edit / delete) are used)
130  $this->ctrl->setParameterByClass(
131  ilUploadLimitsOverviewGUI::class,
133  $policy->getPolicyId()
134  );
135 
136  $deletion_modal = $this->getDeletionConfirmationModal($policy);
137  $dropdowns[$policy->getPolicyId()] = $this->ui_factory->dropdown()->standard(
138  [
139  $this->ui_factory->button()->shy(
140  $this->language->txt('edit'),
141  $this->ctrl->getLinkTargetByClass(
142  ilUploadLimitsOverviewGUI::class,
144  )
145  ),
146  $this->ui_factory->button()->shy(
147  $this->language->txt('delete'),
148  $deletion_modal->getShowSignal()
149  )
150  ]
151  );
152 
153  $this->components[] = $deletion_modal;
154  }
155 
156  return $dropdowns;
157  }
158 
159  protected function filterData(string $filter_value, array $data): array
160  {
161  $filtered_data = [];
162  switch ($filter_value) {
163  case self::ACTIVE_FILTER_ACTIVE:
164  $active_value = true;
165  break;
166  case self::ACTIVE_FILTER_INACTIVE:
167  $active_value = false;
168  break;
169  case self::ACTIVE_FILTER_ALL:
170  default:
171  return $data;
172  }
173 
177  foreach ($data as $data_entry) {
178  if ($data_entry->isActive() === $active_value) {
179  $filtered_data[] = $data_entry;
180  }
181  }
182  return $filtered_data;
183  }
184 
185  protected function getAudienceText(int $audience_type, array $audience_data): string
186  {
187  switch ($audience_type) {
189  $audience_text = $this->language->txt('all_global_roles');
190  // add selected roles to audience_text
191  if (!empty($audience_data['global_roles'])) {
192  $roles = $this->rbac_review->getRolesForIDs($audience_data['global_roles'], false);
193  $counter = 0;
194  foreach ($roles as $role) {
195  $counter++;
196  $audience_text .= " \"" . $role['title'] . "\"";
197  if ($counter !== count($roles)) {
198  $audience_text .= ",";
199  }
200  }
201  }
202  break;
204  default:
205  $audience_text = $this->language->txt('all_users');
206  break;
207  }
208 
209  return $audience_text;
210  }
211 
212  protected function getViewControl(): Mode
213  {
214  $target = $this->ctrl->getLinkTargetByClass(
215  ilUploadLimitsOverviewGUI::class,
217  );
218 
219  $active_control_element = self::ACTIVE_FILTER_ALL;
220  if ($this->http->wrapper()->query()->has(self::ACTIVE_FILTER_PARAM)) {
221  $active_control_element = $this->http->wrapper()->query()->retrieve(
222  self::ACTIVE_FILTER_PARAM,
223  $this->refinery->kindlyTo()->string()
224  );
225  }
226 
227  $actions_prefix = $target . "&" . self::ACTIVE_FILTER_PARAM . "=";
228  $actions = [
229  $this->language->txt(self::ACTIVE_FILTER_ALL) => $actions_prefix . self::ACTIVE_FILTER_ALL,
230  $this->language->txt(self::ACTIVE_FILTER_ACTIVE) => $actions_prefix . self::ACTIVE_FILTER_ACTIVE,
231  $this->language->txt(self::ACTIVE_FILTER_INACTIVE) => $actions_prefix . self::ACTIVE_FILTER_INACTIVE
232  ];
233 
234  return $this->ui_factory->viewControl()->mode($actions, 'policy_filter')->withActive(
235  $this->language->txt($active_control_element)
236  );
237  }
238 
240  {
241  $upload_limit_text = $record->getUploadLimitInMB() . " MB";
242  $active_text = ($record->isActive()) ? $this->language->txt('yes') : $this->language->txt('no');
243  $audience_text = $this->getAudienceText($record->getAudienceType(), $record->getAudience());
244  $valid_until_text = $record->getValidUntil()?->format('d.m.Y') ?? $this->language->txt(
245  "policy_no_validity_limitation_set"
246  );
247 
248  $deletion_items[] = $this->ui_factory->modal()->interruptiveItem()->keyValue(
249  (string) $record->getPolicyId(),
250  $this->language->txt('title'),
251  $record->getTitle()
252  );
253 
254  $deletion_items[] = $this->ui_factory->modal()->interruptiveItem()->keyValue(
255  (string) $record->getPolicyId(),
256  $this->language->txt('policy_upload_limit'),
257  $upload_limit_text
258  );
259 
260  $deletion_items[] = $this->ui_factory->modal()->interruptiveItem()->keyValue(
261  (string) $record->getPolicyId(),
262  $this->language->txt('policy_audience'),
263  $audience_text
264  );
265 
266  $deletion_items[] = $this->ui_factory->modal()->interruptiveItem()->keyValue(
267  (string) $record->getPolicyId(),
268  $this->language->txt('active'),
269  $active_text
270  );
271 
272  $deletion_items[] = $this->ui_factory->modal()->interruptiveItem()->keyValue(
273  (string) $record->getPolicyId(),
274  $this->language->txt('policy_scope'),
275  $record->getScopeDefinition()
276  );
277 
278  $deletion_items[] = $this->ui_factory->modal()->interruptiveItem()->keyValue(
279  (string) $record->getPolicyId(),
280  $this->language->txt('policy_valid_until'),
281  $valid_until_text
282  );
283 
284  return $this->ui_factory->modal()->interruptive(
285  $this->language->txt("delete"),
286  $this->language->txt('policy_confirm_deletion'),
287  $this->ctrl->getLinkTargetByClass(
288  ilUploadLimitsOverviewGUI::class,
290  )
291  )->withAffectedItems(
292  $deletion_items
293  )->withActionButtonLabel($this->language->txt('delete'));
294  }
295 
299  protected function getPresentablePolicies(): array
300  {
301  $policy_data = $this->upload_policy_db_repository->getAll();
302 
303  if ($this->http->wrapper()->query()->has(self::ACTIVE_FILTER_PARAM)) {
304  return $this->filterData(
305  $this->http->wrapper()->query()->retrieve(
306  self::ACTIVE_FILTER_PARAM,
307  $this->refinery->kindlyTo()->string()
308  ),
309  $policy_data
310  );
311  }
312 
313  return $policy_data;
314  }
315 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const AUDIENCE_TYPE_GLOBAL_ROLE
getDeletionConfirmationModal(UploadPolicy $record)
$http
Definition: deliver.php:30
getAudienceText(int $audience_type, array $audience_data)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static http()
Fetches the global http state from ILIAS.
withHeadline(string $headline)
Get a row like this with the given headline.
const AUDIENCE_TYPE_ALL_USERS
buildPolicyActions(array $policies)
This describes a Row used in Presentation Table.
This describes a Mode Control.
Definition: Mode.php:28
withAction($action)
Get a row like this with a button or a dropdown for actions in the expanded row.
language()
description: > Example for rendring a language glyph.
Definition: language.php:41
Class ilChatroomConfigFileHandler .
__construct(protected UploadPolicyDBRepository $upload_policy_db_repository, protected ilCtrlInterface $ctrl, protected HttpServices $http, protected ilLanguage $language, protected ilGlobalTemplateInterface $main_tpl, protected ilRbacReview $rbac_review, protected RefineryFactory $refinery, protected UIFactory $ui_factory, protected Renderer $ui_renderer, protected bool $write_access)