ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMStListCertificatesTableGUI.php
Go to the documentation of this file.
1<?php
19
22
28{
29 protected array $filter = [];
30 protected array $selectable_columns_cached = [];
31 protected array $usr_orgu_names = [];
33 protected \ILIAS\UI\Factory $ui_fac;
34 protected \ILIAS\UI\Renderer $ui_ren;
35
37 {
38 global $DIC;
39
41 $this->ui_fac = $DIC->ui()->factory();
42 $this->ui_ren = $DIC->ui()->renderer();
43
44 $this->setPrefix('myst_lcrt');
45 $this->setFormName('myst_lcrt');
46 $this->setId('myst_lcrt');
47
48 parent::__construct($parent_obj, $parent_cmd, '');
49
50 $this->setRowTemplate('tpl.list_courses_row.html', "components/ILIAS/MyStaff");
51 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
52 $this->setDefaultOrderDirection('desc');
53
54 $this->setShowRowsSelector(true);
55
56 $this->setEnableTitle(true);
57 $this->setDisableFilterHiding(true);
58 $this->setEnableNumInfo(true);
59
60 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
61
62 $this->setFilterCols(5);
63 $this->initFilter();
64
65 $this->addColumns();
66
67 $this->parseData();
68 }
69
70 private function parseData(): void
71 {
72 global $DIC;
73
74 $this->setExternalSorting(true);
75 $this->setExternalSegmentation(true);
76 $this->setDefaultOrderField('obj_title');
77
78 $this->determineLimit();
80
81 $options = array(
82 'filters' => $this->filter,
83 'limit' => array(
84 'start' => $this->getOffset(),
85 'end' => $this->getLimit(),
86 ),
87 'count' => true,
88 'sort' => array(
89 'field' => $this->getOrderField(),
90 'direction' => $this->getOrderDirection(),
91 ),
92 );
93
94 $certificates_fetcher = new ilMStListCertificates($DIC);
95 $data = $certificates_fetcher->getData($options);
96
97 // Workaround because the fillRow Method only accepts arrays
98 $data = array_map(function (UserCertificateDto $it): array {
99 return [$it];
100 }, $data);
101 $this->setData($data);
102
103 $options['limit'] = array(
104 'start' => null,
105 'end' => null,
106 );
107 $max_data = $certificates_fetcher->getData($options);
108 $this->setMaxCount(count($max_data));
109 }
110
111 final public function initFilter(): void
112 {
113 global $DIC;
114
115 $item = new \ilTextInputGUI($DIC->language()->txt("title"), "obj_title");
116 $this->addFilterItem($item);
117 $item->readFromSession();
118 $this->filter['obj_title'] = $item->getValue();
119
120 //user
121 $item = new \ilTextInputGUI(
122 $DIC->language()->txt("login")
123 . "/" . $DIC->language()->txt("email")
124 . "/" . $DIC->language()->txt("name"),
125 "user"
126 );
127
128 $this->addFilterItem($item);
129 $item->readFromSession();
130 $this->filter['user'] = $item->getValue();
131
132 if (\ilUserSearchOptions::_isEnabled('org_units')) {
134 $options[0] = $DIC->language()->txt('mst_opt_all');
135 foreach ($paths as $org_ref_id => $path) {
136 $options[$org_ref_id] = $path;
137 }
138 $item = new \ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
139 $item->setOptions($options);
140 $this->addFilterItem($item);
141 $item->readFromSession();
142 $this->filter['org_unit'] = $item->getValue();
143 }
144 }
145
146 final public function getSelectableColumns(): array
147 {
148 if ($this->selectable_columns_cached) {
150 }
151
152 return $this->selectable_columns_cached = $this->initSelectableColumns();
153 }
154
155 protected function initSelectableColumns(): array
156 {
157 global $DIC;
158
159 $cols = array();
160
161 $arr_searchable_user_columns = \ilUserSearchOptions::getSelectableColumnInfo();
162
163 $cols['objectTitle'] = array(
164 'txt' => $DIC->language()->txt('title'),
165 'default' => true,
166 'width' => 'auto',
167 'sort_field' => 'objectTitle',
168 );
169 $cols['issuedOnTimestamp'] = array(
170 'txt' => $DIC->language()->txt('mst_cert_issued_on'),
171 'default' => true,
172 'width' => 'auto',
173 'sort_field' => 'issuedOnTimestamp',
174 );
175 if ($arr_searchable_user_columns['login'] ?? false) {
176 $cols['userLogin'] = array(
177 'txt' => $DIC->language()->txt('login'),
178 'default' => true,
179 'width' => 'auto',
180 'sort_field' => 'userLogin',
181 );
182 }
183 if ($arr_searchable_user_columns['firstname'] ?? false) {
184 $cols['userFirstName'] = array(
185 'txt' => $DIC->language()->txt('firstname'),
186 'default' => true,
187 'width' => 'auto',
188 'sort_field' => 'userFirstName',
189 );
190 }
191 if ($arr_searchable_user_columns['lastname'] ?? false) {
192 $cols['userLastName'] = array(
193 'txt' => $DIC->language()->txt('lastname'),
194 'default' => true,
195 'width' => 'auto',
196 'sort_field' => 'userLastName',
197 );
198 }
199
200 if ($arr_searchable_user_columns['email'] ?? false) {
201 $cols['userEmail'] = array(
202 'txt' => $DIC->language()->txt('email'),
203 'default' => true,
204 'width' => 'auto',
205 'sort_field' => 'userEmail',
206 );
207 }
208 if ($arr_searchable_user_columns['org_units'] ?? false) {
209 $cols['usr_assinged_orgus'] = array(
210 'txt' => $DIC->language()->txt('objs_orgu'),
211 'default' => true,
212 'width' => 'auto',
213 );
214 }
215
216 return $cols;
217 }
218
219 private function addColumns(): void
220 {
221 global $DIC;
222
223 foreach ($this->getSelectableColumns() as $k => $v) {
224 if ($this->isColumnSelected($k)) {
225 $sort = $v['sort_field'] ?? "";
226 $this->addColumn($v['txt'], $sort);
227 }
228 }
229
230 //Actions
231 if (!$this->getExportMode()) {
232 $this->addColumn($DIC->language()->txt('actions'));
233 }
234 }
235
236 protected function getTextRepresentationOfUsersOrgUnits(int $user_id): string
237 {
238 if (isset($this->usr_orgu_names[$user_id])) {
239 return $this->usr_orgu_names[$user_id];
240 }
241
242 return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
243 }
244
252 final protected function fillRow(array $a_set): void
253 {
254 global $DIC;
255
256 $set = array_pop($a_set);
257
258 $propGetter = \Closure::bind(function ($prop) {
259 return $this->$prop ?? null;
260 }, $set, $set);
261
262 foreach ($this->getSelectedColumns() as $k => $v) {
263 switch ($k) {
264 case 'usr_assinged_orgus':
265 $this->tpl->setCurrentBlock('td');
266 $this->tpl->setVariable(
267 'VALUE',
268 $this->getTextRepresentationOfUsersOrgUnits($set->getUserId())
269 );
270 $this->tpl->parseCurrentBlock();
271 break;
272 case 'issuedOnTimestamp':
273 $date_time = new \ilDateTime($propGetter($k), IL_CAL_UNIX);
274 $this->tpl->setCurrentBlock('td');
275 $this->tpl->setVariable('VALUE', $date_time->get(IL_CAL_DATE));
276 $this->tpl->parseCurrentBlock();
277 break;
278 default:
279 if ($propGetter($k) !== null) {
280 $this->tpl->setCurrentBlock('td');
281 $this->tpl->setVariable(
282 'VALUE',
283 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
284 );
285 $this->tpl->parseCurrentBlock();
286 } else {
287 $this->tpl->setCurrentBlock('td');
288 $this->tpl->setVariable('VALUE', '&nbsp;');
289 $this->tpl->parseCurrentBlock();
290 }
291 break;
292 }
293 }
294
295 $button = $this->ui_fac->button()->shy($this->lng->txt("mst_download_certificate"), $set->getDownloadLink());
296 $dropdown = $this->ui_fac->dropdown()->standard([$button])->withLabel($this->lng->txt("actions"));
297 $this->tpl->setVariable('ACTIONS', $this->ui_ren->render($dropdown));
298 $this->tpl->parseCurrentBlock();
299 }
300
301 protected function fillRowExcel(\ilExcel $a_excel, int &$a_row, array $a_set): void
302 {
303 $set = array_pop($a_set);
304
305 $col = 0;
306 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
307 $a_excel->setCell($a_row, $col, $v);
308 $col++;
309 }
310 }
311
312 protected function fillRowCSV(\ilCSVWriter $a_csv, array $a_set): void
313 {
314 $set = array_pop($a_set);
315
316 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
317 $a_csv->addColumn($v);
318 }
319 $a_csv->addRow();
320 }
321
322 private function getFieldValuesForExport(UserCertificateDto $user_certificate_dto): array
323 {
324 $propGetter = \Closure::bind(function ($prop) {
325 return $this->$prop ?? null;
326 }, $user_certificate_dto, $user_certificate_dto);
327
328 $field_values = array();
329 foreach ($this->getSelectedColumns() as $k => $v) {
330 switch ($k) {
331 case 'usr_assinged_orgus':
332 $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId());
333 break;
334 case 'issuedOnTimestamp':
335 $field_values[$k] = new \ilDateTime($propGetter($k), IL_CAL_UNIX);
336 break;
337 default:
338 $field_values[$k] = strip_tags($propGetter($k) ?? "");
339 break;
340 }
341 }
342
343 return $field_values;
344 }
345}
__construct(\ilMStListCertificatesGUI $parent_obj, $parent_cmd=\ilMStListCertificatesGUI::CMD_INDEX)
const IL_CAL_DATE
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addColumn(string $a_col)
setCell(int $a_row, int $col, $value, ?string $datatype=null, bool $disable_strip_tags_for_strings=false)
Set cell value.
Class ilMStListCertificatesGUI.
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
isColumnSelected(string $col)
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
determineOffsetAndOrder(bool $a_omit_offset=false)
setEnableNumInfo(bool $a_val)
setExportFormats(array $formats)
Set available export formats.
setExternalSegmentation(bool $a_val)
addFilterItem(ilTableFilterItem $a_input_item, bool $a_optional=false)
setEnableTitle(bool $a_enabletitle)
setFormName(string $a_name="")
setPrefix(string $a_prefix)
set prefix for sort and offset fields (if you have two or more tables on a page that you want to sort...
setFormAction(string $a_form_action, bool $a_multipart=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)
setDefaultOrderField(string $a_defaultorderfield)
setDisableFilterHiding(bool $a_val=true)
setExternalSorting(bool $a_val)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setFilterCols(int $a_val)
setData(array $a_data)
Set table data.
setMaxCount(int $a_max_count)
set max.
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
global $DIC
Definition: shib_login.php:26