ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMStListCoursesTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
29{
30 protected array $filter = [];
31 protected array $cached_selectable_columns = [];
32 protected ?array $orgu_names = null;
33 protected array $usr_orgu_names = [];
35 protected \ILIAS\UI\Factory $ui_fac;
36 protected \ILIAS\UI\Renderer $ui_ren;
37
43 {
44 global $DIC;
45
46 $this->access = ilMyStaffAccess::getInstance();
47 $this->ui_fac = $DIC->ui()->factory();
48 $this->ui_ren = $DIC->ui()->renderer();
49
50 $this->setPrefix('myst_lc');
51 $this->setFormName('myst_lc');
52 $this->setId('myst_lc');
53
54 parent::__construct($parent_obj, $parent_cmd, '');
55
56 $this->setRowTemplate('tpl.list_courses_row.html', "components/ILIAS/MyStaff");
57 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
58 $this->setDefaultOrderDirection('desc');
59
60 $this->setShowRowsSelector(true);
61
62 $this->setEnableTitle(true);
63 $this->setDisableFilterHiding(true);
64 $this->setEnableNumInfo(true);
65
66 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
67
68 $this->setFilterCols(5);
69 $this->initFilter();
70
71 $this->addColumns();
72
73 $this->parseData();
74 }
75
76 protected function parseData()
77 {
78 global $DIC;
79
80 $this->setExternalSorting(true);
81 $this->setExternalSegmentation(true);
82 $this->setDefaultOrderField('crs_title');
83
84 $this->determineLimit();
86
87 $options = array(
88 'filters' => $this->filter,
89 'limit' => array(
90 'start' => $this->getOffset(),
91 'end' => $this->getLimit(),
92 ),
93 'count' => true,
94 'sort' => array(
95 'field' => $this->getOrderField(),
96 'direction' => $this->getOrderDirection(),
97 ),
98 );
99
100 $arr_usr_id = $this->access->getUsersForUserOperationAndContext(
101 $DIC->user()->getId(),
102 ilMyStaffAccess::ACCESS_ENROLMENTS_ORG_UNIT_OPERATION,
103 ilMyStaffAccess::COURSE_CONTEXT
104 );
105
106 $list_courses_fetcher = new \ILIAS\MyStaff\ListCourses\ilMStListCourses($DIC);
107 $result = $list_courses_fetcher->getData($arr_usr_id, $options);
108 $this->setMaxCount($result->getTotalDatasetCount());
109 $data = $result->getDataset();
110
111 // Workaround because the fillRow Method only accepts arrays
112 $data = array_map(function (\ILIAS\MyStaff\ListCourses\ilMStListCourse $it): array {
113 return [$it];
114 }, $data);
115 $this->setData($data);
116 }
117
118 final public function initFilter(): void
119 {
120 global $DIC;
121
122 $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
123 $this->addFilterItem($item);
124 $item->readFromSession();
125 $this->filter['crs_title'] = $item->getValue();
126
127 // course members
128 $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
129 //$item->setParent($this->getParentObject());
130 $item->setSelectText($DIC->language()->txt("mst_select_course"));
131 $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
132 $item->setClickableTypes(array(ilMyStaffAccess::COURSE_CONTEXT));
133 $this->addFilterItem($item);
134 $item->readFromSession();
135 //$item->setParent($this->getParentObject());
136 $this->filter["course"] = $item->getValue();
137
138 //membership status
139 $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
140 $item->setOptions(array(
141 "" => $DIC->language()->txt("mst_opt_all"),
142 \ILIAS\MyStaff\ListCourses\ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
143 \ILIAS\MyStaff\ListCourses\ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
144 \ILIAS\MyStaff\ListCourses\ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
145 ));
146 $this->addFilterItem($item);
147 $item->readFromSession();
148 $this->filter["memb_status"] = $item->getValue();
149
150 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
151 //learning progress status
152 $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
153 //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
154 $item->setOptions(array(
155 "" => $DIC->language()->txt("mst_opt_all"),
160 ));
161 $this->addFilterItem($item);
162 $item->readFromSession();
163 $this->filter["lp_status"] = $item->getValue();
164 $this->filter["lp_status"] = (int) $this->filter["lp_status"] - 1;
165 }
166
167
168
169 //user
170 $item = new ilTextInputGUI(
171 $DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
172 ->txt("name"),
173 "user"
174 );
175
176 $this->addFilterItem($item);
177 $item->readFromSession();
178 $this->filter['user'] = $item->getValue();
179
180 if (ilUserSearchOptions::_isEnabled('org_units')) {
181 $paths = $this->getTextRepresentationOfOrgUnits();
182 $options[0] = $DIC->language()->txt('mst_opt_all');
183 foreach ($paths as $org_ref_id => $path) {
184 $options[$org_ref_id] = $path;
185 }
186 $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
187 $item->setOptions($options);
188 $this->addFilterItem($item);
189 $item->readFromSession();
190 $this->filter['org_unit'] = $item->getValue();
191 }
192 }
193
194 protected function getTextRepresentationOfOrgUnits(): array
195 {
196 if (isset($this->orgu_names)) {
197 return $this->orgu_names;
198 }
199
201 }
202
203 protected function getTextRepresentationOfUsersOrgUnits(int $user_id): string
204 {
205 if (isset($this->usr_orgu_names[$user_id])) {
206 return $this->usr_orgu_names[$user_id];
207 }
208
209 return $this->usr_orgu_names[$user_id] = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
210 }
211
212 final public function getSelectableColumns(): array
213 {
214 if ($this->cached_selectable_columns) {
216 }
217
218 return $this->cached_selectable_columns = $this->initSelectableColumns();
219 }
220
221 protected function initSelectableColumns(): array
222 {
223 global $DIC;
224
225 $cols = array();
226
227 $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
228
229 $cols['crs_title'] = array(
230 'txt' => $DIC->language()->txt('crs_title'),
231 'default' => true,
232 'width' => 'auto',
233 'sort_field' => 'crs_title',
234 );
235 $cols['usr_reg_status'] = array(
236 'txt' => $DIC->language()->txt('member_status'),
237 'default' => true,
238 'width' => 'auto',
239 'sort_field' => 'reg_status',
240 );
241 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
242 $cols['usr_lp_status'] = array(
243 'txt' => $DIC->language()->txt('learning_progress'),
244 'default' => true,
245 'width' => 'auto',
246 'sort_field' => 'lp_status',
247 );
248 }
249
250 if ($arr_searchable_user_columns['login'] ?? false) {
251 $cols['usr_login'] = array(
252 'txt' => $DIC->language()->txt('login'),
253 'default' => true,
254 'width' => 'auto',
255 'sort_field' => 'usr_login',
256 );
257 }
258 if ($arr_searchable_user_columns['firstname'] ?? false) {
259 $cols['usr_firstname'] = array(
260 'txt' => $DIC->language()->txt('firstname'),
261 'default' => true,
262 'width' => 'auto',
263 'sort_field' => 'usr_firstname',
264 );
265 }
266 if ($arr_searchable_user_columns['lastname'] ?? false) {
267 $cols['usr_lastname'] = array(
268 'txt' => $DIC->language()->txt('lastname'),
269 'default' => true,
270 'width' => 'auto',
271 'sort_field' => 'usr_lastname',
272 );
273 }
274
275 if ($arr_searchable_user_columns['email'] ?? false) {
276 $cols['usr_email'] = array(
277 'txt' => $DIC->language()->txt('email'),
278 'default' => true,
279 'width' => 'auto',
280 'sort_field' => 'usr_email',
281 );
282 }
283
284 if ($arr_searchable_user_columns['org_units'] ?? false) {
285 $cols['usr_assinged_orgus'] = array(
286 'txt' => $DIC->language()->txt('objs_orgu'),
287 'default' => true,
288 'width' => 'auto',
289 );
290 }
291
292 return $cols;
293 }
294
295 private function addColumns(): void
296 {
297 global $DIC;
298
299 foreach ($this->getSelectableColumns() as $k => $v) {
300 if ($this->isColumnSelected($k)) {
301 $sort = $v['sort_field'] ?? "";
302 $this->addColumn($v['txt'], $sort);
303 }
304 }
305
306 //Actions
307 if (!$this->getExportMode()) {
308 $this->addColumn($DIC->language()->txt('actions'));
309 }
310 }
311
318 final protected function fillRow(array $a_set): void
319 {
320 global $DIC;
321
322 $set = array_pop($a_set);
323
324 $propGetter = Closure::bind(function ($prop) {
325 return $this->$prop ?? null;
326 }, $set, $set);
327
328 foreach ($this->getSelectedColumns() as $k => $v) {
329 switch ($k) {
330 case 'usr_assinged_orgus':
331 $this->tpl->setCurrentBlock('td');
332 $this->tpl->setVariable(
333 'VALUE',
334 $this->getTextRepresentationOfUsersOrgUnits($set->getUsrId())
335 );
336 $this->tpl->parseCurrentBlock();
337 break;
338 case 'usr_reg_status':
339 $this->tpl->setCurrentBlock('td');
340 $this->tpl->setVariable(
341 'VALUE',
342 \ILIAS\MyStaff\ListCourses\ilMStListCourse::getMembershipStatusText($set->getUsrRegStatus())
343 );
344 $this->tpl->parseCurrentBlock();
345 break;
346 case 'usr_lp_status':
347 $this->tpl->setCurrentBlock('td');
348 $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($set));
349 $this->tpl->parseCurrentBlock();
350 break;
351 default:
352 if ($propGetter($k) !== null) {
353 $this->tpl->setCurrentBlock('td');
354 $this->tpl->setVariable(
355 'VALUE',
356 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
357 );
358 $this->tpl->parseCurrentBlock();
359 } else {
360 $this->tpl->setCurrentBlock('td');
361 $this->tpl->setVariable('VALUE', '&nbsp;');
362 $this->tpl->parseCurrentBlock();
363 }
364 break;
365 }
366 }
367
368 $mst_lco_usr_id = $set->getUsrId();
369 $mst_lco_crs_ref_id = $set->getCrsRefId();
370
371 $actions = [];
372
373 if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) {
374 $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::COURSE_CONTEXT);
375 $actions[] = $this->ui_fac->link()->standard(
377 $link
378 );
379 };
380
381 foreach (array_unique(ilObjOrgUnitTree::_getInstance()->getOrgUnitOfUser($mst_lco_usr_id)) as $orgu_id) {
382 if ($DIC->access()->checkAccess("read", "", $orgu_id) && !ilObject::_isInTrash($orgu_id)) {
383 $org_units = $this->getTextRepresentationOfOrgUnits();
384 if (isset($org_units[$orgu_id])) {
385 $link = ilLink::_getStaticLink($orgu_id, 'orgu');
386 $actions[] = $this->ui_fac->link()->standard($org_units[$orgu_id], $link);
387 }
388 }
389 }
390
391 $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_usr_id', $mst_lco_usr_id);
392 $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_crs_ref_id', $mst_lco_crs_ref_id);
393
394 $actions[] = \ilMyStaffGUI::extendActionMenuWithUserActions(
395 $mst_lco_usr_id,
396 rawurlencode($this->ctrl->getLinkTargetByClass(
397 "ilMStListCoursesGUI",
399 ))
400 );
401
402 $dropdown = $this->ui_fac->dropdown()->standard($actions)->withLabel($this->lng->txt("actions"));
403 $this->tpl->setVariable("ACTIONS", $this->ui_ren->render($dropdown));
404 $this->tpl->parseCurrentBlock();
405 }
406
407 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
408 {
409 $set = array_pop($a_set);
410
411 $col = 0;
412 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
413 $a_excel->setCell($a_row, $col, $v);
414 $col++;
415 }
416 }
417
418 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
419 {
420 $set = array_pop($a_set);
421
422 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
423 $a_csv->addColumn($v);
424 }
425 $a_csv->addRow();
426 }
427
428 protected function getFieldValuesForExport(\ILIAS\MyStaff\ListCourses\ilMStListCourse $my_staff_course): array
429 {
430 $propGetter = Closure::bind(function ($prop) {
431 return $this->$prop ?? null;
432 }, $my_staff_course, $my_staff_course);
433
434 $field_values = array();
435 foreach ($this->getSelectedColumns() as $k => $v) {
436 switch ($k) {
437 case 'usr_assinged_orgus':
438 $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($my_staff_course->getUsrId());
439 break;
440 case 'usr_reg_status':
441 $field_values[$k] = \ILIAS\MyStaff\ListCourses\ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
442 break;
443 case 'usr_lp_status':
444 $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
445 break;
446 default:
447 $field_values[$k] = strip_tags($propGetter($k) ?? "");
448 break;
449 }
450 }
451
452 return $field_values;
453 }
454}
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.
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 _isInTrash(int $ref_id)
static _lookupTitle(int $obj_id)
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
This class represents a repository selector in a property form.
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.
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26