ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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;
30
42 static function getNamePresentation($a_user_id,
43 $a_user_image = false, $a_profile_link = false, $a_profile_back_link = "",
44 $a_force_first_lastname = false, $a_omit_login = false, $a_sortable = true)
45 {
46 global $lng, $ilCtrl, $ilDB;
47
48 if (!($return_as_array = is_array($a_user_id)))
49 $a_user_id = array($a_user_id);
50
51 $sql = 'SELECT
52 a.usr_id,
53 firstname,
54 lastname,
55 title,
56 login,
57 b.value public_profile,
58 c.value public_title
59 FROM
60 usr_data a
61 LEFT JOIN
62 usr_pref b ON
63 (a.usr_id = b.usr_id AND
64 b.keyword = %s)
65 LEFT JOIN
66 usr_pref c ON
67 (a.usr_id = c.usr_id AND
68 c.keyword = %s)
69 WHERE ' . $ilDB->in('a.usr_id', $a_user_id, false, 'integer');
70
71 $userrow = $ilDB->queryF($sql, array('text', 'text'), array('public_profile', 'public_title'));
72
73 $names = array();
74
75 while ($row = $ilDB->fetchObject($userrow))
76 {
77 if ($a_force_first_lastname ||
78 $has_public_profile = in_array($row->public_profile, array("y", "g")))
79 {
80 $title = "";
81 if($row->public_title == "y" && $row->title)
82 {
83 $title = $row->title . " ";
84 }
85 if($a_sortable)
86 {
87 $pres = $row->lastname;
88 if(strlen($row->firstname))
89 {
90 $pres .= (', '.$row->firstname.' ');
91 }
92 }
93 else
94 {
95 $pres = $title;
96 if(strlen($row->firstname))
97 {
98 $pres .= $row->firstname.' ';
99 }
100 $pres .= ($row->lastname.' ');
101 }
102
103 }
104
105 if(!$a_omit_login)
106 {
107 $pres.= "[".$row->login."]";
108 }
109
110 if ($a_profile_link && $has_public_profile)
111 {
112 $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $row->usr_id);
113 if ($a_profile_back_link != "")
114 {
115 $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "back_url",
116 rawurlencode($a_profile_back_link));
117 }
118 $pres = '<a href="'.$ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML").'">'.$pres.'</a>';
119 }
120
121 if ($a_user_image)
122 {
123 $img = ilObjUser::_getPersonalPicturePath($row->usr_id, "xxsmall");
124 $pres = '<img border="0" src="'.$img.'" alt="'.$lng->txt("icon").
125 " ".$lng->txt("user_picture").'" /> '.$pres;
126 }
127
128 $names[$row->usr_id] = $pres;
129 }
130
131 foreach($a_user_id as $id)
132 {
133 if (!$names[$id])
134 $names[$id] = "unknown";
135 }
136
137 return $return_as_array ? $names : $names[$a_user_id[0]];
138 }
139
146 public static function getProfileLink($a_usr_id)
147 {
148 $public_profile = ilObjUser::_lookupPref($a_usr_id,'public_profile');
149 if($public_profile != 'y' and $public_profile != 'g')
150 {
151 return '';
152 }
153
154 $GLOBALS['ilCtrl']->setParameterByClass('ilpublicuserprofilegui','user',$a_usr_id);
155 return $GLOBALS['ilCtrl']->getLinkTargetByClass('ilpublicuserprofilegui','getHTML');
156 }
157
158
159 //
160 // Personal starting point
161 //
162
168 public static function getPossibleStartingPoints($a_force_all = false)
169 {
170 global $ilSetting, $lng;
171
172 // for all conditions: see ilMainMenuGUI
173
174 $all = array();
175
176 $all[self::START_PD_OVERVIEW] = 'overview';
177
178 if($a_force_all || ($ilSetting->get('disable_my_offers') == 0 &&
179 $ilSetting->get('disable_my_memberships') == 0))
180 {
181 $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
182 }
183
184 if($a_force_all || !$ilSetting->get("disable_personal_workspace"))
185 {
186 $all[self::START_PD_WORKSPACE] = 'personal_workspace';
187 }
188
189 include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
191 if($a_force_all || $settings->isEnabled())
192 {
193 $all[self::START_PD_CALENDAR] = 'calendar';
194 }
195
196 $all[self::START_REPOSITORY] = 'repository';
197
198 foreach($all as $idx => $lang)
199 {
200 $all[$idx] = $lng->txt($lang);
201 }
202
203 return $all;
204 }
205
213 public static function setStartingPoint($a_value, $a_ref_id = null)
214 {
215 global $ilSetting, $tree;
216
217 if($a_value == self::START_REPOSITORY_OBJ)
218 {
219 $a_ref_id = (int)$a_ref_id;
220 if(ilObject::_lookupObjId($a_ref_id) &&
221 !$tree->isDeleted($a_ref_id))
222 {
223 $ilSetting->set("usr_starting_point", $a_value);
224 $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
225 return true;
226 }
227 }
228 $valid = array_keys(self::getPossibleStartingPoints());
229 if(in_array($a_value, $valid))
230 {
231 $ilSetting->set("usr_starting_point", $a_value);
232 return true;
233 }
234 return false;
235 }
236
242 public static function getStartingPoint()
243 {
244 global $ilSetting, $ilUser;
245
246 $valid = array_keys(self::getPossibleStartingPoints());
247 $current = $ilSetting->get("usr_starting_point");
248 if($current == self::START_REPOSITORY_OBJ)
249 {
250 return $current;
251 }
252 else if(!$current || !in_array($current, $valid))
253 {
254 $current = self::START_PD_OVERVIEW;
255
256 // #10715 - if 1 is disabled overview will display the current default
257 if($ilSetting->get('disable_my_offers') == 0 &&
258 $ilSetting->get('disable_my_memberships') == 0 &&
259 $ilSetting->get('personal_items_default_view') == 1)
260 {
262 }
263
264 self::setStartingPoint($current);
265 }
266 if($ilUser->getId() == ANONYMOUS_USER_ID ||
267 !$ilUser->getId()) // #18531
268 {
269 $current = self::START_REPOSITORY;
270 }
271 return $current;
272 }
273
279 public static function getStartingPointAsUrl()
280 {
281 global $tree, $ilUser;
282
283 $ref_id = 1;
284 if(self::hasPersonalStartingPoint())
285 {
286 $current = self::getPersonalStartingPoint();
287 if($current == self::START_REPOSITORY_OBJ)
288 {
290 }
291 }
292 else
293 {
294 $current = self::getStartingPoint();
295 if($current == self::START_REPOSITORY_OBJ)
296 {
298 }
299 }
300 switch($current)
301 {
304 if($ref_id &&
306 !$tree->isDeleted($ref_id))
307 {
308 include_once('./Services/Link/classes/class.ilLink.php');
309 return ilLink::_getStaticLink($ref_id,'',true);
310 }
311 // invalid starting object, overview is fallback
312 $current = self::START_PD_OVERVIEW;
313 // fallthrough
314
315 default:
316 $map = array(
317 self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems',
318 self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships',
319 // self::START_PD_BOOKMARKS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToBookmarks',
320 // self::START_PD_NOTES => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNotes',
321 // self::START_PD_NEWS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNews',
322 self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace',
323 // self::START_PD_PORTFOLIO => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio',
324 // self::START_PD_SKILLS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSkills',
326 self::START_PD_CALENDAR => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToCalendar',
327 // self::START_PD_MAIL => 'ilias.php?baseClass=ilMailGUI',
328 // self::START_PD_CONTACTS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToContacts',
329 // self::START_PD_PROFILE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToProfile',
330 // self::START_PD_SETTINGS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSettings'
331 );
332 return $map[$current];
333 }
334 }
335
341 public static function getStartingObject()
342 {
343 global $ilSetting;
344
345 return $ilSetting->get("usr_starting_point_ref_id");
346 }
347
353 public static function togglePersonalStartingPoint($a_value)
354 {
355 global $ilSetting;
356
357 $ilSetting->set("usr_starting_point_personal", (bool)$a_value);
358 }
359
365 public static function hasPersonalStartingPoint()
366 {
367 global $ilSetting;
368
369 return $ilSetting->get("usr_starting_point_personal");
370 }
371
377 public static function hasPersonalStartPointPref()
378 {
379 global $ilUser;
380
381 return (bool)$ilUser->getPref("usr_starting_point");
382 }
383
389 public static function getPersonalStartingPoint()
390 {
391 global $ilUser;
392
393 $valid = array_keys(self::getPossibleStartingPoints());
394 $current = $ilUser->getPref("usr_starting_point");
395 if($current == self::START_REPOSITORY_OBJ)
396 {
397 return $current;
398 }
399 else if(!$current || !in_array($current, $valid))
400 {
401 return self::getStartingPoint();
402 }
403 return $current;
404 }
405
413 public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
414 {
415 global $ilUser, $tree;
416
417 if(!$a_value)
418 {
419 $ilUser->setPref("usr_starting_point", null);
420 $ilUser->setPref("usr_starting_point_ref_id", null);
421 return;
422 }
423
424 if($a_value == self::START_REPOSITORY_OBJ)
425 {
426 $a_ref_id = (int)$a_ref_id;
427 if(ilObject::_lookupObjId($a_ref_id) &&
428 !$tree->isDeleted($a_ref_id))
429 {
430 $ilUser->setPref("usr_starting_point", $a_value);
431 $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
432 return true;
433 }
434 }
435 $valid = array_keys(self::getPossibleStartingPoints());
436 if(in_array($a_value, $valid))
437 {
438 $ilUser->setPref("usr_starting_point", $a_value);
439 return true;
440 }
441 return false;
442 }
443
449 public static function getPersonalStartingObject()
450 {
451 global $ilUser;
452
453 $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
454 if(!$ref_id)
455 {
457 }
458 return $ref_id;
459 }
460}
461?>
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.
_lookupPref($a_usr_id, $a_keyword)
static _lookupObjId($a_id)
Class ilUserUtil.
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)
Default behaviour is:
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?
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 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.
$valid
$GLOBALS['ct_recipient']
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:40
global $ilSetting
Definition: privfeed.php:40
$ref_id
Definition: sahs_server.php:39
global $ilDB
global $ilUser
Definition: imgupload.php:15