ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
class.ilRepositoryUserResultTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\HTTP\Services as HTTP;
23use ILIAS\Refinery\Factory as Refinery;
25
34{
39
40 public const TYPE_STANDARD = 1;
41 public const TYPE_GLOBAL_SEARCH = 2;
42
44
45 protected static array $all_selectable_cols = [];
46 protected bool $admin_mode;
47 protected int $type;
48 protected bool $user_limitations = true;
49
50 protected Profile $profile;
51 protected ilObjUser $user;
53 protected UIServices $ui;
54 protected HTTP $http;
55 protected Refinery $refinery;
56
57
58 public function __construct($a_parent_obj, $a_parent_cmd, $a_admin_mode = false, $a_type = self::TYPE_STANDARD)
59 {
60 global $DIC;
61
62 $this->profile = $DIC['user']->getProfile();
63 $this->user = $DIC['user']->getLoggedInUser();
64 $this->review = $DIC->rbac()->review();
65 $this->ui = $DIC->ui();
66 $this->http = $DIC->http();
67 $this->refinery = $DIC->refinery();
68
69 $this->admin_mode = (bool) $a_admin_mode;
70 $this->type = $a_type;
71
72 $this->setId("rep_search_" . $this->user->getId());
73 parent::__construct($a_parent_obj, $a_parent_cmd);
74
75
76 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
77 $this->setTitle($this->lng->txt('search_results'));
78 $this->setEnableTitle(true);
79 $this->setShowRowsSelector(true);
80
81
82 if ($this->getType() == self::TYPE_STANDARD) {
83 $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "components/ILIAS/Search");
84 $this->addColumn("", "", "1", true);
85 $this->enable('select_all');
86 $this->setSelectAllCheckbox("user[]");
87 $this->setDefaultOrderField("login");
88 $this->setDefaultOrderDirection("asc");
89 } else {
90 $this->setRowTemplate("tpl.global_search_usr_result_row.html", "components/ILIAS/Search");
91 $this->addColumn('', '', "110px");
92 $this->setExternalSorting(true);
93 }
94
95 $all_cols = $this->getSelectableColumns();
96 foreach ($this->getSelectedColumns() as $col) {
97 $sort_field = '';
98 if ($this->getType() == self::TYPE_STANDARD) {
99 $sort_field = $col;
100 }
101 $this->addColumn($all_cols[$col]['txt'], $sort_field);
102 }
103
104 if (
105 $this->getType() != self::TYPE_STANDARD &&
106 ilBuddySystem::getInstance()->isEnabled()
107 ) {
108 $this->addColumn('', '');
109 }
110 }
111
112 public function getType(): int
113 {
114 return $this->type;
115 }
116
118 {
119 $this->lucene_result = $res;
120 }
121
123 {
125 }
126
127 public function setUserLimitations(bool $a_limitations): void
128 {
129 $this->user_limitations = $a_limitations;
130 }
131
132 public function getUserLimitations(): bool
133 {
135 }
136
140 public function getSelectableColumns(): array
141 {
142 if (!self::$all_selectable_cols) {
143 $columns = ilUserSearchOptions::getSelectableColumnInfo($this->review->isAssigned($this->user->getId(), SYSTEM_ROLE_ID));
144
145 if ($this->admin_mode) {
146 // #11293
147 $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
148 $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
149 }
150
151 self::$all_selectable_cols = $columns;
152 }
154 }
155
156 public function initMultiCommands(array $a_commands): bool
157 {
158 if (!count($a_commands)) {
159 $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
160 return true;
161 }
162 $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
163 return true;
164 }
165
166 protected function fillRow(array $a_set): void
167 {
168 $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
169
170 $link = '';
171 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
172 $link = ilUserUtil::getProfileLink((int) $a_set['usr_id']);
173 if ($link) {
174 $this->tpl->setVariable('IMG_LINKED_TO_PROFILE', $link);
175 $this->tpl->setVariable(
176 'USR_IMG_SRC_LINKED',
177 ilObjUser::_getPersonalPicturePath((int) $a_set['usr_id'], 'xsmall')
178 );
179 } else {
180 $this->tpl->setVariable(
181 'USR_IMG_SRC',
182 ilObjUser::_getPersonalPicturePath((int) $a_set['usr_id'], 'xsmall')
183 );
184 }
185 }
186
187
188 foreach ($this->getSelectedColumns() as $field) {
189 switch ($field) {
190 case 'gender':
191 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
192 $this->tpl->setCurrentBlock('custom_fields');
193 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
194 $this->tpl->parseCurrentBlock();
195 break;
196
197 case 'birthday':
198 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
199 $this->tpl->setCurrentBlock('custom_fields');
200 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
201 $this->tpl->parseCurrentBlock();
202 break;
203
204 case 'access_until':
205 $this->tpl->setCurrentBlock('custom_fields');
206 $this->tpl->setVariable('CUST_CLASS', ' ' . $a_set['access_class']);
207 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
208 $this->tpl->parseCurrentBlock();
209 break;
210
211 case 'last_login':
212 $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
213 $this->tpl->setCurrentBlock('custom_fields');
214 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
215 $this->tpl->parseCurrentBlock();
216 break;
217
218 case 'org_units':
219 $this->tpl->setCurrentBlock('custom_fields');
220 $this->tpl->setVariable(
221 'VAL_CUST',
222 ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
223 );
224 $this->tpl->parseCurrentBlock();
225 break;
226
227
228 case 'login':
229 if ($this->admin_mode) {
230 $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
231 $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
232 $this->ctrl->setParameterByClass("ilobjusergui", "search", "1");
233 $link = $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
234 $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
235 } elseif ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
236 $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
237 }
238 // fallthrough
239
240 // no break
241 default:
242 $value = $a_set[$field] ?? '';
243 if (is_array($value)) {
244 $value = implode(', ', $value);
245 }
246 $this->tpl->setCurrentBlock('custom_fields');
247 $this->tpl->setVariable('VAL_CUST', $value);
248 $this->tpl->parseCurrentBlock();
249 break;
250 }
251 }
252
253 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
254 if (ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $this->user->getId()) {
255 $this->tpl->setVariable('CONTACT_ACTIONS', ilBuddySystemLinkButton::getInstanceByUserId((int) $a_set['usr_id'])->getHtml());
256 } else {
257 $this->tpl->setVariable('CONTACT_ACTIONS', '');
258 }
259 }
260 }
261
262 public function parseUserIds(array $a_user_ids): bool
263 {
264 if (!$a_user_ids) {
265 $this->setData(array());
266 return true;
267 }
268
269 $additional_fields = $this->getSelectedColumns();
270
271 $parse_access = false;
272 if (isset($additional_fields['access_until'])) {
273 $parse_access = true;
274 unset($additional_fields['access_until']);
275 }
276
277 $udf_ids = $usr_data_fields = $odf_ids = array();
278 foreach ($additional_fields as $field) {
279 if ($field == 'org_units') {
280 continue;
281 }
282 if (substr($field, 0, 3) == 'udf') {
283 $udf_ids[] = substr($field, 4);
284 continue;
285 }
286 $usr_data_fields[] = $field;
287 }
288
289 $u_query = new ilUserQuery();
290 $u_query->setOrderField('login');
291 $u_query->setOrderDirection('ASC');
292 $u_query->setLimit(999999);
293
294 if (!ilSearchSettings::getInstance()->isInactiveUserVisible() && $this->getUserLimitations()) {
295 $u_query->setActionFilter("active");
296 }
297
298 if (!ilSearchSettings::getInstance()->isLimitedUserVisible() && $this->getUserLimitations()) {
299 $u_query->setAccessFilter(true);
300 }
301
302 $u_query->setAdditionalFields($usr_data_fields);
303 $u_query->setUserFilter($a_user_ids);
304
305 $usr_data = $u_query->query();
306
307
308 if ($this->admin_mode && $parse_access) {
309 // see ilUserTableGUI
310 $current_time = time();
311 foreach ($usr_data['set'] as $k => $user) {
312 if ($user['active']) {
313 if ($user["time_limit_unlimited"]) {
314 $txt_access = $this->lng->txt("access_unlimited");
315 $usr_data["set"][$k]["access_class"] = "smallgreen";
316 } elseif ($user["time_limit_until"] < $current_time) {
317 $txt_access = $this->lng->txt("access_expired");
318 $usr_data["set"][$k]["access_class"] = "smallred";
319 } else {
320 $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"], IL_CAL_UNIX));
321 $usr_data["set"][$k]["access_class"] = "small";
322 }
323 } else {
324 $txt_access = $this->lng->txt("inactive");
325 $usr_data["set"][$k]["access_class"] = "smallred";
326 }
327 $usr_data["set"][$k]["access_until"] = $txt_access;
328 }
329 }
330
331 // Custom user data fields
332 if ($udf_ids) {
333 $users = array();
334 $counter = 0;
335 foreach ($usr_data['set'] as $set) {
336 $users[$counter] = $set;
337 if ((int) ($set['usr_id'] ?? 0) === 0) {
338 continue;
339 }
340 $data = $this->profile->getDataFor((int) $set['usr_id']);
341 foreach ($udf_ids as $udf_field) {
342 $users[$counter]['udf_' . $udf_field] = implode(', ', $data->getAdditionalFieldByIdentifier($udf_field) ?? []);
343 }
344 ++$counter;
345 }
346 } else {
347 $users = $usr_data['set'];
348 }
349
350 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
351 if ($this->getLuceneResult() instanceof ilLuceneSearchResult) {
352 foreach ($users as $counter => $ud) {
353 $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance((int) ($ud['usr_id']) ?? 0);
354 }
355 }
356 }
357 if ($this->getType() === self::TYPE_GLOBAL_SEARCH) {
358 $users = $this->applySortation($users);
359 }
360 $this->setData($users);
361 return true;
362 }
363
364 public function getHTML(): string
365 {
366 $html = parent::getHTML();
367 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
368 $html = $this->ui->renderer()->render($this->buildSortationViewControl()) . $html;
369 }
370 return $html;
371 }
372
373 protected function applySortation(array $set): array
374 {
375 $sort = $this->getCurrentSortation();
376
377 if ($sort === 'relevance') {
378 usort($set, function ($a, $b) {
379 return $b['relevance'] <=> $a['relevance'];
380 });
381 return $set;
382 }
383
384 if (str_ends_with($sort, '_asc')) {
385 $col = substr($sort, 0, -4);
386 usort($set, function ($a, $b) use ($col) {
387 return [$a[$col], $b['relevance'] ?? ''] <=> [$b[$col], $a['relevance'] ?? ''];
388 });
389 } elseif (str_ends_with($sort, '_desc')) {
390 $col = substr($sort, 0, -5);
391 usort($set, function ($a, $b) use ($col) {
392 return [$b[$col], $b['relevance'] ?? ''] <=> [$a[$col], $a['relevance'] ?? ''];
393 });
394 }
395
396 return $set;
397 }
398
399 protected function getPossibleSortations(): array
400 {
401 $sorts = ['relevance' => $this->lng->txt('search_sort_relevance')];
402 $all_cols = $this->getSelectableColumns();
403 foreach ($this->getSelectedColumns() as $col) {
404 $sorts[$col . '_asc'] = sprintf(
405 $this->lng->txt('search_sort_generic_asc'),
406 $all_cols[$col]['txt']
407 );
408 $sorts[$col . '_desc'] = sprintf(
409 $this->lng->txt('search_sort_generic_desc'),
410 $all_cols[$col]['txt']
411 );
412 }
413 return $sorts;
414 }
415
416 protected function getDefaultSortation(): string
417 {
418 $lucene_enabled = ($this->getType() == self::TYPE_GLOBAL_SEARCH) &&
419 ($this->getLuceneResult() instanceof ilLuceneSearchResult);
420 return $lucene_enabled ? 'relevance' : 'login_asc';
421 }
422}
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
@classDescription Date and time handling
Class for single dates.
Search result implementing iterator interface.
User class.
static _getPersonalPicturePath(int $usr_id, string $size='small', bool $force_pic=false)
class ilRbacReview Contains Review functions of core Rbac.
fillRow(array $a_set)
Standard Version of Fill Row.
__construct($a_parent_obj, $a_parent_cmd, $a_admin_mode=false, $a_type=self::TYPE_STANDARD)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setShowRowsSelector(bool $a_value)
Toggle rows-per-page selector.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setExternalSorting(bool $a_val)
addMultiItemSelectionButton(string $a_sel_var, array $a_options, string $a_cmd, string $a_text, string $a_default_selection='')
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setId(string $a_val)
setDefaultOrderDirection(string $a_defaultorderdirection)
setData(array $a_data)
Set table data.
enable(string $a_module_name)
User query class.
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
static getProfileLink(int $a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
const SYSTEM_ROLE_ID
Definition: constants.php:29
$res
Definition: ltiservices.php:69
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
global $DIC
Definition: shib_login.php:26
$counter
trait ilSearchResultTableHelper