ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
RegistrationFilterComponent.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Registration;
22 
23 use ilObject;
24 use ilDateTime;
25 use ilLanguage;
26 use ilUIService;
27 use ilRbacReview;
34 
36 {
38 
39  public function __construct(
40  private readonly string $action,
41  private readonly UIFactory $ui_factory,
42  private readonly ilUIService $ui_service,
43  private readonly ilLanguage $lng,
44  private readonly ilRbacReview $rbac_review,
45  private readonly RegistrationCodeRepository $code_repository,
46  ) {
47  $filter_inputs = [];
48  $is_input_initially_rendered = [];
49  $field_factory = $this->ui_factory->input()->field();
50 
51  foreach ($this->getFilterFields($field_factory) as $filter_id => $filter) {
52  [$filter_inputs[$filter_id], $is_input_initially_rendered[$filter_id]] = $filter;
53  }
54 
55  $this->filter = $this->ui_service->filter()->standard(
56  'participant_filter',
57  $this->action,
58  $filter_inputs,
59  $is_input_initially_rendered,
60  true,
61  true
62  );
63  }
64 
66  {
67  return $this->filter;
68  }
69 
70  public function getFilterData(): CodeFilter
71  {
72  return (new CodeFilter())->withData($this->ui_service->filter()->getData($this->filter));
73  }
74 
78  public function getFilterFields(Factory $field_factory): array
79  {
80  $filters = [
81  'code' => [
82  $field_factory->text($this->lng->txt('registration_code'))->withMaxLength(
84  ),
85  true
86  ],
87  ];
88  $role_map = [];
89  foreach ($this->rbac_review->getGlobalRoles() as $role_id) {
90  if (!\in_array($role_id, [SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID], true)) {
91  $role_map[$role_id] = ilObject::_lookupTitle($role_id);
92  }
93  }
94 
95  $options = ['' => $this->lng->txt('registration_roles_all')] + $role_map;
96  $filters['role'] = [$field_factory->select($this->lng->txt('role'), $options), true];
97 
98  $options = [
99  '' => $this->lng->txt('registration_codes_access_limitation_all'),
100  'unlimited' => $this->lng->txt('reg_access_limitation_none'),
101  'absolute' => $this->lng->txt('reg_access_limitation_mode_absolute'),
102  'relative' => $this->lng->txt('reg_access_limitation_mode_relative')
103  ];
104  $filters['alimit'] = [$field_factory->select($this->lng->txt('reg_access_limitations'), $options), true];
105 
106  $options = ['' => $this->lng->txt('registration_generated_all')];
107  foreach ($this->code_repository->getGenerationDates() as $date) {
108  $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date, IL_CAL_UNIX));
109  }
110  $filters['generated'] = [$field_factory->select($this->lng->txt('registration_generated'), $options), true];
111 
112  return $filters;
113  }
114 }
const SYSTEM_ROLE_ID
Definition: constants.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_UNIX
static _lookupTitle(int $obj_id)
Builds data types.
Definition: Factory.php:35
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
__construct(private readonly string $action, private readonly UIFactory $ui_factory, private readonly ilUIService $ui_service, private readonly ilLanguage $lng, private readonly ilRbacReview $rbac_review, private readonly RegistrationCodeRepository $code_repository,)
global $lng
Definition: privfeed.php:31
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)