ILIAS  release_8 Revision v8.24
class.ilUserUtil.php
Go to the documentation of this file.
1<?php
2
21
27{
28 public const START_PD_OVERVIEW = 1;
29 public const START_PD_SUBSCRIPTION = 2;
30 public const START_PD_NOTES = 4;
31 public const START_PD_NEWS = 5;
32 public const START_PD_WORKSPACE = 6;
33 public const START_PD_PORTFOLIO = 7;
34 public const START_PD_SKILLS = 8;
35 public const START_PD_LP = 9;
36 public const START_PD_CALENDAR = 10;
37 public const START_PD_MAIL = 11;
38 public const START_PD_CONTACTS = 12;
39 public const START_PD_PROFILE = 13;
40 public const START_PD_SETTINGS = 14;
41 public const START_REPOSITORY = 15;
42 public const START_REPOSITORY_OBJ = 16;
43 public const START_PD_MYSTAFF = 17;
44
57 public static function getNamePresentation(
58 $a_user_id,
59 bool $a_user_image = false,
60 bool $a_profile_link = false,
61 string $a_profile_back_link = "",
62 bool $a_force_first_lastname = false,
63 bool $a_omit_login = false,
64 bool $a_sortable = true,
65 bool $a_return_data_array = false,
66 $a_ctrl_path = "ilpublicuserprofilegui"
67 ) {
68 global $DIC;
69
70 $lng = $DIC['lng'];
71 $ilCtrl = $DIC['ilCtrl'];
72 $ilDB = $DIC['ilDB'];
73
74 if (!is_array($a_ctrl_path)) {
75 $a_ctrl_path = array($a_ctrl_path);
76 }
77
78 if (!($return_as_array = is_array($a_user_id))) {
79 $a_user_id = array($a_user_id);
80 }
81
82 $sql = 'SELECT
83 a.usr_id,
84 firstname,
85 lastname,
86 title,
87 login,
88 b.value public_profile,
89 c.value public_title
90 FROM
91 usr_data a
92 LEFT JOIN
93 usr_pref b ON
94 (a.usr_id = b.usr_id AND
95 b.keyword = %s)
96 LEFT JOIN
97 usr_pref c ON
98 (a.usr_id = c.usr_id AND
99 c.keyword = %s)
100 WHERE ' . $ilDB->in('a.usr_id', $a_user_id, false, 'integer');
101
102 $userrow = $ilDB->queryF($sql, array('text', 'text'), array('public_profile', 'public_title'));
103
104 $names = array();
105
106 $data = array();
107 while ($row = $ilDB->fetchObject($userrow)) {
108 $pres = '';
109 $d = array(
110 "id" => (int) $row->usr_id,
111 "title" => "",
112 "lastname" => "",
113 "firstname" => "",
114 "img" => "",
115 "link" => ""
116 );
117 $has_public_profile = in_array($row->public_profile, array("y", "g"));
118 if ($a_force_first_lastname || $has_public_profile) {
119 $title = "";
120 if ($row->public_title == "y" && $row->title) {
121 $title = $row->title . " ";
122 }
123 $d["title"] = $title;
124 if ($a_sortable) {
125 $pres = $row->lastname;
126 if (strlen($row->firstname)) {
127 $pres .= (', ' . $row->firstname . ' ');
128 }
129 } else {
130 $pres = $title;
131 if (strlen($row->firstname)) {
132 $pres .= $row->firstname . ' ';
133 }
134 $pres .= ($row->lastname . ' ');
135 }
136 $d["firstname"] = $row->firstname;
137 $d["lastname"] = $row->lastname;
138 }
139 $d["login"] = $row->login;
140 $d["public_profile"] = $has_public_profile;
141
142
143 if (!$a_omit_login) {
144 $pres .= "[" . $row->login . "]";
145 }
146
147 if ($a_profile_link && $has_public_profile) {
148 $ilCtrl->setParameterByClass(end($a_ctrl_path), "user_id", $row->usr_id);
149 if ($a_profile_back_link != "") {
150 $ilCtrl->setParameterByClass(
151 end($a_ctrl_path),
152 "back_url",
153 rawurlencode($a_profile_back_link)
154 );
155 }
156 $link = $ilCtrl->getLinkTargetByClass($a_ctrl_path, "getHTML");
157 $pres = '<a href="' . $link . '">' . $pres . '</a>';
158 $d["link"] = $link;
159 }
160
161 if ($a_user_image) {
162 $img = ilObjUser::_getPersonalPicturePath($row->usr_id, "xxsmall");
163 $pres = '<img class="ilUserXXSmall" src="' . $img . '" alt="' . $lng->txt("icon") .
164 " " . $lng->txt("user_picture") . '" /> ' . $pres;
165 $d["img"] = $img;
166 }
167
168 $names[$row->usr_id] = $pres;
169 $data[$row->usr_id] = $d;
170 }
171
172 foreach ($a_user_id as $id) {
173 if (!isset($names[$id]) || !$names[$id]) {
174 $names[$id] = $lng->txt('usr_name_undisclosed');
175 }
176 }
177
178 if ($a_return_data_array) {
179 if ($return_as_array) {
180 return $data;
181 } else {
182 return current($data);
183 }
184 }
185 return $return_as_array ? $names : $names[$a_user_id[0]];
186 }
187
188 public static function hasPublicProfile(int $a_user_id): bool
189 {
190 global $DIC;
191
192 $ilDB = $DIC['ilDB'];
193
194 $set = $ilDB->query(
195 "SELECT value FROM usr_pref " .
196 " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
197 " and keyword = " . $ilDB->quote("public_profile", "text")
198 );
199 $rec = $ilDB->fetchAssoc($set);
200
201 return in_array($rec["value"] ?? "", array("y", "g"));
202 }
203
204
209 public static function getProfileLink(int $a_usr_id): string
210 {
211 $public_profile = ilObjUser::_lookupPref($a_usr_id, 'public_profile');
212 if ($public_profile != 'y' and $public_profile != 'g') {
213 return '';
214 }
215
216 $GLOBALS['DIC']['ilCtrl']->setParameterByClass('ilpublicuserprofilegui', 'user', $a_usr_id);
217 return $GLOBALS['DIC']['ilCtrl']->getLinkTargetByClass('ilpublicuserprofilegui', 'getHTML');
218 }
219
220
221 //
222 // Personal starting point
223 //
224
229 public static function getPossibleStartingPoints(bool $a_force_all = false): array
230 {
231 global $DIC;
232
233 $ilSetting = $DIC['ilSetting'];
234 $lng = $DIC['lng'];
235
236 // for all conditions: see ilMainMenuGUI
237
238 $all = array();
239
240 $all[self::START_PD_OVERVIEW] = 'mm_dashboard';
241 $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
242
243 if ((new ilMyStaffCachedAccessDecorator($DIC, ilMyStaffAccess::getInstance()))->hasCurrentUserAccessToMyStaff()) {
244 $all[self::START_PD_MYSTAFF] = 'my_staff';
245 }
246
247 if ($a_force_all || !$ilSetting->get("disable_personal_workspace")) {
248 $all[self::START_PD_WORKSPACE] = 'mm_personal_and_shared_r';
249 }
251 if ($a_force_all || $settings->isEnabled()) {
252 $all[self::START_PD_CALENDAR] = 'calendar';
253 }
254
255 $all[self::START_REPOSITORY] = 'obj_root';
256 $all[self::START_REPOSITORY_OBJ] = 'adm_user_starting_point_object';
257
258 foreach ($all as $idx => $lang) {
259 $all[$idx] = $lng->txt($lang);
260 }
261
262 return $all;
263 }
264
268 public static function setStartingPoint(
269 int $a_value,
270 int $a_ref_id = null,
271 array $a_cal_view = []
272 ): bool {
273 global $DIC;
274
275 $ilSetting = $DIC['ilSetting'];
276 $tree = $DIC['tree'];
277
278 if ($a_value == self::START_REPOSITORY_OBJ) {
279 $a_ref_id = (int) $a_ref_id;
280 if (ilObject::_lookupObjId($a_ref_id) &&
281 !$tree->isDeleted($a_ref_id)) {
282 $ilSetting->set("usr_starting_point", $a_value);
283 $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
284 return true;
285 }
286 }
287 $valid = array_keys(self::getPossibleStartingPoints());
288 if (in_array($a_value, $valid)) {
289 $ilSetting->set("usr_starting_point", $a_value);
290 if ($a_value == self::START_PD_CALENDAR) {
291 foreach ($a_cal_view as $key => $value) {
292 $ilSetting->set($key, $value);
293 }
294 }
295 return true;
296 }
297 return false;
298 }
299
303 public static function getStartingPoint(): int
304 {
305 global $DIC;
306
307 $ilSetting = $DIC['ilSetting'];
308 $ilUser = $DIC['ilUser'];
309
310 $valid = array_keys(self::getPossibleStartingPoints());
311 $current = $ilSetting->get("usr_starting_point");
312 if ($current == self::START_REPOSITORY_OBJ) {
313 return $current;
314 } elseif (!$current || !in_array($current, $valid)) {
315 $current = self::START_PD_OVERVIEW;
316
317 // #10715 - if 1 is disabled overview will display the current default
318 if ($ilSetting->get('disable_my_offers') == 0 &&
319 $ilSetting->get('disable_my_memberships') == 0 &&
320 $ilSetting->get('personal_items_default_view') == 1) {
321 $current = self::START_PD_SUBSCRIPTION;
322 }
323
324 self::setStartingPoint($current);
325 }
326 if ($ilUser->getId() == ANONYMOUS_USER_ID ||
327 !$ilUser->getId()) { // #18531
328 $current = self::START_REPOSITORY;
329 }
330 return $current;
331 }
332
333 public static function getStartingPointAsUrl(): string
334 {
336 global $DIC;
337
338 $log = $DIC->logger()->root();
339 $tree = $DIC['tree'];
340 $ilUser = $DIC['ilUser'];
341 $ilSetting = $DIC['ilSetting'];
342 $rbacreview = $DIC['rbacreview'];
343 $rbacsystem = $DIC['rbacsystem'];
344
345 $ref_id = 1;
346 $by_default = true;
347 $current = 0;
348
349 //configuration by user preference
350 #21782
351 if (self::hasPersonalStartingPoint() && $ilUser->getPref('usr_starting_point') != null) {
352 $current = self::getPersonalStartingPoint();
353 if ($current == self::START_REPOSITORY_OBJ) {
354 $ref_id = self::getPersonalStartingObject();
355 }
356 } else {
357 //getting all roles with starting points and store them in array
359
360 $roles_ids = array_keys($roles);
361 $gr = array();
362 foreach ($roles_ids as $role_id) {
363 if ($rbacreview->isAssigned($ilUser->getId(), $role_id)) {
364 $gr[$roles[$role_id]['position']] = array(
365 "point" => $roles[$role_id]['starting_point'],
366 "object" => $roles[$role_id]['starting_object'],
367 "cal_view" => $roles[$role_id]['calendar_view'],
368 "cal_period" => $roles[$role_id]['calendar_period']
369 );
370 }
371 }
372 if (!empty($gr)) {
373 krsort($gr); // ak: if we use array_pop (last element) we need to reverse sort, since we want the one with the smallest number
374 $role_point = array_pop($gr);
375 $current = $role_point['point'];
376 $ref_id = $role_point['object'];
377 $cal_view = $role_point['cal_view'];
378 $cal_period = $role_point['cal_period'];
379 $by_default = false;
380 }
381
382 if ($by_default) {
383 $current = self::getStartingPoint();
384
385 $cal_view = self::getCalendarView();
386 $cal_period = self::getCalendarPeriod();
387 if ($current == self::START_REPOSITORY_OBJ) {
388 $ref_id = self::getStartingObject();
389 }
390 }
391 }
392
393 $calendar_string = "";
394 if (!empty($cal_view) && !empty($cal_period)) {
395 $calendar_string = "&cal_view=" . $cal_view . "&cal_agenda_per=" . $cal_period;
396 }
397
398 if ($current === self::START_REPOSITORY_OBJ
399 && (
400 $ref_id === null
401 || !$rbacsystem->checkAccessOfUser(
402 $ilUser->getId(),
403 'read',
404 $ref_id
405 )
406 )
407 ) {
408 $log->debug(sprintf('Permission to Starting Point Denied. Starting Point Type: %s.', $current));
409 $current = self::START_REPOSITORY;
410 }
411
412 if ($current === self::START_REPOSITORY
413 && !$rbacsystem->checkAccessOfUser(
414 $ilUser->getId(),
415 'read',
416 $tree->getRootId()
417 )
418 || $current === self::START_PD_CALENDAR
419 && !ilCalendarSettings::_getInstance()->isEnabled()
420 ) {
421 $log->debug(sprintf('Permission to Starting Point Denied. Starting Point Type: %s.', $current));
422 $current = self::START_PD_OVERVIEW;
423
424 // #10715 - if 1 is disabled overview will display the current default
425 if ($ilSetting->get('disable_my_offers') == 0 &&
426 $ilSetting->get('disable_my_memberships') == 0 &&
427 $ilSetting->get('personal_items_default_view') == 1) {
428 $log->debug(sprintf('Permission to Starting Point Denied. Starting Point Type: %s.', $current));
429 $current = self::START_PD_SUBSCRIPTION;
430 }
431 }
432
433 switch ($current) {
434 case self::START_REPOSITORY:
435 $ref_id = $tree->readRootId();
436
437 // no break
438 case self::START_REPOSITORY_OBJ:
439 if ($ref_id &&
441 !$tree->isDeleted($ref_id)) {
442 return ilLink::_getStaticLink($ref_id, '', true);
443 }
444 // invalid starting object, overview is fallback
445 $current = self::START_PD_OVERVIEW;
446 // fallthrough
447
448 // no break
449 default:
450 $map = array(
451 self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToSelectedItems',
452 self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilMembershipOverviewGUI',
453 self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToWorkspace',
454 self::START_PD_CALENDAR => 'ilias.php?baseClass=ilDashboardGUI&cmd=jumpToCalendar' . $calendar_string,
455 self::START_PD_MYSTAFF => 'ilias.php?baseClass=' . ilDashboardGUI::class . '&cmd=' . ilDashboardGUI::CMD_JUMP_TO_MY_STAFF
456 );
457 return $map[$current];
458 }
459 }
460
464 public static function getStartingObject(): ?int
465 {
466 global $DIC;
467
468 $ilSetting = $DIC['ilSetting'];
469
470 return $ilSetting->get("usr_starting_point_ref_id");
471 }
472
476 public static function getCalendarView(): int
477 {
478 global $DIC;
479
480 $ilSetting = $DIC['ilSetting'];
481
482 return (int) $ilSetting->get("user_calendar_view");
483 }
484
488 public static function getCalendarPeriod(): int
489 {
490 global $DIC;
491
492 $ilSetting = $DIC['ilSetting'];
493
494 return (int) $ilSetting->get("user_cal_period");
495 }
496
500 public static function togglePersonalStartingPoint(bool $a_value): void
501 {
502 global $DIC;
503
504 $ilSetting = $DIC['ilSetting'];
505
506 $ilSetting->set("usr_starting_point_personal", (string) $a_value);
507 }
508
512 public static function hasPersonalStartingPoint(): bool
513 {
514 global $DIC;
515
516 $ilSetting = $DIC['ilSetting'];
517
518 return (bool) $ilSetting->get("usr_starting_point_personal");
519 }
520
524 public static function hasPersonalStartPointPref(): bool
525 {
526 global $DIC;
527
528 $ilUser = $DIC['ilUser'];
529
530 return (bool) $ilUser->getPref("usr_starting_point");
531 }
532
536 public static function getPersonalStartingPoint(): int
537 {
538 global $DIC;
539
540 $ilUser = $DIC['ilUser'];
541
542 $valid = array_keys(self::getPossibleStartingPoints());
543 $current = $ilUser->getPref("usr_starting_point");
544 if ($current == self::START_REPOSITORY_OBJ) {
545 return $current;
546 } elseif (!$current || !in_array($current, $valid)) {
547 return self::getStartingPoint();
548 }
549 return $current;
550 }
551
555 public static function setPersonalStartingPoint(
556 int $a_value,
557 int $a_ref_id = null
558 ): bool {
559 global $DIC;
560
561 $ilUser = $DIC['ilUser'];
562 $tree = $DIC['tree'];
563
564 if (!$a_value) {
565 $ilUser->setPref("usr_starting_point", null);
566 $ilUser->setPref("usr_starting_point_ref_id", null);
567 return false;
568 }
569
570 if ($a_value == self::START_REPOSITORY_OBJ) {
571 $a_ref_id = (int) $a_ref_id;
572 if (ilObject::_lookupObjId($a_ref_id) &&
573 !$tree->isDeleted($a_ref_id)) {
574 $ilUser->setPref("usr_starting_point", $a_value);
575 $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
576 return true;
577 }
578 }
579 $valid = array_keys(self::getPossibleStartingPoints());
580 if (in_array($a_value, $valid)) {
581 $ilUser->setPref("usr_starting_point", $a_value);
582 return true;
583 }
584 return false;
585 }
586
590 public static function getPersonalStartingObject(): ?int
591 {
592 global $DIC;
593
594 $ilUser = $DIC['ilUser'];
595
596 $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
597 if (!$ref_id) {
598 $ref_id = self::getStartingObject();
599 }
600 return $ref_id;
601 }
602}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
static _lookupPref(int $a_usr_id, string $a_keyword)
static _lookupObjId(int $ref_id)
static getRolesWithStartingPoint()
get array with all roles which have starting point defined.
Class ilUserUtil.
static getCalendarPeriod()
Get time frame of calendar view.
static getPossibleStartingPoints(bool $a_force_all=false)
Get all valid starting points.
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
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(int $a_user_id)
static getProfileLink(int $a_usr_id)
Get link to personal profile Return empty string in case of not public profile.
const START_PD_SETTINGS
const START_PD_CONTACTS
const START_PD_WORKSPACE
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static getPersonalStartingPoint()
Get current personal starting point.
static togglePersonalStartingPoint(bool $a_value)
Toggle personal starting point setting.
const START_PD_CALENDAR
const START_PD_OVERVIEW
static getStartingPoint()
Get current starting point setting.
static getStartingObject()
Get ref id of starting object.
const START_REPOSITORY_OBJ
static setStartingPoint(int $a_value, int $a_ref_id=null, array $a_cal_view=[])
Set starting point setting.
const START_PD_SUBSCRIPTION
static setPersonalStartingPoint(int $a_value, int $a_ref_id=null)
Set personal starting point setting.
const ANONYMOUS_USER_ID
Definition: constants.php:27
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
$valid
global $DIC
Definition: feed.php:28
$img
Definition: imgupload.php:83
$ilUser
Definition: imgupload.php:34
$ref_id
Definition: ltiauth.php:67
string $key
Consumer key/client ID value.
Definition: System.php:193
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
global $ilSetting
Definition: privfeed.php:17
$log
Definition: result.php:33
$lng
$lang
Definition: xapiexit.php:26