ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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: saml.php:7

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

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]) ||
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 }

Referenced by load().

+ Here is the caller graph for this function:

◆ getAggregatedNews()

ilMembershipCronNotificationsData::getAggregatedNews ( )

Get aggregated news.

Returns
array[]

Definition at line 300 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 327 of file class.ilMembershipCronNotificationsData.php.

328 {
329 if (is_array($this->comments[$user_id][$news_id])) {
330 return $this->comments[$user_id][$news_id];
331 }
332 return [];
333 }

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

313 {
314 if (is_array($this->likes[$user_id][$news_id])) {
315 return $this->likes[$user_id][$news_id];
316 }
317 return [];
318 }

◆ getObjectsForRefId()

ilMembershipCronNotificationsData::getObjectsForRefId (   $a_ref_id)
protected

Get subtree object IDs for ref id.

Parameters
int
Returns
array

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

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

References $DIC, $nodes, and $tree.

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 ($news_item->checkNewsExistsForObjects($objs["obj_id"], $this->last_run)) {
94 $this->log->debug("Got news");
95 foreach ($user_ids as $user_id) {
96 // gather news for user
97 $user_news = $news_item->getNewsForRefId(
98 $ref_id,
99 false,
100 false,
101 $this->last_run,
102 false,
103 false,
104 false,
105 false,
106 $user_id
107 );
108 if ($user_news) {
109 $this->user_news_aggr[$user_id][$ref_id] = $user_news;
110
111 // store all single news
112 foreach ($this->user_news_aggr as $agg_news) {
113 if (isset($agg_news["aggregation"]) && is_array($agg_news["aggregation"]) && $agg_news["aggregation"] !== []) {
114 foreach ($agg_news["aggregation"] as $n) {
115 $this->news[$n["id"]] = $n;
116 $this->news_per_user[$user_id][$ref_id][$n["id"]] = $n["id"];
117 }
118 } else {
119 if (is_array($agg_news)) {
120 if (isset($agg_news["id"])) {
121 $this->news[$agg_news["id"]] = $agg_news;
122 $this->news_per_user[$user_id][$ref_id][$agg_news["id"]] = $agg_news["id"];
123 } else {
124 foreach ($agg_news as $agg_news_items) {
125 foreach ($agg_news_items as $agg_news_item) {
126 if (isset($agg_news_item["id"])) {
127 $this->news[$agg_news_item["id"]] = $agg_news_item;
128 $this->news_per_user[$user_id][$ref_id][$agg_news_item["id"]] = $agg_news_item["id"];
129 }
130 }
131 }
132 }
133 }
134 }
135 }
136
137 $this->ping();
138 }
139 }
140 } else {
141 $this->log->debug("Got no news");
142 }
143
144 // gather likes per object and store them "per news item"
145 // currently only news can be liked
146 $ref_for_obj_id = array();
147 foreach ($objs["ref_id"] as $i) {
148 $ref_for_obj_id[$i["obj_id"]][$i["ref_id"]] = $i["ref_id"];
149 }
150 include_once("./Services/Like/classes/class.ilLikeData.php");
151 $like_data = new ilLikeData(array_keys($objs["obj_id"]));
152 foreach (array_keys($objs["obj_id"]) as $obj_id) {
153 $this->log->debug("Get like data for obj_id: " . $obj_id);
154 foreach ($like_data->getExpressionEntriesForObject($obj_id, $this->last_run) as $like) {
155 reset($user_ids);
156 foreach ($user_ids as $user_id) {
157 $has_perm = false;
158 foreach ($ref_for_obj_id[$obj_id] as $perm_ref_id) {
159 if ($ilAccess->checkAccessOfUser($user_id, "read", "", $perm_ref_id)) {
160 $has_perm = true;
161 break;
162 }
163 }
164 if ($has_perm) {
165 $this->likes[$user_id][$like["news_id"]][] = $like;
166
167 // get news data for news that are not included above
168 $this->checkMissingNews($user_id, $ref_id, $like["news_id"]);
169 $this->ping();
170 }
171 }
172 }
173 }
174
175 // gather comments
176 foreach (array_keys($objs["obj_id"]) as $obj_id) {
178 $obj_id,
180 false,
181 false,
182 $this->last_run
183 );
184 foreach ($coms as $c) {
185 if ($c->getNewsId() == 0) {
186 continue;
187 }
188 reset($user_ids);
189 foreach ($user_ids as $user_id) {
190 $has_perm = false;
191 foreach ($ref_for_obj_id[$obj_id] as $perm_ref_id) {
192 if ($ilAccess->checkAccessOfUser($user_id, "read", "", $perm_ref_id)) {
193 $has_perm = true;
194 break;
195 }
196 }
197 if ($has_perm) {
198 $this->comments[$user_id][$c->getNewsId()][] = $c;
199
200 // get news data for news that are not included above
201 $this->checkMissingNews($user_id, $ref_id, $c->getNewsId());
202 $this->ping();
203 }
204 }
205 }
206 }
207 }
208 $this->loadMissingNews();
209 }
210 }
$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
$i
Definition: disco.tpl.php:19

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

234 {
235 include_once("./Services/News/classes/class.ilNewsItem.php");
236 foreach (ilNewsItem::queryNewsByIds($this->missing_news) as $news) {
237 $this->log->debug("Got missing news: " . $news["id"]);
238 $this->news[$news["id"]] = $news;
239 }
240 foreach ($this->missing_news_per_user as $user_id => $r) {
241 foreach ($r as $ref_id => $n) {
242 foreach ($n as $news_id) {
243 $this->log->debug("Load missing news: " . $user_id . "-" . $ref_id . "-" . $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 }
static queryNewsByIds(array $a_news_ids)
Query news data by news ids.
$r
Definition: example_031.php:79

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

291 {
292 ilCronManager::ping($this->cron_id);
293 }
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: