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