ILIAS  release_7 Revision v7.30-3-g800a261c036
ilMembershipCronNotificationsData Class Reference

Manage data for ilMembershipCronNotifications cron job. More...

+ Collaboration diagram for ilMembershipCronNotificationsData:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

 $last_run
 
 $cron_id
 
 $log
 
 $objects
 
 $news = array()
 
 $news_per_user
 
 $user_news_aggr = array()
 
 $likes = array()
 
 $comments = array()
 
 $missing_news_per_user = array()
 
 $missing_news = array()
 

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 11 of file class.ilMembershipCronNotificationsData.php.

Constructor & Destructor Documentation

◆ __construct()

ilMembershipCronNotificationsData::__construct (   $last_run,
  $cron_id 
)
Parameters

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

57 {
58 global $DIC;
59
60 $this->access = $DIC->access();
61
62 $this->last_run = $last_run;
63 $this->cron_id = $cron_id;
64 $this->log = ilLoggerFactory::getLogger("mmbr");
65 $this->load();
66 }
static getLogger($a_component_id)
Get component logger.
global $DIC
Definition: goto.php:24

References $cron_id, $DIC, $last_run, ilLoggerFactory\getLogger(), and load().

+ Here is the call graph for this function:

Member Function Documentation

◆ checkMissingNews()

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

Get missing news.

Parameters
int$user_id
int$ref_id
int$news_id

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

224 {
225 $this->log->debug("Check missing news: " . $user_id . "-" . $ref_id . "-" . $news_id);
226 if (!is_array($this->news_per_user[$user_id][$ref_id]) ||
227 !in_array($news_id, $this->news_per_user[$user_id][$ref_id])) {
228 $this->log->debug("Add missing news: " . $news_id);
229 $this->missing_news[$news_id] = $news_id;
230 $this->missing_news_per_user[$user_id][$ref_id][$news_id] = $news_id;
231 }
232 }

Referenced by load().

+ Here is the caller graph for this function:

◆ getAggregatedNews()

ilMembershipCronNotificationsData::getAggregatedNews ( )

Get aggregated news.

Returns
array[]

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

References $user_news_aggr.

◆ getComments()

ilMembershipCronNotificationsData::getComments (   $news_id,
  $user_id 
)

Get comments for a news and user.

Parameters
int$news_id
int$user_id
Returns
array[ilNote]

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

332 {
333 if (is_array($this->comments[$user_id][$news_id])) {
334 return $this->comments[$user_id][$news_id];
335 }
336 return [];
337 }

◆ getLikes()

ilMembershipCronNotificationsData::getLikes (   $news_id,
  $user_id 
)

Get likes for a news and user.

Parameters
int$news_id
int$user_id
Returns
array

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

317 {
318 if (is_array($this->likes[$user_id][$news_id])) {
319 return $this->likes[$user_id][$news_id];
320 }
321 return [];
322 }

◆ getObjectsForRefId()

ilMembershipCronNotificationsData::getObjectsForRefId (   $a_ref_id)
protected

Get subtree object IDs for ref id.

Parameters
int
Returns
array

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

264 {
265 global $DIC;
266
267 $tree = $DIC->repositoryTree();
268 $nodes = array();
269
270 if (!$tree->isDeleted($a_ref_id)) {
271 // parse repository branch of group
272
273 $node = $tree->getNodeData($a_ref_id);
274 foreach ($tree->getSubTree($node) as $child) {
275 if ($child["type"] != "rolf") {
276 $nodes["obj_id"][$child["obj_id"]] = array(
277 "obj_id" => $child["obj_id"],
278 "type" => $child["type"]);
279 $nodes["ref_id"][$child["child"]] = array(
280 "ref_id" => $child["child"],
281 "obj_id" => $child["obj_id"],
282 "type" => $child["type"]);
283 }
284 }
285 }
286
287 return $nodes;
288 }

References $DIC.

Referenced by load().

+ Here is the caller graph for this function:

◆ load()

ilMembershipCronNotificationsData::load ( )
protected

Load.

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

72 {
73 $ilAccess = $this->access;
74
75 include_once "Services/Membership/classes/class.ilMembershipNotifications.php";
76
77 // all group/course notifications: ref id => user ids
79
80 if (sizeof($this->objects)) {
81 $this->log->debug("nr of objects: " . count($this->objects));
82
83 // gather news for each user over all objects
84 $this->user_news_aggr = array();
85
86 include_once "Services/News/classes/class.ilNewsItem.php";
87 foreach ($this->objects as $ref_id => $user_ids) {
88 $this->log->debug("handle ref id " . $ref_id . ", users: " . count($user_ids));
89
90 // gather news per object
91 $news_item = new ilNewsItem();
92 $objs = $this->getObjectsForRefId($ref_id);
93 if (
94 isset($objs["obj_id"]) &&
95 is_array($objs["obj_id"]) &&
96 $news_item->checkNewsExistsForObjects($objs["obj_id"], $this->last_run)
97 ) {
98 $this->log->debug("Got news");
99 foreach ($user_ids as $user_id) {
100 // gather news for user
101 $user_news = $news_item->getNewsForRefId(
102 $ref_id,
103 false,
104 false,
105 $this->last_run,
106 false,
107 false,
108 false,
109 false,
110 $user_id
111 );
112 if ($user_news) {
113 $this->user_news_aggr[$user_id][$ref_id] = $user_news;
114
115 // store all single news
116 foreach ($this->user_news_aggr as $agg_news) {
117 if (isset($agg_news["aggregation"]) && is_array($agg_news["aggregation"]) && $agg_news["aggregation"] !== []) {
118 foreach ($agg_news["aggregation"] as $n) {
119 $this->news[$n["id"]] = $n;
120 $this->news_per_user[$user_id][$ref_id][$n["id"]] = $n["id"];
121 }
122 } else {
123 if (is_array($agg_news)) {
124 if (isset($agg_news["id"])) {
125 $this->news[$agg_news["id"]] = $agg_news;
126 $this->news_per_user[$user_id][$ref_id][$agg_news["id"]] = $agg_news["id"];
127 } else {
128 foreach ($agg_news as $agg_news_items) {
129 foreach ($agg_news_items as $agg_news_item) {
130 if (isset($agg_news_item["id"])) {
131 $this->news[$agg_news_item["id"]] = $agg_news_item;
132 $this->news_per_user[$user_id][$ref_id][$agg_news_item["id"]] = $agg_news_item["id"];
133 }
134 }
135 }
136 }
137 }
138 }
139 }
140
141 $this->ping();
142 }
143 }
144 } else {
145 $this->log->debug("Got no news");
146 }
147
148 // gather likes per object and store them "per news item"
149 // currently only news can be liked
150 $ref_for_obj_id = array();
151 foreach ($objs["ref_id"] as $i) {
152 $ref_for_obj_id[$i["obj_id"]][$i["ref_id"]] = $i["ref_id"];
153 }
154 include_once("./Services/Like/classes/class.ilLikeData.php");
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) 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", "", $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) {
182 $obj_id,
184 false,
185 false,
186 $this->last_run
187 );
188 foreach ($coms as $c) {
189 if ($c->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", "", $perm_ref_id)) {
197 $has_perm = true;
198 break;
199 }
200 }
201 if ($has_perm) {
202 $this->comments[$user_id][$c->getNewsId()][] = $c;
203
204 // get news data for news that are not included above
205 $this->checkMissingNews($user_id, $ref_id, $c->getNewsId());
206 $this->ping();
207 }
208 }
209 }
210 }
211 }
212 $this->loadMissingNews();
213 }
214 }
$n
Definition: RandomTest.php:85
const IL_NOTE_PUBLIC
Definition: class.ilNote.php:6
Data class for like feature.
loadMissingNews()
Load missing news (news for new likes and/or comments)
getObjectsForRefId($a_ref_id)
Get subtree object IDs for ref id.
checkMissingNews($user_id, $ref_id, $news_id)
Get missing news.
static getActiveUsersforAllObjects()
Get active notifications for all objects.
static _getAllNotesOfSingleRepObject( $a_rep_obj_id, $a_type=IL_NOTE_PRIVATE, $a_incl_sub=false, $a_sort_ascending=false, $a_since="")
get all notes related to a single repository object
$c
Definition: cli.php:37
$i
Definition: metadata.php:24

References $c, $i, $n, ilNote\_getAllNotesOfSingleRepObject(), checkMissingNews(), ilMembershipNotifications\getActiveUsersforAllObjects(), getObjectsForRefId(), IL_NOTE_PUBLIC, 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 237 of file class.ilMembershipCronNotificationsData.php.

238 {
239 include_once("./Services/News/classes/class.ilNewsItem.php");
240 foreach (ilNewsItem::queryNewsByIds($this->missing_news) as $news) {
241 $this->log->debug("Got missing news: " . $news["id"]);
242 $this->news[$news["id"]] = $news;
243 }
244 foreach ($this->missing_news_per_user as $user_id => $r) {
245 foreach ($r as $ref_id => $n) {
246 foreach ($n as $news_id) {
247 $this->log->debug("Load missing news: " . $user_id . "-" . $ref_id . "-" . $news_id);
248 $this->user_news_aggr[$user_id][$ref_id][$news_id] = $this->news[$news_id];
249 $this->news_per_user[$user_id][$ref_id][$news_id] = $news_id;
250 }
251 }
252 }
253 }
static queryNewsByIds(array $a_news_ids)
Query news data by news ids.

References $n, $news, 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 294 of file class.ilMembershipCronNotificationsData.php.

295 {
296 ilCronManager::ping($this->cron_id);
297 }
static ping($a_job_id)
Keep cron job alive.

References ilCronManager\ping().

Referenced by load().

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

Field Documentation

◆ $comments

ilMembershipCronNotificationsData::$comments = array()
protected

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

◆ $cron_id

ilMembershipCronNotificationsData::$cron_id
protected

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

Referenced by __construct().

◆ $last_run

ilMembershipCronNotificationsData::$last_run
protected

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

Referenced by __construct().

◆ $likes

ilMembershipCronNotificationsData::$likes = array()
protected

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

◆ $log

ilMembershipCronNotificationsData::$log
protected

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

◆ $missing_news

ilMembershipCronNotificationsData::$missing_news = array()
protected

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

◆ $missing_news_per_user

ilMembershipCronNotificationsData::$missing_news_per_user = array()
protected

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

◆ $news

ilMembershipCronNotificationsData::$news = array()
protected

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

Referenced by loadMissingNews().

◆ $news_per_user

ilMembershipCronNotificationsData::$news_per_user
protected

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

◆ $objects

ilMembershipCronNotificationsData::$objects
protected

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

◆ $user_news_aggr

ilMembershipCronNotificationsData::$user_news_aggr = array()
protected

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

Referenced by getAggregatedNews().


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