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