ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAwarenessData.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 $user_id;
15  protected $ref_id = 0;
16  protected $user_collector;
17  protected $action_collector;
18  protected $user_collection;
19  protected $data = null;
20  protected $online_user_data = null;
21  static protected $instances = array();
22  protected $filter = "";
23 
30  protected function __construct($a_user_id)
31  {
32  $this->user_id = $a_user_id;
33 
34  include_once("./Services/Awareness/classes/class.ilAwarenessUserCollector.php");
35  $this->user_collector = ilAwarenessUserCollector::getInstance($a_user_id);
36  include_once("./Services/User/Actions/classes/class.ilUserActionCollector.php");
37  $this->action_collector = ilUserActionCollector::getInstance($a_user_id);
38  }
39 
45  function setRefId($a_val)
46  {
47  $this->ref_id = $a_val;
48  }
49 
55  function getRefId()
56  {
57  return $this->ref_id;
58  }
59 
65  function setFilter($a_val)
66  {
67  $this->filter = $a_val;
68  }
69 
75  function getFilter()
76  {
77  return $this->filter;
78  }
79 
84  {
85  return 20;
86  }
87 
88 
95  static function getInstance($a_user_id)
96  {
97  if (!isset(self::$instances[$a_user_id]))
98  {
99  self::$instances[$a_user_id] = new ilAwarenessData($a_user_id);
100  }
101 
102  return self::$instances[$a_user_id];
103  }
104 
105 
106 
113  function getUserCollections($a_online_only = false)
114  {
115  if (!isset($this->user_collections[(int) $a_online_only]))
116  {
117  $this->user_collector->setRefId($this->getRefId());
118  $this->user_collections[(int) $a_online_only] = $this->user_collector->collectUsers($a_online_only);
119  }
120 
121  return $this->user_collections[(int) $a_online_only];
122  }
123 
127  function getUserCounter()
128  {
129  $all_user_ids = array();
130  $hall_user_ids = array();
131 
132  $user_collections = $this->getUserCollections();
133 
134  foreach ($user_collections as $uc)
135  {
136  $user_collection = $uc["collection"];
137  $user_ids = $user_collection->getUsers();
138 
139  foreach ($user_ids as $uid)
140  {
141  if (!in_array($uid, $all_user_ids))
142  {
143  if ($uc["highlighted"])
144  {
145  $hall_user_ids[] = $uid;
146  }
147  else
148  {
149  $all_user_ids[] = $uid;
150  }
151  }
152  }
153  }
154 
155  return count($all_user_ids).":".count($hall_user_ids);
156  }
157 
164  function getOnlineUserData($a_ts = "")
165  {
168  $user_collections = $this->getUserCollections(true); // get user collections with online users only
169  $all_online_user_ids = array();
170 
171  foreach ($user_collections as $uc)
172  {
173  $user_collection = $uc["collection"];
174  $user_ids = $user_collection->getUsers();
175  foreach ($user_ids as $u)
176  {
177  if (!in_array($u, $all_online_user_ids))
178  {
179  // check timestamp and limit the max number of user data records received
180  if (($a_ts == "" || $online_users[$u]["last_login"] > $a_ts)
181  && count($all_online_user_ids) < $this->getMaxOnlineUserCnt())
182  {
183  $all_online_user_ids[] = $u;
184  }
185  }
186  }
187  }
188 
189  include_once("./Services/User/classes/class.ilUserUtil.php");
190  $names = ilUserUtil::getNamePresentation($all_online_user_ids, true,
191  false, "", false, false, true, true);
192 
193  // sort and add online information
194  foreach ($names as $k => $n)
195  {
196  $names[$k]["online"] = true;
197  $names[$k]["last_login"] = $online_users[$n["id"]]["last_login"];
198  $sort_str = "";
199  if ($n["public_profile"])
200  {
201  $sort_str.= $n["lastname"]." ".$n["firstname"];
202  }
203  else
204  {
205  $sort_str.= $n["login"];
206  }
207  $names[$k]["sort_str"] = $sort_str;
208  }
209 
210  $names = ilUtil::sortArray($names, "sort_str", "asc", false, true);
211 
212  foreach ($names as $n)
213  {
214  $obj = new stdClass;
215  $obj->lastname = $n["lastname"];
216  $obj->firstname = $n["firstname"];
217  $obj->login = $n["login"];
218  $obj->id = $n["id"];
219  $obj->public_profile = $n["public_profile"];
220  $obj->online = $n["online"];
221  $obj->last_login = $n["last_login"];;
222 
223  $online_user_data[] = $obj;
224  }
225 
226  return $online_user_data;
227  }
228 
234  function getData()
235  {
236  $awrn_set = new ilSetting("awrn");
237  $max = $awrn_set->get("max_nr_entries");
238 
239  $all_user_ids = array();
240  $hall_user_ids = array();
241 
242  if ($this->data == null)
243  {
245 
246  $user_collections = $this->getUserCollections();
247 
248  $this->data = array();
249 
250  foreach ($user_collections as $uc)
251  {
252 
253  // limit part 1
254  if (count($this->data) >= $max)
255  {
256  continue;
257  }
258 
259  $user_collection = $uc["collection"];
260  $user_ids = $user_collection->getUsers();
261 
262  foreach ($user_ids as $uid)
263  {
264  if (!in_array($uid, $all_user_ids))
265  {
266  if ($uc["highlighted"])
267  {
268  $hall_user_ids[] = $uid;
269  }
270  else
271  {
272  $all_user_ids[] = $uid;
273  }
274  }
275  }
276 
277  include_once("./Services/User/classes/class.ilUserUtil.php");
278  $names = ilUserUtil::getNamePresentation($user_ids, true,
279  false, "", false, false, true, true);
280 
281  // sort and add online information
282  foreach ($names as $k => $n)
283  {
284  if (isset($online_users[$n["id"]]))
285  {
286  $names[$k]["online"] = true;
287  $names[$k]["last_login"] = $online_users[$n["id"]]["last_login"];
288  $sort_str = "1";
289  }
290  else
291  {
292  $names[$k]["online"] = false;
293  $names[$k]["last_login"] = "";
294  $sort_str = "2";
295  }
296  if ($n["public_profile"])
297  {
298  $sort_str.= $n["lastname"]." ".$n["firstname"];
299  }
300  else
301  {
302  $sort_str.= $n["login"];
303  }
304  $names[$k]["sort_str"] = $sort_str;
305  }
306 
307  $names = ilUtil::sortArray($names, "sort_str", "asc", false, true);
308 
309  foreach ($names as $n)
310  {
311  // limit part 2
312  if (count($this->data) >= $max)
313  {
314  continue;
315  }
316 
317  // filter
318  $filter = trim($this->getFilter());
319  if ($filter != "" &&
320  !is_int(stripos($n["login"], $filter)) &&
321  (!$n["public_profile"] || (
322  !is_int(stripos($n["firstname"], $filter)) &&
323  !is_int(stripos($n["lastname"], $filter))
324  )
325  )
326  )
327  {
328  continue;
329  }
330 
331  $obj = new stdClass;
332  $obj->lastname = $n["lastname"];
333  $obj->firstname = $n["firstname"];
334  $obj->login = $n["login"];
335  $obj->id = $n["id"];
336  $obj->collector = $uc["uc_title"];
337  $obj->highlighted = $uc["highlighted"];
338 
339  //$obj->img = $n["img"];
340  $obj->img = ilObjUser::_getPersonalPicturePath($n["id"], "xsmall");
341  $obj->public_profile = $n["public_profile"];
342 
343  $obj->online = $n["online"];
344  $obj->last_login = $n["last_login"];;
345 
346  // get actions
347  $action_collection = $this->action_collector->getActionsForTargetUser($n["id"], "awrn", "toplist");
348  $obj->actions = array();
349  foreach ($action_collection->getActions() as $action)
350  {
351  $f = new stdClass;
352  $f->text = $action->getText();
353  $f->href = $action->getHref();
354  $f->data = $action->getData();
355  $obj->actions[] = $f;
356  }
357 
358  $this->data[] = $obj;
359  }
360  }
361  }
362 
363  return array("data" => $this->data, "cnt" => count($all_user_ids).":".count($hall_user_ids));
364  }
365 
366 }
367 
368 ?>
setRefId($a_val)
Set ref id.
Add some data
ILIAS Setting Class.
static getInstance($a_user_id)
Get instance (for a user)
getOnlineUserData($a_ts="")
Get online user data.
static sortArray($array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray
setFilter($a_val)
Set filter.
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)
Default behaviour is:
$n
Definition: RandomTest.php:80
Create styles array
The data for the language used.
getUserCollections($a_online_only=false)
Get user collections.
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
__construct($a_user_id)
Constructor.
static getInstance($a_user_id)
Get instance (for a user)
getUserCounter()
Get user counter.
static getInstance($a_user_id)
Get instance (for a user)
static getOnlineUsers()
Get online users.
getMaxOnlineUserCnt()
Maximum for online user data.