ILIAS  release_8 Revision v8.24
class.ilRegistrationCodesTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
29{
32
33 public array $filter = [];
35 protected array $role_map = [];
36
40 public function __construct(object $a_parent_obj, string $a_parent_cmd)
41 {
42 global $DIC;
43
44 $this->access = $DIC->access();
45 $this->rbacreview = $DIC->rbac()->review();
46 $this->setId("registration_code");
47 parent::__construct($a_parent_obj, $a_parent_cmd);
48
49 $this->addColumn("", "", "1", true);
50 foreach ($this->getSelectedColumns() as $c => $caption) {
51 if ($c === "role_local" || $c === "alimit") {
52 $c = "";
53 }
54 $this->addColumn($this->lng->txt($caption), $c);
55 }
56
57 $this->setExternalSorting(true);
58 $this->setExternalSegmentation(true);
59 $this->setEnableHeader(true);
60 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj, "listCodes"));
61 $this->setRowTemplate("tpl.code_list_row.html", "Services/Registration");
62 $this->setEnableTitle(true);
63 $this->initFilter();
64 $this->setFilterCommand("applyCodesFilter");
65 $this->setResetCommand("resetCodesFilter");
66 $this->setDefaultOrderField("generated"); // #11341
67 $this->setDefaultOrderDirection("desc");
68
69 $this->setSelectAllCheckbox("id[]");
70 $this->setTopCommands(true);
71
72 if ($this->access->checkAccess("write", '', $a_parent_obj->ref_id)) {
73 $this->addMultiCommand("deleteConfirmation", $this->lng->txt("delete"));
74 }
75 $this->addCommandButton("exportCodes", $this->lng->txt("registration_codes_export"));
76 $this->getItems();
77 }
78
82 private function getItems(): void
83 {
85
86 // #12737
87 if (!array_key_exists($this->getOrderField(), $this->getSelectedColumns())) {
88 $this->setOrderField($this->getDefaultOrderField());
89 }
90
92 $this->getOrderField(),
93 $this->getOrderDirection(),
94 $this->getOffset(),
95 $this->getLimit(),
96 (string) $this->filter["code"],
97 (int) $this->filter["role"],
98 (string) $this->filter["generated"],
99 (string) $this->filter["alimit"]
100 );
101
102 if (count($codes_data["set"]) === 0 && $this->getOffset() > 0) {
103 $this->resetOffset();
105 $this->getOrderField(),
106 $this->getOrderDirection(),
107 $this->getOffset(),
108 $this->getLimit(),
109 (string) $this->filter["code"],
110 (int) $this->filter["role"],
111 (string) $this->filter["generated"],
112 (string) $this->filter["alimit"]
113 );
114 }
115
116 $options = [];
117 $this->role_map = [];
118 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
119 if (!in_array($role_id, [SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID], true)) {
120 $this->role_map[$role_id] = ilObject::_lookupTitle($role_id);
121 }
122 }
123
124 $result = [];
125 foreach ($codes_data["set"] as $k => $code) {
126 $result[$k]["code"] = $code["code"];
127 $result[$k]["code_id"] = $code["code_id"];
128
129 $result[$k]["generated"] = ilDatePresentation::formatDate(new ilDateTime($code["generated"], IL_CAL_UNIX));
130
131 if ($code["used"]) {
132 $result[$k]["used"] = ilDatePresentation::formatDate(new ilDateTime($code["used"], IL_CAL_UNIX));
133 } else {
134 $result[$k]["used"] = "";
135 }
136
137 if ($code["role"]) {
138 $result[$k]["role"] = $this->role_map[$code["role"]] ?? $this->lng->txt('deleted');
139 } else {
140 $result[$k]["role"] = "";
141 }
142
143 if ($code["role_local"]) {
144 $local = [];
145 foreach (explode(";", $code["role_local"]) as $role_id) {
146 $role = ilObject::_lookupTitle((int) $role_id);
147 if ($role) {
148 $local[] = $role;
149 }
150 }
151 if (count($local)) {
152 sort($local);
153 $result[$k]["role_local"] = implode("<br />", $local);
154 }
155 } else {
156 $result[$k]["role_local"] = "";
157 }
158
159 if ($code["alimit"]) {
160 switch ($code["alimit"]) {
161 case "unlimited":
162 $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_none");
163 break;
164
165 case "absolute":
166 $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_mode_absolute_target") .
167 ": " . ilDatePresentation::formatDate(new ilDate($code["alimitdt"], IL_CAL_DATE));
168 break;
169
170 case "relative":
171 $limit_caption = [];
172 $limit = unserialize($code["alimitdt"], ['allowed_classes' => false]);
173 if ((int) $limit["d"]) {
174 $limit_caption[] = (int) $limit["d"] . " " . $this->lng->txt("days");
175 }
176 if ((int) $limit["m"]) {
177 $limit_caption[] = (int) $limit["m"] . " " . $this->lng->txt("months");
178 }
179 if ((int) $limit["y"]) {
180 $limit_caption[] = (int) $limit["y"] . " " . $this->lng->txt("years");
181 }
182 if (count($limit_caption)) {
183 $result[$k]["alimit"] = $this->lng->txt("reg_access_limitation_mode_relative_target") .
184 ": " . implode(", ", $limit_caption);
185 }
186 break;
187 }
188 }
189 }
190
191 $this->setMaxCount((int) $codes_data["cnt"]);
192 $this->setData($result);
193 }
194
198 public function initFilter(): void
199 {
200 // code
201 $ti = new ilTextInputGUI($this->lng->txt("registration_code"), "query");
202 $ti->setMaxLength(ilRegistrationCode::CODE_LENGTH);
203 $ti->setSize(20);
204 $ti->setSubmitFormOnEnter(true);
205 $this->addFilterItem($ti);
206 $ti->readFromSession();
207 $this->filter["code"] = $ti->getValue();
208
209 // role
210
211 $this->role_map = [];
212 foreach ($this->rbacreview->getGlobalRoles() as $role_id) {
213 if (!in_array($role_id, [SYSTEM_ROLE_ID, ANONYMOUS_ROLE_ID], true)) {
214 $this->role_map[$role_id] = ilObject::_lookupTitle($role_id);
215 }
216 }
217
218 $options = ["" => $this->lng->txt("registration_roles_all")] +
220 $si = new ilSelectInputGUI($this->lng->txt("role"), "role");
221 $si->setOptions($options);
222 $this->addFilterItem($si);
223 $si->readFromSession();
224 $this->filter["role"] = $si->getValue();
225
226 // access limitation
227 $options = [
228 "" => $this->lng->txt("registration_codes_access_limitation_all"),
229 "unlimited" => $this->lng->txt("reg_access_limitation_none"),
230 "absolute" => $this->lng->txt("reg_access_limitation_mode_absolute"),
231 "relative" => $this->lng->txt("reg_access_limitation_mode_relative")
232 ];
233 $si = new ilSelectInputGUI($this->lng->txt("reg_access_limitations"), "alimit");
234 $si->setOptions($options);
235 $this->addFilterItem($si);
236 $si->readFromSession();
237 $this->filter["alimit"] = $si->getValue();
238
239 // generated
240 $options = ["" => $this->lng->txt("registration_generated_all")];
241 foreach (ilRegistrationCode::getGenerationDates() as $date) {
242 $options[$date] = ilDatePresentation::formatDate(new ilDateTime($date, IL_CAL_UNIX));
243 }
244 $si = new ilSelectInputGUI($this->lng->txt("registration_generated"), "generated");
245 $si->setOptions($options);
246 $this->addFilterItem($si);
247 $si->readFromSession();
248 $this->filter["generated"] = $si->getValue();
249 }
250
251 public function getSelectedColumns(): array
252 {
253 return [
254 "code" => "registration_code",
255 "role" => "registration_codes_roles",
256 "role_local" => "registration_codes_roles_local",
257 "alimit" => "reg_access_limitations",
258 "generated" => "registration_generated",
259 "used" => "registration_used"
260 ];
261 }
262
263 protected function fillRow(array $a_set): void
264 {
265 $this->tpl->setVariable("ID", $a_set["code_id"]);
266 foreach (array_keys($this->getSelectedColumns()) as $c) {
267 $this->tpl->setVariable("VAL_" . strtoupper($c), $a_set[$c] ?? "");
268 }
269 }
270}
const IL_CAL_DATE
const IL_CAL_UNIX
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
Class for single dates.
static _lookupTitle(int $obj_id)
class ilRbacReview Contains Review functions of core Rbac.
static getCodesData(string $order_field, string $order_direction, int $offset, int $limit, string $filter_code, int $filter_role, string $filter_generated, string $filter_access_limitation)
TableGUI class for registration codes.
__construct(object $a_parent_obj, string $a_parent_cmd)
Constructor.
fillRow(array $a_set)
Standard Version of Fill Row.
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFilterCommand(string $a_val, string $a_caption="")
setOrderField(string $a_order_field)
determineOffsetAndOrder(bool $a_omit_offset=false)
setExternalSegmentation(bool $a_val)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
resetOffset(bool $a_in_determination=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setDefaultOrderField(string $a_defaultorderfield)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setTopCommands(bool $a_val)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setResetCommand(string $a_val, string $a_caption="")
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
This class represents a text property in a property form.
$c
Definition: cli.php:38
const SYSTEM_ROLE_ID
Definition: constants.php:29
const ANONYMOUS_ROLE_ID
Definition: constants.php:28
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc