ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 ()
 
 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 31 of file class.ilMembershipCronNotifications.php.

Constructor & Destructor Documentation

◆ __construct()

ilMembershipCronNotifications::__construct ( )

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

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

39  {
40  global $DIC;
41 
42  $this->lng = $DIC->language();
43  $this->db = $DIC->database();
44  $this->logger = $DIC->logger()->mmbr();
45  $this->tree = $DIC->repositoryTree();
46  }
global $DIC
Definition: shib_login.php:22
+ 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 496 of file class.ilMembershipCronNotifications.php.

References ilSetting\set().

496  : void
497  {
498  $setting->set("crsgrp_ntf", (string) ((int) $a_currently_active));
499  }
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 484 of file class.ilMembershipCronNotifications.php.

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

484  : void
485  {
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");
492  break;
493  }
494  }
+ Here is the call graph for this function:

◆ filterDuplicateItems()

ilMembershipCronNotifications::filterDuplicateItems ( array  $a_objects)
protected

Filter duplicate news items from structure*.

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

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

Referenced by sendMail().

323  : array
324  {
325  $parent_map = $news_map = $parsed_map = array();
326 
327  // gather news ref ids and news parent ref ids
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;
332 
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;
337  }
338  }
339  }
340  }
341  // if news has multiple parents find "lowest" parent in path
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);
346 
347  $level = 0;
348  foreach ($parents as $parent_ref_id) {
349  $level = max($level, (int) ($lookup[$parent_ref_id] ?? 0));
350  }
351 
352  $parsed_map[$news_id] = $path[$level];
353  }
354  }
355 
356  return $parsed_map;
357  }
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDefaultScheduleType()

ilMembershipCronNotifications::getDefaultScheduleType ( )

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

69  {
70  return JobScheduleType::DAILY;
71  }

◆ getDefaultScheduleValue()

ilMembershipCronNotifications::getDefaultScheduleValue ( )

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

References null.

73  : ?int
74  {
75  return null;
76  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ getDescription()

ilMembershipCronNotifications::getDescription ( )

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

References ILIAS\Repository\lng().

63  : string
64  {
65  return $this->lng->txt("enable_course_group_notifications_desc");
66  }
+ Here is the call graph for this function:

◆ getId()

ilMembershipCronNotifications::getId ( )

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

Referenced by run().

53  : string
54  {
55  return "mem_notification";
56  }
+ Here is the caller graph for this function:

◆ getTitle()

ilMembershipCronNotifications::getTitle ( )

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

References ILIAS\Repository\lng().

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

◆ hasAutoActivation()

ilMembershipCronNotifications::hasAutoActivation ( )

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

78  : bool
79  {
80  return false;
81  }

◆ hasFlexibleSchedule()

ilMembershipCronNotifications::hasFlexibleSchedule ( )

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

83  : bool
84  {
85  return true;
86  }

◆ run()

ilMembershipCronNotifications::run ( )

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

References $c, $comments, $DIC, $lng, $res, $user_id, ilLanguageFactory\_getLanguageOfUser(), ilObject\_lookupTitle(), ilNewsItem\determineNewsContent(), ilNewsItem\determineNewsTitle(), ilDatePresentation\formatDate(), ilLikeGUI\getExpressionText(), getId(), ilUserUtil\getNamePresentation(), IL_CAL_DATETIME, ilLanguage\loadLanguageModule(), ILIAS\Repository\logger(), ilObjectPlugin\lookupTxtById(), null, sendMail(), ilDatePresentation\setUseRelativeDates(), ilStr\shortenTextExtended(), ilLanguage\txt(), and ilDatePresentation\useRelativeDates().

88  : JobResult
89  {
90  global $DIC;
91 
92  $this->logger->debug("===Member Notifications=== start");
93 
94  $status = JobResult::STATUS_NO_ACTION;
95  $status_details = null;
96 
97  $setting = new ilSetting("cron");
98  $last_run = $setting->get(get_class($this));
99 
100  // no last run?
101  if (!$last_run) {
102  $last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
103 
104  $status_details = "No previous run found - starting from yesterday.";
105  } // migration: used to be date-only value
106  elseif (strlen($last_run) === 10) {
107  $last_run .= " 00:00:00";
108 
109  $status_details = "Switched from daily runs to open schedule.";
110  }
111 
112  // out-comment for debugging purposes
113  //$last_run = date("Y-m-d H:i:s", strtotime("yesterday"));
114 
115  $last_run_unix = strtotime($last_run);
116 
117  $this->logger->debug("Last run: " . $last_run);
118 
119  $this->data = new ilMembershipCronNotificationsData($last_run_unix, $this->getId());
120 
121  $this->logger->debug("prepare sending mails");
122 
123  // send mails (1 max for each user)
124 
125  $old_lng = $this->lng;
128 
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));
133  $this->sendMail($user_id, $user_news, $last_run);
134  $DIC->cron()->manager()->ping($this->getId());
135  }
136  // mails were sent - set cron job status accordingly
137  $status = JobResult::STATUS_OK;
138  }
139 
141 
142  $this->logger->debug("save run");
143 
144  // save last run
145  $setting->set(get_class($this), date("Y-m-d H:i:s"));
146  $result = new JobResult();
147  $result->setStatus($status);
148  if ($status_details) {
149  $result->setMessage($status_details);
150  }
151  $this->logger->debug("===Member Notifications=== done");
152  return $result;
153  }
static array static setUseRelativeDates(bool $a_status)
set use relative dates
Manage data for ilMembershipCronNotifications cron job.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
global $DIC
Definition: shib_login.php:22
sendMail(int $a_user_id, array $a_objects, string $a_last_run)
Send news mail for 1 user and n objects.
+ 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 363 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(), null, and ilLanguage\txt().

Referenced by run().

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

◆ $db

ilDBInterface ilMembershipCronNotifications::$db
protected

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

◆ $lng

ilLanguage ilMembershipCronNotifications::$lng
protected

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

Referenced by run().

◆ $logger

ilLogger ilMembershipCronNotifications::$logger
protected

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

◆ $tree

ilTree ilMembershipCronNotifications::$tree
protected

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


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