ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
4include_once("./Services/Table/classes/class.ilTable2GUI.php");
5require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystem.php';
6
16{
17 const TYPE_STANDARD = 1;
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 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 {
50 $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "Services/Search");
51 $this->addColumn("", "", "1", true);
52 $this->enable('select_all');
53 $this->setSelectAllCheckbox("user[]");
54 $this->setDefaultOrderField("login");
55 $this->setDefaultOrderDirection("asc");
56 }
57 else
58 {
59 $this->setRowTemplate("tpl.global_search_usr_result_row.html", "Services/Search");
60 $this->addColumn('', '', "110px");
61 }
62
63 $all_cols = $this->getSelectableColumns();
64 foreach($this->getSelectedColumns() as $col)
65 {
66 $this->addColumn($all_cols[$col]['txt'], $col);
67 }
68
69 if($this->getType() == self::TYPE_STANDARD)
70 {
71
72 }
73 else
74 {
75 $this->addColumn($this->lng->txt('lucene_relevance_short'),'relevance');
76 if(ilBuddySystem::getInstance()->isEnabled())
77 {
78 $this->addColumn('', '');
79 }
80 $this->setDefaultOrderField("relevance");
81 $this->setDefaultOrderDirection("desc");
82 }
83
84 }
85
91 public function numericOrdering($a_field)
92 {
93 if($a_field == 'relevance')
94 {
95 return true;
96 }
97 return parent::numericOrdering($a_field);
98 }
99
104 public function getType()
105 {
106 return $this->type;
107 }
108
115 {
116 $this->lucene_result = $res;
117 }
118
123 public function getLuceneResult()
124 {
126 }
127
133 public function setUserLimitations($a_limitations)
134 {
135 $this->user_limitations = (bool) $a_limitations;
136 }
137
142 public function getUserLimitations()
143 {
145 }
146
154 public function getSelectableColumns()
155 {
156 global $rbacreview, $ilUser;
157
158 if(!self::$all_selectable_cols)
159 {
160 include_once './Services/Search/classes/class.ilUserSearchOptions.php';
161 $columns = ilUserSearchOptions::getSelectableColumnInfo($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID));
162
163 if($this->admin_mode)
164 {
165 // #11293
166 $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
167 $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
168 }
169
170 self::$all_selectable_cols = $columns;
171 }
173 }
174
179 public function initMultiCommands($a_commands)
180 {
181 if(!count($a_commands))
182 {
183 $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
184 return true;
185 }
186 $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
187 return true;
188 }
189
193 protected function fillRow($a_set)
194 {
198 global $ilCtrl, $ilUser;
199
200 $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
201
202 $link = '';
203 if($this->getType() == self::TYPE_GLOBAL_SEARCH)
204 {
205 include_once './Services/User/classes/class.ilUserUtil.php';
206 $link = ilUserUtil::getProfileLink($a_set['usr_id']);
207 if($link)
208 {
209 $this->tpl->setVariable('IMG_LINKED_TO_PROFILE',$link);
210 $this->tpl->setVariable(
211 'USR_IMG_SRC_LINKED',
212 ilObjUser::_getPersonalPicturePath($a_set['usr_id'],'xsmall')
213 );
214 }
215 else
216 {
217 $this->tpl->setVariable(
218 'USR_IMG_SRC',
219 ilObjUser::_getPersonalPicturePath($a_set['usr_id'],'xsmall')
220 );
221 }
222 }
223
224
225 foreach($this->getSelectedColumns() as $field)
226 {
227 switch($field)
228 {
229 case 'gender':
230 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
231 $this->tpl->setCurrentBlock('custom_fields');
232 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
233 $this->tpl->parseCurrentBlock();
234 break;
235
236 case 'birthday':
237 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
238 $this->tpl->setCurrentBlock('custom_fields');
239 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
240 $this->tpl->parseCurrentBlock();
241 break;
242
243 case 'access_until':
244 $this->tpl->setCurrentBlock('custom_fields');
245 $this->tpl->setVariable('CUST_CLASS', ' '.$a_set['access_class']);
246 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
247 $this->tpl->parseCurrentBlock();
248 break;
249
250 case 'last_login':
251 $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
252 $this->tpl->setCurrentBlock('custom_fields');
253 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
254 $this->tpl->parseCurrentBlock();
255 break;
256
257 case 'interests_general':
258 case 'interests_help_offered':
259 case 'interests_help_looking':
260 $this->tpl->setCurrentBlock('custom_fields');
261 $this->tpl->setVariable('VAL_CUST', implode(', ', (array) $a_set[$field]));
262 $this->tpl->parseCurrentBlock();
263 break;
264
265 case 'org_units':
266 $this->tpl->setCurrentBlock('custom_fields');
267 include_once './Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php';
268 $this->tpl->setVariable('VAL_CUST', (string) ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_set['usr_id']));
269 $this->tpl->parseCurrentBlock();
270 break;
271
272
273 case 'login':
274 if($this->admin_mode)
275 {
276 $ilCtrl->setParameterByClass("ilobjusergui", "ref_id", "7");
277 $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
278 $ilCtrl->setParameterByClass("ilobjusergui", "search", "1");
279 $link = $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
280 $a_set[$field] = "<a href=\"".$link."\">".$a_set[$field]."</a>";
281 }
282 elseif($this->getType() == self::TYPE_GLOBAL_SEARCH)
283 {
284 $a_set[$field] = "<a href=\"".$link."\">".$a_set[$field]."</a>";
285 }
286 // fallthrough
287
288 default:
289 $this->tpl->setCurrentBlock('custom_fields');
290 $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ? $a_set[$field] : ''));
291 $this->tpl->parseCurrentBlock();
292 break;
293 }
294 }
295
296 if($this->getType() == self::TYPE_GLOBAL_SEARCH)
297 {
298 $this->tpl->setVariable('SEARCH_RELEVANCE',$this->getRelevanceHTML($a_set['relevance']));
299 if(ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $ilUser->getId())
300 {
301 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemLinkButton.php';
302 $this->tpl->setVariable('CONTACT_ACTIONS', ilBuddySystemLinkButton::getInstanceByUserId($a_set['usr_id'])->getHtml());
303 }
304 else
305 {
306 $this->tpl->setVariable('CONTACT_ACTIONS', '');
307 }
308 }
309
310 }
311
317 public function parseUserIds($a_user_ids)
318 {
319 if(!$a_user_ids)
320 {
321 $this->setData(array());
322 return true;
323 }
324
325 $additional_fields = $this->getSelectedColumns();
326
327 $parse_access = false;
328 if(isset($additional_fields['access_until']))
329 {
330 $parse_access = true;
331 unset($additional_fields['access_until']);
332 }
333
334 $udf_ids = $usr_data_fields = $odf_ids = array();
335 foreach($additional_fields as $field)
336 {
337 if($field == 'org_units')
338 {
339 continue;
340 }
341 if(substr($field, 0, 3) == 'udf')
342 {
343 $udf_ids[] = substr($field,4);
344 continue;
345 }
346 $usr_data_fields[] = $field;
347 }
348 include_once './Services/User/classes/class.ilUserQuery.php';
349
350 $u_query = new ilUserQuery();
351 $u_query->setOrderField('login');
352 $u_query->setOrderDirection('ASC');
353 $u_query->setLimit(999999);
354 include_once './Services/Search/classes/class.ilSearchSettings.php';
355
356 if(!ilSearchSettings::getInstance()->isInactiveUserVisible() && $this->getUserLimitations())
357 {
358 $u_query->setActionFilter("activ");
359 }
360
361 if(!ilSearchSettings::getInstance()->isLimitedUserVisible() && $this->getUserLimitations())
362 {
363 $u_query->setAccessFilter(true);
364 }
365
366 $u_query->setAdditionalFields($usr_data_fields);
367 $u_query->setUserFilter($a_user_ids);
368
369 $usr_data = $u_query->query();
370
371
372 if($this->admin_mode && $parse_access)
373 {
374 // see ilUserTableGUI
375 $current_time = time();
376 foreach($usr_data['set'] as $k => $user)
377 {
378 if ($user['active'])
379 {
380 if ($user["time_limit_unlimited"])
381 {
382 $txt_access = $this->lng->txt("access_unlimited");
383 $usr_data["set"][$k]["access_class"] = "smallgreen";
384 }
385 elseif ($user["time_limit_until"] < $current_time)
386 {
387 $txt_access = $this->lng->txt("access_expired");
388 $usr_data["set"][$k]["access_class"] = "smallred";
389 }
390 else
391 {
392 $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
393 $usr_data["set"][$k]["access_class"] = "small";
394 }
395 }
396 else
397 {
398 $txt_access = $this->lng->txt("inactive");
399 $usr_data["set"][$k]["access_class"] = "smallred";
400 }
401 $usr_data["set"][$k]["access_until"] = $txt_access;
402 }
403 }
404
405 // Custom user data fields
406 if($udf_ids)
407 {
408 include_once './Services/User/classes/class.ilUserDefinedData.php';
409 $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids);
410
411 $users = array();
412 $counter = 0;
413 foreach($usr_data['set'] as $set)
414 {
415 $users[$counter] = $set;
416 foreach($udf_ids as $udf_field)
417 {
418 $users[$counter]['udf_'.$udf_field] = $data[$set['usr_id']][$udf_field];
419 }
420 ++$counter;
421 }
422 }
423 else
424 {
425 $users = $usr_data['set'];
426 }
427
428 if($this->getType() == self::TYPE_GLOBAL_SEARCH)
429 {
430 if($this->getLuceneResult() instanceof ilLuceneSearchResult)
431 {
432 foreach($users as $counter => $ud)
433 {
434 $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance($ud['usr_id']);
435 }
436 }
437 }
438
439
440
441 $this->setData($users);
442 }
443
444
448 public function getRelevanceHTML($a_rel)
449 {
450 $tpl = new ilTemplate('tpl.lucene_relevance.html',true,true,'Services/Search');
451
452 include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
454 $pbar->setCurrent($a_rel);
455
456 $tpl->setCurrentBlock('relevance');
457 $tpl->setVariable('REL_PBAR', $pbar->render());
458 $tpl->parseCurrentBlock();
459
460 return $tpl->get();
461 }
462}
463?>
global $tpl
Definition: ilias.php:8
if(! $in) $columns
Definition: Utf8Test.php:45
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_DATE
const IL_CAL_UNIX
const IL_CAL_DATETIME
static formatDate(ilDateTime $date)
Format a date @access public.
@classDescription Date and time handling
Class for single dates.
Search result implementing iterator interface.
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
static getInstance()
Factory.
setLuceneResult(ilLuceneSearchResult $res)
Set lucene result For parsing relevances.
initMultiCommands($a_commands)
Init multi commands.
getUserLimitations()
allow user limitations like inactive and access limitations
setUserLimitations($a_limitations)
allow user limitations like inactive and access limitations
numericOrdering($a_field)
enable numeric ordering for relevance
__construct($a_parent_obj, $a_parent_cmd, $a_admin_mode=false, $a_type=self::TYPE_STANDARD)
Constructor.
Class ilTable2GUI.
getSelectedColumns()
Get selected columns.
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.
setShowRowsSelector($a_value)
Toggle rows-per-page selector.
setTitle($a_title, $a_icon=0, $a_icon_alt=0)
Set title and title icon.
fillRow($a_set)
Standard Version of Fill Row.
setData($a_data)
set table data @access public
setEnableTitle($a_enabletitle)
Set Enable Title.
setRowTemplate($a_template, $a_template_dir="")
Set row template.
addMultiCommand($a_cmd, $a_text)
Add Command button.
setDefaultOrderField($a_defaultorderfield)
Set Default order field.
setSelectAllCheckbox($a_select_all_checkbox)
Set the name of the checkbox that should be toggled with a select all button.
setId($a_val)
Set id.
setFormAction($a_form_action, $a_multipart=false)
Set Form action parameter.
addMultiItemSelectionButton($a_sel_var, $a_options, $a_cmd, $a_text, $a_default_selection='')
Add Selection List + Command button for selected items.
setDefaultOrderDirection($a_defaultorderdirection)
Set Default order direction.
enable($a_module_name)
enables particular modules of table
special template class to simplify handling of ITX/PEAR
static lookupData($a_user_ids, $a_field_ids)
Lookup data.
User query class.
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
static getProfileLink($a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
$counter
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93