ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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;
25use ILIAS\User\Profile\Data as ProfileData;
26
35{
40
41 public const TYPE_STANDARD = 1;
42 public const TYPE_GLOBAL_SEARCH = 2;
43
45
46 protected static array $all_selectable_cols = [];
47 protected bool $admin_mode;
48 protected int $type;
49 protected bool $user_limitations = true;
50
51 protected Profile $profile;
52 protected ilObjUser $user;
54 protected UIServices $ui;
55 protected HTTP $http;
56 protected Refinery $refinery;
57
58
59 public function __construct($a_parent_obj, $a_parent_cmd, $a_admin_mode = false, $a_type = self::TYPE_STANDARD)
60 {
61 global $DIC;
62
63 $this->profile = $DIC['user']->getProfile();
64 $this->user = $DIC['user']->getLoggedInUser();
65 $this->review = $DIC->rbac()->review();
66 $this->ui = $DIC->ui();
67 $this->http = $DIC->http();
68 $this->refinery = $DIC->refinery();
69
70 $this->admin_mode = (bool) $a_admin_mode;
71 $this->type = $a_type;
72
73 $this->setId("rep_search_" . $this->user->getId());
74 parent::__construct($a_parent_obj, $a_parent_cmd);
75
76
77 $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
78 $this->setTitle($this->lng->txt('search_results'));
79 $this->setEnableTitle(true);
80 $this->setShowRowsSelector(true);
81
82
83 if ($this->getType() == self::TYPE_STANDARD) {
84 $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "components/ILIAS/Search");
85 $this->addColumn("", "", "1", true);
86 $this->enable('select_all');
87 $this->setSelectAllCheckbox("user[]");
88 $this->setDefaultOrderField("login");
89 $this->setDefaultOrderDirection("asc");
90 } else {
91 $this->setRowTemplate("tpl.global_search_usr_result_row.html", "components/ILIAS/Search");
92 $this->addColumn('', '', "110px");
93 $this->setExternalSorting(true);
94 }
95
96 $all_cols = $this->getSelectableColumns();
97 foreach ($this->getSelectedColumns() as $col) {
98 $sort_field = '';
99 if ($this->getType() == self::TYPE_STANDARD) {
100 $sort_field = $col;
101 }
102 $this->addColumn($all_cols[$col]['txt'], $sort_field);
103 }
104
105 if (
106 $this->getType() != self::TYPE_STANDARD &&
107 ilBuddySystem::getInstance()->isEnabled()
108 ) {
109 $this->addColumn('', '');
110 }
111 }
112
113 public function getType(): int
114 {
115 return $this->type;
116 }
117
119 {
120 $this->lucene_result = $res;
121 }
122
124 {
126 }
127
128 public function setUserLimitations(bool $a_limitations): void
129 {
130 $this->user_limitations = $a_limitations;
131 }
132
133 public function getUserLimitations(): bool
134 {
136 }
137
141 public function getSelectableColumns(): array
142 {
143 if (!self::$all_selectable_cols) {
144 $columns = ilUserSearchOptions::getSelectableColumnInfo($this->review->isAssigned($this->user->getId(), SYSTEM_ROLE_ID));
145
146 if ($this->admin_mode) {
147 // #11293
148 $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
149 $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
150 }
151
152 self::$all_selectable_cols = $columns;
153 }
155 }
156
157 public function initMultiCommands(array $a_commands): bool
158 {
159 if (!count($a_commands)) {
160 $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
161 return true;
162 }
163 $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
164 return true;
165 }
166
167 protected function fillRow(array $a_set): void
168 {
169 $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
170
171 $link = '';
172 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
173 $link = ilUserUtil::getProfileLink((int) $a_set['usr_id']);
174 if ($link) {
175 $this->tpl->setVariable('IMG_LINKED_TO_PROFILE', $link);
176 $this->tpl->setVariable(
177 'USR_IMG_SRC_LINKED',
178 ilObjUser::_getPersonalPicturePath((int) $a_set['usr_id'], 'xsmall')
179 );
180 } else {
181 $this->tpl->setVariable(
182 'USR_IMG_SRC',
183 ilObjUser::_getPersonalPicturePath((int) $a_set['usr_id'], 'xsmall')
184 );
185 }
186 }
187
188
189 foreach ($this->getSelectedColumns() as $field) {
190 switch ($field) {
191 case 'gender':
192 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
193 $this->tpl->setCurrentBlock('custom_fields');
194 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
195 $this->tpl->parseCurrentBlock();
196 break;
197
198 case 'birthday':
199 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
200 $this->tpl->setCurrentBlock('custom_fields');
201 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
202 $this->tpl->parseCurrentBlock();
203 break;
204
205 case 'access_until':
206 $this->tpl->setCurrentBlock('custom_fields');
207 $this->tpl->setVariable('CUST_CLASS', ' ' . $a_set['access_class']);
208 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
209 $this->tpl->parseCurrentBlock();
210 break;
211
212 case 'last_login':
213 $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
214 $this->tpl->setCurrentBlock('custom_fields');
215 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
216 $this->tpl->parseCurrentBlock();
217 break;
218
219 case 'interests_general':
220 case 'interests_help_offered':
221 case 'interests_help_looking':
222 $this->tpl->setCurrentBlock('custom_fields');
223 $this->tpl->setVariable('VAL_CUST', implode(', ', (array) $a_set[$field]));
224 $this->tpl->parseCurrentBlock();
225 break;
226
227 case 'org_units':
228 $this->tpl->setCurrentBlock('custom_fields');
229 $this->tpl->setVariable(
230 'VAL_CUST',
231 ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
232 );
233 $this->tpl->parseCurrentBlock();
234 break;
235
236
237 case 'login':
238 if ($this->admin_mode) {
239 $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
240 $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
241 $this->ctrl->setParameterByClass("ilobjusergui", "search", "1");
242 $link = $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
243 $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
244 } elseif ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
245 $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
246 }
247 // fallthrough
248
249 // no break
250 default:
251 $this->tpl->setCurrentBlock('custom_fields');
252 $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ?: ''));
253 $this->tpl->parseCurrentBlock();
254 break;
255 }
256 }
257
258 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
259 if (ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $this->user->getId()) {
260 $this->tpl->setVariable('CONTACT_ACTIONS', ilBuddySystemLinkButton::getInstanceByUserId((int) $a_set['usr_id'])->getHtml());
261 } else {
262 $this->tpl->setVariable('CONTACT_ACTIONS', '');
263 }
264 }
265 }
266
267 public function parseUserIds(array $a_user_ids): bool
268 {
269 if (!$a_user_ids) {
270 $this->setData(array());
271 return true;
272 }
273
274 $additional_fields = $this->getSelectedColumns();
275
276 $parse_access = false;
277 if (isset($additional_fields['access_until'])) {
278 $parse_access = true;
279 unset($additional_fields['access_until']);
280 }
281
282 $udf_ids = $usr_data_fields = $odf_ids = array();
283 foreach ($additional_fields as $field) {
284 if ($field == 'org_units') {
285 continue;
286 }
287 if (substr($field, 0, 3) == 'udf') {
288 $udf_ids[] = substr($field, 4);
289 continue;
290 }
291 $usr_data_fields[] = $field;
292 }
293
294 $u_query = new ilUserQuery();
295 $u_query->setOrderField('login');
296 $u_query->setOrderDirection('ASC');
297 $u_query->setLimit(999999);
298
299 if (!ilSearchSettings::getInstance()->isInactiveUserVisible() && $this->getUserLimitations()) {
300 $u_query->setActionFilter("active");
301 }
302
303 if (!ilSearchSettings::getInstance()->isLimitedUserVisible() && $this->getUserLimitations()) {
304 $u_query->setAccessFilter(true);
305 }
306
307 $u_query->setAdditionalFields($usr_data_fields);
308 $u_query->setUserFilter($a_user_ids);
309
310 $usr_data = $u_query->query();
311
312
313 if ($this->admin_mode && $parse_access) {
314 // see ilUserTableGUI
315 $current_time = time();
316 foreach ($usr_data['set'] as $k => $user) {
317 if ($user['active']) {
318 if ($user["time_limit_unlimited"]) {
319 $txt_access = $this->lng->txt("access_unlimited");
320 $usr_data["set"][$k]["access_class"] = "smallgreen";
321 } elseif ($user["time_limit_until"] < $current_time) {
322 $txt_access = $this->lng->txt("access_expired");
323 $usr_data["set"][$k]["access_class"] = "smallred";
324 } else {
325 $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"], IL_CAL_UNIX));
326 $usr_data["set"][$k]["access_class"] = "small";
327 }
328 } else {
329 $txt_access = $this->lng->txt("inactive");
330 $usr_data["set"][$k]["access_class"] = "smallred";
331 }
332 $usr_data["set"][$k]["access_until"] = $txt_access;
333 }
334 }
335
336 // Custom user data fields
337 if ($udf_ids) {
338 $users = array();
339 $counter = 0;
340 foreach ($usr_data['set'] as $set) {
341 $users[$counter] = $set;
342 if ((int) ($set['usr_id'] ?? 0) === 0) {
343 continue;
344 }
345 $data = $this->profile->getDataFor((int) $set['usr_id']);
346 foreach ($udf_ids as $udf_field) {
347 $users[$counter]['udf_' . $udf_field] = $data->getAdditionalFieldByIdentifier($udf_field);
348 }
349 ++$counter;
350 }
351 } else {
352 $users = $usr_data['set'];
353 }
354
355 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
356 if ($this->getLuceneResult() instanceof ilLuceneSearchResult) {
357 foreach ($users as $counter => $ud) {
358 $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance((int) ($ud['usr_id']) ?? 0);
359 }
360 }
361 }
362 if ($this->getType() === self::TYPE_GLOBAL_SEARCH) {
363 $users = $this->applySortation($users);
364 }
365 $this->setData($users);
366 return true;
367 }
368
369 public function getHTML(): string
370 {
371 $html = parent::getHTML();
372 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
373 $html = $this->ui->renderer()->render($this->buildSortationViewControl()) . $html;
374 }
375 return $html;
376 }
377
378 protected function applySortation(array $set): array
379 {
380 $sort = $this->getCurrentSortation();
381
382 if ($sort === 'relevance') {
383 usort($set, function ($a, $b) {
384 return $b['relevance'] <=> $a['relevance'];
385 });
386 return $set;
387 }
388
389 if (str_ends_with($sort, '_asc')) {
390 $col = substr($sort, 0, -4);
391 usort($set, function ($a, $b) use ($col) {
392 return [$a[$col], $b['relevance'] ?? ''] <=> [$b[$col], $a['relevance'] ?? ''];
393 });
394 } elseif (str_ends_with($sort, '_desc')) {
395 $col = substr($sort, 0, -5);
396 usort($set, function ($a, $b) use ($col) {
397 return [$b[$col], $b['relevance'] ?? ''] <=> [$a[$col], $a['relevance'] ?? ''];
398 });
399 }
400
401 return $set;
402 }
403
404 protected function getPossibleSortations(): array
405 {
406 $sorts = ['relevance' => $this->lng->txt('search_sort_relevance')];
407 $all_cols = $this->getSelectableColumns();
408 foreach ($this->getSelectedColumns() as $col) {
409 $sorts[$col . '_asc'] = sprintf(
410 $this->lng->txt('search_sort_generic_asc'),
411 $all_cols[$col]['txt']
412 );
413 $sorts[$col . '_desc'] = sprintf(
414 $this->lng->txt('search_sort_generic_desc'),
415 $all_cols[$col]['txt']
416 );
417 }
418 return $sorts;
419 }
420
421 protected function getDefaultSortation(): string
422 {
423 $lucene_enabled = ($this->getType() == self::TYPE_GLOBAL_SEARCH) &&
424 ($this->getLuceneResult() instanceof ilLuceneSearchResult);
425 return $lucene_enabled ? 'relevance' : 'login_asc';
426 }
427}
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 $a_usr_id, string $a_size='small', bool $a_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