3 declare(strict_types=1);
40 $this->
lng = $DIC->language();
41 $this->db = $DIC->database();
42 $this->
logger = $DIC->logger()->mmbr();
43 $this->tree = $DIC->repositoryTree();
53 return "mem_notification";
58 return $this->
lng->txt(
"enable_course_group_notifications");
63 return $this->
lng->txt(
"enable_course_group_notifications_desc");
68 return CronJobScheduleType::SCHEDULE_TYPE_DAILY;
90 $this->
logger->debug(
"===Member Notifications=== start");
93 $status_details = null;
96 $last_run = $setting->get(get_class($this));
100 $last_run = date(
"Y-m-d H:i:s", strtotime(
"yesterday"));
102 $status_details =
"No previous run found - starting from yesterday.";
104 elseif (strlen($last_run) === 10) {
105 $last_run .=
" 00:00:00";
107 $status_details =
"Switched from daily runs to open schedule.";
113 $last_run_unix = strtotime($last_run);
115 $this->
logger->debug(
"Last run: " . $last_run);
119 $this->
logger->debug(
"prepare sending mails");
127 $user_news_aggr = $this->data->getAggregatedNews();
128 if (count($user_news_aggr)) {
129 foreach ($user_news_aggr as
$user_id => $user_news) {
130 $this->
logger->debug(
"sending mails to user " .
$user_id .
", nr news: " . count($user_news));
132 $DIC->cron()->manager()->ping($this->
getId());
140 $this->
logger->debug(
"save run");
143 $setting->set(get_class($this), date(
"Y-m-d H:i:s"));
145 $result->setStatus($status);
146 if ($status_details) {
147 $result->setMessage($status_details);
149 $this->
logger->debug(
"===Member Notifications=== done");
160 protected function parseNewsItem(
161 int $a_parent_ref_id,
162 array &$a_filter_map,
169 $obj_definiton = $DIC[
"objDefinition"];
173 $wrong_parent = (array_key_exists($a_item[
"id"], $a_filter_map) &&
174 $a_parent_ref_id != $a_filter_map[$a_item[
"id"]]);
182 $item_obj_type = $a_item[
"context_obj_type"];
186 if ($a_item[
"aggregation"] ??
false) {
188 if ($item_obj_type ===
"file" &&
189 count($a_item[
"aggregation"]) === 1) {
194 foreach ($a_item[
"aggregation"] as $subitem) {
195 $sub_res = $this->parseNewsItem($a_parent_ref_id, $a_filter_map, $subitem,
true, $a_user_id);
197 $sub[md5($sub_res)] = $sub_res;
205 $a_item[
"context_obj_type"],
206 (
string) $a_item[
"title"],
207 (
bool) (
int) $a_item[
"content_is_lang_var"],
208 (
int) ($a_item[
"agg_ref_id"] ?? 0),
209 $a_item[
"aggregation"] ?? [],
214 $a_item[
"context_obj_type"],
215 (
string) $a_item[
"title"],
216 (
bool) (
int) $a_item[
"content_is_lang_var"],
224 $a_item[
"context_obj_type"],
225 (
string) $a_item[
"content"],
226 (
bool) (
int) $a_item[
"content_text_is_lang_var"],
230 $title = trim($title);
236 switch ($item_obj_type) {
239 $res = $lng->
txt(
"obj_" . $item_obj_type) .
240 ' "' . $item_obj_title .
'": ' . $title;
242 $res .=
'"' . $title .
'": "' . $content .
'"';
247 if (!isset($a_item[
"aggregation"]) ||
248 count($a_item[
"aggregation"]) === 1) {
249 $res = $lng->
txt(
"obj_" . $item_obj_type) .
250 ' "' . $item_obj_title .
'" - ' . $title;
253 $title = str_replace(
254 " " . count($a_item[
"aggregation"]) .
" ",
255 " " . count($sub) .
" ",
263 $type_txt = ($obj_definiton->isPlugin($item_obj_type))
265 : $lng->
txt(
"obj_" . $item_obj_type);
267 ' "' . $item_obj_title .
'"';
269 $res .=
': "' . $title .
'"';
272 $res .=
' - ' . $content;
278 $comments = $this->data->getComments((
int) $a_item[
"id"], $a_user_id);
280 $res .=
"\n" . $lng->
txt(
"news_new_comments") .
" (" . count(
$comments) .
")";
292 $likes = $this->data->getLikes((
int) $a_item[
"id"], $a_user_id);
293 if (count($likes) > 0) {
294 $res .=
"\n" . $lng->
txt(
"news_new_reactions") .
" (" . count($likes) .
")";
296 foreach ($likes as $l) {
308 if (is_array($sub) && count($sub)) {
309 $res .=
"\n" . implode(
"\n", $sub);
312 $res = str_replace(
"<br />",
" ",
$res);
323 $parent_map = $news_map = $parsed_map = array();
326 foreach ($a_objects as $parent_ref_id => $news) {
327 foreach ($news as $item) {
328 $news_map[$item[
"id"]] = (
int) ($item[
"ref_id"] ?? 0);
329 $parent_map[$item[
"id"]][$parent_ref_id] = $parent_ref_id;
331 if ($item[
"aggregation"] ??
false) {
332 foreach ($item[
"aggregation"] as $subitem) {
333 $news_map[$subitem[
"id"]] = (
int) ($subitem[
"ref_id"] ?? 0);
334 $parent_map[$subitem[
"id"]][$parent_ref_id] = $parent_ref_id;
340 foreach ($parent_map as $news_id => $parents) {
341 if (count($parents) > 1 && $news_map[$news_id] > 0) {
342 $path = $this->tree->getPathId((
int) $news_map[$news_id]);
343 $lookup = array_flip(
$path);
346 foreach ($parents as $parent_ref_id) {
347 $level = max($level, (
int) ($lookup[$parent_ref_id] ?? 0));
350 $parsed_map[$news_id] =
$path[$level];
361 protected function sendMail(
int $a_user_id, array $a_objects,
string $a_last_run): void
365 $ilClientIniFile = $DIC[
'ilClientIniFile'];
368 $ntf->setLangModules(array(
"crs",
"news"));
380 foreach ($a_objects as $parent_ref_id => $items) {
385 foreach ($this->tree->getPathId($parent_ref_id) as $node) {
396 $this->
logger->debug(
"ref id: " . $parent_ref_id .
", items: " . count($items));
400 if (is_array($items)) {
401 foreach ($items as $news_item) {
402 if ($news_item === null) {
407 $parsed_item = $this->parseNewsItem($parent_ref_id, $filter_map, $news_item,
false, $a_user_id);
409 $parsed[md5($parsed_item)] = $parsed_item;
415 if (count($parsed)) {
416 $parent[
"news"] = implode(
"\n\n", $parsed);
417 $tmp[
$path] = $parent;
423 $this->
logger->debug(
"returning");
429 $obj_index = array();
431 foreach ($tmp as $item) {
434 $txt .=
"(" . $counter .
") " . $item[
"title"] .
"\n" .
435 $item[
"url"] .
"\n\n" .
436 $item[
"news"] .
"\n\n";
438 $obj_index[] =
"(" . $counter .
") " . $item[
"title"];
441 $ntf->setIntroductionLangId(
"crs_intro_course_group_notification_for");
445 $lng->
txt(
"crs_intro_course_group_notification_index"),
449 $ntf->addAdditionalInfo(
451 trim(implode(
"\n", $obj_index)),
457 $ntf->addAdditionalInfo(
464 $client = $ilClientIniFile->readVariable(
'client',
'name');
465 $subject = sprintf($lng->
txt(
"crs_subject_course_group_notification"),
$client);
467 $mail_content = $ntf->composeAndGetMessage($a_user_id, null,
"read",
true);
468 $this->
logger->debug(
"sending mail content: " . $mail_content);
484 switch ($a_form_id) {
487 $a_fields[
"enable_course_group_notifications"] = $a_is_active ?
488 $this->
lng->txt(
"enabled") :
489 $this->
lng->txt(
"disabled");
496 $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.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false, ilObjUser $user=null,)
ilMembershipCronNotificationsData $data
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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)
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.
final const STATUS_NO_ACTION
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)
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)