ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
14  const START_PD_OVERVIEW = 1;
16  const START_PD_BOOKMARKS = 3;
17  const START_PD_NOTES = 4;
18  const START_PD_NEWS = 5;
19  const START_PD_WORKSPACE = 6;
20  const START_PD_PORTFOLIO = 7;
21  const START_PD_SKILLS = 8;
22  const START_PD_LP = 9;
23  const START_PD_CALENDAR = 10;
24  const START_PD_MAIL = 11;
25  const START_PD_CONTACTS = 12;
26  const START_PD_PROFILE= 13;
27  const START_PD_SETTINGS = 14;
28  const START_REPOSITORY= 15;
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", $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');
190  $settings = ilCalendarSettings::_getInstance();
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  {
261  $current = self::START_PD_SUBSCRIPTION;
262  }
263 
264  self::setStartingPoint($current);
265  }
266  if($ilUser->getId() == ANONYMOUS_USER_ID)
267  {
268  $current = self::START_REPOSITORY;
269  }
270  return $current;
271  }
272 
278  public static function getStartingPointAsUrl()
279  {
280  global $tree, $ilUser;
281 
282  $ref_id = 1;
283  if(self::hasPersonalStartingPoint())
284  {
285  $current = self::getPersonalStartingPoint();
286  if($current == self::START_REPOSITORY_OBJ)
287  {
289  }
290  }
291  else
292  {
293  $current = self::getStartingPoint();
294  if($current == self::START_REPOSITORY_OBJ)
295  {
297  }
298  }
299  switch($current)
300  {
301  case self::START_REPOSITORY:
302  case self::START_REPOSITORY_OBJ:
303  if($ref_id &&
305  !$tree->isDeleted($ref_id))
306  {
307  include_once('./Services/Link/classes/class.ilLink.php');
308  return ilLink::_getStaticLink($ref_id,'',true);
309  }
310  // invalid starting object, overview is fallback
311  $current = self::START_PD_OVERVIEW;
312  // fallthrough
313 
314  default:
315  $map = array(
316  self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems',
317  self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships',
318  // self::START_PD_BOOKMARKS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToBookmarks',
319  // self::START_PD_NOTES => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNotes',
320  // self::START_PD_NEWS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNews',
321  self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace',
322  // self::START_PD_PORTFOLIO => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio',
323  // self::START_PD_SKILLS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSkills',
325  self::START_PD_CALENDAR => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToCalendar',
326  // self::START_PD_MAIL => 'ilias.php?baseClass=ilMailGUI',
327  // self::START_PD_CONTACTS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToContacts',
328  // self::START_PD_PROFILE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToProfile',
329  // self::START_PD_SETTINGS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSettings'
330  );
331  return $map[$current];
332  }
333  }
334 
340  public static function getStartingObject()
341  {
342  global $ilSetting;
343 
344  return $ilSetting->get("usr_starting_point_ref_id");
345  }
346 
352  public static function togglePersonalStartingPoint($a_value)
353  {
354  global $ilSetting;
355 
356  $ilSetting->set("usr_starting_point_personal", (bool)$a_value);
357  }
358 
364  public static function hasPersonalStartingPoint()
365  {
366  global $ilSetting;
367 
368  return $ilSetting->get("usr_starting_point_personal");
369  }
370 
371 
377  public static function getPersonalStartingPoint()
378  {
379  global $ilUser;
380 
381  $valid = array_keys(self::getPossibleStartingPoints());
382  $current = $ilUser->getPref("usr_starting_point");
383  if($current == self::START_REPOSITORY_OBJ)
384  {
385  return $current;
386  }
387  else if(!$current || !in_array($current, $valid))
388  {
389  return self::getStartingPoint();
390  }
391  return $current;
392  }
393 
401  public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
402  {
403  global $ilUser, $tree;
404 
405  if($a_value == self::START_REPOSITORY_OBJ)
406  {
407  $a_ref_id = (int)$a_ref_id;
408  if(ilObject::_lookupObjId($a_ref_id) &&
409  !$tree->isDeleted($a_ref_id))
410  {
411  $ilUser->setPref("usr_starting_point", $a_value);
412  $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
413  return true;
414  }
415  }
416  $valid = array_keys(self::getPossibleStartingPoints());
417  if(in_array($a_value, $valid))
418  {
419  $ilUser->setPref("usr_starting_point", $a_value);
420  return true;
421  }
422  return false;
423  }
424 
430  public static function getPersonalStartingObject()
431  {
432  global $ilUser;
433 
434  $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
435  if(!$ref_id)
436  {
438  }
439  return $ref_id;
440  }
441 }
442 ?>