ILIAS  release_4-3 Revision
 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
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 pup ON pup.usr_id = ud.usr_id AND pup.keyword = %s
52  WHERE $in
53  ";
54 
55  $res = $ilDB->queryF(
56  $query,
57  array('text', 'text', 'text'),
58  array('public_profile', 'public_gender', 'public_upload')
59  );
60 
61  while($row = $ilDB->fetchAssoc($res))
62  {
63  $user = new ilObjUser;
64  $user->setId($row['usr_id']);
65  $user->setLogin($row['login']);
66  $user->setGender($row['gender']);
67  $user->setTitle($row['title']);
68  $user->setFirstname($row['firstname']);
69  $user->setLastname($row['lastname']);
70  $user->setPref('public_profile', $row['public_profile']);
71  $user->setPref('public_upload', $row['public_upload']);
72 
73  self::$user_instances[$row['usr_id']] = $user;
74  }
75  }
76  }
77 
83  public static function getUserObjectById($usr_id)
84  {
85  if(!$usr_id)
86  {
87  return NULL;
88  }
89 
90  if(!array_key_exists($usr_id, self::$requested_usr_ids_key_map))
91  {
92  self::preloadUserObjects(array($usr_id));
93  }
94 
95  return isset(self::$user_instances[$usr_id]) ? self::$user_instances[$usr_id] : NULL;
96  }
97 }