ILIAS  release_8 Revision v8.24
ilMembershipCronNotifications Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilMembershipCronNotifications:
+ Collaboration diagram for ilMembershipCronNotifications:

Public Member Functions

 __construct ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 run ()
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
- Public Member Functions inherited from ilCronJob
 setDateTimeProvider (?Closure $date_time_provider)
 
 isDue (?DateTimeImmutable $last_run, ?int $schedule_type, ?int $schedule_value, bool $is_manually_executed=false)
 
 getScheduleType ()
 Get current schedule type (if flexible) More...
 
 getScheduleValue ()
 Get current schedule value (if flexible) More...
 
 setSchedule (?int $a_type, ?int $a_value)
 Update current schedule (if flexible) More...
 
 getAllScheduleTypes ()
 Get all available schedule types. More...
 
 getScheduleTypesWithValues ()
 
 getValidScheduleTypes ()
 Returns a collection of all valid schedule types for a specific job. More...
 
 isManuallyExecutable ()
 
 hasCustomSettings ()
 
 addCustomSettingsToForm (ilPropertyFormGUI $a_form)
 
 saveCustomSettings (ilPropertyFormGUI $a_form)
 
 addToExternalSettingsForm (int $a_form_id, array &$a_fields, bool $a_is_active)
 
 activationWasToggled (ilDBInterface $db, ilSetting $setting, bool $a_currently_active)
 Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed. More...
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 hasAutoActivation ()
 Is to be activated on "installation", does only work for ILIAS core cron jobs. More...
 
 hasFlexibleSchedule ()
 
 getDefaultScheduleType ()
 
 getDefaultScheduleValue ()
 
 run ()
 

Protected Member Functions

 filterDuplicateItems (array $a_objects)
 Filter duplicate news items from structure*. More...
 
 sendMail (int $a_user_id, array $a_objects, string $a_last_run)
 Send news mail for 1 user and n objects. More...
 

Protected Attributes

ilLanguage $lng
 
ilDBInterface $db
 
ilLogger $logger
 
ilTree $tree
 
ilMembershipCronNotificationsData $data
 
- Protected Attributes inherited from ilCronJob
int $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Additional Inherited Members

- Data Fields inherited from ilCronJob
const SCHEDULE_TYPE_DAILY = 1
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 @depracated This will be replaced with an ENUM in ILIAS 9 More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Course/group notifications

Author
Jörg Lützenkirchen luetz.nosp@m.enki.nosp@m.rchen.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 27 of file class.ilMembershipCronNotifications.php.

Constructor & Destructor Documentation

◆ __construct()

ilMembershipCronNotifications::__construct ( )

Definition at line 34 of file class.ilMembershipCronNotifications.php.

35 {
36 global $DIC;
37
38 $this->lng = $DIC->language();
39 $this->db = $DIC->database();
40 $this->logger = $DIC->logger()->mmbr();
41 $this->tree = $DIC->repositoryTree();
42 }
global $DIC
Definition: feed.php:28

References $DIC, ILIAS\Repository\lng(), and ILIAS\Repository\logger().

+ Here is the call graph for this function:

Member Function Documentation

◆ activationWasToggled()

ilMembershipCronNotifications::activationWasToggled ( ilDBInterface  $db,
ilSetting  $setting,
bool  $a_currently_active 
)

Important: This method is (also) called from the setup process, where the constructor of an ilCronJob ist NOT executed.

Furthermore only few dependencies may be available in the $DIC.

Parameters
ilDBInterface$db
ilSetting$setting
bool$a_currently_active
Returns
void

Reimplemented from ilCronJob.

Definition at line 486 of file class.ilMembershipCronNotifications.php.

486 : void
487 {
488 $setting->set("crsgrp_ntf", (string) ((int) $a_currently_active));
489 }
set(string $a_key, string $a_val)

References ilSetting\set().

+ Here is the call graph for this function:

◆ addToExternalSettingsForm()

ilMembershipCronNotifications::addToExternalSettingsForm ( int  $a_form_id,
array &  $a_fields,
bool  $a_is_active 
)

Reimplemented from ilCronJob.

Definition at line 474 of file class.ilMembershipCronNotifications.php.

474 : void
475 {
476 switch ($a_form_id) {
479 $a_fields["enable_course_group_notifications"] = $a_is_active ?
480 $this->lng->txt("enabled") :
481 $this->lng->txt("disabled");
482 break;
483 }
484 }

References ilAdministrationSettingsFormHandler\FORM_COURSE, ilAdministrationSettingsFormHandler\FORM_GROUP, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ filterDuplicateItems()

ilMembershipCronNotifications::filterDuplicateItems ( array  $a_objects)
protected

Filter duplicate news items from structure*.

Definition at line 313 of file class.ilMembershipCronNotifications.php.

313 : array
314 {
315 $parent_map = $news_map = $parsed_map = array();
316
317 // gather news ref ids and news parent ref ids
318 foreach ($a_objects as $parent_ref_id => $news) {
319 foreach ($news as $item) {
320 $news_map[$item["id"]] = (int) ($item["ref_id"] ?? 0);
321 $parent_map[$item["id"]][$parent_ref_id] = $parent_ref_id;
322
323 if ($item["aggregation"] ?? false) {
324 foreach ($item["aggregation"] as $subitem) {
325 $news_map[$subitem["id"]] = (int) ($subitem["ref_id"] ?? 0);
326 $parent_map[$subitem["id"]][$parent_ref_id] = $parent_ref_id;
327 }
328 }
329 }
330 }
331 // if news has multiple parents find "lowest" parent in path
332 foreach ($parent_map as $news_id => $parents) {
333 if (count($parents) > 1 && $news_map[$news_id] > 0) {
334 $path = $this->tree->getPathId((int) $news_map[$news_id]);
335 $lookup = array_flip($path);
336
337 $level = 0;
338 foreach ($parents as $parent_ref_id) {
339 $level = max($level, (int) ($lookup[$parent_ref_id] ?? 0));
340 }
341
342 $parsed_map[$news_id] = $path[$level];
343 }
344 }
345
346 return $parsed_map;
347 }
$path
Definition: ltiservices.php:32

References $path, and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilMembershipCronNotifications::getDefaultScheduleType ( )

Reimplemented from ilCronJob.

Definition at line 64 of file class.ilMembershipCronNotifications.php.

64 : int
65 {
67 }
const SCHEDULE_TYPE_DAILY
@depracated This will be replaced with an ENUM in ILIAS 9

References ilCronJob\SCHEDULE_TYPE_DAILY.

◆ getDefaultScheduleValue()

ilMembershipCronNotifications::getDefaultScheduleValue ( )

Reimplemented from ilCronJob.

Definition at line 69 of file class.ilMembershipCronNotifications.php.

69 : ?int
70 {
71 return null;
72 }

◆ getDescription()

ilMembershipCronNotifications::getDescription ( )

Reimplemented from ilCronJob.

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

59 : string
60 {
61 return $this->lng->txt("enable_course_group_notifications_desc");
62 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getId()

ilMembershipCronNotifications::getId ( )

Reimplemented from ilCronJob.

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

49 : string
50 {
51 return "mem_notification";
52 }

Referenced by run().

+ Here is the caller graph for this function:

◆ getTitle()

ilMembershipCronNotifications::getTitle ( )

Reimplemented from ilCronJob.

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

54 : string
55 {
56 return $this->lng->txt("enable_course_group_notifications");
57 }

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ hasAutoActivation()

ilMembershipCronNotifications::hasAutoActivation ( )

Is to be activated on "installation", does only work for ILIAS core cron jobs.

Reimplemented from ilCronJob.

Definition at line 74 of file class.ilMembershipCronNotifications.php.

74 : bool
75 {
76 return false;
77 }

◆ hasFlexibleSchedule()

ilMembershipCronNotifications::hasFlexibleSchedule ( )

Reimplemented from ilCronJob.

Definition at line 79 of file class.ilMembershipCronNotifications.php.

79 : bool
80 {
81 return true;
82 }

◆ run()

ilMembershipCronNotifications::run ( )

Reimplemented from ilCronJob.

Definition at line 84 of file class.ilMembershipCronNotifications.php.

85 {
86 global $DIC;
87
88 $this->logger->debug("===Member Notifications=== start");
89
91 $status_details = null;
92
93 $setting = new ilSetting("cron");
94 $last_run = $setting->get(get_class($this));
95
96 // no last run?
97 if (!$last_run) {
98 $last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
99
100 $status_details = "No previous run found - starting from yesterday.";
101 } // migration: used to be date-only value
102 elseif (strlen($last_run) === 10) {
103 $last_run .= " 00:00:00";
104
105 $status_details = "Switched from daily runs to open schedule.";
106 }
107
108 // out-comment for debugging purposes
109 //$last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
110
111 $last_run_unix = strtotime($last_run);
112
113 $this->logger->debug("Last run: " . $last_run);
114
115 $this->data = new ilMembershipCronNotificationsData($last_run_unix, $this->getId());
116
117 $this->logger->debug("prepare sending mails");
118
119 // send mails (1 max for each user)
120
121 $old_lng = $this->lng;
124
125 $user_news_aggr = $this->data->getAggregatedNews();
126 if (count($user_news_aggr)) {
127 foreach ($user_news_aggr as $user_id => $user_news) {
128 $this->logger->debug("sending mails to user " . $user_id . ", nr news: " . count($user_news));
129 $this->sendMail($user_id, $user_news, $last_run);
130 $DIC->cron()->manager()->ping($this->getId());
131 }
132 // mails were sent - set cron job status accordingly
134 }
135
137
138 $this->logger->debug("save run");
139
140 // save last run
141 $setting->set(get_class($this), date("Y-m-d H:i:s"));
142 $result = new ilCronJobResult();
143 $result->setStatus($status);
144 if ($status_details) {
145 $result->setMessage($status_details);
146 }
147 $this->logger->debug("===Member Notifications=== done");
148 return $result;
149 }
static setUseRelativeDates(bool $a_status)
set use relative dates
Manage data for ilMembershipCronNotifications cron job.
sendMail(int $a_user_id, array $a_objects, string $a_last_run)
Send news mail for 1 user and n objects.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $DIC, $lng, getId(), ILIAS\Repository\logger(), sendMail(), ilDatePresentation\setUseRelativeDates(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ilDatePresentation\useRelativeDates().

+ Here is the call graph for this function:

◆ sendMail()

ilMembershipCronNotifications::sendMail ( int  $a_user_id,
array  $a_objects,
string  $a_last_run 
)
protected

Send news mail for 1 user and n objects.

Exceptions
ilDateTimeException|ilWACException

Definition at line 353 of file class.ilMembershipCronNotifications.php.

353 : void
354 {
355 global $DIC;
356
357 $ilClientIniFile = $DIC['ilClientIniFile'];
358
359 $ntf = new ilSystemNotification();
360 $ntf->setLangModules(array("crs", "news"));
361 // no single object anymore
362 // $ntf->setRefId($a_ref_id);
363 // $ntf->setGotoLangId('url');
364 // $ntf->setSubjectLangId('crs_subject_course_group_notification');
365
366 // user specific language
367 $lng = $ntf->getUserLanguage($a_user_id);
368 $filter_map = $this->filterDuplicateItems($a_objects);
369
370 $tmp = array();
371
372 foreach ($a_objects as $parent_ref_id => $items) {
373 $parent = array();
374
375 // path
376 $path = array();
377 foreach ($this->tree->getPathId($parent_ref_id) as $node) {
378 $path[] = $node;
379 }
380 $path = implode("-", $path);
381
382 $parent_obj_id = ilObject::_lookupObjId((int) $parent_ref_id);
383 $parent_type = ilObject::_lookupType($parent_obj_id);
384
385 $parent["title"] = $lng->txt("obj_" . $parent_type) . ' "' . ilObject::_lookupTitle($parent_obj_id) . '"';
386 $parent["url"] = " " . $lng->txt("crs_course_group_notification_link") . " " . ilLink::_getStaticLink($parent_ref_id);
387
388 $this->logger->debug("ref id: " . $parent_ref_id . ", items: " . count($items));
389
390 // news summary
391 $parsed = array();
392 if (is_array($items)) {
393 foreach ($items as $news_item) {
394 if ($news_item === null) {
395 continue;
396 }
397
398 // # Type "<Object Title>": "<News Title>" - News Text
399 $parsed_item = $this->parseNewsItem($parent_ref_id, $filter_map, $news_item, false, $a_user_id);
400 if ($parsed_item) {
401 $parsed[md5($parsed_item)] = $parsed_item;
402 }
403 }
404 }
405
406 // any news?
407 if (count($parsed)) {
408 $parent["news"] = implode("\n\n", $parsed);
409 $tmp[$path] = $parent;
410 }
411 }
412
413 // any objects?
414 if (!count($tmp)) {
415 $this->logger->debug("returning");
416 return;
417 }
418
419 ksort($tmp);
420 $counter = 0;
421 $obj_index = array();
422 $txt = "";
423 foreach ($tmp as $item) {
424 $counter++;
425
426 $txt .= "(" . $counter . ") " . $item["title"] . "\n" .
427 $item["url"] . "\n\n" .
428 $item["news"] . "\n\n";
429
430 $obj_index[] = "(" . $counter . ") " . $item["title"];
431 }
432
433 $ntf->setIntroductionLangId("crs_intro_course_group_notification_for");
434
435 // index
436 $period = sprintf(
437 $lng->txt("crs_intro_course_group_notification_index"),
440 );
441 $ntf->addAdditionalInfo(
442 $period,
443 trim(implode("\n", $obj_index)),
444 true,
445 true
446 );
447
448 // object list
449 $ntf->addAdditionalInfo(
450 "",
451 trim($txt),
452 true
453 );
454
455 // :TODO: does it make sense to add client to subject?
456 $client = $ilClientIniFile->readVariable('client', 'name');
457 $subject = sprintf($lng->txt("crs_subject_course_group_notification"), $client);
458
459 $mail_content = $ntf->composeAndGetMessage($a_user_id, null, "read", true);
460 $this->logger->debug("sending mail content: " . $mail_content);
461
462 // #10044
463 $mail = new ilMail(ANONYMOUS_USER_ID);
464 $mail->enqueue(
465 ilObjUser::_lookupLogin($a_user_id),
466 (string) null,
467 (string) null,
468 $subject,
469 $mail_content,
470 []
471 );
472 }
const IL_CAL_UNIX
const IL_CAL_DATETIME
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
@classDescription Date and time handling
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.
filterDuplicateItems(array $a_objects)
Filter duplicate news items from structure*.
static _lookupLogin(int $a_user_id)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ANONYMOUS_USER_ID
Definition: constants.php:27
$client
$txt
Definition: error.php:13

References $client, $DIC, $lng, $path, $txt, ilLink\_getStaticLink(), ilObjUser\_lookupLogin(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), ilObject\_lookupType(), ANONYMOUS_USER_ID, ilDatePresentation\formatDate(), IL_CAL_DATETIME, IL_CAL_UNIX, and ILIAS\Repository\logger().

Referenced by run().

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

Field Documentation

◆ $data

ilMembershipCronNotificationsData ilMembershipCronNotifications::$data
protected

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

◆ $db

ilDBInterface ilMembershipCronNotifications::$db
protected

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

◆ $lng

ilLanguage ilMembershipCronNotifications::$lng
protected

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

Referenced by run().

◆ $logger

ilLogger ilMembershipCronNotifications::$logger
protected

Definition at line 31 of file class.ilMembershipCronNotifications.php.

◆ $tree

ilTree ilMembershipCronNotifications::$tree
protected

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


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