ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.Collector.php
Go to the documentation of this file.
1<?php
2
19namespace ILIAS\Awareness\User;
20
25
31{
32 protected static ?array $online_users = null;
34 protected static array $online_user_ids = array();
35 protected \ilRbacReview $rbacreview;
40 protected array $collections;
41 protected int $user_id;
42 protected int $ref_id;
43 protected \ilSetting $settings;
45
46 public function __construct(
47 int $user_id,
48 int $ref_id,
51 InternalDomainService $domain_service
52 ) {
53 $this->user_id = $user_id;
54 $this->settings = $domain_service->settings();
55 $this->provider_factory = $domain_service
56 ->userProvider();
57 $this->data_service = $data_service;
58 $this->admin_manager = $domain_service
59 ->admin($ref_id);
60 $this->rbacreview = $domain_service->rbac()->review();
61 $this->repo_service = $repo_service;
62 }
63
64 public static function getOnlineUsers(): array
65 {
66 if (self::$online_users === null) {
67 self::$online_user_ids = array();
68 self::$online_users = array();
69 foreach (\ilObjUser::_getUsersOnline() as $u) {
70 // ask context $u["context"] if it supports pushMessages
71 if ($u["context"] &&
72 \ilContext::directCall($u["context"], "supportsPushMessages")) {
73 self::$online_users[$u["user_id"]] = $u;
74 self::$online_user_ids[] = $u["user_id"];
75 }
76 }
77 }
79 }
80
81
85 public function collectUsers(bool $a_online_only = false): array
86 {
88
89 $this->collections = array();
90
91 $awrn_logger = \ilLoggerFactory::getLogger('awrn');
92
93 $awrn_logger->debug("Start, Online Only: " . $a_online_only . ", Current User: " . $this->user_id);
94
96 $all_users = array();
97 foreach ($this->provider_factory->getAllProviders() as $prov) {
98 $awrn_logger->debug("Provider: " . $prov->getProviderId() . ", Activation Mode: " . $this->admin_manager->getActivationMode($prov->getProviderId()) . ", Current User: " . $this->user_id);
99
100 // overall collection of users
101 $collection = $this->data_service->userCollection();
102
103 $provider_active = $this->admin_manager->isProviderActivated($prov->getProviderId());
104 $provider_includes_offline = $this->admin_manager->includesProviderOfflineUsers($prov->getProviderId());
105
106 if ($provider_active) {
107 $online_users = null;
108 if (!$provider_includes_offline || $a_online_only) {
109 $awrn_logger->debug("Provider: " . $prov->getProviderId() . ", Online Filter Users: " . count(self::$online_user_ids) . ", Current User: " . $this->user_id);
111 }
112
113 $coll = $this->collectUsersFromProvider($prov, $online_users);
114 $awrn_logger->debug("Provider: " . $prov->getProviderId() . ", Collected Users: " . count($coll) . ", Current User: " . $this->user_id);
115
116 foreach ($coll->getUsers() as $user_id) {
117 // filter out the anonymous user
119 continue;
120 }
121 // filter out current user
122 if ($user_id == $this->user_id) {
123 continue;
124 }
125
126 $awrn_logger->debug("Current User: " . $this->user_id . ", " .
127 "Provider: " . $prov->getProviderId() . ", Collected User: " . $user_id);
128
129 // cross check online, filter out offline users (if necessary)
130 if ((!$a_online_only && $provider_includes_offline)
131 || in_array($user_id, self::$online_user_ids)) {
133 if (!in_array($user_id, $all_users)) {
134 $all_users[] = $user_id;
135 }
136 }
137 }
138 }
139 $this->collections[] = array(
140 "uc_title" => $prov->getTitle(),
141 "highlighted" => $prov->isHighlighted(),
142 "collection" => $collection
143 );
144 }
145
146 $remove_users = array();
147
148 if ($this->settings->get("hide_own_online_status") === "n") {
149 // remove all users with hide_own_online_status "y"
150 foreach (\ilObjUser::getUserSubsetByPreferenceValue($all_users, "hide_own_online_status", "y") as $u) {
151 $remove_users[] = $u;
152 }
153 } else {
154 // remove all, except user with hide_own_online_status "n"
155 $show_users = \ilObjUser::getUserSubsetByPreferenceValue($all_users, "hide_own_online_status", "n");
156 $remove_users = array_filter($all_users, function ($i) use ($show_users) {
157 return !in_array($i, $show_users);
158 });
159 }
160
161 global $DIC;
162 $remove_users = array_merge($remove_users, $DIC['legalDocuments']->usersWithHiddenOnlineStatus($all_users));
163
164 $this->removeUsersFromCollections($remove_users);
165
166 return $this->collections;
167 }
168
170 {
171 $coll = $this->data_service->userCollection();
172 foreach ($prov->getInitialUserSet($online_users) as $user_id) {
173 if ((is_null($online_users) || in_array($user_id, $online_users))) {
174 $coll->addUser($user_id);
175 }
176 }
177 return $coll;
178 }
179
184 protected function removeUsersFromCollections(array $a_remove_users): void
185 {
186 foreach ($this->collections as $c) {
187 reset($a_remove_users);
188 foreach ($a_remove_users as $u) {
189 $c["collection"]->removeUser($u);
190 }
191 }
192 }
193}
Administrate awareness tool.
Represents a set of collected users.
Collects users from all providers.
Awareness AdminManager $admin_manager
Awareness InternalDataService $data_service
removeUsersFromCollections(array $a_remove_users)
Remove users from collection.
__construct(int $user_id, int $ref_id, InternalDataService $data_service, InternalRepoService $repo_service, InternalDomainService $domain_service)
collectUsersFromProvider(Provider $prov, ?array $online_users)
InternalRepoService $repo_service
collectUsers(bool $a_online_only=false)
Collect users.
static directCall(string $a_type, string $a_method)
Call context method directly without internal handling.
static getLogger(string $a_component_id)
Get component logger.
static _getUsersOnline(int $a_user_id=0, bool $a_no_anonymous=false)
static getUserSubsetByPreferenceValue(array $a_user_ids, string $a_keyword, string $a_val)
const ANONYMOUS_USER_ID
Definition: constants.php:27
$c
Definition: deliver.php:25
getInitialUserSet(?array $user_ids=null)
Get initial set of users.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26