ILIAS  release_8 Revision v8.24
class.ilMailSummaryNotification.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 protected ilLanguage $lng;
28 protected ilDBInterface $db;
31
32 public function __construct(bool $a_is_personal_workspace = false)
33 {
34 global $DIC;
35 $this->db = $DIC->database();
36 $this->lng = $DIC->language();
37 $this->settings = $DIC->settings();
38 $this->senderFactory = $DIC["mail.mime.sender.factory"];
39
40 parent::__construct($a_is_personal_workspace);
41 }
42
43 public function send(): void
44 {
45 $is_message_enabled = (bool) $this->settings->get("mail_notification_message", '0');
46
47 $res = $this->db->queryF(
48 'SELECT mail.* FROM mail_options
49 INNER JOIN mail ON mail.user_id = mail_options.user_id
50 INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id
51 INNER JOIN usr_data ud ON ud.usr_id = mail.user_id
52 WHERE mail_options.cronjob_notification = %s
53 AND mail.send_time >= %s
54 AND mail.m_status = %s
55 AND ud.active = %s',
56 ['integer', 'timestamp', 'text', 'integer'],
57 [1, date('Y-m-d H:i:s', time() - 60 * 60 * 24), 'unread', 1]
58 );
59
60 $users = [];
61 $user_id = 0;
62
63 while ($row = $this->db->fetchAssoc($res)) {
64 if ($user_id === 0 || (int) $row['user_id'] !== $user_id) {
65 $user_id = (int) $row['user_id'];
66 }
67 $users[$user_id][] = $row;
68 }
69 $sender = $this->senderFactory->system();
70
71 foreach ($users as $user_id => $mail_data) {
72 $this->initLanguage($user_id);
73 $user_lang = $this->getLanguage();
74
75 $this->initMail();
76
77 $this->setRecipients([$user_id]);
78 $this->setSubject($this->getLanguageText('mail_notification_subject'));
79
80 $this->setBody(ilMail::getSalutation($user_id, $user_lang));
81 $this->appendBody("\n\n");
82 if (count($mail_data) === 1) {
83 $this->appendBody(sprintf(
84 $user_lang->txt('mail_at_the_ilias_installation'),
85 count($mail_data),
87 ));
88 } else {
89 $this->appendBody(sprintf(
90 $user_lang->txt('mails_at_the_ilias_installation'),
91 count($mail_data),
93 ));
94 }
95 $this->appendBody("\n\n");
96
97 $counter = 1;
98 foreach ($mail_data as $mail) {
99 $this->appendBody("----------------------------------------------------------------------------------------------");
100 $this->appendBody("\n\n");
101 $this->appendBody('#' . $counter . "\n\n");
102 $this->appendBody($user_lang->txt('date') . ": " . $mail['send_time']);
103 $this->appendBody("\n");
104 if ((int) $mail['sender_id'] === ANONYMOUS_USER_ID) {
105 $senderName = ilMail::_getIliasMailerName();
106 } else {
107 $senderName = ilObjUser::_lookupLogin((int) $mail['sender_id']);
108 }
109 $this->appendBody($user_lang->txt('sender') . ": " . $senderName);
110 $this->appendBody("\n");
111 $this->appendBody($user_lang->txt('subject') . ": " . $mail['m_subject']);
112 $this->appendBody("\n\n");
113
114 if ($is_message_enabled) {
115 $this->appendBody($user_lang->txt('message') . ": " . $mail['m_message']);
116 $this->appendBody("\n\n");
117 }
118 ++$counter;
119 }
120 $this->appendBody("----------------------------------------------------------------------------------------------");
121 $this->appendBody("\n\n");
122 $this->appendBody($user_lang->txt('follow_link_to_read_mails') . " ");
123 $this->appendBody("\n");
124 $mailbox_link = ilUtil::_getHttpPath();
125 $mailbox_link .= "/goto.php?target=mail&client_id=" . CLIENT_ID;
126
127 $this->appendBody($mailbox_link);
128 $this->appendBody("\n\n");
131
132 $mmail = new ilMimeMail();
133 $mmail->From($sender);
134
135 $mailOptions = new ilMailOptions($user_id);
136 $mmail->To($mailOptions->getExternalEmailAddresses());
137
138 $mmail->Subject($this->getSubject());
139 $mmail->Body($this->getBody());
140 $mmail->Send();
141 }
142 }
143}
language handling
Class ilMailMimeSenderFactory.
Base class for course/group mail notifications.
getLanguageText(string $a_keyword)
setSubject(string $a_subject)
Class ilMailOptions this class handles user mails.
__construct(bool $a_is_personal_workspace=false)
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
static getSalutation(int $a_usr_id, ?ilLanguage $a_language=null)
static _getInstallationSignature()
static _lookupLogin(int $a_user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _getHttpPath()
const CLIENT_ID
Definition: constants.php:41
const ANONYMOUS_USER_ID
Definition: constants.php:27
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc