ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilRepositoryUserResultTableGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Table/classes/class.ilTable2GUI.php");
5 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
6 
16 {
17  const TYPE_STANDARD = 1;
18  const TYPE_GLOBAL_SEARCH = 2;
19 
20  protected $lucene_result = null;
21 
22 
23  protected static $all_selectable_cols = null;
24  protected $admin_mode;
25  protected $type;
26  protected $user_limitations = true;
27 
31  public function __construct($a_parent_obj, $a_parent_cmd, $a_admin_mode = false, $a_type = self::TYPE_STANDARD)
32  {
33  global $ilCtrl, $lng, $ilAccess, $lng, $ilUser;
34 
35  $this->admin_mode = (bool) $a_admin_mode;
36  $this->type = $a_type;
37 
38  $this->setId("rep_search_" . $ilUser->getId());
39  parent::__construct($a_parent_obj, $a_parent_cmd);
40 
41 
42  $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
43  $this->setTitle($this->lng->txt('search_results'));
44  $this->setEnableTitle(true);
45  $this->setShowRowsSelector(true);
46 
47 
48  if ($this->getType() == self::TYPE_STANDARD) {
49  $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "Services/Search");
50  $this->addColumn("", "", "1", true);
51  $this->enable('select_all');
52  $this->setSelectAllCheckbox("user[]");
53  $this->setDefaultOrderField("login");
54  $this->setDefaultOrderDirection("asc");
55  } else {
56  $this->setRowTemplate("tpl.global_search_usr_result_row.html", "Services/Search");
57  $this->addColumn('', '', "110px");
58  }
59 
60  $all_cols = $this->getSelectableColumns();
61  foreach ($this->getSelectedColumns() as $col) {
62  $this->addColumn($all_cols[$col]['txt'], $col);
63  }
64 
65  if ($this->getType() == self::TYPE_STANDARD) {
66  } else {
67  $this->addColumn($this->lng->txt('lucene_relevance_short'), 'relevance');
68  if (ilBuddySystem::getInstance()->isEnabled()) {
69  $this->addColumn('', '');
70  }
71  $this->setDefaultOrderField("relevance");
72  $this->setDefaultOrderDirection("desc");
73  }
74  }
75 
81  public function numericOrdering($a_field)
82  {
83  if ($a_field == 'relevance') {
84  return true;
85  }
86  return parent::numericOrdering($a_field);
87  }
88 
93  public function getType()
94  {
95  return $this->type;
96  }
97 
104  {
105  $this->lucene_result = $res;
106  }
107 
112  public function getLuceneResult()
113  {
114  return $this->lucene_result;
115  }
116 
122  public function setUserLimitations($a_limitations)
123  {
124  $this->user_limitations = (bool) $a_limitations;
125  }
126 
131  public function getUserLimitations()
132  {
134  }
135 
143  public function getSelectableColumns()
144  {
145  global $rbacreview, $ilUser;
146 
147  if (!self::$all_selectable_cols) {
148  include_once './Services/Search/classes/class.ilUserSearchOptions.php';
149  $columns = ilUserSearchOptions::getSelectableColumnInfo($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID));
150 
151  if ($this->admin_mode) {
152  // #11293
153  $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
154  $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
155  }
156 
157  self::$all_selectable_cols = $columns;
158  }
159  return self::$all_selectable_cols;
160  }
161 
166  public function initMultiCommands($a_commands)
167  {
168  if (!count($a_commands)) {
169  $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
170  return true;
171  }
172  $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
173  return true;
174  }
175 
179  protected function fillRow($a_set)
180  {
184  global $ilCtrl, $ilUser;
185 
186  $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
187 
188  $link = '';
189  if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
190  include_once './Services/User/classes/class.ilUserUtil.php';
191  $link = ilUserUtil::getProfileLink($a_set['usr_id']);
192  if ($link) {
193  $this->tpl->setVariable('IMG_LINKED_TO_PROFILE', $link);
194  $this->tpl->setVariable(
195  'USR_IMG_SRC_LINKED',
196  ilObjUser::_getPersonalPicturePath($a_set['usr_id'], 'xsmall')
197  );
198  } else {
199  $this->tpl->setVariable(
200  'USR_IMG_SRC',
201  ilObjUser::_getPersonalPicturePath($a_set['usr_id'], 'xsmall')
202  );
203  }
204  }
205 
206 
207  foreach ($this->getSelectedColumns() as $field) {
208  switch ($field) {
209  case 'gender':
210  $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
211  $this->tpl->setCurrentBlock('custom_fields');
212  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
213  $this->tpl->parseCurrentBlock();
214  break;
215 
216  case 'birthday':
217  $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
218  $this->tpl->setCurrentBlock('custom_fields');
219  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
220  $this->tpl->parseCurrentBlock();
221  break;
222 
223  case 'access_until':
224  $this->tpl->setCurrentBlock('custom_fields');
225  $this->tpl->setVariable('CUST_CLASS', ' ' . $a_set['access_class']);
226  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
227  $this->tpl->parseCurrentBlock();
228  break;
229 
230  case 'last_login':
231  $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
232  $this->tpl->setCurrentBlock('custom_fields');
233  $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
234  $this->tpl->parseCurrentBlock();
235  break;
236 
237  case 'interests_general':
238  case 'interests_help_offered':
239  case 'interests_help_looking':
240  $this->tpl->setCurrentBlock('custom_fields');
241  $this->tpl->setVariable('VAL_CUST', implode(', ', (array) $a_set[$field]));
242  $this->tpl->parseCurrentBlock();
243  break;
244 
245  case 'org_units':
246  $this->tpl->setCurrentBlock('custom_fields');
247  include_once './Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php';
248  $this->tpl->setVariable('VAL_CUST', (string) ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_set['usr_id']));
249  $this->tpl->parseCurrentBlock();
250  break;
251 
252 
253  case 'login':
254  if ($this->admin_mode) {
255  $ilCtrl->setParameterByClass("ilobjusergui", "ref_id", "7");
256  $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
257  $ilCtrl->setParameterByClass("ilobjusergui", "search", "1");
258  $link = $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
259  $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
260  } elseif ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
261  $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
262  }
263  // fallthrough
264 
265  // no break
266  default:
267  $this->tpl->setCurrentBlock('custom_fields');
268  $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ? $a_set[$field] : ''));
269  $this->tpl->parseCurrentBlock();
270  break;
271  }
272  }
273 
274  if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
275  $this->tpl->setVariable('SEARCH_RELEVANCE', $this->getRelevanceHTML($a_set['relevance']));
276  if (ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $ilUser->getId()) {
277  require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemLinkButton.php';
278  $this->tpl->setVariable('CONTACT_ACTIONS', ilBuddySystemLinkButton::getInstanceByUserId($a_set['usr_id'])->getHtml());
279  } else {
280  $this->tpl->setVariable('CONTACT_ACTIONS', '');
281  }
282  }
283  }
284 
290  public function parseUserIds($a_user_ids)
291  {
292  if (!$a_user_ids) {
293  $this->setData(array());
294  return true;
295  }
296 
297  $additional_fields = $this->getSelectedColumns();
298 
299  $parse_access = false;
300  if (isset($additional_fields['access_until'])) {
301  $parse_access = true;
302  unset($additional_fields['access_until']);
303  }
304 
305  $udf_ids = $usr_data_fields = $odf_ids = array();
306  foreach ($additional_fields as $field) {
307  if ($field == 'org_units') {
308  continue;
309  }
310  if (substr($field, 0, 3) == 'udf') {
311  $udf_ids[] = substr($field, 4);
312  continue;
313  }
314  $usr_data_fields[] = $field;
315  }
316  include_once './Services/User/classes/class.ilUserQuery.php';
317 
318  $u_query = new ilUserQuery();
319  $u_query->setOrderField('login');
320  $u_query->setOrderDirection('ASC');
321  $u_query->setLimit(999999);
322  include_once './Services/Search/classes/class.ilSearchSettings.php';
323 
324  if (!ilSearchSettings::getInstance()->isInactiveUserVisible() && $this->getUserLimitations()) {
325  $u_query->setActionFilter("active");
326  }
327 
328  if (!ilSearchSettings::getInstance()->isLimitedUserVisible() && $this->getUserLimitations()) {
329  $u_query->setAccessFilter(true);
330  }
331 
332  $u_query->setAdditionalFields($usr_data_fields);
333  $u_query->setUserFilter($a_user_ids);
334 
335  $usr_data = $u_query->query();
336 
337 
338  if ($this->admin_mode && $parse_access) {
339  // see ilUserTableGUI
340  $current_time = time();
341  foreach ($usr_data['set'] as $k => $user) {
342  if ($user['active']) {
343  if ($user["time_limit_unlimited"]) {
344  $txt_access = $this->lng->txt("access_unlimited");
345  $usr_data["set"][$k]["access_class"] = "smallgreen";
346  } elseif ($user["time_limit_until"] < $current_time) {
347  $txt_access = $this->lng->txt("access_expired");
348  $usr_data["set"][$k]["access_class"] = "smallred";
349  } else {
350  $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"], IL_CAL_UNIX));
351  $usr_data["set"][$k]["access_class"] = "small";
352  }
353  } else {
354  $txt_access = $this->lng->txt("inactive");
355  $usr_data["set"][$k]["access_class"] = "smallred";
356  }
357  $usr_data["set"][$k]["access_until"] = $txt_access;
358  }
359  }
360 
361  // Custom user data fields
362  if ($udf_ids) {
363  include_once './Services/User/classes/class.ilUserDefinedData.php';
364  $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids);
365 
366  $users = array();
367  $counter = 0;
368  foreach ($usr_data['set'] as $set) {
369  $users[$counter] = $set;
370  foreach ($udf_ids as $udf_field) {
371  $users[$counter]['udf_' . $udf_field] = $data[$set['usr_id']][$udf_field];
372  }
373  ++$counter;
374  }
375  } else {
376  $users = $usr_data['set'];
377  }
378 
379  if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
380  if ($this->getLuceneResult() instanceof ilLuceneSearchResult) {
381  foreach ($users as $counter => $ud) {
382  $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance($ud['usr_id']);
383  }
384  }
385  }
386 
387 
388 
389  $this->setData($users);
390  }
391 
392 
396  public function getRelevanceHTML($a_rel)
397  {
398  $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
399 
400  include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
401  $pbar = ilProgressBar::getInstance();
402  $pbar->setCurrent($a_rel);
403 
404  $tpl->setCurrentBlock('relevance');
405  $tpl->setVariable('REL_PBAR', $pbar->render());
406  $tpl->parseCurrentBlock();
407 
408  return $tpl->get();
409  }
410 }
numericOrdering($a_field)
enable numeric ordering for relevance
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
User query class.
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false)
Format a date public.
getUserLimitations()
allow user limitations like inactive and access limitations
const IL_CAL_UNIX
setId($a_val)
Set id.
global $ilCtrl
Definition: ilias.php:18
__construct($a_parent_obj, $a_parent_cmd, $a_admin_mode=false, $a_type=self::TYPE_STANDARD)
Constructor.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
static lookupData($a_user_ids, $a_field_ids)
Lookup data.
$counter
$a_type
Definition: workflow.php:92
Search result implementing iterator interface.
Class ilTable2GUI.
static getInstance()
Factory.
Class for single dates.
foreach($_POST as $key=> $value) $res
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
special template class to simplify handling of ITX/PEAR
addMultiCommand($a_cmd, $a_text)
Add Command button.
enable($a_module_name)
enables particular modules of table
Date and time handling
$ilUser
Definition: imgupload.php:18
getSelectedColumns()
Get selected columns.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection='')
Add Selection List + Command button for selected items.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
const IL_CAL_DATE
setLuceneResult(ilLuceneSearchResult $res)
Set lucene result For parsing relevances.
setUserLimitations($a_limitations)
allow user limitations like inactive and access limitations
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.
initMultiCommands($a_commands)
Init multi commands.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
fillRow($a_set)
Standard Version of Fill Row.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setEnableTitle($a_enabletitle)
Set Enable Title.
if(! $in) $columns
Definition: Utf8Test.php:45
static getProfileLink($a_usr_id)
Get link to personal profile Return empty string in case of not public profile.