ILIAS  release_8 Revision v8.24
class.ilMStListCoursesTableGUI.php
Go to the documentation of this file.
1<?php
18declare(strict_types=1);
19
20/*use Closure;
21use ilAdvancedSelectionListGUI;
22use ilCSVWriter;
23use ilExcel;*/
25
26/*use ilLPStatus;
27use ilMStListCoursesGUI;
28use ilMyStaffGUI;
29use ilObjUserTracking;
30use ilOrgUnitPathStorage;
31use ilRepositorySelectorInputGUI;
32use ilSelectInputGUI;
33use ilTable2GUI;
34use ilTextInputGUI;
35use ilUserSearchOptions;*/
36
43{
44 protected array $filter = [];
45 protected array $selectable_columns_cached = [];
46 protected ?array $orgu_names = null;
47 protected array $usr_orgu_names = [];
49
55 {
56 global $DIC;
57
58 $this->access = ilMyStaffAccess::getInstance();
59
60 $this->setPrefix('myst_lc');
61 $this->setFormName('myst_lc');
62 $this->setId('myst_lc');
63
64 parent::__construct($parent_obj, $parent_cmd, '');
65
66 $this->setRowTemplate('tpl.list_courses_row.html', "Services/MyStaff");
67 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
68 $this->setDefaultOrderDirection('desc');
69
70 $this->setShowRowsSelector(true);
71
72 $this->setEnableTitle(true);
73 $this->setDisableFilterHiding(true);
74 $this->setEnableNumInfo(true);
75
76 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
77
78 $this->setFilterCols(5);
79 $this->initFilter();
80
81 $this->addColumns();
82
83 $this->parseData();
84 }
85
86 protected function parseData()
87 {
88 global $DIC;
89
90 $this->setExternalSorting(true);
91 $this->setExternalSegmentation(true);
92 $this->setDefaultOrderField('crs_title');
93
94 $this->determineLimit();
96
97 $options = array(
98 'filters' => $this->filter,
99 'limit' => array(
100 'start' => $this->getOffset(),
101 'end' => $this->getLimit(),
102 ),
103 'count' => true,
104 'sort' => array(
105 'field' => $this->getOrderField(),
106 'direction' => $this->getOrderDirection(),
107 ),
108 );
109
110 $arr_usr_id = $this->access->getUsersForUserOperationAndContext(
111 $DIC->user()->getId(),
112 ilMyStaffAccess::ACCESS_ENROLMENTS_ORG_UNIT_OPERATION,
113 ilMyStaffAccess::COURSE_CONTEXT
114 );
115
116 $list_courses_fetcher = new \ILIAS\MyStaff\ListCourses\ilMStListCourses($DIC);
117 $result = $list_courses_fetcher->getData($arr_usr_id, $options);
118 $this->setMaxCount($result->getTotalDatasetCount());
119 $data = $result->getDataset();
120
121 // Workaround because the fillRow Method only accepts arrays
122 $data = array_map(function (\ILIAS\MyStaff\ListCourses\ilMStListCourse $it): array {
123 return [$it];
124 }, $data);
125 $this->setData($data);
126 }
127
128 final public function initFilter(): void
129 {
130 global $DIC;
131
132 $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
133 $this->addFilterItem($item);
134 $item->readFromSession();
135 $this->filter['crs_title'] = $item->getValue();
136
137 // course members
138 $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
139 //$item->setParent($this->getParentObject());
140 $item->setSelectText($DIC->language()->txt("mst_select_course"));
141 $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
142 $item->setClickableTypes(array(ilMyStaffAccess::COURSE_CONTEXT));
143 $this->addFilterItem($item);
144 $item->readFromSession();
145 //$item->setParent($this->getParentObject());
146 $this->filter["course"] = $item->getValue();
147
148 //membership status
149 $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
150 $item->setOptions(array(
151 "" => $DIC->language()->txt("mst_opt_all"),
152 \ILIAS\MyStaff\ListCourses\ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
153 \ILIAS\MyStaff\ListCourses\ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
154 \ILIAS\MyStaff\ListCourses\ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
155 ));
156 $this->addFilterItem($item);
157 $item->readFromSession();
158 $this->filter["memb_status"] = $item->getValue();
159
160 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
161 //learning progress status
162 $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
163 //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
164 $item->setOptions(array(
165 "" => $DIC->language()->txt("mst_opt_all"),
170 ));
171 $this->addFilterItem($item);
172 $item->readFromSession();
173 $this->filter["lp_status"] = $item->getValue();
174 $this->filter["lp_status"] = (int) $this->filter["lp_status"] - 1;
175 }
176
177
178
179 //user
180 $item = new ilTextInputGUI(
181 $DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
182 ->txt("name"),
183 "user"
184 );
185
186 $this->addFilterItem($item);
187 $item->readFromSession();
188 $this->filter['user'] = $item->getValue();
189
190 if (ilUserSearchOptions::_isEnabled('org_units')) {
191 $paths = $this->getTextRepresentationOfOrgUnits();
192 $options[0] = $DIC->language()->txt('mst_opt_all');
193 foreach ($paths as $org_ref_id => $path) {
194 $options[$org_ref_id] = $path;
195 }
196 $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
197 $item->setOptions($options);
198 $this->addFilterItem($item);
199 $item->readFromSession();
200 $this->filter['org_unit'] = $item->getValue();
201 }
202 }
203
204 protected function getTextRepresentationOfOrgUnits(): array
205 {
206 if (isset($this->orgu_names)) {
207 return $this->orgu_names;
208 }
209
211 }
212
213 protected function getTextRepresentationOfUsersOrgUnits(int $user_id): string
214 {
215 if (isset($this->usr_orgu_names[$user_id])) {
216 return $this->usr_orgu_names[$user_id];
217 }
218
219 return $this->usr_orgu_names[$user_id] = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
220 }
221
222 final public function getSelectableColumns(): array
223 {
224 if ($this->selectable_columns_cached) {
226 }
227
228 return $this->selectable_columns_cached = $this->initSelectableColumns();
229 }
230
231 protected function initSelectableColumns(): array
232 {
233 global $DIC;
234
235 $cols = array();
236
237 $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
238
239 $cols['crs_title'] = array(
240 'txt' => $DIC->language()->txt('crs_title'),
241 'default' => true,
242 'width' => 'auto',
243 'sort_field' => 'crs_title',
244 );
245 $cols['usr_reg_status'] = array(
246 'txt' => $DIC->language()->txt('member_status'),
247 'default' => true,
248 'width' => 'auto',
249 'sort_field' => 'reg_status',
250 );
251 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
252 $cols['usr_lp_status'] = array(
253 'txt' => $DIC->language()->txt('learning_progress'),
254 'default' => true,
255 'width' => 'auto',
256 'sort_field' => 'lp_status',
257 );
258 }
259
260 if ($arr_searchable_user_columns['login'] ?? false) {
261 $cols['usr_login'] = array(
262 'txt' => $DIC->language()->txt('login'),
263 'default' => true,
264 'width' => 'auto',
265 'sort_field' => 'usr_login',
266 );
267 }
268 if ($arr_searchable_user_columns['firstname'] ?? false) {
269 $cols['usr_firstname'] = array(
270 'txt' => $DIC->language()->txt('firstname'),
271 'default' => true,
272 'width' => 'auto',
273 'sort_field' => 'usr_firstname',
274 );
275 }
276 if ($arr_searchable_user_columns['lastname'] ?? false) {
277 $cols['usr_lastname'] = array(
278 'txt' => $DIC->language()->txt('lastname'),
279 'default' => true,
280 'width' => 'auto',
281 'sort_field' => 'usr_lastname',
282 );
283 }
284
285 if ($arr_searchable_user_columns['email'] ?? false) {
286 $cols['usr_email'] = array(
287 'txt' => $DIC->language()->txt('email'),
288 'default' => true,
289 'width' => 'auto',
290 'sort_field' => 'usr_email',
291 );
292 }
293
294 if ($arr_searchable_user_columns['org_units'] ?? false) {
295 $cols['usr_assinged_orgus'] = array(
296 'txt' => $DIC->language()->txt('objs_orgu'),
297 'default' => true,
298 'width' => 'auto',
299 );
300 }
301
302 return $cols;
303 }
304
305 private function addColumns(): void
306 {
307 global $DIC;
308
309 foreach ($this->getSelectableColumns() as $k => $v) {
310 if ($this->isColumnSelected($k)) {
311 $sort = $v['sort_field'] ?? "";
312 $this->addColumn($v['txt'], $sort);
313 }
314 }
315
316 //Actions
317 if (!$this->getExportMode()) {
318 $this->addColumn($DIC->language()->txt('actions'));
319 }
320 }
321
328 final protected function fillRow(array $a_set): void
329 {
330 global $DIC;
331
332 $set = array_pop($a_set);
333
334 $propGetter = Closure::bind(function ($prop) {
335 return $this->$prop ?? null;
336 }, $set, $set);
337
338 foreach ($this->getSelectedColumns() as $k => $v) {
339 switch ($k) {
340 case 'usr_assinged_orgus':
341 $this->tpl->setCurrentBlock('td');
342 $this->tpl->setVariable(
343 'VALUE',
344 $this->getTextRepresentationOfUsersOrgUnits($set->getUsrId())
345 );
346 $this->tpl->parseCurrentBlock();
347 break;
348 case 'usr_reg_status':
349 $this->tpl->setCurrentBlock('td');
350 $this->tpl->setVariable(
351 'VALUE',
352 \ILIAS\MyStaff\ListCourses\ilMStListCourse::getMembershipStatusText($set->getUsrRegStatus())
353 );
354 $this->tpl->parseCurrentBlock();
355 break;
356 case 'usr_lp_status':
357 $this->tpl->setCurrentBlock('td');
358 $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($set));
359 $this->tpl->parseCurrentBlock();
360 break;
361 default:
362 if ($propGetter($k) !== null) {
363 $this->tpl->setCurrentBlock('td');
364 $this->tpl->setVariable(
365 'VALUE',
366 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
367 );
368 $this->tpl->parseCurrentBlock();
369 } else {
370 $this->tpl->setCurrentBlock('td');
371 $this->tpl->setVariable('VALUE', '&nbsp;');
372 $this->tpl->parseCurrentBlock();
373 }
374 break;
375 }
376 }
377
378 $actions = new ilAdvancedSelectionListGUI();
379 $actions->setListTitle($DIC->language()->txt("actions"));
380 $actions->setId($set->getUsrId() . "-" . $set->getCrsRefId());
381
382 $mst_lco_usr_id = $set->getUsrId();
383 $mst_lco_crs_ref_id = $set->getCrsRefId();
384
385 if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) {
386 $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::COURSE_CONTEXT);
387 $actions->addItem(
389 '',
390 $link
391 );
392 };
393
394 foreach (ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array(
395 'user_id' => $mst_lco_usr_id,
396 'object_reference.deleted' => null
397 ), array('user_id' => '=', 'object_reference.deleted' => '!='))->get() as $org_unit_assignment) {
398 if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) {
399 $org_units = $this->getTextRepresentationOfOrgUnits();
400 $link = ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu');
401 $actions->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link);
402 }
403 }
404
405 $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_usr_id', $mst_lco_usr_id);
406 $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_crs_ref_id', $mst_lco_crs_ref_id);
407
408 $actions = ilMyStaffGUI::extendActionMenuWithUserActions(
409 $actions,
410 $mst_lco_usr_id,
411 rawurlencode($this->ctrl->getLinkTargetByClass(
412 "ilMStListCoursesGUI",
414 ))
415 );
416
417 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
418 $this->tpl->parseCurrentBlock();
419 }
420
421 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
422 {
423 $set = array_pop($a_set);
424
425 $col = 0;
426 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
427 $a_excel->setCell($a_row, $col, $v);
428 $col++;
429 }
430 }
431
432 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
433 {
434 $set = array_pop($a_set);
435
436 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
437 $a_csv->addColumn($v);
438 }
439 $a_csv->addRow();
440 }
441
442 protected function getFieldValuesForExport(\ILIAS\MyStaff\ListCourses\ilMStListCourse $my_staff_course): array
443 {
444 $propGetter = Closure::bind(function ($prop) {
445 return $this->$prop ?? null;
446 }, $my_staff_course, $my_staff_course);
447
448 $field_values = array();
449 foreach ($this->getSelectedColumns() as $k => $v) {
450 switch ($k) {
451 case 'usr_assinged_orgus':
452 $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($my_staff_course->getUsrId());
453 break;
454 case 'usr_reg_status':
455 $field_values[$k] = \ILIAS\MyStaff\ListCourses\ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
456 break;
457 case 'usr_lp_status':
458 $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
459 break;
460 default:
461 $field_values[$k] = strip_tags($propGetter($k) ?? "");
462 break;
463 }
464 }
465
466 return $field_values;
467 }
468}
static innerjoin( $tablename, $on_this, $on_external, array $fields=array(' *'), string $operator='=', bool $both_external=false)
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 $a_col, $a_value, ?string $a_datatype=null)
Set cell value.
const LP_STATUS_COMPLETED_NUM
const LP_STATUS_COMPLETED
const LP_STATUS_FAILED
const LP_STATUS_IN_PROGRESS_NUM
const LP_STATUS_NOT_ATTEMPTED_NUM
const LP_STATUS_FAILED_NUM
const LP_STATUS_NOT_ATTEMPTED
const LP_STATUS_IN_PROGRESS
Class ilMStListCoursesGUI.
Class ilMStListCoursesTableGUI.
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
getSelectableColumns()
Get selectable columns.
getFieldValuesForExport(\ILIAS\MyStaff\ListCourses\ilMStListCourse $my_staff_course)
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
__construct(ilMStListCoursesGUI $parent_obj, $parent_cmd=ilMStListCoursesGUI::CMD_INDEX)
static getUserLpStatusAsText(ilMStListCourse $my_staff_course)
static getUserLpStatusAsHtml(ilMStListCourse $my_staff_course)
static _lookupObjectId(int $ref_id)
static _lookupTitle(int $obj_id)
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...
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.
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
Class ChatMainBarProvider \MainMenu\Provider.
$cols
Definition: xhr_table.php:11