ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilRepositoryUserResultTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
30 {
31  public const TYPE_STANDARD = 1;
32  public const TYPE_GLOBAL_SEARCH = 2;
33 
35 
36  protected static array $all_selectable_cols = [];
37  protected bool $admin_mode;
38  protected int $type;
39  protected bool $user_limitations = true;
40 
41  protected ilObjUser $user;
42  protected ilRbacReview $review;
43 
44 
45  public function __construct($a_parent_obj, $a_parent_cmd, $a_admin_mode = false, $a_type = self::TYPE_STANDARD)
46  {
47  global $DIC;
48 
49  $this->user = $DIC->user();
50  $this->review = $DIC->rbac()->review();
51 
52  $this->admin_mode = (bool) $a_admin_mode;
53  $this->type = $a_type;
54 
55  $this->setId("rep_search_" . $this->user->getId());
56  parent::__construct($a_parent_obj, $a_parent_cmd);
57 
58 
59  $this->setFormAction($this->ctrl->getFormAction($this->parent_obj));
60  $this->setTitle($this->lng->txt('search_results'));
61  $this->setEnableTitle(true);
62  $this->setShowRowsSelector(true);
63 
64 
65  if ($this->getType() == self::TYPE_STANDARD) {
66  $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "Services/Search");
67  $this->addColumn("", "", "1", true);
68  $this->enable('select_all');
69  $this->setSelectAllCheckbox("user[]");
70  $this->setDefaultOrderField("login");
71  $this->setDefaultOrderDirection("asc");
72  } else {
73  $this->setRowTemplate("tpl.global_search_usr_result_row.html", "Services/Search");
74  $this->addColumn('', '', "110px");
75  }
76 
77  $all_cols = $this->getSelectableColumns();
78  foreach ($this->getSelectedColumns() as $col) {
79  $this->addColumn($all_cols[$col]['txt'], $col);
80  }
81 
82  if ($this->getType() == self::TYPE_STANDARD) {
83  } else {
84  $this->addColumn($this->lng->txt('lucene_relevance_short'), 'relevance');
85  if (ilBuddySystem::getInstance()->isEnabled()) {
86  $this->addColumn('', '');
87  }
88  $this->setDefaultOrderField("relevance");
89  $this->setDefaultOrderDirection("desc");
90  }
91  }
92 
98  public function numericOrdering(string $a_field): bool
99  {
100  if ($a_field == 'relevance') {
101  return true;
102  }
103  return parent::numericOrdering($a_field);
104  }
105 
106  public function getType(): int
107  {
108  return $this->type;
109  }
110 
112  {
113  $this->lucene_result = $res;
114  }
115 
117  {
118  return $this->lucene_result;
119  }
120 
121  public function setUserLimitations(bool $a_limitations): void
122  {
123  $this->user_limitations = $a_limitations;
124  }
125 
126  public function getUserLimitations(): bool
127  {
129  }
130 
134  public function getSelectableColumns(): array
135  {
136  if (!self::$all_selectable_cols) {
137  $columns = ilUserSearchOptions::getSelectableColumnInfo($this->review->isAssigned($this->user->getId(), SYSTEM_ROLE_ID));
138 
139  if ($this->admin_mode) {
140  // #11293
141  $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
142  $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
143  }
144 
145  self::$all_selectable_cols = $columns;
146  }
147  return self::$all_selectable_cols;
148  }
149 
150  public function initMultiCommands(array $a_commands): bool
151  {
152  if (!count($a_commands)) {
153  $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
154  return true;
155  }
156  $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
157  return true;
158  }
159 
160  protected function fillRow(array $a_set): void
161  {
162  $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
163 
164  $link = '';
165  if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
166  $link = ilUserUtil::getProfileLink((int) $a_set['usr_id']);
167  if ($link) {
168  $this->tpl->setVariable('IMG_LINKED_TO_PROFILE', $link);
169  $this->tpl->setVariable(
170  'USR_IMG_SRC_LINKED',
171  ilObjUser::_getPersonalPicturePath((int) $a_set['usr_id'], 'xsmall')
172  );
173  } else {
174  $this->tpl->setVariable(
175  'USR_IMG_SRC',
176  ilObjUser::_getPersonalPicturePath((int) $a_set['usr_id'], 'xsmall')
177  );
178  }
179  }
180 
181 
182  foreach ($this->getSelectedColumns() as $field) {
183  switch ($field) {
184  case 'gender':
185  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
186  $this->tpl->setCurrentBlock('custom_fields');
187  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
188  $this->tpl->parseCurrentBlock();
189  break;
190 
191  case 'birthday':
192  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
193  $this->tpl->setCurrentBlock('custom_fields');
194  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
195  $this->tpl->parseCurrentBlock();
196  break;
197 
198  case 'access_until':
199  $this->tpl->setCurrentBlock('custom_fields');
200  $this->tpl->setVariable('CUST_CLASS', ' ' . $a_set['access_class']);
201  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
202  $this->tpl->parseCurrentBlock();
203  break;
204 
205  case 'last_login':
206  $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
207  $this->tpl->setCurrentBlock('custom_fields');
208  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
209  $this->tpl->parseCurrentBlock();
210  break;
211 
212  case 'interests_general':
213  case 'interests_help_offered':
214  case 'interests_help_looking':
215  $this->tpl->setCurrentBlock('custom_fields');
216  $this->tpl->setVariable('VAL_CUST', implode(', ', (array) $a_set[$field]));
217  $this->tpl->parseCurrentBlock();
218  break;
219 
220  case 'org_units':
221  $this->tpl->setCurrentBlock('custom_fields');
222  $this->tpl->setVariable(
223  'VAL_CUST',
224  ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits((int) $a_set['usr_id'])
225  );
226  $this->tpl->parseCurrentBlock();
227  break;
228 
229 
230  case 'login':
231  if ($this->admin_mode) {
232  $this->ctrl->setParameterByClass("ilobjusergui", "ref_id", "7");
233  $this->ctrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
234  $this->ctrl->setParameterByClass("ilobjusergui", "search", "1");
235  $link = $this->ctrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
236  $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
237  } elseif ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
238  $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
239  }
240  // fallthrough
241 
242  // no break
243  default:
244  $this->tpl->setCurrentBlock('custom_fields');
245  $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ?: ''));
246  $this->tpl->parseCurrentBlock();
247  break;
248  }
249  }
250 
251  if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
252  $this->tpl->setVariable('SEARCH_RELEVANCE', $this->getRelevanceHTML($a_set['relevance']));
253  if (ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $this->user->getId()) {
254  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemLinkButton.php';
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  $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids);
334 
335  $users = array();
336  $counter = 0;
337  foreach ($usr_data['set'] as $set) {
338  $users[$counter] = $set;
339  foreach ($udf_ids as $udf_field) {
340  $users[$counter]['udf_' . $udf_field] = ($data[(int) ($set['usr_id'] ?? 0)][$udf_field] ?? '');
341  }
342  ++$counter;
343  }
344  } else {
345  $users = $usr_data['set'];
346  }
347 
348  if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
349  if ($this->getLuceneResult() instanceof ilLuceneSearchResult) {
350  foreach ($users as $counter => $ud) {
351  $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance((int) ($ud['usr_id']) ?? 0);
352  }
353  }
354  }
355  $this->setData($users);
356  return true;
357  }
358 
359 
360  public function getRelevanceHTML(float $a_rel): string
361  {
362  $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
363 
364  $pbar = ilProgressBar::getInstance();
365  $pbar->setCurrent($a_rel);
366 
367  $tpl->setCurrentBlock('relevance');
368  $tpl->setVariable('REL_PBAR', $pbar->render());
369  $tpl->parseCurrentBlock();
370 
371  return $tpl->get();
372  }
373 }
static lookupData(array $a_user_ids, array $a_field_ids)
Lookup data.
setData(array $a_data)
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
enable(string $a_module_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const IL_CAL_DATETIME
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
const SYSTEM_ROLE_ID
Definition: constants.php:29
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
numericOrdering(string $a_field)
enable numeric ordering for relevance
static getProfileLink(int $a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
const IL_CAL_UNIX
setId(string $a_val)
__construct($a_parent_obj, $a_parent_cmd, $a_admin_mode=false, $a_type=self::TYPE_STANDARD)
global $DIC
Definition: feed.php:28
addMultiItemSelectionButton(string $a_sel_var, array $a_options, string $a_cmd, string $a_text, string $a_default_selection='')
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.
setDefaultOrderField(string $a_defaultorderfield)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setDefaultOrderDirection(string $a_defaultorderdirection)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
const IL_CAL_DATE
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
__construct(Container $dic, ilPlugin $plugin)
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)
addMultiCommand(string $a_cmd, string $a_text)