ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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, \ilUserActionProviderFactory $user_action_provider_factory, \ilUserActionAdmin $user_action_admin)
 
 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,
\ilUserActionProviderFactory  $user_action_provider_factory,
\ilUserActionAdmin  $user_action_admin 
)

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

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

57  {
58  $this->lng = $domain_service->lng();
59  $this->user_id = $a_user_id;
60  $this->ref_id = $ref_id;
61  $this->session_repo = $repo_service->awarenessSession();
62  $this->settings = $domain_service->awarenessSettings();
63  $this->data_service = $data_service;
64  $this->user_collector = $domain_service->userCollector($a_user_id, $ref_id);
65  $this->action_collector = new \ilUserActionCollector(
66  $a_user_id,
68  $user_action_provider_factory,
69  $user_action_admin
70  );
71  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
+ 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

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

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

151  : array
152  {
153  if ($this->user_id == ANONYMOUS_USER_ID) {
154  return [
155  "data" => [],
156  "cnt" => "0:0"
157  ];
158  }
159  $awrn_set = $this->settings;
160  $max = $awrn_set->get("max_nr_entries");
161 
162  $all_user_ids = array();
163  $hall_user_ids = array();
164 
165  if ($this->data == null) {
166  $online_users = $this->user_collector->getOnlineUsers();
167 
169 
170  $this->data = array();
171 
172  foreach ($user_collections as $uc) {
173  // limit part 1
174  if (count($this->data) >= $max) {
175  continue;
176  }
177 
178  $user_collection = $uc["collection"];
179  $user_ids = $user_collection->getUsers();
180 
181  foreach ($user_ids as $uid) {
182  if (!in_array($uid, $all_user_ids)) {
183  if ($uc["highlighted"]) {
184  $hall_user_ids[] = $uid;
185  } else {
186  $all_user_ids[] = $uid;
187  }
188  }
189  }
190 
192  $user_ids,
193  true,
194  false,
195  "",
196  false,
197  false,
198  true,
199  true
200  );
201 
202  // sort and add online information
203  foreach ($names as $k => $n) {
204  if (isset($online_users[$n["id"]])) {
205  $names[$k]["online"] = true;
206  $names[$k]["last_login"] = $online_users[$n["id"]]["last_login"];
207  $sort_str = "1";
208  } else {
209  $names[$k]["online"] = false;
210  $names[$k]["last_login"] = "";
211  $sort_str = "2";
212  }
213  if ($n["public_profile"]) {
214  $sort_str .= $n["lastname"] . " " . $n["firstname"];
215  } else {
216  $sort_str .= $n["login"];
217  }
218  $names[$k]["sort_str"] = $sort_str;
219  }
220 
221  $names = ilArrayUtil::sortArray($names, "sort_str", "asc", false, true);
222 
223  foreach ($names as $n) {
224  // limit part 2
225  if (count($this->data) >= $max) {
226  continue;
227  }
228 
229  // filter
230  $filter = trim($filter);
231  if ($filter != "" &&
232  !is_int(stripos($n["login"], $filter)) &&
233  (
234  !$n["public_profile"] || (
235  !is_int(stripos($n["firstname"], $filter)) &&
236  !is_int(stripos($n["lastname"], $filter))
237  )
238  )
239  ) {
240  continue;
241  }
242 
243  $obj = new \stdClass();
244  $obj->lastname = $n["lastname"];
245  $obj->firstname = $n["firstname"];
246  $obj->login = $n["login"];
247  $obj->id = $n["id"];
248  $obj->collector = $uc["uc_title"];
249  $obj->highlighted = $uc["highlighted"];
250 
251  //$obj->img = $n["img"];
252  $obj->img = \ilObjUser::_getPersonalPicturePath($n["id"], "xsmall");
253  $obj->public_profile = $n["public_profile"];
254 
255  $obj->online = $n["online"];
256  $obj->last_login = $n["last_login"];
257 
258  // get actions
259  $action_collection = $this->action_collector->getActionsForTargetUser($n["id"]);
260  $obj->actions = array();
261  foreach ($action_collection->getActions() as $action) {
262  $f = new \stdClass();
263  $f->text = $action->getText();
264  $f->href = $action->getHref();
265  $f->data = $action->getData();
266  $obj->actions[] = $f;
267  }
268 
269  $this->data[] = $obj;
270  }
271  }
272  }
273 
274  // update counter
275  $this->updateCounter(
276  count($all_user_ids),
277  count($hall_user_ids)
278  );
279 
280  return array("data" => $this->data, "cnt" => count($all_user_ids) . ":" . count($hall_user_ids));
281  }
get(string $a_keyword, ?string $a_default_value=null)
get setting
const ANONYMOUS_USER_ID
Definition: constants.php:27
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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:
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)
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)
+ 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 109 of file class.WidgetManager.php.

References ILIAS\Repository\int().

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

109  : array
110  {
111  if (!isset($this->user_collections[(int) $a_online_only])) {
112  $this->user_collections[(int) $a_online_only] = $this->user_collector->collectUsers($a_online_only);
113  }
114  return $this->user_collections[(int) $a_online_only];
115  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getUserCounter()

ILIAS\Awareness\WidgetManager::getUserCounter ( )

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

References ILIAS\Awareness\WidgetManager\getUserCollections().

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

117  : Counter
118  {
119  $all_user_ids = array();
120  $hall_user_ids = array();
121 
123 
124  foreach ($user_collections as $uc) {
125  $user_collection = $uc["collection"];
126  $user_ids = $user_collection->getUsers();
127 
128  foreach ($user_ids as $uid) {
129  if (!in_array($uid, $all_user_ids)) {
130  if ($uc["highlighted"]) {
131  $hall_user_ids[] = $uid;
132  } else {
133  $all_user_ids[] = $uid;
134  }
135  }
136  }
137  }
138 
139  return $this->data_service->counter(
140  count($all_user_ids),
141  count($hall_user_ids)
142  );
143  }
getUserCollections(bool $a_online_only=false)
Get user collections.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isWidgetVisible()

ILIAS\Awareness\WidgetManager::isWidgetVisible ( )

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

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

73  : bool
74  {
75  $awrn_set = $this->settings;
76  if (!$awrn_set->get("awrn_enabled", "0") ||
77  ANONYMOUS_USER_ID == $this->user_id ||
78  $this->user_id == 0) {
79  return false;
80  }
81  return true;
82  }
const ANONYMOUS_USER_ID
Definition: constants.php:27

◆ processMetaBar()

ILIAS\Awareness\WidgetManager::processMetaBar ( )

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

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

84  : Counter
85  {
86  $cache_period = (int) $this->settings->get("caching_period");
87  $last_update = $this->session_repo->getLastUpdate();
88  $now = time();
89 
90  if ($last_update == "" || ($now - $last_update) >= $cache_period) {
91  $counter = $this->getUserCounter();
92  $hcnt = $counter->getHighlightCount();
93  $cnt = $counter->getCount();
94  $this->session_repo->setLastUpdate($now);
95  $this->session_repo->setCount($cnt);
96  $this->session_repo->setHighlightCount($hcnt);
97  } else {
98  $cnt = $this->session_repo->getCount();
99  $hcnt = $this->session_repo->getHighlightCount();
100  }
101  return $this->data_service->counter($cnt, $hcnt);
102  }
+ Here is the call graph for this function:

◆ updateCounter()

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

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

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

286  : void {
287  // update counter
288  $now = time();
289  $this->session_repo->setLastUpdate($now);
290  $this->session_repo->setCount($cnt);
291  $this->session_repo->setHighlightCount($hcnt);
292  }
+ 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

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

◆ $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: