ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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;
19 protected $data = null;
20 protected $online_user_data = null;
21 protected static $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 include_once("./Services/Awareness/classes/class.ilAwarenessUserActionContext.php");
38 $this->action_collector = ilUserActionCollector::getInstance($a_user_id, new ilAwarenessUserActionContext());
39 }
40
46 public function setRefId($a_val)
47 {
48 $this->ref_id = $a_val;
49 }
50
56 public function getRefId()
57 {
58 return $this->ref_id;
59 }
60
66 public function setFilter($a_val)
67 {
68 $this->filter = $a_val;
69 }
70
76 public function getFilter()
77 {
78 return $this->filter;
79 }
80
84 public function getMaxOnlineUserCnt()
85 {
86 return 20;
87 }
88
89
96 public static function getInstance($a_user_id)
97 {
98 if (!isset(self::$instances[$a_user_id])) {
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 public function getUserCollections($a_online_only = false)
114 {
115 if (!isset($this->user_collections[(int) $a_online_only])) {
116 $this->user_collector->setRefId($this->getRefId());
117 $this->user_collections[(int) $a_online_only] = $this->user_collector->collectUsers($a_online_only);
118 }
119
120 return $this->user_collections[(int) $a_online_only];
121 }
122
126 public function getUserCounter()
127 {
128 $all_user_ids = array();
129 $hall_user_ids = array();
130
131 $user_collections = $this->getUserCollections();
132
133 foreach ($user_collections as $uc) {
134 $user_collection = $uc["collection"];
135 $user_ids = $user_collection->getUsers();
136
137 foreach ($user_ids as $uid) {
138 if (!in_array($uid, $all_user_ids)) {
139 if ($uc["highlighted"]) {
140 $hall_user_ids[] = $uid;
141 } else {
142 $all_user_ids[] = $uid;
143 }
144 }
145 }
146 }
147
148 return count($all_user_ids) . ":" . count($hall_user_ids);
149 }
150
157 public function getOnlineUserData($a_ts = "")
158 {
159 $online_user_data = array();
161 $user_collections = $this->getUserCollections(true); // get user collections with online users only
162 $all_online_user_ids = array();
163
164 foreach ($user_collections as $uc) {
165 $user_collection = $uc["collection"];
166 $user_ids = $user_collection->getUsers();
167 foreach ($user_ids as $u) {
168 if (!in_array($u, $all_online_user_ids)) {
169 // check timestamp and limit the max number of user data records received
170 if (($a_ts == "" || $online_users[$u]["last_login"] > $a_ts)
171 && count($all_online_user_ids) < $this->getMaxOnlineUserCnt()) {
172 $all_online_user_ids[] = $u;
173 }
174 }
175 }
176 }
177
178 include_once("./Services/User/classes/class.ilUserUtil.php");
180 $all_online_user_ids,
181 true,
182 false,
183 "",
184 false,
185 false,
186 true,
187 true
188 );
189
190 // sort and add online information
191 foreach ($names as $k => $n) {
192 $names[$k]["online"] = true;
193 $names[$k]["last_login"] = $online_users[$n["id"]]["last_login"];
194 $sort_str = "";
195 if ($n["public_profile"]) {
196 $sort_str .= $n["lastname"] . " " . $n["firstname"];
197 } else {
198 $sort_str .= $n["login"];
199 }
200 $names[$k]["sort_str"] = $sort_str;
201 }
202
203 $names = ilUtil::sortArray($names, "sort_str", "asc", false, true);
204
205 foreach ($names as $n) {
206 $obj = new stdClass;
207 $obj->lastname = $n["lastname"];
208 $obj->firstname = $n["firstname"];
209 $obj->login = $n["login"];
210 $obj->id = $n["id"];
211 $obj->public_profile = $n["public_profile"];
212 $obj->online = $n["online"];
213 $obj->last_login = $n["last_login"];
214 ;
215
216 $online_user_data[] = $obj;
217 }
218
219 return $online_user_data;
220 }
221
227 public function getData()
228 {
229 if ($this->user_id == ANONYMOUS_USER_ID) {
230 return [
231 "data" => [],
232 "cnt" => "0:0"
233 ];
234 }
235 $awrn_set = new ilSetting("awrn");
236 $max = $awrn_set->get("max_nr_entries");
237
238 $all_user_ids = array();
239 $hall_user_ids = array();
240
241 if ($this->data == null) {
243
244 $user_collections = $this->getUserCollections();
245
246 $this->data = array();
247
248 foreach ($user_collections as $uc) {
249
250 // limit part 1
251 if (count($this->data) >= $max) {
252 continue;
253 }
254
255 $user_collection = $uc["collection"];
256 $user_ids = $user_collection->getUsers();
257
258 foreach ($user_ids as $uid) {
259 if (!in_array($uid, $all_user_ids)) {
260 if ($uc["highlighted"]) {
261 $hall_user_ids[] = $uid;
262 } else {
263 $all_user_ids[] = $uid;
264 }
265 }
266 }
267
268 include_once("./Services/User/classes/class.ilUserUtil.php");
270 $user_ids,
271 true,
272 false,
273 "",
274 false,
275 false,
276 true,
277 true
278 );
279
280 // sort and add online information
281 foreach ($names as $k => $n) {
282 if (isset($online_users[$n["id"]])) {
283 $names[$k]["online"] = true;
284 $names[$k]["last_login"] = $online_users[$n["id"]]["last_login"];
285 $sort_str = "1";
286 } else {
287 $names[$k]["online"] = false;
288 $names[$k]["last_login"] = "";
289 $sort_str = "2";
290 }
291 if ($n["public_profile"]) {
292 $sort_str .= $n["lastname"] . " " . $n["firstname"];
293 } else {
294 $sort_str .= $n["login"];
295 }
296 $names[$k]["sort_str"] = $sort_str;
297 }
298
299 $names = ilUtil::sortArray($names, "sort_str", "asc", false, true);
300
301 foreach ($names as $n) {
302 // limit part 2
303 if (count($this->data) >= $max) {
304 continue;
305 }
306
307 // filter
308 $filter = trim($this->getFilter());
309 if ($filter != "" &&
310 !is_int(stripos($n["login"], $filter)) &&
311 (
312 !$n["public_profile"] || (
313 !is_int(stripos($n["firstname"], $filter)) &&
314 !is_int(stripos($n["lastname"], $filter))
315 )
316 )
317 ) {
318 continue;
319 }
320
321 $obj = new stdClass;
322 $obj->lastname = $n["lastname"];
323 $obj->firstname = $n["firstname"];
324 $obj->login = $n["login"];
325 $obj->id = $n["id"];
326 $obj->collector = $uc["uc_title"];
327 $obj->highlighted = $uc["highlighted"];
328
329 //$obj->img = $n["img"];
330 $obj->img = ilObjUser::_getPersonalPicturePath($n["id"], "xsmall");
331 $obj->public_profile = $n["public_profile"];
332
333 $obj->online = $n["online"];
334 $obj->last_login = $n["last_login"];
335 ;
336
337 // get actions
338 $action_collection = $this->action_collector->getActionsForTargetUser($n["id"]);
339 $obj->actions = array();
340 foreach ($action_collection->getActions() as $action) {
341 $f = new stdClass;
342 $f->text = $action->getText();
343 $f->href = $action->getHref();
344 $f->data = $action->getData();
345 $obj->actions[] = $f;
346 }
347
348 $this->data[] = $obj;
349 }
350 }
351 }
352
353 return array("data" => $this->data, "cnt" => count($all_user_ids) . ":" . count($hall_user_ids));
354 }
355}
$n
Definition: RandomTest.php:85
An exception for terminatinating execution or to throw for unit testing.
getMaxOnlineUserCnt()
Maximum for online user data.
getUserCollections($a_online_only=false)
Get user collections.
__construct($a_user_id)
Constructor.
getUserCounter()
Get user counter.
getOnlineUserData($a_ts="")
Get online user data.
setRefId($a_val)
Set ref id.
setFilter($a_val)
Set filter.
static getInstance($a_user_id)
Get instance (for a user)
Awareness context for user actions.
static getOnlineUsers()
Get online users.
static getInstance($a_user_id)
Get instance (for a user)
static _getPersonalPicturePath( $a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
ILIAS Setting Class.
static getInstance($a_user_id, ilUserActionContext $a_context)
Get instance (for a user)
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, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
static sortArray( $array, $a_array_sortby, $a_array_sortorder=0, $a_numeric=false, $a_keep_keys=false)
sortArray