ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilMStListUsersTableGUI.php
Go to the documentation of this file.
1 <?php
3 
4 use Closure;
6 use ilCSVWriter;
7 use ilExcel;
10 use ilObjOrgUnit;
14 use ilTable2GUI;
15 use ilTextInputGUI;
17 
24 {
25 
29  protected $filter = array();
33  protected $access;
41  protected $usr_orgu_names = [];
42 
43 
49  {
50  global $DIC;
51 
52  $this->access = ilMyStaffAccess::getInstance();
53 
54  $this->setPrefix('myst_lu');
55  $this->setFormName('myst_lu');
56  $this->setId('myst_lu');
57 
58  parent::__construct($parent_obj, $parent_cmd, '');
59 
60  $this->setRowTemplate('tpl.list_users_row.html', "Services/MyStaff");
61  $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
62  $this->setDefaultOrderDirection('desc');
63 
64  $this->setShowRowsSelector(true);
65 
66  $this->setEnableTitle(true);
67  $this->setDisableFilterHiding(true);
68  $this->setEnableNumInfo(true);
69 
70  $this->setExportFormats(array( self::EXPORT_EXCEL, self::EXPORT_CSV ));
71 
72  $this->setFilterCols(4);
73  $this->initFilter();
74  $this->addColumns();
75 
76  $this->parseData();
77  }
78 
79 
83  protected function parseData()
84  {
85  global $DIC;
86 
87  $this->setExternalSorting(true);
88  $this->setExternalSegmentation(true);
89  $this->setDefaultOrderField('lastname');
90 
91  $this->determineLimit();
92  $this->determineOffsetAndOrder();
93 
94  //Permission Filter
95  $arr_usr_id = $this->access->getUsersForUser($DIC->user()->getId());
96 
97  $options = array(
98  'filters' => $this->filter,
99  'limit' => array(),
100  'count' => true,
101  'sort' => array(
102  'field' => $this->getOrderField(),
103  'direction' => $this->getOrderDirection(),
104  ),
105  );
106 
107  $list_users_fetcher = new ilMStListUsers($DIC);
108  $count = $list_users_fetcher->getData($arr_usr_id, $options);
109  $options['limit'] = array(
110  'start' => intval($this->getOffset()),
111  'end' => intval($this->getLimit()),
112  );
113  $options['count'] = false;
114  $data = $list_users_fetcher->getData($arr_usr_id, $options);
115 
116  $this->setMaxCount($count);
117  $this->setData($data);
118  }
119 
120 
124  public function initFilter()
125  {
126  global $DIC;
127 
128  // User name, login, email filter
129  $item = new ilTextInputGUI($DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
130  ->txt("name"), "user");
131  //$item->setDataSource($DIC->ctrl()->getLinkTarget($this->getParentObject(),"addUserAutoComplete", "", true));
132  //$item->setSize(20);
133  //$item->setSubmitFormOnEnter(true);
134  $this->addFilterItem($item);
135  $item->readFromSession();
136  $this->filter['user'] = $item->getValue();
137 
138  if (ilUserSearchOptions::_isEnabled('org_units')) {
140  $options[0] = $DIC->language()->txt('mst_opt_all');
141  foreach ($paths as $org_ref_id => $path) {
142  $options[$org_ref_id] = $path;
143  }
144  $item = new ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
145  $item->setOptions($options);
146  $item->addCustomAttribute("style='width:100%'");
147  $this->addFilterItem($item);
148  $item->readFromSession();
149  $this->filter['org_unit'] = $item->getValue();
150  }
151  }
152 
153  public function getSelectableColumns() : array
154  {
155  if ($this->selectable_columns_cached) {
157  }
158 
159  return $this->selectable_columns_cached = $this->initSelectableColumns();
160  }
161 
162  protected function initSelectableColumns() : array
163  {
164  $arr_fields_without_table_sort = array(
165  'org_units',
166  'interests_general',
167  'interests_help_offered',
168  'interests_help_looking',
169  );
170  $cols = array();
171  foreach (ilUserSearchOptions::getSelectableColumnInfo() as $key => $col) {
172  $cols[$key] = $col;
173  if (!in_array($key, $arr_fields_without_table_sort)) {
174  $cols[$key]['sort_field'] = $key;
175  }
176  }
177 
178  $user_defined_fields = \ilUserDefinedFields::_getInstance();
179  foreach ($user_defined_fields->getDefinitions() as $field => $definition) {
180  unset($cols["udf_" . $field]);
181  }
182 
183  return $cols;
184  }
185 
186 
190  private function addColumns()
191  {
192  global $DIC;
193 
194  //User Profile Picture
195  if (!$this->getExportMode()) {
196  $this->addColumn('');
197  }
198 
199  foreach ($this->getSelectableColumns() as $k => $v) {
200  if ($this->isColumnSelected($k)) {
201  if (isset($v['sort_field'])) {
202  $sort = $v['sort_field'];
203  } else {
204  $sort = null;
205  }
206  $this->addColumn($v['txt'], $sort, $v['width']);
207  }
208  }
209  //Actions
210  if (!$this->getExportMode()) {
211  $this->addColumn($DIC->language()->txt('actions'));
212  }
213  }
214 
215  protected function getTextRepresentationOfUsersOrgUnits(int $user_id) : string
216  {
217  if (isset($this->usr_orgu_names[$user_id])) {
218  return $this->usr_orgu_names[$user_id];
219  }
220 
221  return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
222  }
223 
227  public function fillRow($my_staff_user)
228  {
229  global $DIC;
230 
231  $propGetter = Closure::bind(function ($prop) {
232  return $this->$prop;
233  }, $my_staff_user, $my_staff_user);
234 
235  //Avatar
236  $this->tpl->setCurrentBlock('user_profile_picture');
237  $f = $DIC->ui()->factory();
238  $renderer = $DIC->ui()->renderer();
239  $il_obj_user = $my_staff_user->returnIlUserObj();
240  $avatar = $f->image()->standard($il_obj_user->getPersonalPicturePath('small'), $il_obj_user->getPublicName());
241  $this->tpl->setVariable('user_profile_picture', $renderer->render($avatar));
242  $this->tpl->parseCurrentBlock();
243 
244  foreach ($this->getSelectedColumns() as $k => $v) {
245  switch ($k) {
246  case 'org_units':
247  $this->tpl->setCurrentBlock('td');
248  $this->tpl->setVariable('VALUE', $this->getTextRepresentationOfUsersOrgUnits($my_staff_user->getUsrId()));
249  $this->tpl->parseCurrentBlock();
250  break;
251  case 'gender':
252  $this->tpl->setCurrentBlock('td');
253  $this->tpl->setVariable('VALUE', $DIC->language()->txt('gender_' . $my_staff_user->getGender()));
254  $this->tpl->parseCurrentBlock();
255  break;
256  case 'interests_general':
257  $this->tpl->setCurrentBlock('td');
258  $this->tpl->setVariable('VALUE', ($my_staff_user->returnIlUserObj()
259  ->getGeneralInterestsAsText() ? $my_staff_user->returnIlUserObj()->getGeneralInterestsAsText() : '&nbsp;'));
260  $this->tpl->parseCurrentBlock();
261  break;
262  case 'interests_help_offered':
263  $this->tpl->setCurrentBlock('td');
264  $this->tpl->setVariable('VALUE', ($my_staff_user->returnIlUserObj()
265  ->getOfferingHelpAsText() ? $my_staff_user->returnIlUserObj()->getOfferingHelpAsText() : '&nbsp;'));
266  $this->tpl->parseCurrentBlock();
267  break;
268  case 'interests_help_looking':
269  $this->tpl->setCurrentBlock('td');
270  $this->tpl->setVariable('VALUE', ($my_staff_user->returnIlUserObj()
271  ->getLookingForHelpAsText() ? $my_staff_user->returnIlUserObj()->getLookingForHelpAsText() : '&nbsp;'));
272  $this->tpl->parseCurrentBlock();
273  break;
274  default:
275  if ($propGetter($k) !== null) {
276  $this->tpl->setCurrentBlock('td');
277  $this->tpl->setVariable('VALUE', (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k)));
278  $this->tpl->parseCurrentBlock();
279  } else {
280  $this->tpl->setCurrentBlock('td');
281  $this->tpl->setVariable('VALUE', '&nbsp;');
282  $this->tpl->parseCurrentBlock();
283  }
284  break;
285  }
286  }
287 
288  $actions = new ilAdvancedSelectionListGUI();
289  $actions->setListTitle($DIC->language()->txt("actions"));
290  $actions->setId($my_staff_user->getUsrId());
291 
292  $mst_lus_usr_id = $my_staff_user->getUsrId();
293 
294  if ($this->access->hasCurrentUserAccessToCourseMemberships()) {
295  $DIC->ctrl()->setParameterByClass(\ilMStShowUserCoursesGUI::class, 'usr_id', $mst_lus_usr_id);
296  $actions->addItem($DIC->language()->txt('mst_show_courses'), '', $DIC->ctrl()->getLinkTargetByClass(array(
297  \ilDashboardGUI::class,
298  \ilMyStaffGUI::class,
299  \ilMStShowUserGUI::class,
300  \ilMStShowUserCoursesGUI::class,
301  )));
302  }
303 
304  if ($this->access->hasCurrentUserAccessToCertificates()) {
305  $DIC->ctrl()->setParameterByClass(\ilUserCertificateGUI::class, 'usr_id', $mst_lus_usr_id);
306  $actions->addItem($DIC->language()->txt('mst_list_certificates'), '', $DIC->ctrl()->getLinkTargetByClass(array(
307  \ilDashboardGUI::class,
308  \ilMyStaffGUI::class,
309  \ilMStShowUserGUI::class,
310  \ilUserCertificateGUI::class,
311  )));
312  }
313 
314  if ($this->access->hasCurrentUserAccessToCompetences()) {
315  $DIC->ctrl()->setParameterByClass(\ilMStShowUserCompetencesGUI::class, 'usr_id', $mst_lus_usr_id);
316  $actions->addItem($DIC->language()->txt('mst_list_competences'), '', $DIC->ctrl()->getLinkTargetByClass(array(
317  \ilDashboardGUI::class,
318  \ilMyStaffGUI::class,
319  \ilMStShowUserGUI::class,
320  \ilMStShowUserCompetencesGUI::class,
321  )));
322  }
323 
324  $this->ctrl->setParameterByClass(\ilMStListUsersGUI::class, 'mst_lus_usr_id', $mst_lus_usr_id);
325 
326  $actions = \ilMyStaffGUI::extendActionMenuWithUserActions(
327  $actions,
328  $mst_lus_usr_id,
329  rawurlencode($this->ctrl->getLinkTargetByClass("ilMStListUsersGUI", \ilMStListUsersGUI::CMD_INDEX))
330  );
331 
332  $this->tpl->setVariable('ACTIONS', $actions->getHTML());
333  $this->tpl->parseCurrentBlock();
334  }
335 
336 
342  private function getProfileBackUrl()
343  {
344  global $DIC;
345 
346  return rawurlencode($DIC->ctrl()->getLinkTargetByClass(strtolower(ilMyStaffGUI::class), ilMyStaffGUI::CMD_INDEX));
347  }
348 
349 
355  protected function fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_user)
356  {
357  $col = 0;
358  foreach ($this->getFieldValuesForExport($my_staff_user) as $k => $v) {
359  $a_excel->setCell($a_row, $col, $v);
360  $col++;
361  }
362  }
363 
364 
369  protected function fillRowCSV($a_csv, $my_staff_user)
370  {
371  foreach ($this->getFieldValuesForExport($my_staff_user) as $k => $v) {
372  $a_csv->addColumn($v);
373  }
374  $a_csv->addRow();
375  }
376 
377 
383  protected function getFieldValuesForExport(ilMStListUser $my_staff_user)
384  {
385  global $DIC;
386 
387  $propGetter = Closure::bind(function ($prop) {
388  return $this->$prop;
389  }, $my_staff_user, $my_staff_user);
390 
391  $field_values = array();
392 
393  foreach ($this->getSelectedColumns() as $k => $v) {
394  switch ($k) {
395  case 'org_units':
396  $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($my_staff_user->getUsrId());
397  break;
398  case 'gender':
399  $field_values[$k] = $DIC->language()->txt('gender_' . $my_staff_user->getGender());
400  break;
401  case 'interests_general':
402  $field_values[$k] = $my_staff_user->returnIlUserObj()->getGeneralInterestsAsText();
403  break;
404  case 'interests_help_offered':
405  $field_values[$k] = $my_staff_user->returnIlUserObj()->getOfferingHelpAsText();
406  break;
407  case 'interests_help_looking':
408  $field_values[$k] = $my_staff_user->returnIlUserObj()->getLookingForHelpAsText();
409  break;
410  default:
411  $field_values[$k] = strip_tags($propGetter($k));
412  break;
413  }
414  }
415 
416  return $field_values;
417  }
418 }
setExternalSorting($a_val)
Set external sorting.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setExportFormats(array $formats)
Set available export formats.
static _getInstance()
Get instance.
__construct(ilMStListUsersGUI $parent_obj, $parent_cmd=ilMStListUsersGUI::CMD_INDEX)
setEnableNumInfo($a_val)
Set enable num info.
setFilterCols($a_val)
Set filter columns.
setExternalSegmentation($a_val)
Set external segmentation.
addFilterItem($a_input_item, $a_optional=false)
Add filter item.
determineLimit()
Determine the limit.
getOrderDirection()
Get order direction.
setId($a_val)
Set id.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
fillRowExcel(ilExcel $a_excel, &$a_row, $my_staff_user)
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)
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?
determineOffsetAndOrder($a_omit_offset=false)
Determine offset and order.
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.
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.
$cols
Definition: xhr_table.php:11