ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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();
35  protected $access;
36 
37 
43  {
44  global $DIC;
45 
46  $this->access = ilMyStaffAccess::getInstance();
47 
48  $this->setPrefix('myst_lc');
49  $this->setFormName('myst_lc');
50  $this->setId('myst_lc');
51 
52  parent::__construct($parent_obj, $parent_cmd, '');
53 
54  $this->setRowTemplate('tpl.list_courses_row.html', "Services/MyStaff");
55  $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
56  $this->setDefaultOrderDirection('desc');
57 
58  $this->setShowRowsSelector(true);
59 
60  $this->setEnableTitle(true);
61  $this->setDisableFilterHiding(true);
62  $this->setEnableNumInfo(true);
63 
64  $this->setExportFormats(array( self::EXPORT_EXCEL, self::EXPORT_CSV ));
65 
66  $this->setFilterCols(5);
67  $this->initFilter();
68 
69  $this->addColumns();
70 
71  $this->parseData();
72  }
73 
74 
78  protected function parseData()
79  {
80  global $DIC;
81 
82  $this->setExternalSorting(true);
83  $this->setExternalSegmentation(true);
84  $this->setDefaultOrderField('crs_title');
85 
86  $this->determineLimit();
87  $this->determineOffsetAndOrder();
88 
89  $options = array(
90  'filters' => $this->filter,
91  'limit' => array(),
92  'count' => true,
93  'sort' => array(
94  'field' => $this->getOrderField(),
95  'direction' => $this->getOrderDirection(),
96  ),
97  );
98 
99  $all_users_for_user = $this->access->getUsersForUser($DIC->user()->getId());
100 
101  $list_courses_fetcher = new ilMStListCourses($DIC);
102  $count = $list_courses_fetcher->getData($all_users_for_user, $options);
103  $options['limit'] = array(
104  'start' => intval($this->getOffset()),
105  'end' => intval($this->getLimit()),
106  );
107  $options['count'] = false;
108  $data = $list_courses_fetcher->getData($all_users_for_user, $options);
109  $this->setMaxCount($count);
110  $this->setData($data);
111  }
112 
113 
117  public function initFilter()
118  {
119  global $DIC;
120 
121  $item = new ilTextInputGUI($DIC->language()->txt("crs_title"), "crs_title");
122  $this->addFilterItem($item);
123  $item->readFromSession();
124  $this->filter['crs_title'] = $item->getValue();
125 
126  // course members
127  $item = new ilRepositorySelectorInputGUI($DIC->language()->txt("usr_filter_coursemember"), "course");
128  $item->setParent($this->getParentObject());
129  $item->setSelectText($DIC->language()->txt("mst_select_course"));
130  $item->setHeaderMessage($DIC->language()->txt("mst_please_select_course"));
131  $item->setClickableTypes(array( ilMyStaffAccess::DEFAULT_CONTEXT ));
132  $this->addFilterItem($item);
133  $item->readFromSession();
134  $item->setParent($this->getParentObject());
135  $this->filter["course"] = $item->getValue();
136 
137  //membership status
138  $item = new ilSelectInputGUI($DIC->language()->txt('member_status'), 'memb_status');
139  $item->setOptions(array(
140  "" => $DIC->language()->txt("mst_opt_all"),
141  ilMStListCourse::MEMBERSHIP_STATUS_REQUESTED => $DIC->language()->txt('mst_memb_status_requested'),
142  ilMStListCourse::MEMBERSHIP_STATUS_WAITINGLIST => $DIC->language()->txt('mst_memb_status_waitinglist'),
143  ilMStListCourse::MEMBERSHIP_STATUS_REGISTERED => $DIC->language()->txt('mst_memb_status_registered'),
144  ));
145  $this->addFilterItem($item);
146  $item->readFromSession();
147  $this->filter["memb_status"] = $item->getValue();
148 
149  if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
150  //learning progress status
151  $item = new ilSelectInputGUI($DIC->language()->txt('learning_progress'), 'lp_status');
152  //+1 because LP_STATUS_NOT_ATTEMPTED_NUM is 0.
153  $item->setOptions(array(
154  "" => $DIC->language()->txt("mst_opt_all"),
159  ));
160  $this->addFilterItem($item);
161  $item->readFromSession();
162  $this->filter["lp_status"] = $item->getValue();
163  if ($this->filter["lp_status"]) {
164  $this->filter["lp_status"] = $this->filter["lp_status"] - 1;
165  }
166  }
167 
168  //user
169  $item = new ilTextInputGUI($DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
170  ->txt("name"), "user");
171 
172  $this->addFilterItem($item);
173  $item->readFromSession();
174  $this->filter['user'] = $item->getValue();
175 
176  if (ilUserSearchOptions::_isEnabled('org_units')) {
178  $options[0] = $DIC->language()->txt('mst_opt_all');
179  foreach ($paths as $org_ref_id => $path) {
180  $options[$org_ref_id] = $path;
181  }
182  $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
183  $item->setOptions($options);
184  $this->addFilterItem($item);
185  $item->readFromSession();
186  $this->filter['org_unit'] = $item->getValue();
187  }
188  }
189 
190 
194  public function getSelectableColumns()
195  {
196  global $DIC;
197 
198  $cols = array();
199 
200  $arr_searchable_user_columns = ilUserSearchOptions::getSelectableColumnInfo();
201 
202  $cols['crs_title'] = array(
203  'txt' => $DIC->language()->txt('crs_title'),
204  'default' => true,
205  'width' => 'auto',
206  'sort_field' => 'crs_title',
207  );
208  $cols['usr_reg_status'] = array(
209  'txt' => $DIC->language()->txt('member_status'),
210  'default' => true,
211  'width' => 'auto',
212  'sort_field' => 'reg_status',
213  );
214  if (ilObjUserTracking::_enabledLearningProgress() && $this->access->hasCurrentUserAccessToCourseLearningProgressForAtLeastOneUser()) {
215  $cols['usr_lp_status'] = array(
216  'txt' => $DIC->language()->txt('learning_progress'),
217  'default' => true,
218  'width' => 'auto',
219  'sort_field' => 'lp_status',
220  );
221  }
222 
223  if ($arr_searchable_user_columns['login']) {
224  $cols['usr_login'] = array(
225  'txt' => $DIC->language()->txt('login'),
226  'default' => true,
227  'width' => 'auto',
228  'sort_field' => 'usr_login',
229  );
230  }
231  if ($arr_searchable_user_columns['firstname']) {
232  $cols['usr_firstname'] = array(
233  'txt' => $DIC->language()->txt('firstname'),
234  'default' => true,
235  'width' => 'auto',
236  'sort_field' => 'usr_firstname',
237  );
238  }
239  if ($arr_searchable_user_columns['lastname']) {
240  $cols['usr_lastname'] = array(
241  'txt' => $DIC->language()->txt('lastname'),
242  'default' => true,
243  'width' => 'auto',
244  'sort_field' => 'usr_lastname',
245  );
246  }
247 
248  if ($arr_searchable_user_columns['email']) {
249  $cols['usr_email'] = array(
250  'txt' => $DIC->language()->txt('email'),
251  'default' => true,
252  'width' => 'auto',
253  'sort_field' => 'usr_email',
254  );
255  }
256 
257  if ($arr_searchable_user_columns['org_units']) {
258  $cols['usr_assinged_orgus'] = array(
259  'txt' => $DIC->language()->txt('objs_orgu'),
260  'default' => true,
261  'width' => 'auto',
262  );
263  }
264 
265  return $cols;
266  }
267 
268 
272  private function addColumns()
273  {
274  global $DIC;
275 
276  foreach ($this->getSelectableColumns() as $k => $v) {
277  if ($this->isColumnSelected($k)) {
278  if (isset($v['sort_field'])) {
279  $sort = $v['sort_field'];
280  } else {
281  $sort = null;
282  }
283  $this->addColumn($v['txt'], $sort, $v['width']);
284  }
285  }
286 
287  //Actions
288  if (!$this->getExportMode()) {
289  $this->addColumn($DIC->language()->txt('actions'));
290  }
291  }
292 
293 
297  public function fillRow($profile)
298  {
299  global $DIC;
300 
301  $propGetter = Closure::bind(function ($prop) {
302  return $this->$prop;
303  }, $profile, $profile);
304 
305  foreach ($this->getSelectableColumns() as $k => $v) {
306  if ($this->isColumnSelected($k)) {
307  switch ($k) {
308  case 'usr_assinged_orgus':
309  $this->tpl->setCurrentBlock('td');
310  $this->tpl->setVariable('VALUE', strval(ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($profile->getUsrId())));
311  $this->tpl->parseCurrentBlock();
312  break;
313  case 'usr_reg_status':
314  $this->tpl->setCurrentBlock('td');
315  $this->tpl->setVariable('VALUE', ilMStListCourse::getMembershipStatusText($profile->getUsrRegStatus()));
316  $this->tpl->parseCurrentBlock();
317  break;
318  case 'usr_lp_status':
319  $this->tpl->setCurrentBlock('td');
320  $this->tpl->setVariable('VALUE', ilMyStaffGUI::getUserLpStatusAsHtml($profile));
321  $this->tpl->parseCurrentBlock();
322  break;
323  default:
324  if ($propGetter($k) !== null) {
325  $this->tpl->setCurrentBlock('td');
326  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
327  $this->tpl->parseCurrentBlock();
328  } else {
329  $this->tpl->setCurrentBlock('td');
330  $this->tpl->setVariable('VALUE', '&nbsp;');
331  $this->tpl->parseCurrentBlock();
332  }
333  break;
334  }
335  }
336  }
337 
338  $actions = new ilAdvancedSelectionListGUI();
339  $actions->setListTitle($DIC->language()->txt("actions"));
340  $actions->setAsynch(true);
341  $actions->setId($profile->getUsrId() . "-" . $profile->getCrsRefId());
342 
343  $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_usr_id', $profile->getUsrId());
344  $DIC->ctrl()->setParameterByClass(ilMStListCoursesGUI::class, 'mst_lco_crs_ref_id', $profile->getCrsRefId());
345 
346  $actions->setAsynchUrl(str_replace("\\", "\\\\", $DIC->ctrl()
347  ->getLinkTarget($this->parent_obj, ilMStListCoursesGUI::CMD_GET_ACTIONS, "", true)));
348  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
349  $this->tpl->parseCurrentBlock();
350  }
351 
352 
358  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $selected_skill)
359  {
360  $col = 0;
361  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
362  $a_excel->setCell($a_row, $col, $v);
363  $col++;
364  }
365  }
366 
367 
372  protected function fillRowCSV($a_csv, $selected_skill)
373  {
374  foreach ($this->getFieldValuesForExport($selected_skill) as $k => $v) {
375  $a_csv->addColumn($v);
376  }
377  $a_csv->addRow();
378  }
379 
380 
386  protected function getFieldValuesForExport(ilMStListCourse $my_staff_course)
387  {
388  $propGetter = Closure::bind(function ($prop) {
389  return $this->$prop;
390  }, $my_staff_course, $my_staff_course);
391 
392  $field_values = array();
393  foreach ($this->getSelectedColumns() as $k => $v) {
394  switch ($k) {
395  case 'usr_assinged_orgus':
396  $field_values[$k] = ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($my_staff_course->getUsrId());
397  break;
398  case 'usr_reg_status':
399  $field_values[$k] = ilMStListCourse::getMembershipStatusText($my_staff_course->getUsrRegStatus());
400  break;
401  case 'usr_lp_status':
402  $field_values[$k] = ilMyStaffGUI::getUserLpStatusAsText($my_staff_course);
403  break;
404  default:
405  $field_values[$k] = strip_tags($propGetter($k));
406  break;
407  }
408  }
409 
410  return $field_values;
411  }
412 }
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.
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
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.
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)
$DIC
Definition: xapitoken.php:46
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
getLimit()
Get limit.
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