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