ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
5
15{
18 const START_PD_NOTES = 4;
19 const START_PD_NEWS = 5;
22 const START_PD_SKILLS = 8;
23 const START_PD_LP = 9;
25 const START_PD_MAIL = 11;
27 const START_PD_PROFILE = 13;
29 const START_REPOSITORY = 15;
31 const START_PD_MYSTAFF = 17;
32
44 public static function getNamePresentation(
45 $a_user_id,
46 $a_user_image = false,
47 $a_profile_link = false,
48 $a_profile_back_link = "",
49 $a_force_first_lastname = false,
50 $a_omit_login = false,
51 $a_sortable = true,
52 $a_return_data_array = false,
53 $a_ctrl_path = "ilpublicuserprofilegui"
54 ) {
55 global $DIC;
56
57 $lng = $DIC['lng'];
58 $ilCtrl = $DIC['ilCtrl'];
59 $ilDB = $DIC['ilDB'];
60
61 if (!is_array($a_ctrl_path)) {
62 $a_ctrl_path = array($a_ctrl_path);
63 }
64
65 if (!($return_as_array = is_array($a_user_id))) {
66 $a_user_id = array($a_user_id);
67 }
68
69 $sql = 'SELECT
70 a.usr_id,
71 firstname,
72 lastname,
73 title,
74 login,
75 b.value public_profile,
76 c.value public_title
77 FROM
78 usr_data a
79 LEFT JOIN
80 usr_pref b ON
81 (a.usr_id = b.usr_id AND
82 b.keyword = %s)
83 LEFT JOIN
84 usr_pref c ON
85 (a.usr_id = c.usr_id AND
86 c.keyword = %s)
87 WHERE ' . $ilDB->in('a.usr_id', $a_user_id, false, 'integer');
88
89 $userrow = $ilDB->queryF($sql, array('text', 'text'), array('public_profile', 'public_title'));
90
91 $names = array();
92
93 $data = array();
94 while ($row = $ilDB->fetchObject($userrow)) {
95 $pres = '';
96 $d = array("id" => (int) $row->usr_id, "title" => "", "lastname" => "", "firstname" => "", "img" => "", "link" => "",
97 "public_profile" => "");
98 $has_public_profile = in_array($row->public_profile, array("y", "g"));
99 if ($a_force_first_lastname || $has_public_profile) {
100 $title = "";
101 if ($row->public_title == "y" && $row->title) {
102 $title = $row->title . " ";
103 }
104 $d["title"] = $title;
105 if ($a_sortable) {
106 $pres = $row->lastname;
107 if (strlen($row->firstname)) {
108 $pres .= (', ' . $row->firstname . ' ');
109 }
110 } else {
111 $pres = $title;
112 if (strlen($row->firstname)) {
113 $pres .= $row->firstname . ' ';
114 }
115 $pres .= ($row->lastname . ' ');
116 }
117 $d["firstname"] = $row->firstname;
118 $d["lastname"] = $row->lastname;
119 }
120 $d["login"] = $row->login;
121 $d["public_profile"] = $has_public_profile;
122
123
124 if (!$a_omit_login) {
125 $pres .= "[" . $row->login . "]";
126 }
127
128 if ($a_profile_link && $has_public_profile) {
129 $ilCtrl->setParameterByClass(end($a_ctrl_path), "user_id", $row->usr_id);
130 if ($a_profile_back_link != "") {
131 $ilCtrl->setParameterByClass(
132 end($a_ctrl_path),
133 "back_url",
134 rawurlencode($a_profile_back_link)
135 );
136 }
137 $link = $ilCtrl->getLinkTargetByClass($a_ctrl_path, "getHTML");
138 $pres = '<a href="' . $link . '">' . $pres . '</a>';
139 $d["link"] = $link;
140 }
141
142 if ($a_user_image) {
143 $img = ilObjUser::_getPersonalPicturePath($row->usr_id, "xxsmall");
144 $pres = '<img class="ilUserXXSmall" src="' . $img . '" alt="' . $lng->txt("icon") .
145 " " . $lng->txt("user_picture") . '" /> ' . $pres;
146 $d["img"] = $img;
147 }
148
149 $names[$row->usr_id] = $pres;
150 $data[$row->usr_id] = $d;
151 }
152
153 foreach ($a_user_id as $id) {
154 if (!$names[$id]) {
155 $names[$id] = $lng->txt('usr_name_undisclosed');
156 }
157 }
158
159 if ($a_return_data_array) {
160 if ($return_as_array) {
161 return $data;
162 } else {
163 return current($data);
164 }
165 }
166 return $return_as_array ? $names : $names[$a_user_id[0]];
167 }
168
175 public static function hasPublicProfile($a_user_id)
176 {
177 global $DIC;
178
179 $ilDB = $DIC['ilDB'];
180
181 $set = $ilDB->query(
182 "SELECT value FROM usr_pref " .
183 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
184 " and keyword = " . $ilDB->quote("public_profile", "text")
185 );
186 $rec = $ilDB->fetchAssoc($set);
187
188 return in_array($rec["value"], array("y", "g"));
189 }
190
191
198 public static function getProfileLink($a_usr_id)
199 {
200 $public_profile = ilObjUser::_lookupPref($a_usr_id, 'public_profile');
201 if ($public_profile != 'y' and $public_profile != 'g') {
202 return '';
203 }
204
205 $GLOBALS['DIC']['ilCtrl']->setParameterByClass('ilpublicuserprofilegui', 'user', $a_usr_id);
206 return $GLOBALS['DIC']['ilCtrl']->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
207 }
208
209
210 //
211 // Personal starting point
212 //
213
219 public static function getPossibleStartingPoints($a_force_all = false)
220 {
221 global $DIC;
222
223 $ilSetting = $DIC['ilSetting'];
224 $lng = $DIC['lng'];
225
226 // for all conditions: see ilMainMenuGUI
227
228 $all = array();
229
230 $all[self::START_PD_OVERVIEW] = 'mm_dashboard';
231
232 if ($a_force_all || ($ilSetting->get('disable_my_offers') == 0 &&
233 $ilSetting->get('disable_my_memberships') == 0)) {
234 $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
235 }
236
237 if (ilMyStaffAccess::getInstance()->hasCurrentUserAccessToMyStaff()) {
238 $all[self::START_PD_MYSTAFF] = 'my_staff';
239 }
240
241 if ($a_force_all || !$ilSetting->get("disable_personal_workspace")) {
242 $all[self::START_PD_WORKSPACE] = 'mm_personal_and_shared_r';
243 }
244
245 include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
247 if ($a_force_all || $settings->isEnabled()) {
248 $all[self::START_PD_CALENDAR] = 'calendar';
249 }
250
251 $all[self::START_REPOSITORY] = 'obj_root';
252
253 foreach ($all as $idx => $lang) {
254 $all[$idx] = $lng->txt($lang);
255 }
256
257 return $all;
258 }
259
267 public static function setStartingPoint($a_value, $a_ref_id = null)
268 {
269 global $DIC;
270
271 $ilSetting = $DIC['ilSetting'];
272 $tree = $DIC['tree'];
273
274 if ($a_value == self::START_REPOSITORY_OBJ) {
275 $a_ref_id = (int) $a_ref_id;
276 if (ilObject::_lookupObjId($a_ref_id) &&
277 !$tree->isDeleted($a_ref_id)) {
278 $ilSetting->set("usr_starting_point", $a_value);
279 $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
280 return true;
281 }
282 }
283 $valid = array_keys(self::getPossibleStartingPoints());
284 if (in_array($a_value, $valid)) {
285 $ilSetting->set("usr_starting_point", $a_value);
286 return true;
287 }
288 return false;
289 }
290
296 public static function getStartingPoint()
297 {
298 global $DIC;
299
300 $ilSetting = $DIC['ilSetting'];
301 $ilUser = $DIC['ilUser'];
302
303 $valid = array_keys(self::getPossibleStartingPoints());
304 $current = $ilSetting->get("usr_starting_point");
305 if ($current == self::START_REPOSITORY_OBJ) {
306 return $current;
307 } elseif (!$current || !in_array($current, $valid)) {
308 $current = self::START_PD_OVERVIEW;
309
310 // #10715 - if 1 is disabled overview will display the current default
311 if ($ilSetting->get('disable_my_offers') == 0 &&
312 $ilSetting->get('disable_my_memberships') == 0 &&
313 $ilSetting->get('personal_items_default_view') == 1) {
315 }
316
317 self::setStartingPoint($current);
318 }
319 if ($ilUser->getId() == ANONYMOUS_USER_ID ||
320 !$ilUser->getId()) { // #18531
321 $current = self::START_REPOSITORY;
322 }
323 return $current;
324 }
325
331 public static function getStartingPointAsUrl()
332 {
333 global $DIC;
334
335 $tree = $DIC['tree'];
336 $ilUser = $DIC['ilUser'];
337 $rbacreview = $DIC['rbacreview'];
338
339 $ref_id = 1;
340 $by_default = true;
341
342 //configuration by user preference
343 #21782
344 if (self::hasPersonalStartingPoint() && $ilUser->getPref('usr_starting_point') != null) {
346 if ($current == self::START_REPOSITORY_OBJ) {
348 }
349 } else {
350 include_once './Services/AccessControl/classes/class.ilStartingPoint.php';
351
353 //getting all roles with starting points and store them in array
355
356 $roles_ids = array_keys($roles);
357
358 $gr = array();
359 foreach ($rbacreview->getGlobalRoles() as $role_id) {
360 if ($rbacreview->isAssigned($ilUser->getId(), $role_id)) {
361 if (in_array($role_id, $roles_ids)) {
362 $gr[$roles[$role_id]['position']] = array(
363 "point" => $roles[$role_id]['starting_point'],
364 "object" => $roles[$role_id]['starting_object']
365 );
366 }
367 }
368 }
369 if (!empty($gr)) {
370 krsort($gr); // ak: if we use array_pop (last element) we need to reverse sort, since we want the one with the smallest number
371 $role_point = array_pop($gr);
372 $current = $role_point['point'];
373 $ref_id = $role_point['object'];
374 $by_default = false;
375 }
376 }
377 if ($by_default) {
378 $current = self::getStartingPoint();
379
380 if ($current == self::START_REPOSITORY_OBJ) {
381 $ref_id = self::getStartingObject();
382 }
383 }
384 }
385
386 switch ($current) {
388 $ref_id = $tree->readRootId();
389
390 // no break
392 if ($ref_id &&
393 ilObject::_lookupObjId($ref_id) &&
394 !$tree->isDeleted($ref_id)) {
395 include_once('./Services/Link/classes/class.ilLink.php');
396 return ilLink::_getStaticLink($ref_id, '', true);
397 }
398 // invalid starting object, overview is fallback
399 $current = self::START_PD_OVERVIEW;
400 // fallthrough
401
402 // no break
403 default:
404 $map = array(
405 self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToSelectedItems',
406 self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilMembershipOverviewGUI',
407 self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToWorkspace',
408 self::START_PD_CALENDAR => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToCalendar',
409 self::START_PD_MYSTAFF => 'ilias.php?baseClass=' . ilDashboardGUI::class . '&cmd=' . ilDashboardGUI::CMD_JUMP_TO_MY_STAFF
410 );
411 return $map[$current];
412 }
413 }
414
420 public static function getStartingObject()
421 {
422 global $DIC;
423
424 $ilSetting = $DIC['ilSetting'];
425
426 return $ilSetting->get("usr_starting_point_ref_id");
427 }
428
434 public static function togglePersonalStartingPoint($a_value)
435 {
436 global $DIC;
437
438 $ilSetting = $DIC['ilSetting'];
439
440 $ilSetting->set("usr_starting_point_personal", (bool) $a_value);
441 }
442
448 public static function hasPersonalStartingPoint()
449 {
450 global $DIC;
451
452 $ilSetting = $DIC['ilSetting'];
453
454 return $ilSetting->get("usr_starting_point_personal");
455 }
456
462 public static function hasPersonalStartPointPref()
463 {
464 global $DIC;
465
466 $ilUser = $DIC['ilUser'];
467
468 return (bool) $ilUser->getPref("usr_starting_point");
469 }
470
476 public static function getPersonalStartingPoint()
477 {
478 global $DIC;
479
480 $ilUser = $DIC['ilUser'];
481
482 $valid = array_keys(self::getPossibleStartingPoints());
483 $current = $ilUser->getPref("usr_starting_point");
484 if ($current == self::START_REPOSITORY_OBJ) {
485 return $current;
486 } elseif (!$current || !in_array($current, $valid)) {
487 return self::getStartingPoint();
488 }
489 return $current;
490 }
491
499 public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
500 {
501 global $DIC;
502
503 $ilUser = $DIC['ilUser'];
504 $tree = $DIC['tree'];
505
506 if (!$a_value) {
507 $ilUser->setPref("usr_starting_point", null);
508 $ilUser->setPref("usr_starting_point_ref_id", null);
509 return;
510 }
511
512 if ($a_value == self::START_REPOSITORY_OBJ) {
513 $a_ref_id = (int) $a_ref_id;
514 if (ilObject::_lookupObjId($a_ref_id) &&
515 !$tree->isDeleted($a_ref_id)) {
516 $ilUser->setPref("usr_starting_point", $a_value);
517 $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
518 return true;
519 }
520 }
521 $valid = array_keys(self::getPossibleStartingPoints());
522 if (in_array($a_value, $valid)) {
523 $ilUser->setPref("usr_starting_point", $a_value);
524 return true;
525 }
526 return false;
527 }
528
534 public static function getPersonalStartingObject()
535 {
536 global $DIC;
537
538 $ilUser = $DIC['ilUser'];
539
540 $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
541 if (!$ref_id) {
542 $ref_id = self::getStartingObject();
543 }
544 return $ref_id;
545 }
546}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
static _getInstance()
get singleton instance
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
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
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
global $ilCtrl
Definition: ilias.php:18
global $ilSetting
Definition: privfeed.php:17
$lng
global $ilDB
$data
Definition: storeScorm.php:23
$ilUser
Definition: imgupload.php:18
$lang
Definition: xapiexit.php:8
$DIC
Definition: xapitoken.php:46