ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
ilMembershipCronNotifications Class Reference

Course/group notifications. 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)
 
- Public Member Functions inherited from ILIAS\Cron\CronJob
 setDateTimeProvider (?\Closure $date_time_provider)
 
 isDue (?\DateTimeImmutable $last_run, ?JobScheduleType $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 (?JobScheduleType $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 ()
 
 usesLegacyForms ()
 
 getCustomConfigurationInput (\ILIAS\UI\Factory $ui_factory, \ILIAS\Refinery\Factory $factory, \ilLanguage $lng)
 
 addCustomSettingsToForm (\ilPropertyFormGUI $a_form)
 
 saveCustomConfiguration (mixed $form_data)
 
 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 ILIAS\Cron\CronJob
JobScheduleType $schedule_type = null
 
int $schedule_value = null
 
Closure $date_time_provider = null
 

Detailed Description

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 29 of file class.ilMembershipCronNotifications.php.

Constructor & Destructor Documentation

◆ __construct()

ilMembershipCronNotifications::__construct ( )

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

37 {
38 global $DIC;
39
40 $this->lng = $DIC->language();
41 $this->db = $DIC->database();
42 $this->logger = $DIC->logger()->mmbr();
43 $this->tree = $DIC->repositoryTree();
44 }
global $DIC
Definition: shib_login.php:26

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 
)

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

494 : void
495 {
496 $setting->set("crsgrp_ntf", (string) ((int) $a_currently_active));
497 }
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 
)
Parameters
array<string,mixed>$a_fields

Reimplemented from ILIAS\Cron\CronJob.

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

482 : void
483 {
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");
490 break;
491 }
492 }

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 321 of file class.ilMembershipCronNotifications.php.

321 : array
322 {
323 $parent_map = $news_map = $parsed_map = array();
324
325 // gather news ref ids and news parent ref ids
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;
330
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;
335 }
336 }
337 }
338 }
339 // if news has multiple parents find "lowest" parent in path
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);
344
345 $level = 0;
346 foreach ($parents as $parent_ref_id) {
347 $level = max($level, (int) ($lookup[$parent_ref_id] ?? 0));
348 }
349
350 $parsed_map[$news_id] = $path[$level];
351 }
352 }
353
354 return $parsed_map;
355 }
$path
Definition: ltiservices.php:30

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

+ Here is the call graph for this function:

◆ getDefaultScheduleType()

ilMembershipCronNotifications::getDefaultScheduleType ( )

Reimplemented from ILIAS\Cron\CronJob.

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

67 {
68 return JobScheduleType::DAILY;
69 }

◆ getDefaultScheduleValue()

ilMembershipCronNotifications::getDefaultScheduleValue ( )

Reimplemented from ILIAS\Cron\CronJob.

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

71 : ?int
72 {
73 return null;
74 }

◆ getDescription()

ilMembershipCronNotifications::getDescription ( )

Reimplemented from ILIAS\Cron\CronJob.

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

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

References ILIAS\Repository\lng().

+ Here is the call graph for this function:

◆ getId()

ilMembershipCronNotifications::getId ( )

Reimplemented from ILIAS\Cron\CronJob.

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

51 : string
52 {
53 return "mem_notification";
54 }

Referenced by run().

+ Here is the caller graph for this function:

◆ getTitle()

ilMembershipCronNotifications::getTitle ( )

Reimplemented from ILIAS\Cron\CronJob.

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

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

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 ILIAS\Cron\CronJob.

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

76 : bool
77 {
78 return false;
79 }

◆ hasFlexibleSchedule()

ilMembershipCronNotifications::hasFlexibleSchedule ( )

Reimplemented from ILIAS\Cron\CronJob.

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

81 : bool
82 {
83 return true;
84 }

◆ run()

ilMembershipCronNotifications::run ( )

Reimplemented from ILIAS\Cron\CronJob.

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

86 : JobResult
87 {
88 global $DIC;
89
90 $this->logger->debug("===Member Notifications=== start");
91
92 $status = JobResult::STATUS_NO_ACTION;
93 $status_details = null;
94
95 $setting = new ilSetting("cron");
96 $last_run = $setting->get(get_class($this));
97
98 // no last run?
99 if (!$last_run) {
100 $last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
101
102 $status_details = "No previous run found - starting from yesterday.";
103 } // migration: used to be date-only value
104 elseif (strlen($last_run) === 10) {
105 $last_run .= " 00:00:00";
106
107 $status_details = "Switched from daily runs to open schedule.";
108 }
109
110 // out-comment for debugging purposes
111 //$last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
112
113 $last_run_unix = strtotime($last_run);
114
115 $this->logger->debug("Last run: " . $last_run);
116
117 $this->data = new ilMembershipCronNotificationsData($last_run_unix, $this->getId());
118
119 $this->logger->debug("prepare sending mails");
120
121 // send mails (1 max for each user)
122
123 $old_lng = $this->lng;
126
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));
131 $this->sendMail($user_id, $user_news, $last_run);
132 $DIC->cron()->manager()->ping($this->getId());
133 }
134 // mails were sent - set cron job status accordingly
135 $status = JobResult::STATUS_OK;
136 }
137
139
140 $this->logger->debug("save run");
141
142 // save last run
143 $setting->set(get_class($this), date("Y-m-d H:i:s"));
144 $result = new JobResult();
145 $result->setStatus($status);
146 if ($status_details) {
147 $result->setMessage($status_details);
148 }
149 $this->logger->debug("===Member Notifications=== done");
150 return $result;
151 }
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.
ILIAS Setting Class.

References $DIC, $lng, $user_id, getId(), ILIAS\Repository\logger(), sendMail(), ilDatePresentation\setUseRelativeDates(), 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 361 of file class.ilMembershipCronNotifications.php.

361 : void
362 {
363 global $DIC;
364
365 $ilClientIniFile = $DIC['ilClientIniFile'];
366
367 $ntf = new ilSystemNotification();
368 $ntf->setLangModules(array("crs", "news"));
369 // no single object anymore
370 // $ntf->setRefId($a_ref_id);
371 // $ntf->setGotoLangId('url');
372 // $ntf->setSubjectLangId('crs_subject_course_group_notification');
373
374 // user specific language
375 $lng = $ntf->getUserLanguage($a_user_id);
376 $filter_map = $this->filterDuplicateItems($a_objects);
377
378 $tmp = array();
379
380 foreach ($a_objects as $parent_ref_id => $items) {
381 $parent = array();
382
383 // path
384 $path = array();
385 foreach ($this->tree->getPathId($parent_ref_id) as $node) {
386 $path[] = $node;
387 }
388 $path = implode("-", $path);
389
390 $parent_obj_id = ilObject::_lookupObjId((int) $parent_ref_id);
391 $parent_type = ilObject::_lookupType($parent_obj_id);
392
393 $parent["title"] = $lng->txt("obj_" . $parent_type) . ' "' . ilObject::_lookupTitle($parent_obj_id) . '"';
394 $parent["url"] = " " . $lng->txt("crs_course_group_notification_link") . " " . ilLink::_getStaticLink($parent_ref_id);
395
396 $this->logger->debug("ref id: " . $parent_ref_id . ", items: " . count($items));
397
398 // news summary
399 $parsed = array();
400 if (is_array($items)) {
401 foreach ($items as $news_item) {
402 if ($news_item === null) {
403 continue;
404 }
405
406 // # Type "<Object Title>": "<News Title>" - News Text
407 $parsed_item = $this->parseNewsItem($parent_ref_id, $filter_map, $news_item, false, $a_user_id);
408 if ($parsed_item) {
409 $parsed[md5($parsed_item)] = $parsed_item;
410 }
411 }
412 }
413
414 // any news?
415 if (count($parsed)) {
416 $parent["news"] = implode("\n\n", $parsed);
417 $tmp[$path] = $parent;
418 }
419 }
420
421 // any objects?
422 if (!count($tmp)) {
423 $this->logger->debug("returning");
424 return;
425 }
426
427 ksort($tmp);
428 $counter = 0;
429 $obj_index = array();
430 $txt = "";
431 foreach ($tmp as $item) {
432 $counter++;
433
434 $txt .= "(" . $counter . ") " . $item["title"] . "\n" .
435 $item["url"] . "\n\n" .
436 $item["news"] . "\n\n";
437
438 $obj_index[] = "(" . $counter . ") " . $item["title"];
439 }
440
441 $ntf->setIntroductionLangId("crs_intro_course_group_notification_for");
442
443 // index
444 $period = sprintf(
445 $lng->txt("crs_intro_course_group_notification_index"),
448 );
449 $ntf->addAdditionalInfo(
450 $period,
451 trim(implode("\n", $obj_index)),
452 true,
453 true
454 );
455
456 // object list
457 $ntf->addAdditionalInfo(
458 "",
459 trim($txt),
460 true
461 );
462
463 // :TODO: does it make sense to add client to subject?
464 $client = $ilClientIniFile->readVariable('client', 'name');
465 $subject = sprintf($lng->txt("crs_subject_course_group_notification"), $client);
466
467 $mail_content = $ntf->composeAndGetMessage($a_user_id, null, "read", true);
468 $this->logger->debug("sending mail content: " . $mail_content);
469
470 // #10044
471 $mail = new ilMail(ANONYMOUS_USER_ID);
472 $mail->enqueue(
473 ilObjUser::_lookupLogin($a_user_id),
474 (string) null,
475 (string) null,
476 $subject,
477 $mail_content,
478 []
479 );
480 }
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, ?ilObjUser $user=null,)
@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
$counter

References $client, $counter, $DIC, $lng, $path, 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 49 of file class.ilMembershipCronNotifications.php.

◆ $db

ilDBInterface ilMembershipCronNotifications::$db
protected

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

◆ $lng

ilLanguage ilMembershipCronNotifications::$lng
protected

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

Referenced by run().

◆ $logger

ilLogger ilMembershipCronNotifications::$logger
protected

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

◆ $tree

ilTree ilMembershipCronNotifications::$tree
protected

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


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