ILIAS  release_8 Revision v8.24
class.ilMStListCertificatesTableGUI.php
Go to the documentation of this file.
1<?php
20
22use Closure;
24use ilCSVWriter;
25use ilDateTime;
26use ilExcel;
31use ilTable2GUI;
34
40{
41 protected array $filter = [];
42 protected array $selectable_columns_cached = [];
43 protected array $usr_orgu_names = [];
45
47 {
48 global $DIC;
49
51
52 $this->setPrefix('myst_lcrt');
53 $this->setFormName('myst_lcrt');
54 $this->setId('myst_lcrt');
55
56 parent::__construct($parent_obj, $parent_cmd, '');
57
58 $this->setRowTemplate('tpl.list_courses_row.html', "Services/MyStaff");
59 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
60 $this->setDefaultOrderDirection('desc');
61
62 $this->setShowRowsSelector(true);
63
64 $this->setEnableTitle(true);
65 $this->setDisableFilterHiding(true);
66 $this->setEnableNumInfo(true);
67
68 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
69
70 $this->setFilterCols(5);
71 $this->initFilter();
72
73 $this->addColumns();
74
75 $this->parseData();
76 }
77
78 private function parseData(): void
79 {
80 global $DIC;
81
82 $this->setExternalSorting(true);
83 $this->setExternalSegmentation(true);
84 $this->setDefaultOrderField('obj_title');
85
86 $this->determineLimit();
88
89 $options = array(
90 'filters' => $this->filter,
91 'limit' => array(
92 'start' => $this->getOffset(),
93 'end' => $this->getLimit(),
94 ),
95 'count' => true,
96 'sort' => array(
97 'field' => $this->getOrderField(),
98 'direction' => $this->getOrderDirection(),
99 ),
100 );
101
102 $certificates_fetcher = new ilMStListCertificates($DIC);
103 $data = $certificates_fetcher->getData($options);
104
105 // Workaround because the fillRow Method only accepts arrays
106 $data = array_map(function (UserCertificateDto $it): array {
107 return [$it];
108 }, $data);
109 $this->setData($data);
110
111 $options['limit'] = array(
112 'start' => null,
113 'end' => null,
114 );
115 $max_data = $certificates_fetcher->getData($options);
116 $this->setMaxCount(count($max_data));
117 }
118
119 final public function initFilter(): void
120 {
121 global $DIC;
122
123 $item = new ilTextInputGUI($DIC->language()->txt("title"), "obj_title");
124 $this->addFilterItem($item);
125 $item->readFromSession();
126 $this->filter['obj_title'] = $item->getValue();
127
128 //user
129 $item = new ilTextInputGUI(
130 $DIC->language()->txt("login")
131 . "/" . $DIC->language()->txt("email")
132 . "/" . $DIC->language()->txt("name"),
133 "user"
134 );
135
136 $this->addFilterItem($item);
137 $item->readFromSession();
138 $this->filter['user'] = $item->getValue();
139
140 if (ilUserSearchOptions::_isEnabled('org_units')) {
142 $options[0] = $DIC->language()->txt('mst_opt_all');
143 foreach ($paths as $org_ref_id => $path) {
144 $options[$org_ref_id] = $path;
145 }
146 $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
147 $item->setOptions($options);
148 $this->addFilterItem($item);
149 $item->readFromSession();
150 $this->filter['org_unit'] = $item->getValue();
151 }
152 }
153
154 final public function getSelectableColumns(): array
155 {
156 if ($this->selectable_columns_cached) {
158 }
159
160 return $this->selectable_columns_cached = $this->initSelectableColumns();
161 }
162
163 protected function initSelectableColumns(): array
164 {
165 global $DIC;
166
167 $cols = array();
168
169 $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
170
171 $cols['objectTitle'] = array(
172 'txt' => $DIC->language()->txt('title'),
173 'default' => true,
174 'width' => 'auto',
175 'sort_field' => 'objectTitle',
176 );
177 $cols['issuedOnTimestamp'] = array(
178 'txt' => $DIC->language()->txt('mst_cert_issued_on'),
179 'default' => true,
180 'width' => 'auto',
181 'sort_field' => 'issuedOnTimestamp',
182 );
183 if ($arr_searchable_user_columns['login'] ?? false) {
184 $cols['userLogin'] = array(
185 'txt' => $DIC->language()->txt('login'),
186 'default' => true,
187 'width' => 'auto',
188 'sort_field' => 'userLogin',
189 );
190 }
191 if ($arr_searchable_user_columns['firstname'] ?? false) {
192 $cols['userFirstName'] = array(
193 'txt' => $DIC->language()->txt('firstname'),
194 'default' => true,
195 'width' => 'auto',
196 'sort_field' => 'userFirstName',
197 );
198 }
199 if ($arr_searchable_user_columns['lastname'] ?? false) {
200 $cols['userLastName'] = array(
201 'txt' => $DIC->language()->txt('lastname'),
202 'default' => true,
203 'width' => 'auto',
204 'sort_field' => 'userLastName',
205 );
206 }
207
208 if ($arr_searchable_user_columns['email'] ?? false) {
209 $cols['userEmail'] = array(
210 'txt' => $DIC->language()->txt('email'),
211 'default' => true,
212 'width' => 'auto',
213 'sort_field' => 'userEmail',
214 );
215 }
216 if ($arr_searchable_user_columns['org_units'] ?? false) {
217 $cols['usr_assinged_orgus'] = array(
218 'txt' => $DIC->language()->txt('objs_orgu'),
219 'default' => true,
220 'width' => 'auto',
221 );
222 }
223
224 return $cols;
225 }
226
227 private function addColumns(): void
228 {
229 global $DIC;
230
231 foreach ($this->getSelectableColumns() as $k => $v) {
232 if ($this->isColumnSelected($k)) {
233 $sort = $v['sort_field'] ?? "";
234 $this->addColumn($v['txt'], $sort);
235 }
236 }
237
238 //Actions
239 if (!$this->getExportMode()) {
240 $this->addColumn($DIC->language()->txt('actions'));
241 }
242 }
243
244 protected function getTextRepresentationOfUsersOrgUnits(int $user_id): string
245 {
246 if (isset($this->usr_orgu_names[$user_id])) {
247 return $this->usr_orgu_names[$user_id];
248 }
249
250 return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
251 }
252
260 final protected function fillRow(array $a_set): void
261 {
262 global $DIC;
263
264 $set = array_pop($a_set);
265
266 $propGetter = Closure::bind(function ($prop) {
267 return $this->$prop ?? null;
268 }, $set, $set);
269
270 foreach ($this->getSelectedColumns() as $k => $v) {
271 switch ($k) {
272 case 'usr_assinged_orgus':
273 $this->tpl->setCurrentBlock('td');
274 $this->tpl->setVariable(
275 'VALUE',
276 $this->getTextRepresentationOfUsersOrgUnits($set->getUserId())
277 );
278 $this->tpl->parseCurrentBlock();
279 break;
280 case 'issuedOnTimestamp':
281 $date_time = new ilDateTime($propGetter($k), IL_CAL_UNIX);
282 $this->tpl->setCurrentBlock('td');
283 $this->tpl->setVariable('VALUE', $date_time->get(IL_CAL_DATE));
284 $this->tpl->parseCurrentBlock();
285 break;
286 default:
287 if ($propGetter($k) !== null) {
288 $this->tpl->setCurrentBlock('td');
289 $this->tpl->setVariable(
290 'VALUE',
291 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
292 );
293 $this->tpl->parseCurrentBlock();
294 } else {
295 $this->tpl->setCurrentBlock('td');
296 $this->tpl->setVariable('VALUE', '&nbsp;');
297 $this->tpl->parseCurrentBlock();
298 }
299 break;
300 }
301 }
302
303 $actions = new ilAdvancedSelectionListGUI();
304 $actions->setListTitle($DIC->language()->txt("actions"));
305 $actions->setId($set->getCertificateId());
306 $actions->addItem($DIC->language()->txt("mst_download_certificate"), '', $set->getDownloadLink());
307
308 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
309 $this->tpl->parseCurrentBlock();
310 }
311
312 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
313 {
314 $set = array_pop($a_set);
315
316 $col = 0;
317 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
318 $a_excel->setCell($a_row, $col, $v);
319 $col++;
320 }
321 }
322
323 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
324 {
325 $set = array_pop($a_set);
326
327 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
328 $a_csv->addColumn($v);
329 }
330 $a_csv->addRow();
331 }
332
333 private function getFieldValuesForExport(UserCertificateDto $user_certificate_dto): array
334 {
335 $propGetter = Closure::bind(function ($prop) {
336 return $this->$prop ?? null;
337 }, $user_certificate_dto, $user_certificate_dto);
338
339 $field_values = array();
340 foreach ($this->getSelectedColumns() as $k => $v) {
341 switch ($k) {
342 case 'usr_assinged_orgus':
343 $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($user_certificate_dto->getUserId());
344 break;
345 case 'issuedOnTimestamp':
346 $field_values[$k] = new ilDateTime($propGetter($k), IL_CAL_UNIX);
347 break;
348 default:
349 $field_values[$k] = strip_tags($propGetter($k) ?? "");
350 break;
351 }
352 }
353
354 return $field_values;
355 }
356}
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
__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)
@classDescription Date and time handling
setCell(int $a_row, int $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
Class ilMStListCertificatesGUI.
Class ilOrgUnitPathStorage.
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
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...
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.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$cols
Definition: xhr_table.php:11