ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAwarenessUserCollector.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
13 {
14  protected static $instances = array();
15  protected static $online_users = false;
16  protected static $online_user_ids = array();
17 
21  protected $collection;
22  protected $collections;
23  protected $user_id;
24  protected $ref_id;
25 
31  protected function __construct($a_user_id)
32  {
33  $this->user_id = $a_user_id;
34  }
35 
41  function setRefId($a_val)
42  {
43  $this->ref_id = $a_val;
44  }
45 
51  function getRefId()
52  {
53  return $this->ref_id;
54  }
55 
62  static function getInstance($a_user_id)
63  {
64  if (!isset(self::$instances[$a_user_id]))
65  {
66  self::$instances[$a_user_id] = new ilAwarenessUserCollector($a_user_id);
67  }
68 
69  return self::$instances[$a_user_id];
70  }
71 
78  static function getOnlineUsers()
79  {
80  if (self::$online_users === false)
81  {
82  self::$online_user_ids = array();
83  include_once("./Services/User/classes/class.ilObjUser.php");
84  self::$online_users = ilObjUser::_getUsersOnline();
85  foreach (self::$online_users as $u)
86  {
87  self::$online_user_ids[] = $u["user_id"];
88  }
89  }
90  return self::$online_users;
91  }
92 
93 
99  public function collectUsers($a_online_only = false)
100  {
101  global $rbacreview;
102 
103  $this->collections = array();
104 
105  $awrn_logger = ilLoggerFactory::getLogger('awrn');
106 
107  self::getOnlineUsers();
108  include_once("./Services/Awareness/classes/class.ilAwarenessUserProviderFactory.php");
109  $all_users = array();
111  {
112  // overall collection of users
113  include_once("./Services/Awareness/classes/class.ilAwarenessUserCollection.php");
115 
116  if ($prov->getActivationMode() != ilAwarenessUserProvider::MODE_INACTIVE)
117  {
118  $prov->setUserId($this->user_id);
119  $prov->setRefId($this->ref_id);
120  $prov->setOnlineUserFilter(false);
121  if ($prov->getActivationMode() == ilAwarenessUserProvider::MODE_ONLINE_ONLY || $a_online_only)
122  {
123  $prov->setOnlineUserFilter(self::$online_user_ids);
124  }
125 
126  $coll = $prov->collectUsers();
127  foreach ($coll->getUsers() as $user_id)
128  {
129  // filter out the anonymous user
130  if ($user_id == ANONYMOUS_USER_ID)
131  {
132  continue;
133  }
134 
135  $awrn_logger->debug("AwarenessUserCollector: Current User: ".$this->user_id.", ".
136  "Provider: ".$prov->getProviderId().", Collected User: ".$user_id);
137 
138  // cross check online, filter out offline users (if necessary)
139  if ((!$a_online_only && $prov->getActivationMode() == ilAwarenessUserProvider::MODE_INCL_OFFLINE)
140  || in_array($user_id, self::$online_user_ids))
141  {
142  $collection->addUser($user_id);
143  if (!in_array($user_id, $all_users))
144  {
145  $all_users[] = $user_id;
146  }
147  }
148  }
149  }
150  $this->collections[] = array(
151  "uc_title" => $prov->getTitle(),
152  "highlighted" => $prov->isHighlighted(),
153  "collection" => $collection
154  );
155  }
156 
157  $remove_users = array();
158 
159  // remove all users that hide their online status
160  foreach (ilObjUser::getUserSubsetByPreferenceValue($all_users, "hide_own_online_status", "y") as $u)
161  {
162  $remove_users[] = $u;
163  }
164 
165  // remove all users that have not accepted the terms of service yet
166  require_once 'Services/TermsOfService/classes/class.ilTermsOfServiceHelper.php';
168  {
169  foreach (ilObjUser::getUsersAgreed(false, $all_users) as $u)
170  {
171  if ($u != SYSTEM_USER_ID && !$rbacreview->isAssigned($u, SYSTEM_ROLE_ID))
172  //if ($u != SYSTEM_USER_ID)
173  {
174  $remove_users[] = $u;
175  }
176  }
177  }
178 
179  $this->removeUsersFromCollections($remove_users);
180 
181  return $this->collections;
182  }
183 
189  protected function removeUsersFromCollections($a_remove_users)
190  {
191  foreach ($this->collections as $c)
192  {
193  reset($a_remove_users);
194  foreach ($a_remove_users as $u)
195  {
196  $c["collection"]->removeUser($u);
197  }
198  }
199  }
200 
201 }
202 
203 ?>
Collects users from all providers.
removeUsersFromCollections($a_remove_users)
Remove users from collection.
collectUsers($a_online_only=false)
Collect users.
static getAllProviders()
Get all awareness providers.
Create styles array
The data for the language used.
static getUserSubsetByPreferenceValue($a_user_ids, $a_keyword, $a_val)
For a given set of user IDs return a subset that has a given user preference set. ...
static getInstance($a_user_id)
Get instance (for a user)
static getLogger($a_component_id)
Get component logger.
static getOnlineUsers()
Get online users.
static getUsersAgreed($a_agreed=true, $a_users=null)
Get users that have or have not agreed to the user agreement.