ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMailUserCache.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
15  protected static $user_instances = array();
16 
21  protected static $requested_usr_ids = array();
22 
27  protected static $requested_usr_ids_key_map = array();
28 
33  public static function preloadUserObjects(array $usr_ids)
34  {
38  global $ilDB;
39 
40  $usr_ids_to_request = array_diff($usr_ids, self::$requested_usr_ids);
41  self::$requested_usr_ids = array_merge(self::$requested_usr_ids, $usr_ids_to_request);
42  self::$requested_usr_ids_key_map = array_flip(self::$requested_usr_ids);
43 
44  if($usr_ids_to_request)
45  {
46  $in = $ilDB->in('ud.usr_id', $usr_ids_to_request, false, 'integer');
47  $query = "
48  SELECT ud.usr_id, login, firstname, lastname, title, gender, pprof.value public_profile,pup.value public_upload, pupgen.value public_gender
49  FROM usr_data ud
50  LEFT JOIN usr_pref pprof ON pprof.usr_id = ud.usr_id AND pprof.keyword = %s
51  LEFT JOIN usr_pref pupgen ON pupgen.usr_id = ud.usr_id AND pupgen.keyword = %s
52  LEFT JOIN usr_pref pup ON pup.usr_id = ud.usr_id AND pup.keyword = %s
53  WHERE $in
54  ";
55 
56  $res = $ilDB->queryF(
57  $query,
58  array('text', 'text', 'text'),
59  array('public_profile', 'public_gender', 'public_upload')
60  );
61 
62  while($row = $ilDB->fetchAssoc($res))
63  {
64  $user = new ilObjUser;
65  $user->setId($row['usr_id']);
66  $user->setLogin($row['login']);
67  $user->setGender($row['gender']);
68  $user->setTitle($row['title']);
69  $user->setFirstname($row['firstname']);
70  $user->setLastname($row['lastname']);
71  $user->setPref('public_profile', $row['public_profile']);
72  $user->setPref('public_upload', $row['public_upload']);
73  $user->setPref('public_gender', $row['public_gender']);
74 
75  self::$user_instances[$row['usr_id']] = $user;
76  }
77  }
78  }
79 
85  public static function getUserObjectById($usr_id)
86  {
87  if(!$usr_id)
88  {
89  return NULL;
90  }
91 
92  if(!array_key_exists($usr_id, self::$requested_usr_ids_key_map))
93  {
94  self::preloadUserObjects(array($usr_id));
95  }
96 
97  return isset(self::$user_instances[$usr_id]) ? self::$user_instances[$usr_id] : NULL;
98  }
99 }