ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMStListUsersTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
31{
32 protected array $filter = [];
33 protected array $cached_selectable_columns = [];
34 protected array $usr_orgu_names = [];
36
37 private \ILIAS\UI\Factory $uiFactory;
38 private \ILIAS\UI\Renderer $uiRenderer;
39 private \ilLanguage $language;
41
47 {
48 global $DIC;
49
51
52 $this->setPrefix('myst_lu');
53 $this->setFormName('myst_lu');
54 $this->setId('myst_lu');
55
56 parent::__construct($parent_obj, $parent_cmd, '');
57
58 $this->uiFactory = $DIC->ui()->factory();
59 $this->uiRenderer = $DIC->ui()->renderer();
60 $this->language = $DIC->language();
61 $this->profile = $DIC['user']->getProfile();
62
63 $this->setRowTemplate('tpl.list_users_row.html', "components/ILIAS/MyStaff");
64 $this->setFormAction($DIC->ctrl()->getFormAction($parent_obj));
65 $this->setDefaultOrderDirection('desc');
66
67 $this->setShowRowsSelector(true);
68
69 $this->setEnableTitle(true);
70 $this->setDisableFilterHiding(true);
71 $this->setEnableNumInfo(true);
72
73 $this->setExportFormats(array(self::EXPORT_EXCEL, self::EXPORT_CSV));
74
75 $this->setFilterCols(4);
76 $this->initFilter();
77 $this->addColumns();
78
79 $this->parseData();
80 }
81
82 protected function parseData(): void
83 {
84 global $DIC;
85
86 $this->setExternalSorting(true);
87 $this->setExternalSegmentation(true);
88 $this->setDefaultOrderField('lastname');
89
90 $this->determineLimit();
92
93 //Permission Filter
94 $arr_usr_id = $this->access->getUsersForUser($DIC->user()->getId());
95
96 $options = array(
97 'filters' => $this->filter,
98 'limit' => array(
99 'start' => $this->getOffset(),
100 'end' => $this->getLimit(),
101 ),
102 'sort' => array(
103 'field' => $this->getOrderField(),
104 'direction' => $this->getOrderDirection(),
105 ),
106 );
107
108 $list_users_fetcher = new ilMStListUsers($DIC);
109 $result = $list_users_fetcher->getData($arr_usr_id, $options);
110
111 $this->setMaxCount($result->getTotalDatasetCount());
112 $data = $result->getDataset();
113
114 // Workaround because the fillRow Method only accepts arrays
115 $data = array_map(function (ilMStListUser $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 // User name, login, email filter
126 $item = new \ilTextInputGUI(
127 $DIC->language()->txt("login") . "/" . $DIC->language()->txt("email") . "/" . $DIC->language()
128 ->txt("name"),
129 "user"
130 );
131 $this->addFilterItem($item);
132 $item->readFromSession();
133 $this->filter['user'] = $item->getValue();
134
135 if (\ilUserSearchOptions::_isEnabled('org_units')) {
137 $options[0] = $DIC->language()->txt('mst_opt_all');
138 foreach ($paths as $org_ref_id => $path) {
139 $options[$org_ref_id] = $path;
140 }
141 $item = new \ilSelectInputGUI($DIC->language()->txt('obj_orgu'), 'org_unit');
142 $item->setOptions($options);
143 $item->addCustomAttribute("style='width:100%'");
144 $this->addFilterItem($item);
145 $item->readFromSession();
146 $this->filter['org_unit'] = $item->getValue();
147 }
148 }
149
150 final public function getSelectableColumns(): array
151 {
152 if ($this->cached_selectable_columns) {
154 }
155
156 return $this->cached_selectable_columns = $this->initSelectableColumns();
157 }
158
159 protected function initSelectableColumns(): array
160 {
161 $arr_fields_without_table_sort = array(
162 'org_units',
163 'interests_general',
164 'interests_help_offered',
165 'interests_help_looking',
166 );
167 $cols = array();
168 foreach (\ilUserSearchOptions::getSelectableColumnInfo() as $key => $col) {
169 $cols[$key] = $col;
170 if (!in_array($key, $arr_fields_without_table_sort)) {
171 $cols[$key]['sort_field'] = $key;
172 }
173 }
174
175 foreach ($this->profile->getAllUserDefinedFields() as $field) {
176 unset($cols["udf_" . $field->getIdentifier()]);
177 }
178
179 return $cols;
180 }
181
182 private function addColumns(): void
183 {
184 global $DIC;
185
186 //User Profile Picture
187 if (!$this->getExportMode()) {
188 $this->addColumn('');
189 }
190
191 foreach ($this->getSelectableColumns() as $k => $v) {
192 if ($this->isColumnSelected($k)) {
193 $sort = $v['sort_field'] ?? "";
194 $this->addColumn($v['txt'], $sort);
195 }
196 }
197 //Actions
198 if (!$this->getExportMode()) {
199 $this->addColumn($DIC->language()->txt('actions'));
200 }
201 }
202
203 protected function getTextRepresentationOfUsersOrgUnits(int $user_id): string
204 {
205 if (isset($this->usr_orgu_names[$user_id])) {
206 return $this->usr_orgu_names[$user_id];
207 }
208
209 return $this->usr_orgu_names[$user_id] = \ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($user_id);
210 }
211
218 final protected function fillRow(array $a_set): void
219 {
220 $set = array_pop($a_set);
221
222 $propGetter = \Closure::bind(function ($prop) {
223 return $this->$prop ?? null;
224 }, $set, $set);
225
226 //Avatar
227 $this->tpl->setCurrentBlock('user_profile_picture');
228 $il_obj_user = $set->returnIlUserObj();
229 $avatar = $this->uiFactory->image()->standard($il_obj_user->getPersonalPicturePath('small'), $il_obj_user->getPublicName());
230 $this->tpl->setVariable('user_profile_picture', $this->uiRenderer->render($avatar));
231 $this->tpl->parseCurrentBlock();
232
233 foreach ($this->getSelectedColumns() as $k => $v) {
234 switch ($k) {
235 case 'org_units':
236 $this->tpl->setCurrentBlock('td');
237 $this->tpl->setVariable(
238 'VALUE',
239 $this->getTextRepresentationOfUsersOrgUnits($set->getUsrId())
240 );
241 $this->tpl->parseCurrentBlock();
242 break;
243 case 'gender':
244 $this->tpl->setCurrentBlock('td');
245 $this->tpl->setVariable('VALUE', $this->language->txt('gender_' . $set->getGender()));
246 $this->tpl->parseCurrentBlock();
247 break;
248 case 'interests_general':
249 $this->tpl->setCurrentBlock('td');
250 $this->tpl->setVariable('VALUE', ($set->returnIlUserObj()
251 ->getGeneralInterestsAsText() ? $set->returnIlUserObj()->getGeneralInterestsAsText() : '&nbsp;'));
252 $this->tpl->parseCurrentBlock();
253 break;
254 case 'interests_help_offered':
255 $this->tpl->setCurrentBlock('td');
256 $this->tpl->setVariable('VALUE', ($set->returnIlUserObj()
257 ->getOfferingHelpAsText() ? $set->returnIlUserObj()->getOfferingHelpAsText() : '&nbsp;'));
258 $this->tpl->parseCurrentBlock();
259 break;
260 case 'interests_help_looking':
261 $this->tpl->setCurrentBlock('td');
262 $this->tpl->setVariable('VALUE', ($set->returnIlUserObj()
263 ->getLookingForHelpAsText() ? $set->returnIlUserObj()->getLookingForHelpAsText() : '&nbsp;'));
264 $this->tpl->parseCurrentBlock();
265 break;
266 default:
267 if ($propGetter($k) !== null) {
268 $this->tpl->setCurrentBlock('td');
269 $this->tpl->setVariable(
270 'VALUE',
271 (is_array($propGetter($k)) ? implode(", ", $propGetter($k)) : $propGetter($k))
272 );
273 $this->tpl->parseCurrentBlock();
274 } else {
275 $this->tpl->setCurrentBlock('td');
276 $this->tpl->setVariable('VALUE', '&nbsp;');
277 $this->tpl->parseCurrentBlock();
278 }
279 break;
280 }
281 }
282
283 $mst_lus_usr_id = $set->getUsrId();
284
285 $actions = [];
286
287 if ($this->access->hasCurrentUserAccessToCourseMemberships()) {
288 $this->ctrl->setParameterByClass(\ilMStShowUserCoursesGUI::class, 'usr_id', $mst_lus_usr_id);
289 $actions[] = $this->uiFactory->link()->standard(
290 $this->language->txt("mst_show_courses"),
291 $this->ctrl->getLinkTargetByClass([
292 \ilDashboardGUI::class,
293 \ilMyStaffGUI::class,
294 \ilMStShowUserGUI::class,
295 \ilMStShowUserCoursesGUI::class,
296 ])
297 );
298 }
299
300 if ($this->access->hasCurrentUserAccessToCertificates()) {
301 $this->ctrl->setParameterByClass(\ilUserCertificateGUI::class, 'usr_id', $mst_lus_usr_id);
302 $actions[] = $this->uiFactory->link()->standard(
303 $this->language->txt("mst_list_certificates"),
304 $this->ctrl->getLinkTargetByClass([
305 \ilDashboardGUI::class,
306 \ilMyStaffGUI::class,
307 \ilMStShowUserGUI::class,
308 \ilUserCertificateGUI::class,
309 ])
310 );
311 }
312
313 if ($this->access->hasCurrentUserAccessToCompetences()) {
314 $this->ctrl->setParameterByClass(\ilMStShowUserCompetencesGUI::class, 'usr_id', $mst_lus_usr_id);
315 $actions[] = $this->uiFactory->link()->standard(
316 $this->language->txt("mst_list_competences"),
317 $this->ctrl->getLinkTargetByClass([
318 \ilDashboardGUI::class,
319 \ilMyStaffGUI::class,
320 \ilMStShowUserGUI::class,
321 \ilMStShowUserCompetencesGUI::class,
322 ])
323 );
324 }
325
326
327 $this->ctrl->setParameterByClass(\ilMStListUsersGUI::class, 'mst_lus_usr_id', $mst_lus_usr_id);
328
329 $actions[] = \ilMyStaffGUI::extendActionMenuWithUserActions(
330 $mst_lus_usr_id,
331 rawurlencode($this->ctrl->getLinkTargetByClass("ilMStListUsersGUI", \ilMStListUsersGUI::CMD_INDEX))
332 );
333
334 $dropdown = $this->uiFactory->dropdown()->standard($actions)->withLabel($this->lng->txt("actions"));
335 $this->tpl->setVariable("ACTIONS", $this->uiRenderer->render($dropdown));
336 $this->tpl->parseCurrentBlock();
337 }
338
339 private function getProfileBackUrl(): string
340 {
341 global $DIC;
342
343 return rawurlencode($DIC->ctrl()->getLinkTargetByClass(
344 strtolower(\ilMyStaffGUI::class),
346 ));
347 }
348
349 protected function fillRowExcel(\ilExcel $a_excel, int &$a_row, array $a_set): void
350 {
351 $set = array_pop($a_set);
352
353 $col = 0;
354 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
355 $a_excel->setCell($a_row, $col, $v);
356 $col++;
357 }
358 }
359
360 protected function fillRowCSV(\ilCSVWriter $a_csv, array $a_set): void
361 {
362 $set = array_pop($a_set);
363
364 foreach ($this->getFieldValuesForExport($set) as $k => $v) {
365 $a_csv->addColumn($v);
366 }
367 $a_csv->addRow();
368 }
369
370 protected function getFieldValuesForExport(ilMStListUser $my_staff_user): array
371 {
372 global $DIC;
373
374 $propGetter = \Closure::bind(function ($prop) {
375 return $this->$prop ?? null;
376 }, $my_staff_user, $my_staff_user);
377
378 $field_values = array();
379
380 foreach ($this->getSelectedColumns() as $k => $v) {
381 switch ($k) {
382 case 'org_units':
383 $field_values[$k] = $this->getTextRepresentationOfUsersOrgUnits($my_staff_user->getUsrId());
384 break;
385 case 'gender':
386 $field_values[$k] = $DIC->language()->txt('gender_' . $my_staff_user->getGender());
387 break;
388 case 'interests_general':
389 $field_values[$k] = $my_staff_user->returnIlUserObj()->getGeneralInterestsAsText();
390 break;
391 case 'interests_help_offered':
392 $field_values[$k] = $my_staff_user->returnIlUserObj()->getOfferingHelpAsText();
393 break;
394 case 'interests_help_looking':
395 $field_values[$k] = $my_staff_user->returnIlUserObj()->getLookingForHelpAsText();
396 break;
397 default:
398 $field_values[$k] = strip_tags($propGetter($k) ?? "");
399 break;
400 }
401 }
402
403 return $field_values;
404 }
405}
fillRowExcel(\ilExcel $a_excel, int &$a_row, array $a_set)
__construct(\ilMStListUsersGUI $parent_obj, $parent_cmd=\ilMStListUsersGUI::CMD_INDEX)
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.
Class ilMStListUsersGUI.
const string CMD_INDEX
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
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.
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
$path
Definition: ltiservices.php:30
__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