ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMStListCoursesTableGUI.php
Go to the documentation of this file.
1 <?php
3 
4 use Closure;
6 use ilCSVWriter;
7 use ilExcel;
9 use ilLPStatus;
11 use ilMyStaffGUI;
16 use ilTable2GUI;
17 use ilTextInputGUI;
19 
26 {
27 
31  protected $filter = array();
39  protected $orgu_names = null;
43  protected $usr_orgu_names = [];
47  protected $access;
48 
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 
90  protected function parseData()
91  {
92  global $DIC;
93 
94  $this->setExternalSorting(true);
95  $this->setExternalSegmentation(true);
96  $this->setDefaultOrderField('crs_title');
97 
98  $this->determineLimit();
99  $this->determineOffsetAndOrder();
100 
101  $options = array(
102  'filters' => $this->filter,
103  'limit' => array(),
104  'count' => true,
105  'sort' => array(
106  'field' => $this->getOrderField(),
107  'direction' => $this->getOrderDirection(),
108  ),
109  );
110 
111  $arr_usr_id = $this->access->getUsersForUserOperationAndContext(
112  $DIC->user()->getId(),
115  );
116 
117  $list_courses_fetcher = new ilMStListCourses($DIC);
118  $count = $list_courses_fetcher->getData($arr_usr_id, $options);
119  $options['limit'] = array(
120  'start' => intval($this->getOffset()),
121  'end' => intval($this->getLimit()),
122  );
123  $options['count'] = false;
124  $data = $list_courses_fetcher->getData($arr_usr_id, $options);
125  $this->setMaxCount($count);
126  $this->setData($data);
127  }
128 
129 
133  public function initFilter()
134  {
135  global $DIC;
136 
137  $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
138  $this->addFilterItem($item);
139  $item->readFromSession();
140  $this->filter['crs_title'] = $item->getValue();
141 
142  // course members
143  $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
144  $item->setParent($this->getParentObject());
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  //user
183  $item = new ilTextInputGUI($DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
184  ->txt("name"), "user");
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 
210  return $this->orgu_names = ilOrgUnitPathStorage::getTextRepresentationOfOrgUnits();
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  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']) {
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']) {
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']) {
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']) {
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']) {
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 
309  private function addColumns()
310  {
311  global $DIC;
312 
313  foreach ($this->getSelectableColumns() as $k => $v) {
314  if ($this->isColumnSelected($k)) {
315  if (isset($v['sort_field'])) {
316  $sort = $v['sort_field'];
317  } else {
318  $sort = null;
319  }
320  $this->addColumn($v['txt'], $sort, $v['width']);
321  }
322  }
323 
324  //Actions
325  if (!$this->getExportMode()) {
326  $this->addColumn($DIC->language()->txt('actions'));
327  }
328  }
329 
330 
334  public function fillRow($profile)
335  {
336  global $DIC;
337 
338  $propGetter = Closure::bind(function ($prop) {
339  return $this->$prop;
340  }, $profile, $profile);
341 
342  foreach ($this->getSelectedColumns() as $k => $v) {
343  switch ($k) {
344  case 'usr_assinged_orgus':
345  $this->tpl->setCurrentBlock('td');
346  $this->tpl->setVariable('VALUE', $this->getTextRepresentationOfUsersOrgUnits($profile->getUsrId()));
347  $this->tpl->parseCurrentBlock();
348  break;
349  case 'usr_reg_status':
350  $this->tpl->setCurrentBlock('td');
351  $this->tpl->setVariable('VALUE', ilMStListCourse::getMembershipStatusText($profile->getUsrRegStatus()));
352  $this->tpl->parseCurrentBlock();
353  break;
354  case 'usr_lp_status':
355  $this->tpl->setCurrentBlock('td');
356  $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($profile));
357  $this->tpl->parseCurrentBlock();
358  break;
359  default:
360  if ($propGetter($k) !== null) {
361  $this->tpl->setCurrentBlock('td');
362  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
363  $this->tpl->parseCurrentBlock();
364  } else {
365  $this->tpl->setCurrentBlock('td');
366  $this->tpl->setVariable('VALUE', '&nbsp;');
367  $this->tpl->parseCurrentBlock();
368  }
369  break;
370  }
371  }
372 
373  $actions = new ilAdvancedSelectionListGUI();
374  $actions->setListTitle($DIC->language()->txt("actions"));
375  $actions->setId($profile->getUsrId() . "-" . $profile->getCrsRefId());
376 
377  $mst_lco_usr_id = $profile->getUsrId();
378  $mst_lco_crs_ref_id = $profile->getCrsRefId();
379 
380  if ($DIC->access()->checkAccess("visible", "", $mst_lco_crs_ref_id)) {
381  $link = \ilLink::_getStaticLink($mst_lco_crs_ref_id, ilMyStaffAccess::COURSE_CONTEXT);
382  $actions->addItem(\ilObject2::_lookupTitle(\ilObject2::_lookupObjectId($mst_lco_crs_ref_id)), '', $link);
383  };
384 
385  foreach (\ilOrgUnitUserAssignment::innerjoin('object_reference', 'orgu_id', 'ref_id')->where(array(
386  'user_id' => $mst_lco_usr_id,
387  'object_reference.deleted' => null
388  ), array( 'user_id' => '=', 'object_reference.deleted' => '!=' ))->get() as $org_unit_assignment) {
389  if ($DIC->access()->checkAccess("read", "", $org_unit_assignment->getOrguId())) {
390  $org_units = $this->getTextRepresentationOfOrgUnits();
391  $link = \ilLink::_getStaticLink($org_unit_assignment->getOrguId(), 'orgu');
392  $actions->addItem($org_units[$org_unit_assignment->getOrguId()], '', $link);
393  }
394  }
395 
396  $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_usr_id', $mst_lco_usr_id);
397  $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_crs_ref_id', $mst_lco_crs_ref_id);
398 
399  $actions = ilMyStaffGUI::extendActionMenuWithUserActions(
400  $actions,
401  $mst_lco_usr_id,
402  rawurlencode($this->ctrl->getLinkTargetByClass(
403  "ilMStListCoursesGUI",
405  ))
406  );
407 
408  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
409  $this->tpl->parseCurrentBlock();
410  }
411 
412 
418  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
419  {
420  $col = 0;
421  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
422  $a_excel->setCell($a_row, $col, $v);
423  $col++;
424  }
425  }
426 
427 
432  protected function fillRowCSV($a_csv, $selected_skill)
433  {
434  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
435  $a_csv->addColumn($v);
436  }
437  $a_csv->addRow();
438  }
439 
440 
446  protected function getFieldValuesForExport(ilMStListCourse $my_staff_course)
447  {
448  $propGetter = Closure::bind(function ($prop) {
449  return $this->$prop;
450  }, $my_staff_course, $my_staff_course);
451 
452  $field_values = array();
453  foreach ($this->getSelectedColumns() as $k => $v) {
454  switch ($k) {
455  case 'usr_assinged_orgus':
456  $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($my_staff_course->getUsrId());
457  break;
458  case 'usr_reg_status':
459  $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
460  break;
461  case 'usr_lp_status':
462  $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
463  break;
464  default:
465  $field_values[$k] = strip_tags($propGetter($k));
466  break;
467  }
468  }
469 
470  return $field_values;
471  }
472 }
const LP_STATUS_COMPLETED_NUM
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
static _lookupTitle($a_id)
static innerjoin($tablename, $on_this, $on_external, $fields=array(' *'), $operator='=', $both_external=false)
setEnableNumInfo($a_val)
Set enable num info.
const LP_STATUS_NOT_ATTEMPTED
setFilterCols($a_val)
Set filter columns.
setExternalSegmentation($a_val)
Set external segmentation.
const LP_STATUS_IN_PROGRESS_NUM
static _lookupObjectId($a_ref_id)
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
determineLimit()
Determine the limit.
getOrderDirection()
Get order direction.
static getUserLpStatusAsHtml(ilMStListCourse $my_staff_course)
getParentObject()
Get parent object.
setId($a_val)
Set id.
const LP_STATUS_IN_PROGRESS
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
static _enabledLearningProgress()
check wether learing progress is enabled or not
const LP_STATUS_FAILED
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
getOffset()
Get offset.
setDisableFilterHiding($a_val=true)
Set disable filter hiding.
global $DIC
Definition: goto.php:24
setPrefix($a_prefix)
static getUserLpStatusAsText(ilMStListCourse $my_staff_course)
getSelectedColumns()
Get selected columns.
setCell($a_row, $a_col, $a_value, $a_datatype=null)
Set cell value.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
isColumnSelected($a_col)
Is given column selected?
fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
const LP_STATUS_NOT_ATTEMPTED_NUM
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
setFormName($a_formname="")
Set Form name.
__construct(Container $dic, ilPlugin $plugin)
addColumn( $a_text, $a_sort_field="", $a_width="", $a_is_checkbox_action_column=false, $a_class="", $a_tooltip="", $a_tooltip_with_html=false)
Add a column to the header.
__construct(ilMStListCoursesGUI $parent_obj, $parent_cmd=ilMStListCoursesGUI::CMD_INDEX)
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getLimit()
Get limit.
filter()
Definition: filter.php:2
setMaxCount($a_max_count)
set max.
getExportMode()
Was export activated?
setEnableTitle($a_enabletitle)
Set Enable Title.
const LP_STATUS_COMPLETED
$cols
Definition: xhr_table.php:11
const LP_STATUS_FAILED_NUM