ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 'login':
266 if($this->admin_mode)
267 {
268 $ilCtrl->setParameterByClass("ilobjusergui", "ref_id", "7");
269 $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
270 $ilCtrl->setParameterByClass("ilobjusergui", "search", "1");
271 $link = $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
272 $a_set[$field] = "<a href=\"".$link."\">".$a_set[$field]."</a>";
273 }
274 elseif($this->getType() == self::TYPE_GLOBAL_SEARCH)
275 {
276 $a_set[$field] = "<a href=\"".$link."\">".$a_set[$field]."</a>";
277 }
278 // fallthrough
279
280 default:
281 $this->tpl->setCurrentBlock('custom_fields');
282 $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ? $a_set[$field] : ''));
283 $this->tpl->parseCurrentBlock();
284 break;
285 }
286 }
287
288 if($this->getType() == self::TYPE_GLOBAL_SEARCH)
289 {
290 $this->tpl->setVariable('SEARCH_RELEVANCE',$this->getRelevanceHTML($a_set['relevance']));
291 if(ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $ilUser->getId())
292 {
293 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemLinkButton.php';
294 $this->tpl->setVariable('CONTACT_ACTIONS', ilBuddySystemLinkButton::getInstanceByUserId($a_set['usr_id'])->getHtml());
295 }
296 else
297 {
298 $this->tpl->setVariable('CONTACT_ACTIONS', '');
299 }
300 }
301
302 }
303
309 public function parseUserIds($a_user_ids)
310 {
311 if(!$a_user_ids)
312 {
313 $this->setData(array());
314 return true;
315 }
316
317 $additional_fields = $this->getSelectedColumns();
318
319 $parse_access = false;
320 if(isset($additional_fields['access_until']))
321 {
322 $parse_access = true;
323 unset($additional_fields['access_until']);
324 }
325
326 $udf_ids = $usr_data_fields = $odf_ids = array();
327 foreach($additional_fields as $field)
328 {
329 if(substr($field, 0, 3) == 'udf')
330 {
331 $udf_ids[] = substr($field,4);
332 continue;
333 }
334 $usr_data_fields[] = $field;
335 }
336 include_once './Services/User/classes/class.ilUserQuery.php';
337 /* $usr_data = ilUserQuery::getUserListData(
338 'login',
339 'ASC',
340 0,
341 999999,
342 '',
343 '',
344 null,
345 false,
346 false,
347 0,
348 0,
349 null,
350 $usr_data_fields,
351 $a_user_ids
352 );*/
353
354 $u_query = new ilUserQuery();
355 $u_query->setOrderField('login');
356 $u_query->setOrderDirection('ASC');
357 $u_query->setLimit(999999);
358 include_once './Services/Search/classes/class.ilSearchSettings.php';
359
360 if(!ilSearchSettings::getInstance()->isInactiveUserVisible() && $this->getUserLimitations())
361 {
362 $u_query->setActionFilter("activ");
363 }
364
365 if(!ilSearchSettings::getInstance()->isLimitedUserVisible() && $this->getUserLimitations())
366 {
367 $u_query->setAccessFilter(true);
368 }
369
370 $u_query->setAdditionalFields($usr_data_fields);
371 $u_query->setUserFilter($a_user_ids);
372
373 $usr_data = $u_query->query();
374
375
376 if($this->admin_mode && $parse_access)
377 {
378 // see ilUserTableGUI
379 $current_time = time();
380 foreach($usr_data['set'] as $k => $user)
381 {
382 if ($user['active'])
383 {
384 if ($user["time_limit_unlimited"])
385 {
386 $txt_access = $this->lng->txt("access_unlimited");
387 $usr_data["set"][$k]["access_class"] = "smallgreen";
388 }
389 elseif ($user["time_limit_until"] < $current_time)
390 {
391 $txt_access = $this->lng->txt("access_expired");
392 $usr_data["set"][$k]["access_class"] = "smallred";
393 }
394 else
395 {
396 $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"],IL_CAL_UNIX));
397 $usr_data["set"][$k]["access_class"] = "small";
398 }
399 }
400 else
401 {
402 $txt_access = $this->lng->txt("inactive");
403 $usr_data["set"][$k]["access_class"] = "smallred";
404 }
405 $usr_data["set"][$k]["access_until"] = $txt_access;
406 }
407 }
408
409 // Custom user data fields
410 if($udf_ids)
411 {
412 include_once './Services/User/classes/class.ilUserDefinedData.php';
413 $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids);
414
415 $users = array();
416 $counter = 0;
417 foreach($usr_data['set'] as $set)
418 {
419 $users[$counter] = $set;
420 foreach($udf_ids as $udf_field)
421 {
422 $users[$counter]['udf_'.$udf_field] = $data[$set['usr_id']][$udf_field];
423 }
424 ++$counter;
425 }
426 }
427 else
428 {
429 $users = $usr_data['set'];
430 }
431
432 if($this->getType() == self::TYPE_GLOBAL_SEARCH)
433 {
434 if($this->getLuceneResult() instanceof ilLuceneSearchResult)
435 {
436 foreach($users as $counter => $ud)
437 {
438 $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance($ud['usr_id']);
439 }
440 }
441 }
442
443
444
445 $this->setData($users);
446 }
447
448
452 public function getRelevanceHTML($a_rel)
453 {
454 $tpl = new ilTemplate('tpl.lucene_relevance.html',true,true,'Services/Search');
455
456 include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
458 $pbar->setCurrent($a_rel);
459
460 $tpl->setCurrentBlock('relevance');
461 $tpl->setVariable('REL_PBAR', $pbar->render());
462 $tpl->parseCurrentBlock();
463
464 return $tpl->get();
465 }
466}
467?>
global $tpl
Definition: ilias.php:8
if(! $in) $columns
Definition: Utf8Test.php:46
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.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
global $ilUser
Definition: imgupload.php:15