ILIAS  release_8 Revision v8.24
ILIAS\Awareness\WidgetManager Class Reference

High level business class, interface to front ends. More...

+ Collaboration diagram for ILIAS\Awareness\WidgetManager:

Public Member Functions

 __construct (int $a_user_id, int $ref_id, InternalDataService $data_service, InternalRepoService $repo_service, InternalDomainService $domain_service)
 
 isWidgetVisible ()
 
 processMetaBar ()
 
 getUserCollections (bool $a_online_only=false)
 Get user collections. More...
 
 getUserCounter ()
 
 getListData (string $filter="")
 Get data. More...
 

Protected Member Functions

 updateCounter (int $cnt, int $hcnt)
 

Protected Attributes

InternalDataService $data_service
 
ilSetting $settings
 
AwarenessSessionRepository $session_repo
 
ilLanguage $lng
 
int $user_id
 
int $ref_id = 0
 
User Collector $user_collector
 
ilUserActionCollector $action_collector
 
array $user_collections
 
array $data = null
 
array $online_user_data = null
 

Static Protected Attributes

static array $instances = array()
 

Detailed Description

High level business class, interface to front ends.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 33 of file class.WidgetManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Awareness\WidgetManager::__construct ( int  $a_user_id,
int  $ref_id,
InternalDataService  $data_service,
InternalRepoService  $repo_service,
InternalDomainService  $domain_service 
)

Definition at line 49 of file class.WidgetManager.php.

55 {
56 $this->lng = $domain_service->lng();
57 $this->user_id = $a_user_id;
58 $this->ref_id = $ref_id;
59 $this->session_repo = $repo_service->awarenessSession();
60 $this->settings = $domain_service->awarenessSettings();
61 $this->data_service = $data_service;
62 $this->user_collector = $domain_service->userCollector($a_user_id, $ref_id);
63 $this->action_collector = \ilUserActionCollector::getInstance($a_user_id, new \ilAwarenessUserActionContext());
64 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getInstance(int $a_user_id, ilUserActionContext $a_context)
Get instance (for a user)

References ILIAS\Awareness\WidgetManager\$data_service, ILIAS\Awareness\WidgetManager\$ref_id, ILIAS\Awareness\InternalRepoService\awarenessSession(), ILIAS\Awareness\InternalDomainService\awarenessSettings(), ilUserActionCollector\getInstance(), ILIAS\Repository\lng(), ILIAS\Repository\settings(), and ILIAS\Awareness\InternalDomainService\userCollector().

+ Here is the call graph for this function:

Member Function Documentation

◆ getListData()

ILIAS\Awareness\WidgetManager::getListData ( string  $filter = "")

Get data.

Parameters
string$filter
Returns
array array of data objects
Exceptions

ilWACException

Definition at line 144 of file class.WidgetManager.php.

144 : array
145 {
146 if ($this->user_id == ANONYMOUS_USER_ID) {
147 return [
148 "data" => [],
149 "cnt" => "0:0"
150 ];
151 }
152 $awrn_set = $this->settings;
153 $max = $awrn_set->get("max_nr_entries");
154
155 $all_user_ids = array();
156 $hall_user_ids = array();
157
158 if ($this->data == null) {
159 $online_users = $this->user_collector->getOnlineUsers();
160
162
163 $this->data = array();
164
165 foreach ($user_collections as $uc) {
166
167 // limit part 1
168 if (count($this->data) >= $max) {
169 continue;
170 }
171
172 $user_collection = $uc["collection"];
173 $user_ids = $user_collection->getUsers();
174
175 foreach ($user_ids as $uid) {
176 if (!in_array($uid, $all_user_ids)) {
177 if ($uc["highlighted"]) {
178 $hall_user_ids[] = $uid;
179 } else {
180 $all_user_ids[] = $uid;
181 }
182 }
183 }
184
186 $user_ids,
187 true,
188 false,
189 "",
190 false,
191 false,
192 true,
193 true
194 );
195
196 // sort and add online information
197 foreach ($names as $k => $n) {
198 if (isset($online_users[$n["id"]])) {
199 $names[$k]["online"] = true;
200 $names[$k]["last_login"] = $online_users[$n["id"]]["last_login"];
201 $sort_str = "1";
202 } else {
203 $names[$k]["online"] = false;
204 $names[$k]["last_login"] = "";
205 $sort_str = "2";
206 }
207 if ($n["public_profile"]) {
208 $sort_str .= $n["lastname"] . " " . $n["firstname"];
209 } else {
210 $sort_str .= $n["login"];
211 }
212 $names[$k]["sort_str"] = $sort_str;
213 }
214
215 $names = ilArrayUtil::sortArray($names, "sort_str", "asc", false, true);
216
217 foreach ($names as $n) {
218 // limit part 2
219 if (count($this->data) >= $max) {
220 continue;
221 }
222
223 // filter
224 $filter = trim($filter);
225 if ($filter != "" &&
226 !is_int(stripos($n["login"], $filter)) &&
227 (
228 !$n["public_profile"] || (
229 !is_int(stripos($n["firstname"], $filter)) &&
230 !is_int(stripos($n["lastname"], $filter))
231 )
232 )
233 ) {
234 continue;
235 }
236
237 $obj = new \stdClass();
238 $obj->lastname = $n["lastname"];
239 $obj->firstname = $n["firstname"];
240 $obj->login = $n["login"];
241 $obj->id = $n["id"];
242 $obj->collector = $uc["uc_title"];
243 $obj->highlighted = $uc["highlighted"];
244
245 //$obj->img = $n["img"];
246 $obj->img = \ilObjUser::_getPersonalPicturePath($n["id"], "xsmall");
247 $obj->public_profile = $n["public_profile"];
248
249 $obj->online = $n["online"];
250 $obj->last_login = $n["last_login"];
251
252 // get actions
253 $action_collection = $this->action_collector->getActionsForTargetUser($n["id"]);
254 $obj->actions = array();
255 foreach ($action_collection->getActions() as $action) {
256 $f = new \stdClass();
257 $f->text = $action->getText();
258 $f->href = $action->getHref();
259 $f->data = $action->getData();
260 $obj->actions[] = $f;
261 }
262
263 $this->data[] = $obj;
264 }
265 }
266 }
267
268 // update counter
269 $this->updateCounter(
270 count($all_user_ids),
271 count($hall_user_ids)
272 );
273
274 return array("data" => $this->data, "cnt" => count($all_user_ids) . ":" . count($hall_user_ids));
275 }
getUserCollections(bool $a_online_only=false)
Get user collections.
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
get(string $a_keyword, ?string $a_default_value=null)
get setting
static getNamePresentation( $a_user_id, bool $a_user_image=false, bool $a_profile_link=false, string $a_profile_back_link="", bool $a_force_first_lastname=false, bool $a_omit_login=false, bool $a_sortable=true, bool $a_return_data_array=false, $a_ctrl_path="ilpublicuserprofilegui")
Default behaviour is:
const ANONYMOUS_USER_ID
Definition: constants.php:27

References Vendor\Package\$f, ILIAS\Awareness\WidgetManager\$settings, ILIAS\Awareness\WidgetManager\$user_collections, ilObjUser\_getPersonalPicturePath(), ANONYMOUS_USER_ID, ilSetting\get(), ilUserUtil\getNamePresentation(), ILIAS\Awareness\WidgetManager\getUserCollections(), ilArrayUtil\sortArray(), and ILIAS\Awareness\WidgetManager\updateCounter().

+ Here is the call graph for this function:

◆ getUserCollections()

ILIAS\Awareness\WidgetManager::getUserCollections ( bool  $a_online_only = false)

Get user collections.

Parameters
bool$a_online_onlytrue, if only online users should be collected
Returns
array array of collections

Definition at line 102 of file class.WidgetManager.php.

102 : array
103 {
104 if (!isset($this->user_collections[(int) $a_online_only])) {
105 $this->user_collections[(int) $a_online_only] = $this->user_collector->collectUsers($a_online_only);
106 }
107 return $this->user_collections[(int) $a_online_only];
108 }

References ILIAS\Repository\int().

Referenced by ILIAS\Awareness\WidgetManager\getListData(), and ILIAS\Awareness\WidgetManager\getUserCounter().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserCounter()

ILIAS\Awareness\WidgetManager::getUserCounter ( )

Definition at line 110 of file class.WidgetManager.php.

110 : Counter
111 {
112 $all_user_ids = array();
113 $hall_user_ids = array();
114
116
117 foreach ($user_collections as $uc) {
118 $user_collection = $uc["collection"];
119 $user_ids = $user_collection->getUsers();
120
121 foreach ($user_ids as $uid) {
122 if (!in_array($uid, $all_user_ids)) {
123 if ($uc["highlighted"]) {
124 $hall_user_ids[] = $uid;
125 } else {
126 $all_user_ids[] = $uid;
127 }
128 }
129 }
130 }
131
132 return $this->data_service->counter(
133 count($all_user_ids),
134 count($hall_user_ids)
135 );
136 }

References ILIAS\Awareness\WidgetManager\$user_collections, and ILIAS\Awareness\WidgetManager\getUserCollections().

Referenced by ILIAS\Awareness\WidgetManager\processMetaBar().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isWidgetVisible()

ILIAS\Awareness\WidgetManager::isWidgetVisible ( )

Definition at line 66 of file class.WidgetManager.php.

66 : bool
67 {
68 $awrn_set = $this->settings;
69 if (!$awrn_set->get("awrn_enabled", "0") ||
70 ANONYMOUS_USER_ID == $this->user_id ||
71 $this->user_id == 0) {
72 return false;
73 }
74 return true;
75 }

References ILIAS\Awareness\WidgetManager\$settings, and ANONYMOUS_USER_ID.

◆ processMetaBar()

ILIAS\Awareness\WidgetManager::processMetaBar ( )

Definition at line 77 of file class.WidgetManager.php.

77 : Counter
78 {
79 $cache_period = (int) $this->settings->get("caching_period");
80 $last_update = $this->session_repo->getLastUpdate();
81 $now = time();
82
83 if ($last_update == "" || ($now - $last_update) >= $cache_period) {
84 $counter = $this->getUserCounter();
85 $hcnt = $counter->getHighlightCount();
86 $cnt = $counter->getCount();
87 $this->session_repo->setLastUpdate($now);
88 $this->session_repo->setCount($cnt);
89 $this->session_repo->setHighlightCount($hcnt);
90 } else {
91 $cnt = $this->session_repo->getCount();
92 $hcnt = $this->session_repo->getHighlightCount();
93 }
94 return $this->data_service->counter($cnt, $hcnt);
95 }

References ILIAS\Awareness\WidgetManager\getUserCounter(), ILIAS\Repository\int(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ updateCounter()

ILIAS\Awareness\WidgetManager::updateCounter ( int  $cnt,
int  $hcnt 
)
protected

Definition at line 277 of file class.WidgetManager.php.

280 : void {
281 // update counter
282 $now = time();
283 $this->session_repo->setLastUpdate($now);
284 $this->session_repo->setCount($cnt);
285 $this->session_repo->setHighlightCount($hcnt);
286 }

Referenced by ILIAS\Awareness\WidgetManager\getListData().

+ Here is the caller graph for this function:

Field Documentation

◆ $action_collector

ilUserActionCollector ILIAS\Awareness\WidgetManager::$action_collector
protected

Definition at line 43 of file class.WidgetManager.php.

◆ $data

array ILIAS\Awareness\WidgetManager::$data = null
protected

Definition at line 45 of file class.WidgetManager.php.

◆ $data_service

InternalDataService ILIAS\Awareness\WidgetManager::$data_service
protected

Definition at line 35 of file class.WidgetManager.php.

Referenced by ILIAS\Awareness\WidgetManager\__construct().

◆ $instances

array ILIAS\Awareness\WidgetManager::$instances = array()
staticprotected

Definition at line 47 of file class.WidgetManager.php.

◆ $lng

ilLanguage ILIAS\Awareness\WidgetManager::$lng
protected

Definition at line 38 of file class.WidgetManager.php.

◆ $online_user_data

array ILIAS\Awareness\WidgetManager::$online_user_data = null
protected

Definition at line 46 of file class.WidgetManager.php.

◆ $ref_id

int ILIAS\Awareness\WidgetManager::$ref_id = 0
protected

Definition at line 41 of file class.WidgetManager.php.

Referenced by ILIAS\Awareness\WidgetManager\__construct().

◆ $session_repo

AwarenessSessionRepository ILIAS\Awareness\WidgetManager::$session_repo
protected

Definition at line 37 of file class.WidgetManager.php.

◆ $settings

ilSetting ILIAS\Awareness\WidgetManager::$settings
protected

◆ $user_collections

array ILIAS\Awareness\WidgetManager::$user_collections
protected

◆ $user_collector

User Collector ILIAS\Awareness\WidgetManager::$user_collector
protected

Definition at line 42 of file class.WidgetManager.php.

◆ $user_id

int ILIAS\Awareness\WidgetManager::$user_id
protected

Definition at line 40 of file class.WidgetManager.php.


The documentation for this class was generated from the following file: