ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilMembershipCronNotificationsData Class Reference

Manage data for ilMembershipCronNotifications cron job. More...

+ Collaboration diagram for ilMembershipCronNotificationsData:

Public Member Functions

 __construct (int $last_run, string $cron_id)
 
 getAggregatedNews ()
 Get aggregated news. More...
 
 getLikes (int $news_id, int $user_id)
 Get likes for a news and user. More...
 
 getComments (int $news_id, int $user_id)
 Get comments for a news and user. More...
 

Protected Member Functions

 load ()
 Load. More...
 
 checkMissingNews (int $user_id, int $ref_id, int $news_id)
 Get missing news*. More...
 
 loadMissingNews ()
 Load missing news (news for new likes and/or comments) More...
 
 getObjectsForRefId (int $a_ref_id)
 Get subtree object IDs for ref id. More...
 
 ping ()
 Ping. More...
 

Protected Attributes

Service $notes
 
int $last_run_unix
 
string $last_run_date
 
string $cron_id
 
ilLogger $log
 
array $objects = []
 
array $news = []
 
array $news_per_user = []
 
array $user_news_aggr = []
 news array (may include aggregated news which contains news as subitems) More...
 
array $likes = []
 
array $comments = []
 
array $missing_news_per_user = []
 
array $missing_news = []
 
ilAccessHandler $access
 

Detailed Description

Manage data for ilMembershipCronNotifications cron job.

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

Definition at line 30 of file class.ilMembershipCronNotificationsData.php.

Constructor & Destructor Documentation

◆ __construct()

ilMembershipCronNotificationsData::__construct ( int  $last_run,
string  $cron_id 
)

Definition at line 59 of file class.ilMembershipCronNotificationsData.php.

60 {
61 global $DIC;
62
63 $this->access = $DIC->access();
64
65 $this->last_run_unix = $last_run;
66 $this->last_run_date = date('Y-m-d H:i:s', $last_run);
67 $this->cron_id = $cron_id;
68 $this->log = ilLoggerFactory::getLogger("mmbr");
69 $this->notes = $DIC->notes();
70 $this->load();
71 }
static getLogger(string $a_component_id)
Get component logger.
global $DIC
Definition: shib_login.php:26

References $cron_id, $DIC, ILIAS\Repository\access(), ilLoggerFactory\getLogger(), and load().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkMissingNews()

ilMembershipCronNotificationsData::checkMissingNews ( int  $user_id,
int  $ref_id,
int  $news_id 
)
protected

Get missing news*.

Definition at line 219 of file class.ilMembershipCronNotificationsData.php.

219 : void
220 {
221 $this->log->debug("Check missing news: " . $user_id . "-" . $ref_id . "-" . $news_id);
222 if (!is_array($this->news_per_user[$user_id][$ref_id] ?? null) ||
223 !in_array($news_id, $this->news_per_user[$user_id][$ref_id])) {
224 $this->log->debug("Add missing news: " . $news_id);
225 $this->missing_news[$news_id] = $news_id;
226 $this->missing_news_per_user[$user_id][$ref_id][$news_id] = $news_id;
227 }
228 }
$ref_id
Definition: ltiauth.php:66

References $ref_id, and $user_id.

Referenced by load().

+ Here is the caller graph for this function:

◆ getAggregatedNews()

ilMembershipCronNotificationsData::getAggregatedNews ( )

Get aggregated news.

Definition at line 297 of file class.ilMembershipCronNotificationsData.php.

297 : array
298 {
300 }
array $user_news_aggr
news array (may include aggregated news which contains news as subitems)

References $user_news_aggr.

◆ getComments()

ilMembershipCronNotificationsData::getComments ( int  $news_id,
int  $user_id 
)

Get comments for a news and user.

Definition at line 316 of file class.ilMembershipCronNotificationsData.php.

316 : array
317 {
318 if (isset($this->comments[$user_id][$news_id])) {
319 return $this->comments[$user_id][$news_id];
320 }
321 return [];
322 }

References $user_id.

◆ getLikes()

ilMembershipCronNotificationsData::getLikes ( int  $news_id,
int  $user_id 
)

Get likes for a news and user.

Definition at line 305 of file class.ilMembershipCronNotificationsData.php.

305 : array
306 {
307 if (isset($this->likes[$user_id][$news_id])) {
308 return $this->likes[$user_id][$news_id];
309 }
310 return [];
311 }

References $user_id.

◆ getObjectsForRefId()

ilMembershipCronNotificationsData::getObjectsForRefId ( int  $a_ref_id)
protected

Get subtree object IDs for ref id.

Definition at line 255 of file class.ilMembershipCronNotificationsData.php.

255 : array
256 {
257 global $DIC;
258
259 $tree = $DIC->repositoryTree();
260 $nodes = array();
261
262 if (!$tree->isDeleted($a_ref_id)) {
263 // parse repository branch of group
264
265 $node = $tree->getNodeData($a_ref_id);
266 foreach ($tree->getSubTree($node) as $child) {
267 if ($child["type"] !== "rolf") {
268 $nodes["obj_id"][$child["obj_id"]] = array(
269 "obj_id" => $child["obj_id"],
270 "type" => $child["type"]
271 );
272 $nodes["ref_id"][$child["child"]] = array(
273 "ref_id" => $child["child"],
274 "obj_id" => $child["obj_id"],
275 "type" => $child["type"]
276 );
277 }
278 }
279 }
280
281 return $nodes;
282 }

References $DIC.

Referenced by load().

+ Here is the caller graph for this function:

◆ load()

ilMembershipCronNotificationsData::load ( )
protected

Load.

Definition at line 76 of file class.ilMembershipCronNotificationsData.php.

76 : void
77 {
78 $ilAccess = $this->access;
79
80 // all group/course notifications: ref id => user ids
82
83 if (count($this->objects)) {
84 $this->log->debug("nr of objects: " . count($this->objects));
85
86 // gather news for each user over all objects
87 $this->user_news_aggr = array();
88
89 foreach ($this->objects as $ref_id => $user_ids) {
90 $this->log->debug("handle ref id " . $ref_id . ", users: " . count($user_ids));
91 $this->log->debug("last run unix: " . $this->last_run_unix);
92 $this->log->debug("last run date: " . $this->last_run_date);
93 // gather news per object
94 $news_item = new ilNewsItem();
95 $objs = $this->getObjectsForRefId($ref_id);
96 if (
97 isset($objs["obj_id"]) &&
98 is_array($objs["obj_id"]) &&
99 $news_item->checkNewsExistsForObjects($objs["obj_id"], $this->last_run_date)
100 ) {
101 $this->log->debug("Got news");
102 foreach ($user_ids as $user_id) {
103 // gather news for user
104 $user_news = $news_item->getNewsForRefId(
105 $ref_id,
106 false,
107 false,
108 $this->last_run_date,
109 false,
110 false,
111 false,
112 false,
114 );
115 if ($user_news) {
116 $this->user_news_aggr[$user_id][$ref_id] = $user_news;
117
118 // store all single news
119 foreach ($this->user_news_aggr as $agg_news) {
120 if (isset($agg_news["aggregation"]) && is_array($agg_news["aggregation"]) && $agg_news["aggregation"] !== []) {
121 foreach ($agg_news["aggregation"] as $n) {
122 $this->news[$n["id"]] = $n;
123 $this->news_per_user[$user_id][$ref_id][$n["id"]] = $n["id"];
124 }
125 } elseif (is_array($agg_news)) {
126 if (isset($agg_news["id"])) {
127 $this->news[$agg_news["id"]] = $agg_news;
128 $this->news_per_user[$user_id][$ref_id][$agg_news["id"]] = $agg_news["id"];
129 } else {
130 foreach ($agg_news as $agg_news_items) {
131 foreach ($agg_news_items as $agg_news_item) {
132 if (isset($agg_news_item["id"])) {
133 $this->news[$agg_news_item["id"]] = $agg_news_item;
134 $this->news_per_user[$user_id][$ref_id][$agg_news_item["id"]] = $agg_news_item["id"];
135 }
136 }
137 }
138 }
139 }
140 }
141
142 $this->ping();
143 }
144 }
145 } else {
146 $this->log->debug("Got no news");
147 }
148
149 // gather likes per object and store them "per news item"
150 // currently only news can be liked
151 $ref_for_obj_id = array();
152 foreach ($objs["ref_id"] as $i) {
153 $ref_for_obj_id[$i["obj_id"]][$i["ref_id"]] = $i["ref_id"];
154 }
155 $like_data = new ilLikeData(array_keys($objs["obj_id"]));
156 foreach (array_keys($objs["obj_id"]) as $obj_id) {
157 $this->log->debug("Get like data for obj_id: " . $obj_id);
158 foreach ($like_data->getExpressionEntriesForObject($obj_id, $this->last_run_date) as $like) {
159 reset($user_ids);
160 foreach ($user_ids as $user_id) {
161 $has_perm = false;
162 foreach ($ref_for_obj_id[$obj_id] as $perm_ref_id) {
163 if ($ilAccess->checkAccessOfUser($user_id, "read", "", (int) $perm_ref_id)) {
164 $has_perm = true;
165 break;
166 }
167 }
168 if ($has_perm) {
169 $this->likes[$user_id][$like["news_id"]][] = $like;
170
171 // get news data for news that are not included above
172 $this->checkMissingNews($user_id, $ref_id, $like["news_id"]);
173 $this->ping();
174 }
175 }
176 }
177 }
178
179 // gather comments
180 foreach (array_keys($objs["obj_id"]) as $obj_id) {
181 $coms = $this->notes
182 ->domain()
183 ->getAllCommentsForObjId(
184 $obj_id,
185 $this->last_run_date
186 );
187 foreach ($coms as $c) {
188 $comment_context = $c->getContext();
189 if ($comment_context->getNewsId() === 0) {
190 continue;
191 }
192 reset($user_ids);
193 foreach ($user_ids as $user_id) {
194 $has_perm = false;
195 foreach ($ref_for_obj_id[$obj_id] as $perm_ref_id) {
196 if ($ilAccess->checkAccessOfUser($user_id, "read", "", (int) $perm_ref_id)) {
197 $has_perm = true;
198 break;
199 }
200 }
201 if ($has_perm) {
202 $this->comments[$user_id][$comment_context->getNewsId()][] = $c;
203
204 // get news data for news that are not included above
205 $this->checkMissingNews($user_id, $ref_id, $comment_context->getNewsId());
206 $this->ping();
207 }
208 }
209 }
210 }
211 }
212 $this->loadMissingNews();
213 }
214 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadMissingNews()
Load missing news (news for new likes and/or comments)
getObjectsForRefId(int $a_ref_id)
Get subtree object IDs for ref id.
checkMissingNews(int $user_id, int $ref_id, int $news_id)
Get missing news*.
static getActiveUsersforAllObjects()
Get active notifications for all objects.
A news item can be created by different sources.
$c
Definition: deliver.php:25

References $access, $c, $ref_id, $user_id, checkMissingNews(), ilMembershipNotifications\getActiveUsersforAllObjects(), getObjectsForRefId(), loadMissingNews(), and ping().

Referenced by __construct().

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

◆ loadMissingNews()

ilMembershipCronNotificationsData::loadMissingNews ( )
protected

Load missing news (news for new likes and/or comments)

Definition at line 233 of file class.ilMembershipCronNotificationsData.php.

233 : void
234 {
235 foreach (ilNewsItem::queryNewsByIds($this->missing_news) as $news) {
236 $this->log->debug("Got missing news: " . $news["id"]);
237 $this->news[$news["id"]] = $news;
238 }
239 foreach ($this->missing_news_per_user as $user_id => $r) {
240 foreach ($r as $ref_id => $n) {
241 foreach ($n as $news_id) {
242 $this->log->debug("Load missing news: " . $user_id . "-" . $ref_id . "-" . $news_id);
243 if (isset($this->news[$news_id])) {
244 $this->user_news_aggr[$user_id][$ref_id][$news_id] = $this->news[$news_id];
245 $this->news_per_user[$user_id][$ref_id][$news_id] = $news_id;
246 }
247 }
248 }
249 }
250 }
static queryNewsByIds(array $a_news_ids)
Query news data by news ids.

References $news, $ref_id, $user_id, and ilNewsItem\queryNewsByIds().

Referenced by load().

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

◆ ping()

ilMembershipCronNotificationsData::ping ( )
protected

Ping.

Definition at line 287 of file class.ilMembershipCronNotificationsData.php.

287 : void
288 {
289 global $DIC;
290
291 $DIC->cron()->manager()->ping($this->cron_id);
292 }

References $DIC.

Referenced by load().

+ Here is the caller graph for this function:

Field Documentation

◆ $access

ilAccessHandler ilMembershipCronNotificationsData::$access
protected

Definition at line 57 of file class.ilMembershipCronNotificationsData.php.

Referenced by load().

◆ $comments

array ilMembershipCronNotificationsData::$comments = []
protected

Definition at line 53 of file class.ilMembershipCronNotificationsData.php.

◆ $cron_id

string ilMembershipCronNotificationsData::$cron_id
protected

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

Referenced by __construct().

◆ $last_run_date

string ilMembershipCronNotificationsData::$last_run_date
protected

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

◆ $last_run_unix

int ilMembershipCronNotificationsData::$last_run_unix
protected
Todo:
convert to DateTime

Definition at line 36 of file class.ilMembershipCronNotificationsData.php.

◆ $likes

array ilMembershipCronNotificationsData::$likes = []
protected

Definition at line 52 of file class.ilMembershipCronNotificationsData.php.

◆ $log

ilLogger ilMembershipCronNotificationsData::$log
protected

Definition at line 39 of file class.ilMembershipCronNotificationsData.php.

◆ $missing_news

array ilMembershipCronNotificationsData::$missing_news = []
protected

Definition at line 55 of file class.ilMembershipCronNotificationsData.php.

◆ $missing_news_per_user

array ilMembershipCronNotificationsData::$missing_news_per_user = []
protected

Definition at line 54 of file class.ilMembershipCronNotificationsData.php.

◆ $news

array ilMembershipCronNotificationsData::$news = []
protected

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

Referenced by loadMissingNews().

◆ $news_per_user

array ilMembershipCronNotificationsData::$news_per_user = []
protected

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

◆ $notes

Service ilMembershipCronNotificationsData::$notes
protected

Definition at line 32 of file class.ilMembershipCronNotificationsData.php.

◆ $objects

array ilMembershipCronNotificationsData::$objects = []
protected

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

◆ $user_news_aggr

array ilMembershipCronNotificationsData::$user_news_aggr = []
protected

news array (may include aggregated news which contains news as subitems)

Definition at line 51 of file class.ilMembershipCronNotificationsData.php.

Referenced by getAggregatedNews().


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