ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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, $a_return_data_array = false)
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 $data = array();
76 while ($row = $ilDB->fetchObject($userrow))
77 {
78 $pres = '';
79 $d = array("id" => $row->usr_id, "title" => "", "lastname" => "", "firstname" => "", "img" => "", "link" => "",
80 "public_profile" => "");
81 $has_public_profile = in_array($row->public_profile, array("y", "g"));
82 if ($a_force_first_lastname || $has_public_profile)
83 {
84 $title = "";
85 if($row->public_title == "y" && $row->title)
86 {
87 $title = $row->title . " ";
88 }
89 $d["title"] = $title;
90 if($a_sortable)
91 {
92 $pres = $row->lastname;
93 if(strlen($row->firstname))
94 {
95 $pres .= (', '.$row->firstname.' ');
96 }
97 }
98 else
99 {
100 $pres = $title;
101 if(strlen($row->firstname))
102 {
103 $pres .= $row->firstname.' ';
104 }
105 $pres .= ($row->lastname.' ');
106 }
107 $d["firstname"] = $row->firstname;
108 $d["lastname"] = $row->lastname;
109 }
110 $d["login"] = $row->login;
111 $d["public_profile"] = $has_public_profile;
112
113
114 if(!$a_omit_login)
115 {
116 $pres.= "[".$row->login."]";
117 }
118
119 if ($a_profile_link && $has_public_profile)
120 {
121 $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "user_id", $row->usr_id);
122 if ($a_profile_back_link != "")
123 {
124 $ilCtrl->setParameterByClass("ilpublicuserprofilegui", "back_url",
125 rawurlencode($a_profile_back_link));
126 }
127 $link = $ilCtrl->getLinkTargetByClass("ilpublicuserprofilegui", "getHTML");
128 $pres = '<a href="'.$link.'">'.$pres.'</a>';
129 $d["link"] = $link;
130 }
131
132 if ($a_user_image)
133 {
134 $img = ilObjUser::_getPersonalPicturePath($row->usr_id, "xxsmall");
135 $pres = '<img border="0" src="'.$img.'" alt="'.$lng->txt("icon").
136 " ".$lng->txt("user_picture").'" /> '.$pres;
137 $d["img"] = $img;
138 }
139
140 $names[$row->usr_id] = $pres;
141 $data[$row->usr_id] = $d;
142 }
143
144 foreach($a_user_id as $id)
145 {
146 if (!$names[$id])
147 $names[$id] = "unknown";
148 }
149
150 if ($a_return_data_array)
151 {
152 if ($return_as_array)
153 {
154 return $data;
155 }
156 else
157 {
158 return current($data);
159 }
160 }
161 return $return_as_array ? $names : $names[$a_user_id[0]];
162 }
163
170 static function hasPublicProfile($a_user_id)
171 {
172 global $ilDB;
173
174 $set = $ilDB->query("SELECT value FROM usr_pref ".
175 " WHERE usr_id = ".$ilDB->quote($a_user_id, "integer").
176 " and keyword = ".$ilDB->quote("public_profile", "text")
177 );
178 $rec = $ilDB->fetchAssoc($set);
179
180 return in_array($rec["value"], array("y", "g"));
181 }
182
183
190 public static function getProfileLink($a_usr_id)
191 {
192 $public_profile = ilObjUser::_lookupPref($a_usr_id,'public_profile');
193 if($public_profile != 'y' and $public_profile != 'g')
194 {
195 return '';
196 }
197
198 $GLOBALS['ilCtrl']->setParameterByClass('ilpublicuserprofilegui','user',$a_usr_id);
199 return $GLOBALS['ilCtrl']->getLinkTargetByClass('ilpublicuserprofilegui','getHTML');
200 }
201
202
203 //
204 // Personal starting point
205 //
206
212 public static function getPossibleStartingPoints($a_force_all = false)
213 {
214 global $ilSetting, $lng;
215
216 // for all conditions: see ilMainMenuGUI
217
218 $all = array();
219
220 $all[self::START_PD_OVERVIEW] = 'overview';
221
222 if($a_force_all || ($ilSetting->get('disable_my_offers') == 0 &&
223 $ilSetting->get('disable_my_memberships') == 0))
224 {
225 $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
226 }
227
228 if($a_force_all || !$ilSetting->get("disable_personal_workspace"))
229 {
230 $all[self::START_PD_WORKSPACE] = 'personal_workspace';
231 }
232
233 include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
235 if($a_force_all || $settings->isEnabled())
236 {
237 $all[self::START_PD_CALENDAR] = 'calendar';
238 }
239
240 $all[self::START_REPOSITORY] = 'repository';
241
242 foreach($all as $idx => $lang)
243 {
244 $all[$idx] = $lng->txt($lang);
245 }
246
247 return $all;
248 }
249
257 public static function setStartingPoint($a_value, $a_ref_id = null)
258 {
259 global $ilSetting, $tree;
260
261 if($a_value == self::START_REPOSITORY_OBJ)
262 {
263 $a_ref_id = (int)$a_ref_id;
264 if(ilObject::_lookupObjId($a_ref_id) &&
265 !$tree->isDeleted($a_ref_id))
266 {
267 $ilSetting->set("usr_starting_point", $a_value);
268 $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
269 return true;
270 }
271 }
272 $valid = array_keys(self::getPossibleStartingPoints());
273 if(in_array($a_value, $valid))
274 {
275 $ilSetting->set("usr_starting_point", $a_value);
276 return true;
277 }
278 return false;
279 }
280
286 public static function getStartingPoint()
287 {
288 global $ilSetting, $ilUser;
289
290 $valid = array_keys(self::getPossibleStartingPoints());
291 $current = $ilSetting->get("usr_starting_point");
292 if($current == self::START_REPOSITORY_OBJ)
293 {
294 return $current;
295 }
296 else if(!$current || !in_array($current, $valid))
297 {
298 $current = self::START_PD_OVERVIEW;
299
300 // #10715 - if 1 is disabled overview will display the current default
301 if($ilSetting->get('disable_my_offers') == 0 &&
302 $ilSetting->get('disable_my_memberships') == 0 &&
303 $ilSetting->get('personal_items_default_view') == 1)
304 {
306 }
307
308 self::setStartingPoint($current);
309 }
310 if($ilUser->getId() == ANONYMOUS_USER_ID ||
311 !$ilUser->getId()) // #18531
312 {
313 $current = self::START_REPOSITORY;
314 }
315 return $current;
316 }
317
323 public static function getStartingPointAsUrl()
324 {
325 global $tree, $ilUser;
326
327 $ref_id = 1;
328 if(self::hasPersonalStartingPoint())
329 {
330 $current = self::getPersonalStartingPoint();
331 if($current == self::START_REPOSITORY_OBJ)
332 {
334 }
335 }
336 else
337 {
338 $current = self::getStartingPoint();
339 if($current == self::START_REPOSITORY_OBJ)
340 {
342 }
343 }
344 switch($current)
345 {
348 if($ref_id &&
350 !$tree->isDeleted($ref_id))
351 {
352 include_once('./Services/Link/classes/class.ilLink.php');
353 return ilLink::_getStaticLink($ref_id,'',true);
354 }
355 // invalid starting object, overview is fallback
356 $current = self::START_PD_OVERVIEW;
357 // fallthrough
358
359 default:
360 $map = array(
361 self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems',
362 self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships',
363 // self::START_PD_BOOKMARKS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToBookmarks',
364 // self::START_PD_NOTES => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNotes',
365 // self::START_PD_NEWS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNews',
366 self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace',
367 // self::START_PD_PORTFOLIO => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio',
368 // self::START_PD_SKILLS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSkills',
370 self::START_PD_CALENDAR => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToCalendar',
371 // self::START_PD_MAIL => 'ilias.php?baseClass=ilMailGUI',
372 // self::START_PD_CONTACTS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToContacts',
373 // self::START_PD_PROFILE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToProfile',
374 // self::START_PD_SETTINGS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSettings'
375 );
376 return $map[$current];
377 }
378 }
379
385 public static function getStartingObject()
386 {
387 global $ilSetting;
388
389 return $ilSetting->get("usr_starting_point_ref_id");
390 }
391
397 public static function togglePersonalStartingPoint($a_value)
398 {
399 global $ilSetting;
400
401 $ilSetting->set("usr_starting_point_personal", (bool)$a_value);
402 }
403
409 public static function hasPersonalStartingPoint()
410 {
411 global $ilSetting;
412
413 return $ilSetting->get("usr_starting_point_personal");
414 }
415
421 public static function hasPersonalStartPointPref()
422 {
423 global $ilUser;
424
425 return (bool)$ilUser->getPref("usr_starting_point");
426 }
427
433 public static function getPersonalStartingPoint()
434 {
435 global $ilUser;
436
437 $valid = array_keys(self::getPossibleStartingPoints());
438 $current = $ilUser->getPref("usr_starting_point");
439 if($current == self::START_REPOSITORY_OBJ)
440 {
441 return $current;
442 }
443 else if(!$current || !in_array($current, $valid))
444 {
445 return self::getStartingPoint();
446 }
447 return $current;
448 }
449
457 public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
458 {
459 global $ilUser, $tree;
460
461 if(!$a_value)
462 {
463 $ilUser->setPref("usr_starting_point", null);
464 $ilUser->setPref("usr_starting_point_ref_id", null);
465 return;
466 }
467
468 if($a_value == self::START_REPOSITORY_OBJ)
469 {
470 $a_ref_id = (int)$a_ref_id;
471 if(ilObject::_lookupObjId($a_ref_id) &&
472 !$tree->isDeleted($a_ref_id))
473 {
474 $ilUser->setPref("usr_starting_point", $a_value);
475 $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
476 return true;
477 }
478 }
479 $valid = array_keys(self::getPossibleStartingPoints());
480 if(in_array($a_value, $valid))
481 {
482 $ilUser->setPref("usr_starting_point", $a_value);
483 return true;
484 }
485 return false;
486 }
487
493 public static function getPersonalStartingObject()
494 {
495 global $ilUser;
496
497 $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
498 if(!$ref_id)
499 {
501 }
502 return $ref_id;
503 }
504}
505?>
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.
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.
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)
Default behaviour is:
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
$data
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
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