ILIAS  release_7 Revision v7.30-3-g800a261c036
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 $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
232
233 if (ilMyStaffAccess::getInstance()->hasCurrentUserAccessToMyStaff()) {
234 $all[self::START_PD_MYSTAFF] = 'my_staff';
235 }
236
237 if ($a_force_all || !$ilSetting->get("disable_personal_workspace")) {
238 $all[self::START_PD_WORKSPACE] = 'mm_personal_and_shared_r';
239 }
240
241 include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
243 if ($a_force_all || $settings->isEnabled()) {
244 $all[self::START_PD_CALENDAR] = 'calendar';
245 }
246
247 $all[self::START_REPOSITORY] = 'obj_root';
248
249 foreach ($all as $idx => $lang) {
250 $all[$idx] = $lng->txt($lang);
251 }
252
253 return $all;
254 }
255
264 public static function setStartingPoint($a_value, $a_ref_id = null, $a_cal_view = [])
265 {
266 global $DIC;
267
268 $ilSetting = $DIC['ilSetting'];
269 $tree = $DIC['tree'];
270
271 if ($a_value == self::START_REPOSITORY_OBJ) {
272 $a_ref_id = (int) $a_ref_id;
273 if (ilObject::_lookupObjId($a_ref_id) &&
274 !$tree->isDeleted($a_ref_id)) {
275 $ilSetting->set("usr_starting_point", $a_value);
276 $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
277 return true;
278 }
279 }
280 $valid = array_keys(self::getPossibleStartingPoints());
281 if (in_array($a_value, $valid)) {
282 $ilSetting->set("usr_starting_point", $a_value);
283 if ($a_value == self::START_PD_CALENDAR) {
284 foreach ($a_cal_view as $key => $value) {
285 $ilSetting->set($key, $value);
286 }
287 }
288 return true;
289 }
290 return false;
291 }
292
298 public static function getStartingPoint()
299 {
300 global $DIC;
301
302 $ilSetting = $DIC['ilSetting'];
303 $ilUser = $DIC['ilUser'];
304
305 $valid = array_keys(self::getPossibleStartingPoints());
306 $current = $ilSetting->get("usr_starting_point");
307 if ($current == self::START_REPOSITORY_OBJ) {
308 return $current;
309 } elseif (!$current || !in_array($current, $valid)) {
310 $current = self::START_PD_OVERVIEW;
311
312 // #10715 - if 1 is disabled overview will display the current default
313 if ($ilSetting->get('disable_my_offers') == 0 &&
314 $ilSetting->get('disable_my_memberships') == 0 &&
315 $ilSetting->get('personal_items_default_view') == 1) {
317 }
318
319 self::setStartingPoint($current);
320 }
321 if ($ilUser->getId() == ANONYMOUS_USER_ID ||
322 !$ilUser->getId()) { // #18531
323 $current = self::START_REPOSITORY;
324 }
325 return $current;
326 }
327
333 public static function getStartingPointAsUrl()
334 {
336 global $DIC;
337
338 $log = $DIC->logger()->root();
339 $lng = $DIC['lng'];
340 $tree = $DIC['tree'];
341 $ilUser = $DIC['ilUser'];
342 $ilSetting = $DIC['ilSetting'];
343 $rbacreview = $DIC['rbacreview'];
344 $rbacsystem = $DIC['rbacsystem'];
345
346 $ref_id = 1;
347 $by_default = true;
348
349 //configuration by user preference
350 #21782
351 if (self::hasPersonalStartingPoint() && $ilUser->getPref('usr_starting_point') != null) {
353 if ($current == self::START_REPOSITORY_OBJ) {
355 }
356 } else {
357 include_once './Services/AccessControl/classes/class.ilStartingPoint.php';
358
359 //getting all roles with starting points and store them in array
361
362 $roles_ids = array_keys($roles);
363 $gr = array();
364 foreach ($roles_ids as $role_id) {
365 if ($rbacreview->isAssigned($ilUser->getId(), $role_id)) {
366 $gr[$roles[$role_id]['position']] = array(
367 "point" => $roles[$role_id]['starting_point'],
368 "object" => $roles[$role_id]['starting_object'],
369 "cal_view" => $roles[$role_id]['calendar_view'],
370 "cal_period" => $roles[$role_id]['calendar_period']
371 );
372 }
373 }
374 if (!empty($gr)) {
375 krsort($gr); // ak: if we use array_pop (last element) we need to reverse sort, since we want the one with the smallest number
376 $role_point = array_pop($gr);
377 $current = $role_point['point'];
378 $ref_id = $role_point['object'];
379 $cal_view = $role_point['cal_view'];
380 $cal_period = $role_point['cal_period'];
381 $by_default = false;
382 }
383
384 if ($by_default) {
385 $current = self::getStartingPoint();
386
387 $cal_view = self::getCalendarView();
388 $cal_period = self::getCalendarPeriod();
389 if ($current == self::START_REPOSITORY_OBJ) {
390 $ref_id = self::getStartingObject();
391 }
392 }
393 }
394
395 $calendar_string = "";
396 if (!empty($cal_view) && !empty($cal_period)) {
397 $calendar_string = "&cal_view=" . $cal_view . "&cal_agenda_per=" . $cal_period;
398 }
399
400 if ($current == self::START_REPOSITORY_OBJ
401 && (
402 $ref_id === null
403 || !$rbacsystem->checkAccessOfUser(
404 $ilUser->getId(),
405 'read',
406 $ref_id
407 )
408 )
409 ) {
410 $log->warning(sprintf('Permission to Starting Point Denied. Starting Point Type: %s.', $current));
411 $current = self::START_REPOSITORY;
412 }
413
414 if ($current == self::START_REPOSITORY
415 && !$rbacsystem->checkAccessOfUser(
416 $ilUser->getId(),
417 'read',
418 $tree->getRootId()
419 )
420 || $current == self::START_PD_CALENDAR
421 && !ilCalendarSettings::_getInstance()->isEnabled()
422 ) {
423 $log->warning(sprintf('Permission to Starting Point Denied. Starting Point Type: %s.', $current));
424 $current = self::START_PD_OVERVIEW;
425
426 // #10715 - if 1 is disabled overview will display the current default
427 if ($ilSetting->get('disable_my_offers') == 0 &&
428 $ilSetting->get('disable_my_memberships') == 0 &&
429 $ilSetting->get('personal_items_default_view') == 1) {
430 $log->warning(sprintf('Permission to Starting Point Denied. Starting Point Type: %s.', $current));
432 }
433 }
434
435 switch ($current) {
437 $ref_id = $tree->readRootId();
438
439 // no break
441 if ($ref_id &&
442 ilObject::_lookupObjId($ref_id) &&
443 !$tree->isDeleted($ref_id)) {
444 include_once('./Services/Link/classes/class.ilLink.php');
445 return ilLink::_getStaticLink($ref_id, '', true);
446 }
447 // invalid starting object, overview is fallback
448 $current = self::START_PD_OVERVIEW;
449 // fallthrough
450
451 // no break
452 default:
453 $map = array(
454 self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToSelectedItems',
455 self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilMembershipOverviewGUI',
456 self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToWorkspace',
457 self::START_PD_CALENDAR => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToCalendar' . $calendar_string,
458 self::START_PD_MYSTAFF => 'ilias.php?baseClass=' . ilDashboardGUI::class . '&cmd=' . ilDashboardGUI::CMD_JUMP_TO_MY_STAFF
459 );
460 return $map[$current];
461 }
462 }
463
469 public static function getStartingObject()
470 {
471 global $DIC;
472
473 $ilSetting = $DIC['ilSetting'];
474
475 return $ilSetting->get("usr_starting_point_ref_id");
476 }
477
483 public static function getCalendarView()
484 {
485 global $DIC;
486
487 $ilSetting = $DIC['ilSetting'];
488
489 return $ilSetting->get("user_calendar_view");
490 }
491
497 public static function getCalendarPeriod()
498 {
499 global $DIC;
500
501 $ilSetting = $DIC['ilSetting'];
502
503 return $ilSetting->get("user_cal_period");
504 }
505
511 public static function togglePersonalStartingPoint($a_value)
512 {
513 global $DIC;
514
515 $ilSetting = $DIC['ilSetting'];
516
517 $ilSetting->set("usr_starting_point_personal", (bool) $a_value);
518 }
519
525 public static function hasPersonalStartingPoint()
526 {
527 global $DIC;
528
529 $ilSetting = $DIC['ilSetting'];
530
531 return $ilSetting->get("usr_starting_point_personal");
532 }
533
539 public static function hasPersonalStartPointPref()
540 {
541 global $DIC;
542
543 $ilUser = $DIC['ilUser'];
544
545 return (bool) $ilUser->getPref("usr_starting_point");
546 }
547
553 public static function getPersonalStartingPoint()
554 {
555 global $DIC;
556
557 $ilUser = $DIC['ilUser'];
558
559 $valid = array_keys(self::getPossibleStartingPoints());
560 $current = $ilUser->getPref("usr_starting_point");
561 if ($current == self::START_REPOSITORY_OBJ) {
562 return $current;
563 } elseif (!$current || !in_array($current, $valid)) {
564 return self::getStartingPoint();
565 }
566 return $current;
567 }
568
576 public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
577 {
578 global $DIC;
579
580 $ilUser = $DIC['ilUser'];
581 $tree = $DIC['tree'];
582
583 if (!$a_value) {
584 $ilUser->setPref("usr_starting_point", null);
585 $ilUser->setPref("usr_starting_point_ref_id", null);
586 return;
587 }
588
589 if ($a_value == self::START_REPOSITORY_OBJ) {
590 $a_ref_id = (int) $a_ref_id;
591 if (ilObject::_lookupObjId($a_ref_id) &&
592 !$tree->isDeleted($a_ref_id)) {
593 $ilUser->setPref("usr_starting_point", $a_value);
594 $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
595 return true;
596 }
597 }
598 $valid = array_keys(self::getPossibleStartingPoints());
599 if (in_array($a_value, $valid)) {
600 $ilUser->setPref("usr_starting_point", $a_value);
601 return true;
602 }
603 return false;
604 }
605
611 public static function getPersonalStartingObject()
612 {
613 global $DIC;
614
615 $ilUser = $DIC['ilUser'];
616
617 $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
618 if (!$ref_id) {
619 $ref_id = self::getStartingObject();
620 }
621 return $ref_id;
622 }
623}
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 _lookupPref($a_usr_id, $a_keyword)
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false, $html_export=false)
Get path to personal picture.
static _lookupObjId($a_id)
static getRolesWithStartingPoint()
get array with all roles which have starting point defined.
Class ilUserUtil.
static getCalendarPeriod()
Get time frame of calendar view.
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 getCalendarView()
Get specific view of calendar starting point.
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 setStartingPoint($a_value, $a_ref_id=null, $a_cal_view=[])
Set starting point setting.
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 getStartingObject()
Get ref id of starting object.
const START_REPOSITORY_OBJ
const START_PD_SUBSCRIPTION
const ANONYMOUS_USER_ID
Definition: constants.php:25
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$valid
global $DIC
Definition: goto.php:24
$img
Definition: imgupload.php:57
$ilUser
Definition: imgupload.php:18
global $ilSetting
Definition: privfeed.php:17
$log
Definition: result.php:15
$lng
global $ilDB
$data
Definition: storeScorm.php:23
$lang
Definition: xapiexit.php:8