ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  const START_PD_MYSTAFF = 17;
31 
43  public static function getNamePresentation(
44  $a_user_id,
45  $a_user_image = false,
46  $a_profile_link = false,
47  $a_profile_back_link = "",
48  $a_force_first_lastname = false,
49  $a_omit_login = false,
50  $a_sortable = true,
51  $a_return_data_array = false,
52  $a_ctrl_path = "ilpublicuserprofilegui"
53  ) {
54  global $lng, $ilCtrl, $ilDB;
55 
56  if (!is_array($a_ctrl_path)) {
57  $a_ctrl_path = array($a_ctrl_path);
58  }
59 
60  if (!($return_as_array = is_array($a_user_id))) {
61  $a_user_id = array($a_user_id);
62  }
63 
64  $sql = 'SELECT
65  a.usr_id,
66  firstname,
67  lastname,
68  title,
69  login,
70  b.value public_profile,
71  c.value public_title
72  FROM
73  usr_data a
74  LEFT JOIN
75  usr_pref b ON
76  (a.usr_id = b.usr_id AND
77  b.keyword = %s)
78  LEFT JOIN
79  usr_pref c ON
80  (a.usr_id = c.usr_id AND
81  c.keyword = %s)
82  WHERE ' . $ilDB->in('a.usr_id', $a_user_id, false, 'integer');
83 
84  $userrow = $ilDB->queryF($sql, array('text', 'text'), array('public_profile', 'public_title'));
85 
86  $names = array();
87 
88  $data = array();
89  while ($row = $ilDB->fetchObject($userrow)) {
90  $pres = '';
91  $d = array("id" => $row->usr_id, "title" => "", "lastname" => "", "firstname" => "", "img" => "", "link" => "",
92  "public_profile" => "");
93  $has_public_profile = in_array($row->public_profile, array("y", "g"));
94  if ($a_force_first_lastname || $has_public_profile) {
95  $title = "";
96  if ($row->public_title == "y" && $row->title) {
97  $title = $row->title . " ";
98  }
99  $d["title"] = $title;
100  if ($a_sortable) {
101  $pres = $row->lastname;
102  if (strlen($row->firstname)) {
103  $pres .= (', ' . $row->firstname . ' ');
104  }
105  } else {
106  $pres = $title;
107  if (strlen($row->firstname)) {
108  $pres .= $row->firstname . ' ';
109  }
110  $pres .= ($row->lastname . ' ');
111  }
112  $d["firstname"] = $row->firstname;
113  $d["lastname"] = $row->lastname;
114  }
115  $d["login"] = $row->login;
116  $d["public_profile"] = $has_public_profile;
117 
118 
119  if (!$a_omit_login) {
120  $pres.= "[" . $row->login . "]";
121  }
122 
123  if ($a_profile_link && $has_public_profile) {
124  $ilCtrl->setParameterByClass(end($a_ctrl_path), "user_id", $row->usr_id);
125  if ($a_profile_back_link != "") {
126  $ilCtrl->setParameterByClass(
127  end($a_ctrl_path),
128  "back_url",
129  rawurlencode($a_profile_back_link)
130  );
131  }
132  $link = $ilCtrl->getLinkTargetByClass($a_ctrl_path, "getHTML");
133  $pres = '<a href="' . $link . '">' . $pres . '</a>';
134  $d["link"] = $link;
135  }
136 
137  if ($a_user_image) {
138  $img = ilObjUser::_getPersonalPicturePath($row->usr_id, "xxsmall");
139  $pres = '<img class="ilUserXXSmall" border="0" src="' . $img . '" alt="' . $lng->txt("icon") .
140  " " . $lng->txt("user_picture") . '" /> ' . $pres;
141  $d["img"] = $img;
142  }
143 
144  $names[$row->usr_id] = $pres;
145  $data[$row->usr_id] = $d;
146  }
147 
148  foreach ($a_user_id as $id) {
149  if (!$names[$id]) {
150  $names[$id] = $lng->txt('usr_name_undisclosed');
151  }
152  }
153 
154  if ($a_return_data_array) {
155  if ($return_as_array) {
156  return $data;
157  } else {
158  return current($data);
159  }
160  }
161  return $return_as_array ? $names : $names[$a_user_id[0]];
162  }
163 
170  public static function hasPublicProfile($a_user_id)
171  {
172  global $ilDB;
173 
174  $set = $ilDB->query(
175  "SELECT value FROM usr_pref " .
176  " WHERE usr_id = " . $ilDB->quote($a_user_id, "integer") .
177  " and keyword = " . $ilDB->quote("public_profile", "text")
178  );
179  $rec = $ilDB->fetchAssoc($set);
180 
181  return in_array($rec["value"], array("y", "g"));
182  }
183 
184 
191  public static function getProfileLink($a_usr_id)
192  {
193  $public_profile = ilObjUser::_lookupPref($a_usr_id, 'public_profile');
194  if ($public_profile != 'y' and $public_profile != 'g') {
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  $all[self::START_PD_SUBSCRIPTION] = 'my_courses_groups';
225  }
226 
227  if (ilMyStaffAccess::getInstance()->hasCurrentUserAccessToMyStaff()) {
228  $all[self::START_PD_MYSTAFF] = 'my_staff';
229  }
230 
231  if ($a_force_all || !$ilSetting->get("disable_personal_workspace")) {
232  $all[self::START_PD_WORKSPACE] = 'personal_workspace';
233  }
234 
235  include_once('./Services/Calendar/classes/class.ilCalendarSettings.php');
236  $settings = ilCalendarSettings::_getInstance();
237  if ($a_force_all || $settings->isEnabled()) {
238  $all[self::START_PD_CALENDAR] = 'calendar';
239  }
240 
241  $all[self::START_REPOSITORY] = 'repository';
242 
243  foreach ($all as $idx => $lang) {
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  $a_ref_id = (int) $a_ref_id;
263  if (ilObject::_lookupObjId($a_ref_id) &&
264  !$tree->isDeleted($a_ref_id)) {
265  $ilSetting->set("usr_starting_point", $a_value);
266  $ilSetting->set("usr_starting_point_ref_id", $a_ref_id);
267  return true;
268  }
269  }
270  $valid = array_keys(self::getPossibleStartingPoints());
271  if (in_array($a_value, $valid)) {
272  $ilSetting->set("usr_starting_point", $a_value);
273  return true;
274  }
275  return false;
276  }
277 
283  public static function getStartingPoint()
284  {
285  global $ilSetting, $ilUser;
286 
287  $valid = array_keys(self::getPossibleStartingPoints());
288  $current = $ilSetting->get("usr_starting_point");
289  if ($current == self::START_REPOSITORY_OBJ) {
290  return $current;
291  } elseif (!$current || !in_array($current, $valid)) {
292  $current = self::START_PD_OVERVIEW;
293 
294  // #10715 - if 1 is disabled overview will display the current default
295  if ($ilSetting->get('disable_my_offers') == 0 &&
296  $ilSetting->get('disable_my_memberships') == 0 &&
297  $ilSetting->get('personal_items_default_view') == 1) {
298  $current = self::START_PD_SUBSCRIPTION;
299  }
300 
301  self::setStartingPoint($current);
302  }
303  if ($ilUser->getId() == ANONYMOUS_USER_ID ||
304  !$ilUser->getId()) { // #18531
305  $current = self::START_REPOSITORY;
306  }
307  return $current;
308  }
309 
315  public static function getStartingPointAsUrl()
316  {
317  global $tree, $ilUser, $rbacreview;
318 
319  $ref_id = 1;
320  $by_default = true;
321 
322  //configuration by user preference
323  #21782
324  if (self::hasPersonalStartingPoint() && $ilUser->getPref('usr_starting_point') != null) {
325  $current = self::getPersonalStartingPoint();
326  if ($current == self::START_REPOSITORY_OBJ) {
327  $ref_id = self::getPersonalStartingObject();
328  }
329  } else {
330  include_once './Services/AccessControl/classes/class.ilStartingPoint.php';
331 
333  //getting all roles with starting points and store them in array
335 
336  $roles_ids = array_keys($roles);
337 
338  $gr = array();
339  foreach ($rbacreview->getGlobalRoles() as $role_id) {
340  if ($rbacreview->isAssigned($ilUser->getId(), $role_id)) {
341  if (in_array($role_id, $roles_ids)) {
342  $gr[$roles[$role_id]['position']] = array(
343  "point" => $roles[$role_id]['starting_point'],
344  "object" => $roles[$role_id]['starting_object']
345  );
346  }
347  }
348  }
349  if (!empty($gr)) {
350  krsort($gr); // ak: if we use array_pop (last element) we need to reverse sort, since we want the one with the smallest number
351  $role_point = array_pop($gr);
352  $current = $role_point['point'];
353  $ref_id = $role_point['object'];
354  $by_default = false;
355  }
356  }
357  if ($by_default) {
358  $current = self::getStartingPoint();
359 
360  if ($current == self::START_REPOSITORY_OBJ) {
361  $ref_id = self::getStartingObject();
362  }
363  }
364  }
365 
366  switch ($current) {
367  case self::START_REPOSITORY:
368  $ref_id = $tree->readRootId();
369 
370  // no break
371  case self::START_REPOSITORY_OBJ:
372  if ($ref_id &&
373  ilObject::_lookupObjId($ref_id) &&
374  !$tree->isDeleted($ref_id)) {
375  include_once('./Services/Link/classes/class.ilLink.php');
376  return ilLink::_getStaticLink($ref_id, '', true);
377  }
378  // invalid starting object, overview is fallback
379  $current = self::START_PD_OVERVIEW;
380  // fallthrough
381 
382  // no break
383  default:
384  $map = array(
385  self::START_PD_OVERVIEW => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSelectedItems',
386  self::START_PD_SUBSCRIPTION => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToMemberships',
387  // self::START_PD_BOOKMARKS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToBookmarks',
388  // self::START_PD_NOTES => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNotes',
389  // self::START_PD_NEWS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToNews',
390  self::START_PD_WORKSPACE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToWorkspace',
391  // self::START_PD_PORTFOLIO => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToPortfolio',
392  // self::START_PD_SKILLS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSkills',
394  self::START_PD_CALENDAR => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToCalendar',
395  // self::START_PD_MAIL => 'ilias.php?baseClass=ilMailGUI',
396  // self::START_PD_CONTACTS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToContacts',
397  // self::START_PD_PROFILE => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToProfile',
398  // self::START_PD_SETTINGS => 'ilias.php?baseClass=ilPersonalDesktopGUI&cmd=jumpToSettings'
399  self::START_PD_MYSTAFF => 'ilias.php?baseClass=' . ilPersonalDesktopGUI::class . '&cmd=' . ilPersonalDesktopGUI::CMD_JUMP_TO_MY_STAFF
400  );
401  return $map[$current];
402  }
403  }
404 
410  public static function getStartingObject()
411  {
412  global $ilSetting;
413 
414  return $ilSetting->get("usr_starting_point_ref_id");
415  }
416 
422  public static function togglePersonalStartingPoint($a_value)
423  {
424  global $ilSetting;
425 
426  $ilSetting->set("usr_starting_point_personal", (bool) $a_value);
427  }
428 
434  public static function hasPersonalStartingPoint()
435  {
436  global $ilSetting;
437 
438  return $ilSetting->get("usr_starting_point_personal");
439  }
440 
446  public static function hasPersonalStartPointPref()
447  {
448  global $ilUser;
449 
450  return (bool) $ilUser->getPref("usr_starting_point");
451  }
452 
458  public static function getPersonalStartingPoint()
459  {
460  global $ilUser;
461 
462  $valid = array_keys(self::getPossibleStartingPoints());
463  $current = $ilUser->getPref("usr_starting_point");
464  if ($current == self::START_REPOSITORY_OBJ) {
465  return $current;
466  } elseif (!$current || !in_array($current, $valid)) {
467  return self::getStartingPoint();
468  }
469  return $current;
470  }
471 
479  public static function setPersonalStartingPoint($a_value, $a_ref_id = null)
480  {
481  global $ilUser, $tree;
482 
483  if (!$a_value) {
484  $ilUser->setPref("usr_starting_point", null);
485  $ilUser->setPref("usr_starting_point_ref_id", null);
486  return;
487  }
488 
489  if ($a_value == self::START_REPOSITORY_OBJ) {
490  $a_ref_id = (int) $a_ref_id;
491  if (ilObject::_lookupObjId($a_ref_id) &&
492  !$tree->isDeleted($a_ref_id)) {
493  $ilUser->setPref("usr_starting_point", $a_value);
494  $ilUser->setPref("usr_starting_point_ref_id", $a_ref_id);
495  return true;
496  }
497  }
498  $valid = array_keys(self::getPossibleStartingPoints());
499  if (in_array($a_value, $valid)) {
500  $ilUser->setPref("usr_starting_point", $a_value);
501  return true;
502  }
503  return false;
504  }
505 
511  public static function getPersonalStartingObject()
512  {
513  global $ilUser;
514 
515  $ref_id = $ilUser->getPref("usr_starting_point_ref_id");
516  if (!$ref_id) {
517  $ref_id = self::getStartingObject();
518  }
519  return $ref_id;
520  }
521 }
const START_PD_MYSTAFF
static _getInstance()
get singleton instance
const START_PD_OVERVIEW
static hasPersonalStartPointPref()
Did user set any personal starting point (yet)?
$valid
const START_PD_SETTINGS
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static getPersonalStartingPoint()
Get current personal starting point.
if(!array_key_exists('StateId', $_REQUEST)) $id
Class ilUserUtil.
static getRolesWithStartingPoint()
get array with all roles which have starting point defined.
static getStartingPoint()
Get current starting point setting.
static getStartingPointAsUrl()
Get current starting point setting as URL.
static hasPersonalStartingPoint()
Can starting point be personalized?
global $ilCtrl
Definition: ilias.php:18
static getPossibleStartingPoints($a_force_all=false)
Get all valid starting points.
const START_PD_PROFILE
const START_PD_CONTACTS
static hasPublicProfile($a_user_id)
Has public profile.
static _lookupObjId($a_id)
static getStartingObject()
Get ref id of starting object.
$ilUser
Definition: imgupload.php:18
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, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
const START_PD_CALENDAR
Create styles array
The data for the language used.
const START_PD_SKILLS
global $ilSetting
Definition: privfeed.php:17
static _lookupPref($a_usr_id, $a_keyword)
global $lng
Definition: privfeed.php:17
global $ilDB
const START_PD_BOOKMARKS
const START_PD_SUBSCRIPTION
const START_REPOSITORY_OBJ
static getPersonalStartingObject()
Get ref id of personal starting object.
static setStartingPoint($a_value, $a_ref_id=null)
Set starting point setting.
const START_PD_NOTES
static togglePersonalStartingPoint($a_value)
Toggle personal starting point setting.
const START_REPOSITORY
for($i=6; $i< 13; $i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
static setPersonalStartingPoint($a_value, $a_ref_id=null)
Set personal starting point setting.
const START_PD_PORTFOLIO
const START_PD_WORKSPACE
static getProfileLink($a_usr_id)
Get link to personal profile Return empty string in case of not public profile.