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