ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMailSummaryNotification.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once './Services/Mail/classes/class.ilMailNotification.php';
5include_once './Services/Mail/classes/class.ilMailOptions.php';
6
7include_once 'Services/Mail/classes/class.ilMimeMail.php';
8include_once 'Services/Mail/classes/class.ilMail.php';
9
17{
21 protected $lng;
22
26 protected $db;
27
31 protected $settings;
32
36 public function __construct($a_is_personal_workspace = false)
37 {
38 global $DIC;
39
40 $this->db = $DIC->database();
41 $this->lng = $DIC->language();
42 $this->settings = $DIC->settings();
43
44 parent::__construct($a_is_personal_workspace);
45 }
46
47 public function send()
48 {
49 $is_message_enabled = $this->settings->get("mail_notification_message");
50
51 $res = $this->db->queryF(
52 'SELECT mail.* FROM mail_options
53 INNER JOIN mail ON mail.user_id = mail_options.user_id
54 INNER JOIN mail_obj_data ON mail_obj_data.obj_id = mail.folder_id
55 INNER JOIN usr_data ud ON ud.usr_id = mail.user_id
56 WHERE mail_options.cronjob_notification = %s
57 AND mail.send_time >= %s
58 AND mail.m_status = %s
59 AND ud.active = %s',
60 array('integer', 'timestamp', 'text', 'integer'),
61 array(1, date('Y-m-d H:i:s', time() - 60 * 60 * 24), 'unread', 1)
62 );
63
64 $users = array();
65 $user_id = 0;
66
67 while ($row = $this->db->fetchAssoc($res)) {
68 if ($user_id == 0 || $row['user_id'] != $user_id) {
69 $user_id = $row['user_id'];
70 }
71 $users[$user_id][] = $row;
72 }
73
75 $senderFactory = $GLOBALS["DIC"]["mail.mime.sender.factory"];
76 $sender = $senderFactory->system();
77
78 foreach ($users as $user_id => $mail_data) {
79 $this->initLanguage($user_id);
80 $user_lang = $this->getLanguage() ? $this->getLanguage() : $this->lng;
81
82 $this->initMail();
83
84 $this->setRecipients(array($user_id));
85 $this->setSubject($this->getLanguageText('mail_notification_subject'));
86
87 $this->setBody(ilMail::getSalutation($user_id, $user_lang));
88 $this->appendBody("\n\n");
89 if (count($mail_data) == 1) {
90 $this->appendBody(sprintf($user_lang->txt('mail_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
91 } else {
92 $this->appendBody(sprintf($user_lang->txt('mails_at_the_ilias_installation'), count($mail_data), ilUtil::_getHttpPath()));
93 }
94 $this->appendBody("\n\n");
95
96 $counter = 1;
97 foreach ($mail_data as $mail) {
98 $this->appendBody("----------------------------------------------------------------------------------------------");
99 $this->appendBody("\n\n");
100 $this->appendBody('#' . $counter . "\n\n");
101 $this->appendBody($user_lang->txt('date') . ": " . $mail['send_time']);
102 $this->appendBody("\n");
103 if ($mail['sender_id'] == ANONYMOUS_USER_ID) {
104 $senderName = ilMail::_getIliasMailerName();
105 } else {
106 $senderName = ilObjUser::_lookupLogin($mail['sender_id']);
107 }
108 $this->appendBody($user_lang->txt('sender') . ": " . $senderName);
109 $this->appendBody("\n");
110 $this->appendBody($user_lang->txt('subject') . ": " . $mail['m_subject']);
111 $this->appendBody("\n\n");
112
113 if ($is_message_enabled == true) {
114 $this->appendBody($user_lang->txt('message') . ": " . $mail['m_message']);
115 $this->appendBody("\n\n");
116 }
117 ++$counter;
118 }
119 $this->appendBody("----------------------------------------------------------------------------------------------");
120 $this->appendBody("\n\n");
121 $this->appendBody($user_lang->txt('follow_link_to_read_mails') . " ");
122 $this->appendBody("\n");
123 $mailbox_link = ilUtil::_getHttpPath();
124 $mailbox_link .= "/goto.php?target=mail&client_id=" . CLIENT_ID;
125
126 $this->appendBody($mailbox_link);
127 $this->appendBody("\n\n");
130
131 $mmail = new ilMimeMail();
132 $mmail->From($sender);
133
134 $mailOptions = new \ilMailOptions($user_id);
135 $mmail->To($mailOptions->getExternalEmailAddresses());
136
137 $mmail->Subject($this->getSubject());
138 $mmail->Body($this->getBody());
139 $mmail->Send();
140 }
141 }
142}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
Base class for course/group mail notifications.
appendBody($a_body)
Append body text.
initLanguage($a_usr_id)
Init language.
__construct($a_is_personal_workspace=false)
{}
static _getAutoGeneratedMessageString(ilLanguage $lang=null)
Get auto generated info string.
static _getInstallationSignature()
static getSalutation($a_usr_id, ilLanguage $a_language=null)
Class ilMimeMail.
static _lookupLogin($a_user_id)
lookup login
static _getHttpPath()
const CLIENT_ID
Definition: constants.php:39
const ANONYMOUS_USER_ID
Definition: constants.php:25
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
catch(ilCmiXapiException $e) send($response)
Definition: xapitoken.php:82