ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 public function __construct($a_parent_obj, $a_parent_cmd, $a_admin_mode = false, $a_type = self::TYPE_STANDARD)
32 {
33 global $DIC;
34
35 $ilCtrl = $DIC['ilCtrl'];
36 $lng = $DIC['lng'];
37 $ilAccess = $DIC['ilAccess'];
38 $lng = $DIC['lng'];
39 $ilUser = $DIC['ilUser'];
40
41 $this->admin_mode = (bool) $a_admin_mode;
42 $this->type = $a_type;
43
44 $this->setId("rep_search_" . $ilUser->getId());
45 parent::__construct($a_parent_obj, $a_parent_cmd);
46
47
48 $this->setFormAction($ilCtrl->getFormAction($this->parent_obj));
49 $this->setTitle($this->lng->txt('search_results'));
50 $this->setEnableTitle(true);
51 $this->setShowRowsSelector(true);
52
53
54 if ($this->getType() == self::TYPE_STANDARD) {
55 $this->setRowTemplate("tpl.rep_search_usr_result_row.html", "Services/Search");
56 $this->addColumn("", "", "1", true);
57 $this->enable('select_all');
58 $this->setSelectAllCheckbox("user[]");
59 $this->setDefaultOrderField("login");
60 $this->setDefaultOrderDirection("asc");
61 } else {
62 $this->setRowTemplate("tpl.global_search_usr_result_row.html", "Services/Search");
63 $this->addColumn('', '', "110px");
64 }
65
66 $all_cols = $this->getSelectableColumns();
67 foreach ($this->getSelectedColumns() as $col) {
68 $this->addColumn($all_cols[$col]['txt'], $col);
69 }
70
71 if ($this->getType() == self::TYPE_STANDARD) {
72 } else {
73 $this->addColumn($this->lng->txt('lucene_relevance_short'), 'relevance');
74 if (ilBuddySystem::getInstance()->isEnabled()) {
75 $this->addColumn('', '');
76 }
77 $this->setDefaultOrderField("relevance");
78 $this->setDefaultOrderDirection("desc");
79 }
80 }
81
87 public function numericOrdering($a_field)
88 {
89 if ($a_field == 'relevance') {
90 return true;
91 }
92 return parent::numericOrdering($a_field);
93 }
94
99 public function getType()
100 {
101 return $this->type;
102 }
103
110 {
111 $this->lucene_result = $res;
112 }
113
118 public function getLuceneResult()
119 {
121 }
122
128 public function setUserLimitations($a_limitations)
129 {
130 $this->user_limitations = (bool) $a_limitations;
131 }
132
137 public function getUserLimitations()
138 {
140 }
141
149 public function getSelectableColumns()
150 {
151 global $DIC;
152
153 $rbacreview = $DIC['rbacreview'];
154 $ilUser = $DIC['ilUser'];
155
156 if (!self::$all_selectable_cols) {
157 include_once './Services/Search/classes/class.ilUserSearchOptions.php';
158 $columns = ilUserSearchOptions::getSelectableColumnInfo($rbacreview->isAssigned($ilUser->getId(), SYSTEM_ROLE_ID));
159
160 if ($this->admin_mode) {
161 // #11293
162 $columns['access_until'] = array('txt' => $this->lng->txt('access_until'));
163 $columns['last_login'] = array('txt' => $this->lng->txt('last_login'));
164 }
165
166 self::$all_selectable_cols = $columns;
167 }
169 }
170
175 public function initMultiCommands($a_commands)
176 {
177 if (!count($a_commands)) {
178 $this->addMultiCommand('addUser', $this->lng->txt('btn_add'));
179 return true;
180 }
181 $this->addMultiItemSelectionButton('member_type', $a_commands, 'addUser', $this->lng->txt('btn_add'));
182 return true;
183 }
184
188 protected function fillRow($a_set)
189 {
193 global $DIC;
194
195 $ilCtrl = $DIC['ilCtrl'];
196 $ilUser = $DIC['ilUser'];
197
198 $this->tpl->setVariable("VAL_ID", $a_set["usr_id"]);
199
200 $link = '';
201 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
202 include_once './Services/User/classes/class.ilUserUtil.php';
203 $link = ilUserUtil::getProfileLink($a_set['usr_id']);
204 if ($link) {
205 $this->tpl->setVariable('IMG_LINKED_TO_PROFILE', $link);
206 $this->tpl->setVariable(
207 'USR_IMG_SRC_LINKED',
208 ilObjUser::_getPersonalPicturePath($a_set['usr_id'], 'xsmall')
209 );
210 } else {
211 $this->tpl->setVariable(
212 'USR_IMG_SRC',
213 ilObjUser::_getPersonalPicturePath($a_set['usr_id'], 'xsmall')
214 );
215 }
216 }
217
218
219 foreach ($this->getSelectedColumns() as $field) {
220 switch ($field) {
221 case 'gender':
222 $a_set['gender'] = $a_set['gender'] ? $this->lng->txt('gender_' . $a_set['gender']) : '';
223 $this->tpl->setCurrentBlock('custom_fields');
224 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
225 $this->tpl->parseCurrentBlock();
226 break;
227
228 case 'birthday':
229 $a_set['birthday'] = $a_set['birthday'] ? ilDatePresentation::formatDate(new ilDate($a_set['birthday'], IL_CAL_DATE)) : $this->lng->txt('no_date');
230 $this->tpl->setCurrentBlock('custom_fields');
231 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
232 $this->tpl->parseCurrentBlock();
233 break;
234
235 case 'access_until':
236 $this->tpl->setCurrentBlock('custom_fields');
237 $this->tpl->setVariable('CUST_CLASS', ' ' . $a_set['access_class']);
238 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
239 $this->tpl->parseCurrentBlock();
240 break;
241
242 case 'last_login':
243 $a_set['last_login'] = $a_set['last_login'] ? ilDatePresentation::formatDate(new ilDateTime($a_set['last_login'], IL_CAL_DATETIME)) : $this->lng->txt('no_date');
244 $this->tpl->setCurrentBlock('custom_fields');
245 $this->tpl->setVariable('VAL_CUST', $a_set[$field]);
246 $this->tpl->parseCurrentBlock();
247 break;
248
249 case 'interests_general':
250 case 'interests_help_offered':
251 case 'interests_help_looking':
252 $this->tpl->setCurrentBlock('custom_fields');
253 $this->tpl->setVariable('VAL_CUST', implode(', ', (array) $a_set[$field]));
254 $this->tpl->parseCurrentBlock();
255 break;
256
257 case 'org_units':
258 $this->tpl->setCurrentBlock('custom_fields');
259 include_once './Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php';
260 $this->tpl->setVariable('VAL_CUST', (string) ilOrgUnitPathStorage::getTextRepresentationOfUsersOrgUnits($a_set['usr_id']));
261 $this->tpl->parseCurrentBlock();
262 break;
263
264
265 case 'login':
266 if ($this->admin_mode) {
267 $ilCtrl->setParameterByClass("ilobjusergui", "ref_id", "7");
268 $ilCtrl->setParameterByClass("ilobjusergui", "obj_id", $a_set["usr_id"]);
269 $ilCtrl->setParameterByClass("ilobjusergui", "search", "1");
270 $link = $ilCtrl->getLinkTargetByClass(array("iladministrationgui", "ilobjusergui"), "view");
271 $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
272 } elseif ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
273 $a_set[$field] = "<a href=\"" . $link . "\">" . $a_set[$field] . "</a>";
274 }
275 // fallthrough
276
277 // no break
278 default:
279 $this->tpl->setCurrentBlock('custom_fields');
280 $this->tpl->setVariable('VAL_CUST', (string) ($a_set[$field] ? $a_set[$field] : ''));
281 $this->tpl->parseCurrentBlock();
282 break;
283 }
284 }
285
286 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
287 $this->tpl->setVariable('SEARCH_RELEVANCE', $this->getRelevanceHTML($a_set['relevance']));
288 if (ilBuddySystem::getInstance()->isEnabled() && $a_set['usr_id'] != $ilUser->getId()) {
289 require_once 'Services/Contact/BuddySystem/classes/class.ilBuddySystemLinkButton.php';
290 $this->tpl->setVariable('CONTACT_ACTIONS', ilBuddySystemLinkButton::getInstanceByUserId($a_set['usr_id'])->getHtml());
291 } else {
292 $this->tpl->setVariable('CONTACT_ACTIONS', '');
293 }
294 }
295 }
296
302 public function parseUserIds($a_user_ids)
303 {
304 if (!$a_user_ids) {
305 $this->setData(array());
306 return true;
307 }
308
309 $additional_fields = $this->getSelectedColumns();
310
311 $parse_access = false;
312 if (isset($additional_fields['access_until'])) {
313 $parse_access = true;
314 unset($additional_fields['access_until']);
315 }
316
317 $udf_ids = $usr_data_fields = $odf_ids = array();
318 foreach ($additional_fields as $field) {
319 if ($field == 'org_units') {
320 continue;
321 }
322 if (substr($field, 0, 3) == 'udf') {
323 $udf_ids[] = substr($field, 4);
324 continue;
325 }
326 $usr_data_fields[] = $field;
327 }
328 include_once './Services/User/classes/class.ilUserQuery.php';
329
330 $u_query = new ilUserQuery();
331 $u_query->setOrderField('login');
332 $u_query->setOrderDirection('ASC');
333 $u_query->setLimit(999999);
334 include_once './Services/Search/classes/class.ilSearchSettings.php';
335
336 if (!ilSearchSettings::getInstance()->isInactiveUserVisible() && $this->getUserLimitations()) {
337 $u_query->setActionFilter("active");
338 }
339
340 if (!ilSearchSettings::getInstance()->isLimitedUserVisible() && $this->getUserLimitations()) {
341 $u_query->setAccessFilter(true);
342 }
343
344 $u_query->setAdditionalFields($usr_data_fields);
345 $u_query->setUserFilter($a_user_ids);
346
347 $usr_data = $u_query->query();
348
349
350 if ($this->admin_mode && $parse_access) {
351 // see ilUserTableGUI
352 $current_time = time();
353 foreach ($usr_data['set'] as $k => $user) {
354 if ($user['active']) {
355 if ($user["time_limit_unlimited"]) {
356 $txt_access = $this->lng->txt("access_unlimited");
357 $usr_data["set"][$k]["access_class"] = "smallgreen";
358 } elseif ($user["time_limit_until"] < $current_time) {
359 $txt_access = $this->lng->txt("access_expired");
360 $usr_data["set"][$k]["access_class"] = "smallred";
361 } else {
362 $txt_access = ilDatePresentation::formatDate(new ilDateTime($user["time_limit_until"], IL_CAL_UNIX));
363 $usr_data["set"][$k]["access_class"] = "small";
364 }
365 } else {
366 $txt_access = $this->lng->txt("inactive");
367 $usr_data["set"][$k]["access_class"] = "smallred";
368 }
369 $usr_data["set"][$k]["access_until"] = $txt_access;
370 }
371 }
372
373 // Custom user data fields
374 if ($udf_ids) {
375 include_once './Services/User/classes/class.ilUserDefinedData.php';
376 $data = ilUserDefinedData::lookupData($a_user_ids, $udf_ids);
377
378 $users = array();
379 $counter = 0;
380 foreach ($usr_data['set'] as $set) {
381 $users[$counter] = $set;
382 foreach ($udf_ids as $udf_field) {
383 $users[$counter]['udf_' . $udf_field] = $data[$set['usr_id']][$udf_field];
384 }
385 ++$counter;
386 }
387 } else {
388 $users = $usr_data['set'];
389 }
390
391 if ($this->getType() == self::TYPE_GLOBAL_SEARCH) {
392 if ($this->getLuceneResult() instanceof ilLuceneSearchResult) {
393 foreach ($users as $counter => $ud) {
394 $users[$counter]['relevance'] = $this->getLuceneResult()->getRelevance($ud['usr_id']);
395 }
396 }
397 }
398
399
400
401 $this->setData($users);
402 }
403
404
408 public function getRelevanceHTML($a_rel)
409 {
410 $tpl = new ilTemplate('tpl.lucene_relevance.html', true, true, 'Services/Search');
411
412 include_once "Services/UIComponent/ProgressBar/classes/class.ilProgressBar.php";
414 $pbar->setCurrent($a_rel);
415
416 $tpl->setCurrentBlock('relevance');
417 $tpl->setVariable('REL_PBAR', $pbar->render());
418 $tpl->parseCurrentBlock();
419
420 return $tpl->get();
421 }
422}
if(! $in) $columns
Definition: Utf8Test.php:45
$users
Definition: authpage.php:44
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, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date @access public.
@classDescription Date and time handling
Class for single dates.
Search result implementing iterator interface.
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.
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.
setSelectAllCheckbox($a_select_all_checkbox, $a_select_all_on_top=false)
Set the name of the checkbox that should be toggled with a select all button.
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.
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.
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
$user
Definition: migrateto20.php:57
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92