ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilUserUtil.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3
13{
17 const START_PD_NOTES = 4;
18 const START_PD_NEWS = 5;
21 const START_PD_SKILLS = 8;
22 const START_PD_LP = 9;
24 const START_PD_MAIL = 11;
26 const START_PD_PROFILE = 13;
28 const START_REPOSITORY = 15;
30 const START_PD_MYSTAFF = 17;
31
43 public static function getNamePresentation(
44 $a_user_id,
45 $a_user_image = false,
46 $a_profile_link = false,
47 $a_profile_back_link = "",
48 $a_force_first_lastname = false,
49 $a_omit_login = false,
50 $a_sortable = true,
51 $a_return_data_array = false,
52 $a_ctrl_path = "ilpublicuserprofilegui"
53 ) {
54 global $DIC;
55
56 $lng = $DIC['lng'];
57 $ilCtrl = $DIC['ilCtrl'];
58 $ilDB = $DIC['ilDB'];
59
60 if (!is_array($a_ctrl_path)) {
61 $a_ctrl_path = array($a_ctrl_path);
62 }
63
64 if (!($return_as_array = is_array($a_user_id))) {
65 $a_user_id = array($a_user_id);
66 }
67
68 $sql = 'SELECT
69 a.usr_id,
70 firstname,
71 lastname,
72 title,
73 login,
74 b.value public_profile,
75 c.value public_title
76 FROM
77 usr_data a
78 LEFT JOIN
79 usr_pref b ON
80 (a.usr_id = b.usr_id AND
81 b.keyword = %s)
82 LEFT JOIN
83 usr_pref c ON
84 (a.usr_id = c.usr_id AND
85 c.keyword = %s)
86 WHERE ' . $ilDB->in('a.usr_id', $a_user_id, false, 'integer');
87
88 $userrow = $ilDB->queryF($sql, array('text', 'text'), array('public_profile', 'public_title'));
89
90 $names = array();
91
92 $data = array();
93 while ($row = $ilDB->fetchObject($userrow)) {
94 $pres = '';
95 $d = array("id" => $row->usr_id, "title" => "", "lastname" => "", "firstname" => "", "img" => "", "link" => "",
96 "public_profile" => "");
97 $has_public_profile = in_array($row->public_profile, array("y", "g"));
98 if ($a_force_first_lastname || $has_public_profile) {
99 $title = "";
100 if ($row->public_title == "y" && $row->title) {
101 $title = $row->title . " ";
102 }
103 $d["title"] = $title;
104 if ($a_sortable) {
105 $pres = $row->lastname;
106 if (strlen($row->firstname)) {
107 $pres .= (', ' . $row->firstname . ' ');
108 }
109 } else {
110 $pres = $title;
111 if (strlen($row->firstname)) {
112 $pres .= $row->firstname . ' ';
113 }
114 $pres .= ($row->lastname . ' ');
115 }
116 $d["firstname"] = $row->firstname;
117 $d["lastname"] = $row->lastname;
118 }
119 $d["login"] = $row->login;
120 $d["public_profile"] = $has_public_profile;
121
122
123 if (!$a_omit_login) {
124 $pres .= "[" . $row->login . "]";
125 }
126
127 if ($a_profile_link && $has_public_profile) {
128 $ilCtrl->setParameterByClass(end($a_ctrl_path), "user_id", $row->usr_id);
129 if ($a_profile_back_link != "") {
130 $ilCtrl->setParameterByClass(
131 end($a_ctrl_path),
132 "back_url",
133 rawurlencode($a_profile_back_link)
134 );
135 }
136 $link = $ilCtrl->getLinkTargetByClass($a_ctrl_path, "getHTML");
137 $pres = '<a href="' . $link . '">' . $pres . '</a>';
138 $d["link"] = $link;
139 }
140
141 if ($a_user_image) {
142 $img = ilObjUser::_getPersonalPicturePath($row->usr_id, "xxsmall");
143 $pres = '<img class="ilUserXXSmall" src="' . $img . '" alt="' . $lng->txt("icon") .
144 " " . $lng->txt("user_picture") . '" /> ' . $pres;
145 $d["img"] = $img;
146 }
147
148 $names[$row->usr_id] = $pres;
149 $data[$row->usr_id] = $d;
150 }
151
152 foreach ($a_user_id as $id) {
153 if (!$names[$id]) {
154 $names[$id] = $lng->txt('usr_name_undisclosed');
155 }
156 }
157
158 if ($a_return_data_array) {
159 if ($return_as_array) {
160 return $data;
161 } else {
162 return current($data);
163 }
164 }
165 return $return_as_array ? $names : $names[$a_user_id[0]];
166 }
167
174 public static function hasPublicProfile($a_user_id)
175 {
176 global $DIC;
177
178 $ilDB = $DIC['ilDB'];
179
180 $set = $ilDB->query(
181 "SELECT value FROM usr_pref " .
182 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
183 " and keyword = " . $ilDB->quote("public_profile", "text")
184 );
185 $rec = $ilDB->fetchAssoc($set);
186
187 return in_array($rec["value"], array("y", "g"));
188 }
189
190
197 public static function getProfileLink($a_usr_id)
198 {
199 $public_profile = ilObjUser::_lookupPref($a_usr_id, 'public_profile');
200 if ($public_profile != 'y' and $public_profile != 'g') {
201 return '';
202 }
203
204 $GLOBALS['DIC']['ilCtrl']->setParameterByClass('ilpublicuserprofilegui', 'user', $a_usr_id);
205 return $GLOBALS['DIC']['ilCtrl']->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
206 }
207
208
209 //
210 // Personal starting point
211 //
212
218 public static function getPossibleStartingPoints($a_force_all = false)
219 {
220 global $DIC;
221
222 $ilSetting = $DIC['ilSetting'];
223 $lng = $DIC['lng'];
224
225 // for all conditions: see ilMainMenuGUI
226
227 $all = array();
228
229 $all[self::START_PD_OVERVIEW] = 'overview';
230
231 if ($a_force_all || ($ilSetting->get('disable_my_offers') == 0 &&
232 $ilSetting->get('disable_my_memberships') == 0)) {
233 $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
234 }
235
236 if (ilMyStaffAccess::getInstance()->hasCurrentUserAccessToMyStaff()) {
237 $all[self::START_PD_MYSTAFF] = 'my_staff';
238 }
239
240 if ($a_force_all || !$ilSetting->get("disable_personal_workspace")) {
241 $all[self::START_PD_WORKSPACE] = 'personal_workspace';
242 }
243
244 include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
246 if ($a_force_all || $settings->isEnabled()) {
247 $all[self::START_PD_CALENDAR] = 'calendar';
248 }
249
250 $all[self::START_REPOSITORY] = 'repository';
251
252 foreach ($all as $idx => $lang) {
253 $all[$idx] = $lng->txt($lang);
254 }
255
256 return $all;
257 }
258
266 public static function setStartingPoint($a_value, $a_ref_id = null)
267 {
268 global $DIC;
269
270 $ilSetting = $DIC['ilSetting'];
271 $tree = $DIC['tree'];
272
273 if ($a_value == self::START_REPOSITORY_OBJ) {
274 $a_ref_id = (int) $a_ref_id;
275 if (ilObject::_lookupObjId($a_ref_id) &&
276 !$tree->isDeleted($a_ref_id)) {
277 $ilSetting->set("usr_starting_point", $a_value);
278 $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
279 return true;
280 }
281 }
282 $valid = array_keys(self::getPossibleStartingPoints());
283 if (in_array($a_value, $valid)) {
284 $ilSetting->set("usr_starting_point", $a_value);
285 return true;
286 }
287 return false;
288 }
289
295 public static function getStartingPoint()
296 {
297 global $DIC;
298
299 $ilSetting = $DIC['ilSetting'];
300 $ilUser = $DIC['ilUser'];
301
302 $valid = array_keys(self::getPossibleStartingPoints());
303 $current = $ilSetting->get("usr_starting_point");
304 if ($current == self::START_REPOSITORY_OBJ) {
305 return $current;
306 } elseif (!$current || !in_array($current, $valid)) {
308
309 // #10715 - if 1 is disabled overview will display the current default
310 if ($ilSetting->get('disable_my_offers') == 0 &&
311 $ilSetting->get('disable_my_memberships') == 0 &&
312 $ilSetting->get('personal_items_default_view') == 1) {
314 }
315
317 }
318 if ($ilUser->getId() == ANONYMOUS_USER_ID ||
319 !$ilUser->getId()) { // #18531
321 }
322 return $current;
323 }
324
330 public static function getStartingPointAsUrl()
331 {
332 global $DIC;
333
334 $tree = $DIC['tree'];
335 $ilUser = $DIC['ilUser'];
336 $rbacreview = $DIC['rbacreview'];
337
338 $ref_id = 1;
339 $by_default = true;
340
341 //configuration by user preference
342 #21782
343 if (self::hasPersonalStartingPoint() && $ilUser->getPref('usr_starting_point') != null) {
345 if ($current == self::START_REPOSITORY_OBJ) {
347 }
348 } else {
349 include_once './Services/AccessControl/classes/class.ilStartingPoint.php';
350
352 //getting all roles with starting points and store them in array
354
355 $roles_ids = array_keys($roles);
356
357 $gr = array();
358 foreach ($rbacreview->getGlobalRoles() as $role_id) {
359 if ($rbacreview->isAssigned($ilUser->getId(), $role_id)) {
360 if (in_array($role_id, $roles_ids)) {
361 $gr[$roles[$role_id]['position']] = array(
362 "point" => $roles[$role_id]['starting_point'],
363 "object" => $roles[$role_id]['starting_object']
364 );
365 }
366 }
367 }
368 if (!empty($gr)) {
369 krsort($gr); // ak: if we use array_pop (last element) we need to reverse sort, since we want the one with the smallest number
370 $role_point = array_pop($gr);
371 $current = $role_point['point'];
372 $ref_id = $role_point['object'];
373 $by_default = false;
374 }
375 }
376 if ($by_default) {
378
379 if ($current == self::START_REPOSITORY_OBJ) {
380 $ref_id = self::getStartingObject();
381 }
382 }
383 }
384
385 switch ($current) {
387 $ref_id = $tree->readRootId();
388
389 // no break
391 if ($ref_id &&
392 ilObject::_lookupObjId($ref_id) &&
393 !$tree->isDeleted($ref_id)) {
394 include_once('./Services/Link/classes/class.ilLink.php');
395 return ilLink::_getStaticLink($ref_id, '', true);
396 }
397 // invalid starting object, overview is fallback
399 // fallthrough
400
401 // no break
402 default:
403 $map = array(
404 self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems',
405 self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships',
406 // self::START_PD_BOOKMARKS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToBookmarks',
407 // self::START_PD_NOTES => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNotes',
408 // self::START_PD_NEWS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNews',
409 self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace',
410 // self::START_PD_PORTFOLIO => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio',
411 // self::START_PD_SKILLS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSkills',
413 self::START_PD_CALENDAR => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToCalendar',
414 // self::START_PD_MAIL => 'ilias.php?baseClass=ilMailGUI',
415 // self::START_PD_CONTACTS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToContacts',
416 // self::START_PD_PROFILE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToProfile',
417 // self::START_PD_SETTINGS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSettings'
418 self::START_PD_MYSTAFF => 'ilias.php?baseClass=' . ilPersonalDesktopGUI::class . '&cmd=' . ilPersonalDesktopGUI::CMD_JUMP_TO_MY_STAFF
419 );
420 return $map[$current];
421 }
422 }
423
429 public static function getStartingObject()
430 {
431 global $DIC;
432
433 $ilSetting = $DIC['ilSetting'];
434
435 return $ilSetting->get("usr_starting_point_ref_id");
436 }
437
443 public static function togglePersonalStartingPoint($a_value)
444 {
445 global $DIC;
446
447 $ilSetting = $DIC['ilSetting'];
448
449 $ilSetting->set("usr_starting_point_personal", (bool) $a_value);
450 }
451
457 public static function hasPersonalStartingPoint()
458 {
459 global $DIC;
460
461 $ilSetting = $DIC['ilSetting'];
462
463 return $ilSetting->get("usr_starting_point_personal");
464 }
465
471 public static function hasPersonalStartPointPref()
472 {
473 global $DIC;
474
475 $ilUser = $DIC['ilUser'];
476
477 return (bool) $ilUser->getPref("usr_starting_point");
478 }
479
485 public static function getPersonalStartingPoint()
486 {
487 global $DIC;
488
489 $ilUser = $DIC['ilUser'];
490
491 $valid = array_keys(self::getPossibleStartingPoints());
492 $current = $ilUser->getPref("usr_starting_point");
493 if ($current == self::START_REPOSITORY_OBJ) {
494 return $current;
495 } elseif (!$current || !in_array($current, $valid)) {
496 return self::getStartingPoint();
497 }
498 return $current;
499 }
500
508 public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
509 {
510 global $DIC;
511
512 $ilUser = $DIC['ilUser'];
513 $tree = $DIC['tree'];
514
515 if (!$a_value) {
516 $ilUser->setPref("usr_starting_point", null);
517 $ilUser->setPref("usr_starting_point_ref_id", null);
518 return;
519 }
520
521 if ($a_value == self::START_REPOSITORY_OBJ) {
522 $a_ref_id = (int) $a_ref_id;
523 if (ilObject::_lookupObjId($a_ref_id) &&
524 !$tree->isDeleted($a_ref_id)) {
525 $ilUser->setPref("usr_starting_point", $a_value);
526 $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
527 return true;
528 }
529 }
530 $valid = array_keys(self::getPossibleStartingPoints());
531 if (in_array($a_value, $valid)) {
532 $ilUser->setPref("usr_starting_point", $a_value);
533 return true;
534 }
535 return false;
536 }
537
543 public static function getPersonalStartingObject()
544 {
545 global $DIC;
546
547 $ilUser = $DIC['ilUser'];
548
549 $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
550 if (!$ref_id) {
551 $ref_id = self::getStartingObject();
552 }
553 return $ref_id;
554 }
555}
An exception for terminatinating execution or to throw for unit testing.
static _getInstance()
get singleton instance
static _lookupPref($a_usr_id, $a_keyword)
static _lookupObjId($a_id)
static getRolesWithStartingPoint()
get array with all roles which have starting point defined.
Class ilUserUtil.
const START_PD_MYSTAFF
const START_PD_NOTES
const START_PD_SKILLS
const START_REPOSITORY
const START_PD_BOOKMARKS
static getPersonalStartingObject()
Get ref id of personal starting object.
const START_PD_PORTFOLIO
static getPossibleStartingPoints($a_force_all=false)
Get all valid starting points.
const START_PD_PROFILE
static hasPersonalStartPointPref()
Did user set any personal starting point (yet)?
static hasPersonalStartingPoint()
Can starting point be personalized?
static hasPublicProfile($a_user_id)
Has public profile.
const START_PD_SETTINGS
static togglePersonalStartingPoint($a_value)
Toggle personal starting point setting.
const START_PD_CONTACTS
const START_PD_WORKSPACE
static getPersonalStartingPoint()
Get current personal starting point.
const START_PD_CALENDAR
const START_PD_OVERVIEW
static getNamePresentation( $a_user_id, $a_user_image=false, $a_profile_link=false, $a_profile_back_link="", $a_force_first_lastname=false, $a_omit_login=false, $a_sortable=true, $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static getStartingPoint()
Get current starting point setting.
static getProfileLink($a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
static setPersonalStartingPoint($a_value, $a_ref_id=null)
Set personal starting point setting.
static getStartingPointAsUrl()
Get current starting point setting as URL.
static getStartingObject()
Get ref id of starting object.
const START_REPOSITORY_OBJ
const START_PD_SUBSCRIPTION
static setStartingPoint($a_value, $a_ref_id=null)
Set starting point setting.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$valid
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilCtrl
Definition: ilias.php:18
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
$row
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
global $ilSetting
Definition: privfeed.php:17
global $DIC
Definition: saml.php:7
$lng
global $ilDB
$ilUser
Definition: imgupload.php:18
$data
Definition: bench.php:6