ILIAS  release_8 Revision v8.24
class.ilMStShowUserCoursesTableGUI.php
Go to the documentation of this file.
1<?php
19// no namespace for ilCtrl classes
20//namespace ILIAS\MyStaff\Courses\ShowUser;
21
22/*
23use Closure;
24use ilAdvancedSelectionListGUI;
25use ilCSVWriter;
26use ilExcel;*/
29
30/*
31use ilLPStatus;
32use ilMStShowUserCoursesGUI;
33use ilMyStaffGUI;
34use ilObjUserTracking;
35use ilOrgUnitOperation;
36use ilRepositorySelectorInputGUI;
37use ilSelectInputGUI;
38use ilTable2GUI;
39use ilTextInputGUI;*/
40
47{
48 protected int $usr_id;
49 protected array $filter = array();
51 protected ?array $columnDefinition = null;
52 protected ?array $orgu_names = null;
53
59 {
60 global $DIC;
61
62 $this->access = ilMyStaffAccess::getInstance();
63
64 $this->usr_id = $DIC->http()->request()->getQueryParams()['usr_id'];
65
66 $this->setPrefix('myst_su');
67 $this->setFormName('myst_su');
68 $this->setId('myst_su');
69
70 parent::__construct($parent_obj, $parent_cmd, '');
71 $this->setRowTemplate('tpl.list_user_courses_row.html', "Services/MyStaff");
72 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
73 ;
74 $this->setDefaultOrderDirection('desc');
75
76 $this->setShowRowsSelector(true);
77
78 $this->setEnableTitle(true);
79 $this->setDisableFilterHiding(true);
80 $this->setEnableNumInfo(true);
81
82 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
83
84 $this->setFilterCols(5);
85 $this->initFilter();
86 $this->addColumns();
87
88 $this->parseData();
89 }
90
91 protected function parseData(): void
92 {
93 global $DIC;
94
95 $this->setExternalSorting(true);
96 $this->setExternalSegmentation(true);
97 $this->setDefaultOrderField('crs_title');
98
99 $this->determineLimit();
101
102 $arr_usr_id = $this->access->getUsersForUserOperationAndContext(
103 $DIC->user()->getId(),
104 ilMyStaffAccess::ACCESS_ENROLMENTS_ORG_UNIT_OPERATION,
105 ilMyStaffAccess::COURSE_CONTEXT
106 );
107
108 $this->filter['usr_id'] = $this->usr_id;
109 $options = array(
110 'filters' => $this->filter,
111 'limit' => array(
112 'start' => $this->getOffset(),
113 'end' => $this->getLimit(),
114 ),
115 'count' => true,
116 'sort' => array(
117 'field' => $this->getOrderField(),
118 'direction' => $this->getOrderDirection(),
119 ),
120 );
121
122 $user_courses_fetcher = new \ILIAS\MyStaff\Courses\ShowUser\ilMStShowUserCourses($DIC);
123 $result = $user_courses_fetcher->getData($arr_usr_id, $options);
124 $this->setMaxCount($result->getTotalDatasetCount());
125 $data = $result->getDataset();
126
127 // Workaround because the fillRow Method only accepts arrays
128 $data = array_map(function (ilMStListCourse $it): array {
129 return [$it];
130 }, $data);
131 $this->setData($data);
132 }
133
134 final public function initFilter(): void
135 {
136 global $DIC;
137
138 $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
139 $this->addFilterItem($item);
140 $item->readFromSession();
141 $this->filter['crs_title'] = $item->getValue();
142
143 // course members
144 $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
145 $item->setSelectText($DIC->language()->txt("mst_select_course"));
146 $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
147 $item->setClickableTypes(array(ilMyStaffAccess::COURSE_CONTEXT));
148 $this->addFilterItem($item);
149 $item->readFromSession();
150 //$item->setParent($this->getParentObject());
151 $this->filter["course"] = $item->getValue();
152
153 //membership status
154 $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
155 $item->setOptions(array(
156 "" => $DIC->language()->txt("mst_opt_all"),
157 ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
158 ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
159 ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
160 ));
161 $this->addFilterItem($item);
162 $item->readFromSession();
163 $this->filter["memb_status"] = $item->getValue();
164
165 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
166 //learning progress status
167 $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
168 //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
169 $item->setOptions(array(
170 "" => $DIC->language()->txt("mst_opt_all"),
175 ));
176 $this->addFilterItem($item);
177 $item->readFromSession();
178 $this->filter["lp_status"] = $item->getValue();
179 $this->filter["lp_status"] = (int) $this->filter["lp_status"] - 1;
180 }
181 }
182
183 final public function getSelectableColumns(): array
184 {
185 global $DIC;
186
187 if ($this->columnDefinition !== null) {
189 }
190
191 $cols = array();
192
193 $cols['crs_title'] = array(
194 'txt' => $DIC->language()->txt('crs_title'),
195 'default' => true,
196 'width' => 'auto',
197 'sort_field' => 'crs_title',
198 );
199 $cols['usr_reg_status'] = array(
200 'txt' => $DIC->language()->txt('member_status'),
201 'default' => true,
202 'width' => 'auto',
203 'sort_field' => 'reg_status',
204 );
205 if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
206 $cols['usr_lp_status'] = array(
207 'txt' => $DIC->language()->txt('learning_progress'),
208 'default' => true,
209 'width' => 'auto',
210 'sort_field' => 'lp_status',
211 );
212 }
213
214 $this->columnDefinition = $cols;
215
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 //Actions
230 if (!$this->getExportMode()) {
231 $this->addColumn($DIC->language()->txt('actions'));
232 }
233 }
234
235 protected function getTextRepresentationOfOrgUnits(): array
236 {
237 if (isset($this->orgu_names)) {
238 return $this->orgu_names;
239 }
240
242 }
243
244 public function fillRow(array $a_set): void
245 {
246 global $DIC;
247
248 $set = array_pop($a_set);
249
250 $propGetter = Closure::bind(function ($prop) {
251 return $this->$prop ?? null;
252 }, $set, $set);
253
254 foreach ($this->getSelectedColumns() as $k => $v) {
255 switch ($k) {
256 case 'usr_reg_status':
257 $this->tpl->setCurrentBlock('td');
258 $this->tpl->setVariable(
259 'VALUE',
260 $this->getSpaceOrValue(ilMStListCourse::getMembershipStatusText($set->getUsrRegStatus()))
261 );
262 $this->tpl->parseCurrentBlock();
263 break;
264 case 'usr_lp_status':
265 $this->tpl->setCurrentBlock('td');
266 $this->tpl->setVariable(
267 'VALUE',
269 );
270 $this->tpl->parseCurrentBlock();
271 break;
272 default:
273 if ($propGetter($k) !== null) {
274 $this->tpl->setCurrentBlock('td');
275 $this->tpl->setVariable(
276 'VALUE',
277 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
278 );
279 $this->tpl->parseCurrentBlock();
280 } else {
281 $this->tpl->setCurrentBlock('td');
282 $this->tpl->setVariable('VALUE', '&nbsp;');
283 $this->tpl->parseCurrentBlock();
284 }
285 break;
286 }
287 }
288
289 $actions = new ilAdvancedSelectionListGUI();
290 $actions->setListTitle($DIC->language()->txt("actions"));
291 $actions->setId($set->getUsrId() . "-" . $set->getCrsRefId());
292
293 $mst_lco_usr_id = $set->getUsrId();
294 $mst_lco_crs_ref_id = $set->getCrsRefId();
295
296 if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) {
297 $link = ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::COURSE_CONTEXT);
298 $actions->addItem(
300 '',
301 $link
302 );
303 };
304
305 foreach (
306 ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array(
307 'user_id' => $mst_lco_usr_id,
308 'object_reference.deleted' => null
309 ), array('user_id' => '=', 'object_reference.deleted' => '!='))->get() as $org_unit_assignment
310 ) {
311 if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) {
312 $org_units = $this->getTextRepresentationOfOrgUnits();
313 $link = ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu');
314 $actions->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link);
315 }
316 }
317
318 $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_usr_id', $mst_lco_usr_id);
319 $DIC->ctrl()->setParameterByClass(ilMStShowUserCoursesGUI::class, 'mst_lco_crs_ref_id', $mst_lco_crs_ref_id);
320
321 $actions = ilMyStaffGUI::extendActionMenuWithUserActions(
322 $actions,
323 $mst_lco_usr_id,
324 rawurlencode($this->ctrl->getLinkTargetByClass(
325 "ilMStShowUserCoursesGUI",
327 ))
328 );
329
330 $this->tpl->setVariable('ACTIONS', $actions->getHTML());
331 $this->tpl->parseCurrentBlock();
332 }
333
334 protected function fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set): void
335 {
336 $set = array_pop($a_set);
337
338 $col = 0;
339 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
340 $a_excel->setCell($a_row, $col, $v);
341 $col++;
342 }
343 }
344
345 protected function fillRowCSV(ilCSVWriter $a_csv, array $a_set): void
346 {
347 $set = array_pop($a_set);
348
349 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
350 $a_csv->addColumn($v);
351 }
352 $a_csv->addRow();
353 }
354
355 protected function getFieldValuesForExport(ilMStListCourse $my_staff_course): array
356 {
357 $propGetter = Closure::bind(function ($prop) {
358 return $this->$prop ?? null;
359 }, $my_staff_course, $my_staff_course);
360
361 $field_values = array();
362
363 foreach ($this->getSelectedColumns() as $k => $v) {
364 switch ($k) {
365 case 'usr_reg_status':
366 $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
367 break;
368 case 'usr_lp_status':
369 $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
370 break;
371 default:
372 $field_values[$k] = strip_tags($propGetter($k) ?? "");
373 break;
374 }
375 }
376
377 return $field_values;
378 }
379
380 protected function getSpaceOrValue(string $string): string
381 {
382 if (!$this->getExportMode()) {
383 if (empty($string)) {
384 return "&nbsp";
385 }
386 }
387
388 return $string;
389 }
390}
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 ilMStShowUserCoursesTableGUI.
__construct(ilMStShowUserCoursesGUI $parent_obj, $parent_cmd=ilMStShowUserCoursesGUI::CMD_INDEX)
fillRowCSV(ilCSVWriter $a_csv, array $a_set)
CSV Version of Fill Row.
getFieldValuesForExport(ilMStListCourse $my_staff_course)
fillRow(array $a_set)
Standard Version of Fill Row.
fillRowExcel(ilExcel $a_excel, int &$a_row, array $a_set)
Excel Version of Fill Row.
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.
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$cols
Definition: xhr_table.php:11