ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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 ()
 
 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 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
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_MINUTES = 2
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_HOURS = 3
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_IN_DAYS = 4
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_WEEKLY = 5
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_MONTHLY = 6
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_QUARTERLY = 7
 This will be replaced with an ENUM in ILIAS 9 More...
 
const SCHEDULE_TYPE_YEARLY = 8
 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.

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

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

References ilSetting\set().

486  : void
487  {
488  $setting->set("crsgrp_ntf", (string) ((int) $a_currently_active));
489  }
set(string $a_key, string $a_val)
+ Here is the call graph for this function:

◆ addToExternalSettingsForm()

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

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

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

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  }
+ 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.

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

Referenced by sendMail().

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
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilMembershipCronNotifications::getDefaultScheduleType ( )

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

64  : int
65  {
66  return self::SCHEDULE_TYPE_DAILY;
67  }

◆ getDefaultScheduleValue()

ilMembershipCronNotifications::getDefaultScheduleValue ( )

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

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

◆ getDescription()

ilMembershipCronNotifications::getDescription ( )

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

References ILIAS\Repository\lng().

59  : string
60  {
61  return $this->lng->txt("enable_course_group_notifications_desc");
62  }
+ Here is the call graph for this function:

◆ getId()

ilMembershipCronNotifications::getId ( )

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

Referenced by run().

49  : string
50  {
51  return "mem_notification";
52  }
+ Here is the caller graph for this function:

◆ getTitle()

ilMembershipCronNotifications::getTitle ( )

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

References ILIAS\Repository\lng().

54  : string
55  {
56  return $this->lng->txt("enable_course_group_notifications");
57  }
+ Here is the call graph for this function:

◆ hasAutoActivation()

ilMembershipCronNotifications::hasAutoActivation ( )

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

74  : bool
75  {
76  return false;
77  }

◆ hasFlexibleSchedule()

ilMembershipCronNotifications::hasFlexibleSchedule ( )

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

79  : bool
80  {
81  return true;
82  }

◆ run()

ilMembershipCronNotifications::run ( )

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

References $c, $comments, $DIC, $lng, $res, ilObject\_lookupTitle(), ilNewsItem\determineNewsContent(), ilNewsItem\determineNewsTitle(), ilDatePresentation\formatDate(), ilLikeGUI\getExpressionText(), getId(), ilUserUtil\getNamePresentation(), IL_CAL_DATETIME, ILIAS\Repository\lng(), ILIAS\Repository\logger(), ilObjectPlugin\lookupTxtById(), sendMail(), ilDatePresentation\setUseRelativeDates(), ilStr\shortenTextExtended(), ilCronJobResult\STATUS_NO_ACTION, ilCronJobResult\STATUS_OK, and ilDatePresentation\useRelativeDates().

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
133  $status = ilCronJobResult::STATUS_OK;
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  }
Manage data for ilMembershipCronNotifications cron job.
global $DIC
Definition: feed.php:28
sendMail(int $a_user_id, array $a_objects, string $a_last_run)
Send news mail for 1 user and n objects.
static setUseRelativeDates(bool $a_status)
set use relative dates
+ 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.

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

Referenced by run().

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_DATETIME
const ANONYMOUS_USER_ID
Definition: constants.php:27
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.
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
filterDuplicateItems(array $a_objects)
Filter duplicate news items from structure*.
const IL_CAL_UNIX
$path
Definition: ltiservices.php:32
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
$client
static _lookupTitle(int $obj_id)
$txt
Definition: error.php:13
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)
+ 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: