ILIAS  release_4-3 Revision
 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 
140 
141  //
142  // Personal starting point
143  //
144 
150  public static function getPossibleStartingPoints()
151  {
152  global $ilSetting, $rbacsystem, $lng;
153 
154  // for all conditions: see ilMainMenuGUI
155 
156  $all = array();
157 
158  $all[self::START_PD_OVERVIEW] = 'overview';
159 
160  if($ilSetting->get('disable_my_offers') == 0 &&
161  $ilSetting->get('disable_my_memberships') == 0)
162  {
163  $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
164  }
165 
166  /*
167  if (!$ilSetting->get("disable_bookmarks"))
168  {
169  $all[self::START_PD_BOOKMARKS] = 'bookmarks';
170  }
171 
172  if (!$ilSetting->get("disable_notes"))
173  {
174  $all[self::START_PD_NOTES] = 'notes_and_comments';
175  }
176 
177  if ($ilSetting->get("block_activated_news"))
178  {
179  $all[self::START_PD_NEWS] = 'news';
180  }
181  */
182 
183  if(!$ilSetting->get("disable_personal_workspace"))
184  {
185  $all[self::START_PD_WORKSPACE] = 'personal_workspace';
186  }
187 
188  /*
189  if ($ilSetting->get('user_portfolios'))
190  {
191  $all[self::START_PD_PORTFOLIO] = 'portfolio';
192  }
193 
194  $skmg_set = new ilSetting("skmg");
195  if ($skmg_set->get("enable_skmg"))
196  {
197  $all[self::START_PD_SKILLS] = 'skills';
198  }
199 
200  include_once("Services/Tracking/classes/class.ilObjUserTracking.php");
201  if (ilObjUserTracking::_enabledLearningProgress() &&
202  ilObjUserTracking::_hasLearningProgressDesktop())
203  {
204  $all[self::START_PD_LP] = 'learning_progress';
205  }
206  */
207 
208  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
209  $settings = ilCalendarSettings::_getInstance();
210  if($settings->isEnabled())
211  {
212  $all[self::START_PD_CALENDAR] = 'calendar';
213  }
214 
215  /*
216  if($rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId()))
217  {
218  $all[self::START_PD_MAIL] = 'mail';
219  }
220 
221  if(!$ilSetting->get('disable_contacts') &&
222  ($ilSetting->get('disable_contacts_require_mail') ||
223  $rbacsystem->checkAccess('internal_mail', ilMailGlobalServices::getMailObjectRefId())))
224  {
225  $all[self::START_PD_CONTACTS] = 'mail_addressbook';
226  }
227 
228  $all[self::START_PD_PROFILE] = 'personal_profile';
229  $all[self::START_PD_SETTINGS] = 'personal_settings';
230  */
231 
232  $all[self::START_REPOSITORY] = 'repository';
233 
234  foreach($all as $idx => $lang)
235  {
236  $all[$idx] = $lng->txt($lang);
237  }
238 
239  return $all;
240  }
241 
249  public static function setStartingPoint($a_value, $a_ref_id = null)
250  {
251  global $ilSetting, $tree;
252 
253  if($a_value == self::START_REPOSITORY_OBJ)
254  {
255  $a_ref_id = (int)$a_ref_id;
256  if(ilObject::_lookupObjId($a_ref_id) &&
257  !$tree->isDeleted($a_ref_id))
258  {
259  $ilSetting->set("usr_starting_point", $a_value);
260  $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
261  return true;
262  }
263  }
264  $valid = array_keys(self::getPossibleStartingPoints());
265  if(in_array($a_value, $valid))
266  {
267  $ilSetting->set("usr_starting_point", $a_value);
268  return true;
269  }
270  return false;
271  }
272 
278  public static function getStartingPoint()
279  {
280  global $ilSetting, $ilUser;
281 
282  $valid = array_keys(self::getPossibleStartingPoints());
283  $current = $ilSetting->get("usr_starting_point");
284  if($current == self::START_REPOSITORY_OBJ)
285  {
286  return $current;
287  }
288  else if(!$current || !in_array($current, $valid))
289  {
290  $current = self::START_PD_OVERVIEW;
291 
292  // #10715 - if 1 is disabled overview will display the current default
293  if($ilSetting->get('disable_my_offers') == 0 &&
294  $ilSetting->get('disable_my_memberships') == 0 &&
295  $ilSetting->get('personal_items_default_view') == 1)
296  {
297  $current = self::START_PD_SUBSCRIPTION;
298  }
299 
300  self::setStartingPoint($current);
301  }
302  if($ilUser->getId() == ANONYMOUS_USER_ID)
303  {
304  $current = self::START_REPOSITORY;
305  }
306  return $current;
307  }
308 
314  public static function getStartingPointAsUrl()
315  {
316  global $tree, $ilUser;
317 
318  $ref_id = 1;
319  if(self::hasPersonalStartingPoint())
320  {
321  $current = self::getPersonalStartingPoint();
322  if($current == self::START_REPOSITORY_OBJ)
323  {
325  }
326  }
327  else
328  {
329  $current = self::getStartingPoint();
330  if($current == self::START_REPOSITORY_OBJ)
331  {
333  }
334  }
335  switch($current)
336  {
337  case self::START_REPOSITORY:
338  case self::START_REPOSITORY_OBJ:
339  if($ref_id &&
341  !$tree->isDeleted($ref_id))
342  {
343  include_once('./Services/Link/classes/class.ilLink.php');
344  return ilLink::_getStaticLink($ref_id,'',true);
345  }
346  // invalid starting object, overview is fallback
347  $current = self::START_PD_OVERVIEW;
348  // fallthrough
349 
350  default:
351  $map = array(
352  self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems',
353  self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships',
354  // self::START_PD_BOOKMARKS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToBookmarks',
355  // self::START_PD_NOTES => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNotes',
356  // self::START_PD_NEWS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNews',
357  self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace',
358  // self::START_PD_PORTFOLIO => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio',
359  // self::START_PD_SKILLS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSkills',
361  self::START_PD_CALENDAR => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToCalendar',
362  // self::START_PD_MAIL => 'ilias.php?baseClass=ilMailGUI',
363  // self::START_PD_CONTACTS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToContacts',
364  // self::START_PD_PROFILE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToProfile',
365  // self::START_PD_SETTINGS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSettings'
366  );
367  return $map[$current];
368  }
369  }
370 
376  public static function getStartingObject()
377  {
378  global $ilSetting;
379 
380  return $ilSetting->get("usr_starting_point_ref_id");
381  }
382 
388  public static function togglePersonalStartingPoint($a_value)
389  {
390  global $ilSetting;
391 
392  $ilSetting->set("usr_starting_point_personal", (bool)$a_value);
393  }
394 
400  public static function hasPersonalStartingPoint()
401  {
402  global $ilSetting;
403 
404  return $ilSetting->get("usr_starting_point_personal");
405  }
406 
407 
413  public static function getPersonalStartingPoint()
414  {
415  global $ilUser;
416 
417  $valid = array_keys(self::getPossibleStartingPoints());
418  $current = $ilUser->getPref("usr_starting_point");
419  if($current == self::START_REPOSITORY_OBJ)
420  {
421  return $current;
422  }
423  else if(!$current || !in_array($current, $valid))
424  {
425  return self::getStartingPoint();
426  }
427  return $current;
428  }
429 
437  public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
438  {
439  global $ilUser, $tree;
440 
441  if($a_value == self::START_REPOSITORY_OBJ)
442  {
443  $a_ref_id = (int)$a_ref_id;
444  if(ilObject::_lookupObjId($a_ref_id) &&
445  !$tree->isDeleted($a_ref_id))
446  {
447  $ilUser->setPref("usr_starting_point", $a_value);
448  $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
449  return true;
450  }
451  }
452  $valid = array_keys(self::getPossibleStartingPoints());
453  if(in_array($a_value, $valid))
454  {
455  $ilUser->setPref("usr_starting_point", $a_value);
456  return true;
457  }
458  return false;
459  }
460 
466  public static function getPersonalStartingObject()
467  {
468  global $ilUser;
469 
470  $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
471  if(!$ref_id)
472  {
474  }
475  return $ref_id;
476  }
477 }
478 ?>