3 declare(strict_types=1);
42 $this->
lng = $DIC->language();
43 $this->db = $DIC->database();
44 $this->
logger = $DIC->logger()->mmbr();
45 $this->tree = $DIC->repositoryTree();
55 return "mem_notification";
60 return $this->
lng->txt(
"enable_course_group_notifications");
65 return $this->
lng->txt(
"enable_course_group_notifications_desc");
70 return JobScheduleType::DAILY;
92 $this->
logger->debug(
"===Member Notifications=== start");
94 $status = JobResult::STATUS_NO_ACTION;
95 $status_details =
null;
98 $last_run = $setting->get(get_class($this));
102 $last_run = date(
"Y-m-d H:i:s", strtotime(
"yesterday"));
104 $status_details =
"No previous run found - starting from yesterday.";
106 elseif (strlen($last_run) === 10) {
107 $last_run .=
" 00:00:00";
109 $status_details =
"Switched from daily runs to open schedule.";
115 $last_run_unix = strtotime($last_run);
117 $this->
logger->debug(
"Last run: " . $last_run);
121 $this->
logger->debug(
"prepare sending mails");
129 $user_news_aggr = $this->data->getAggregatedNews();
130 if (count($user_news_aggr)) {
131 foreach ($user_news_aggr as
$user_id => $user_news) {
132 $this->
logger->debug(
"sending mails to user " .
$user_id .
", nr news: " . count($user_news));
134 $DIC->cron()->manager()->ping($this->
getId());
137 $status = JobResult::STATUS_OK;
142 $this->
logger->debug(
"save run");
145 $setting->set(get_class($this), date(
"Y-m-d H:i:s"));
147 $result->setStatus($status);
148 if ($status_details) {
149 $result->setMessage($status_details);
151 $this->
logger->debug(
"===Member Notifications=== done");
162 protected function parseNewsItem(
163 int $a_parent_ref_id,
164 array &$a_filter_map,
171 $obj_definiton = $DIC[
"objDefinition"];
175 $wrong_parent = (array_key_exists($a_item[
"id"], $a_filter_map) &&
176 $a_parent_ref_id != $a_filter_map[$a_item[
"id"]]);
184 $item_obj_type = $a_item[
"context_obj_type"];
188 if ($a_item[
"aggregation"] ??
false) {
190 if ($item_obj_type ===
"file" &&
191 count($a_item[
"aggregation"]) === 1) {
196 foreach ($a_item[
"aggregation"] as $subitem) {
197 $sub_res = $this->parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem,
true, $a_user_id);
199 $sub[md5($sub_res)] = $sub_res;
207 $a_item[
"context_obj_type"],
208 (
string) $a_item[
"title"],
209 (
bool) (
int) $a_item[
"content_is_lang_var"],
210 (
int) ($a_item[
"agg_ref_id"] ?? 0),
211 $a_item[
"aggregation"] ?? [],
216 $a_item[
"context_obj_type"],
217 (
string) $a_item[
"title"],
218 (
bool) (
int) $a_item[
"content_is_lang_var"],
226 $a_item[
"context_obj_type"],
227 (
string) $a_item[
"content"],
228 (
bool) (
int) $a_item[
"content_text_is_lang_var"],
232 $title = trim($title);
238 switch ($item_obj_type) {
241 $res = $lng->
txt(
"obj_" . $item_obj_type) .
242 ' "' . $item_obj_title .
'": ' . $title;
244 $res .=
'"' . $title .
'": "' . $content .
'"';
249 if (!isset($a_item[
"aggregation"]) ||
250 count($a_item[
"aggregation"]) === 1) {
251 $res = $lng->
txt(
"obj_" . $item_obj_type) .
252 ' "' . $item_obj_title .
'" - ' . $title;
255 $title = str_replace(
256 " " . count($a_item[
"aggregation"]) .
" ",
257 " " . count($sub) .
" ",
265 $type_txt = ($obj_definiton->isPlugin($item_obj_type))
267 : $lng->
txt(
"obj_" . $item_obj_type);
269 ' "' . $item_obj_title .
'"';
271 $res .=
': "' . $title .
'"';
274 $res .=
' - ' . $content;
280 $comments = $this->data->getComments((
int) $a_item[
"id"], $a_user_id);
282 $res .=
"\n" . $lng->
txt(
"news_new_comments") .
" (" . count(
$comments) .
")";
294 $likes = $this->data->getLikes((
int) $a_item[
"id"], $a_user_id);
295 if (count($likes) > 0) {
296 $res .=
"\n" . $lng->
txt(
"news_new_reactions") .
" (" . count($likes) .
")";
298 foreach ($likes as $l) {
310 if (is_array($sub) && count($sub)) {
311 $res .=
"\n" . implode(
"\n", $sub);
314 $res = str_replace(
"<br />",
" ",
$res);
325 $parent_map = $news_map = $parsed_map = array();
328 foreach ($a_objects as $parent_ref_id => $news) {
329 foreach ($news as $item) {
330 $news_map[$item[
"id"]] = (
int) ($item[
"ref_id"] ?? 0);
331 $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
333 if ($item[
"aggregation"] ??
false) {
334 foreach ($item[
"aggregation"] as $subitem) {
335 $news_map[$subitem[
"id"]] = (
int) ($subitem[
"ref_id"] ?? 0);
336 $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
342 foreach ($parent_map as $news_id => $parents) {
343 if (count($parents) > 1 && $news_map[$news_id] > 0) {
344 $path = $this->tree->getPathId((
int) $news_map[$news_id]);
345 $lookup = array_flip(
$path);
348 foreach ($parents as $parent_ref_id) {
349 $level = max($level, (
int) ($lookup[$parent_ref_id] ?? 0));
352 $parsed_map[$news_id] =
$path[$level];
363 protected function sendMail(
int $a_user_id, array $a_objects,
string $a_last_run): void
367 $ilClientIniFile = $DIC[
'ilClientIniFile'];
370 $ntf->setLangModules(array(
"crs",
"news"));
382 foreach ($a_objects as $parent_ref_id => $items) {
387 foreach ($this->tree->getPathId($parent_ref_id) as $node) {
398 $this->
logger->debug(
"ref id: " . $parent_ref_id .
", items: " . count($items));
402 if (is_array($items)) {
403 foreach ($items as $news_item) {
404 if ($news_item ===
null) {
409 $parsed_item = $this->parseNewsItem($parent_ref_id, $filter_map, $news_item,
false, $a_user_id);
411 $parsed[md5($parsed_item)] = $parsed_item;
417 if (count($parsed)) {
418 $parent[
"news"] = implode(
"\n\n", $parsed);
419 $tmp[
$path] = $parent;
425 $this->
logger->debug(
"returning");
431 $obj_index = array();
433 foreach ($tmp as $item) {
436 $txt .=
"(" . $counter .
") " . $item[
"title"] .
"\n" .
437 $item[
"url"] .
"\n\n" .
438 $item[
"news"] .
"\n\n";
440 $obj_index[] =
"(" . $counter .
") " . $item[
"title"];
443 $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
447 $lng->
txt(
"crs_intro_course_group_notification_index"),
451 $ntf->addAdditionalInfo(
453 trim(implode(
"\n", $obj_index)),
459 $ntf->addAdditionalInfo(
466 $client = $ilClientIniFile->readVariable(
'client',
'name');
467 $subject = sprintf($lng->
txt(
"crs_subject_course_group_notification"),
$client);
469 $mail_content = $ntf->composeAndGetMessage($a_user_id,
null,
"read",
true);
470 $this->
logger->debug(
"sending mail content: " . $mail_content);
486 switch ($a_form_id) {
489 $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
490 $this->
lng->txt(
"enabled") :
491 $this->
lng->txt(
"disabled");
498 $setting->
set(
"crsgrp_ntf", (
string) ((
int) $a_currently_active));
static array static setUseRelativeDates(bool $a_status)
set use relative dates
static determineNewsContent(string $a_context_obj_type, string $a_content, bool $a_is_lang_var, ?ilLanguage $lng=null)
Determine new content.
ilMembershipCronNotificationsData $data
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
getUserLanguage()
Return language of user.
set(string $a_key, string $a_val)
addToExternalSettingsForm(int $a_form_id, array &$a_fields, bool $a_is_active)
static getExpressionText(int $a_const)
Get expression text for const.
Manage data for ilMembershipCronNotifications cron job.
activationWasToggled(ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
loadLanguageModule(string $a_module)
Load language module.
filterDuplicateItems(array $a_objects)
Filter duplicate news items from structure*.
static useRelativeDates()
static _lookupObjId(int $ref_id)
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:
getDefaultScheduleValue()
static _lookupTitle(int $obj_id)
static _getLanguageOfUser(int $a_usr_id)
Get language object of user.
static _getStaticLink(?int $a_ref_id, string $a_type='', bool $a_fallback_goto=true, string $append="")
static determineNewsTitle(string $a_context_obj_type, string $a_title, bool $a_content_is_lang_var, int $a_agg_ref_id=0, array $a_aggregation=[], ?ilLanguage $lng=null)
Determine title for news item entry.
Course/group notifications.
static lookupTxtById(string $plugin_id, string $lang_var)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ?ilObjUser $user=null,)
sendMail(int $a_user_id, array $a_objects, string $a_last_run)
Send news mail for 1 user and n objects.
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupLogin(int $a_user_id)