ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilMailOptions.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 const INCOMING_LOCAL = 0;
13 const INCOMING_EMAIL = 1;
14 const INCOMING_BOTH = 2;
15
16 const FIRST_EMAIL = 3;
17 const SECOND_EMAIL = 4;
18 const BOTH_EMAIL = 5;
19
21
23 protected $ilias;
25 protected $db;
27 protected $usrId = 0;
29 protected $settings;
31 protected $table_mail_options = 'mail_options';
33 protected $linebreak = 0;
35 protected $signature = '';
45 protected $firstEmailAddress = '';
47 protected $secondEmailAddress = '';
48
54 {
55 global $DIC;
56
57 $this->usrId = $usrId;
58
59 $this->db = $DIC->database();
60 $this->settings = $DIC->settings();
61
62 if ($mailTransportSettings === null) {
64 }
65 $this->mailTransportSettings = $mailTransportSettings;
66
67 $this->read();
68 }
69
74 public function createMailOptionsEntry() : void
75 {
76 $this->incomingType = self::INCOMING_LOCAL;
77 if (strlen($this->settings->get('mail_incoming_mail', '')) > 0) {
78 $this->incomingType = (int) $this->settings->get('mail_incoming_mail');
79 }
80
81 $this->emailAddressMode = self::FIRST_EMAIL;
82 if (strlen($this->settings->get('mail_address_option', '')) > 0) {
83 $this->emailAddressMode = (int) $this->settings->get('mail_address_option');
84 }
85
86 $this->linebreak = self::DEFAULT_LINE_BREAK;
87 $this->isCronJobNotificationEnabled = false;
88 $this->signature = '';
89
90 $this->db->replace(
91 $this->table_mail_options,
92 [
93 'user_id' => ['integer', $this->usrId],
94 ],
95 [
96 'linebreak' => ['integer', $this->linebreak],
97 'signature' => ['text', $this->signature],
98 'incoming_type' => ['integer', $this->incomingType],
99 'mail_address_option' => ['integer', $this->emailAddressMode],
100 'cronjob_notification' => ['integer', (int) $this->isCronJobNotificationEnabled]
101 ]
102 );
103 }
104
105 protected function read() : void
106 {
107 $query = implode(' ', [
108 'SELECT mail_options.cronjob_notification,',
109 'mail_options.signature, mail_options.linebreak, mail_options.incoming_type,',
110 'mail_options.mail_address_option, usr_data.email, usr_data.second_email',
111 'FROM mail_options',
112 'LEFT JOIN usr_data ON mail_options.user_id = usr_data.usr_id',
113 'WHERE mail_options.user_id = %s',
114 ]);
115 $res = $this->db->queryF(
116 $query,
117 ['integer'],
118 [$this->usrId]
119 );
120 $row = $this->db->fetchObject($res);
121 if ($row !== null) {
122 $this->isCronJobNotificationEnabled = (bool) $row->cronjob_notification;
123 $this->signature = (string) $row->signature;
124 $this->linebreak = (int) $row->linebreak;
125 $this->incomingType = (int) $row->incoming_type;
126 $this->emailAddressMode = (int) $row->mail_address_option;
127
128 if (false === filter_var(
129 $this->incomingType,
130 FILTER_VALIDATE_INT,
131 ['options' => ['min_range' => self::INCOMING_LOCAL, 'max_range' => self::INCOMING_BOTH]]
132 )) {
133 $this->incomingType = self::INCOMING_LOCAL;
134 }
135
136 if (false === filter_var(
137 $this->emailAddressMode,
138 FILTER_VALIDATE_INT,
139 ['options' => ['min_range' => self::FIRST_EMAIL, 'max_range' => self::BOTH_EMAIL]]
140 )) {
141 $this->emailAddressMode = self::FIRST_EMAIL;
142 }
143
144 $this->firstEmailAddress = (string) $row->email;
145 $this->secondEmailAddress = (string) $row->second_email;
146
147 $this->mailTransportSettings->adjust($this->firstEmailAddress, $this->secondEmailAddress);
148 }
149 }
150
151 public function updateOptions()
152 {
153 $data = [
154 'signature' => ['text', $this->getSignature()],
155 'linebreak' => ['integer', (int) $this->getLinebreak()],
156 'incoming_type' => ['integer', $this->getIncomingType()],
157 'mail_address_option' => ['integer', $this->getEmailAddressMode()]
158 ];
159
160 if ($this->settings->get('mail_notification')) {
161 $data['cronjob_notification'] = ['integer', (int) $this->isCronJobNotificationEnabled()];
162 } else {
163 $data['cronjob_notification'] = ['integer', (int) self::lookupNotificationSetting($this->usrId)];
164 }
165
166 return $this->db->replace(
167 $this->table_mail_options,
168 [
169 'user_id' => ['integer', $this->usrId]
170 ],
171 $data
172 );
173 }
174
178 public function getLinebreak() : int
179 {
180 return $this->linebreak;
181 }
182
186 public function getSignature() : string
187 {
188 return $this->signature;
189 }
190
194 public function getIncomingType() : int
195 {
196 return $this->incomingType;
197 }
198
202 public function setLinebreak(int $linebreak) : void
203 {
204 $this->linebreak = $linebreak;
205 }
206
210 public function setSignature(string $signature) : void
211 {
212 $this->signature = $signature;
213 }
214
218 public function setIncomingType(int $incomingType) : void
219 {
220 $this->incomingType = $incomingType;
221 }
222
227 {
229 }
230
234 public function isCronJobNotificationEnabled() : bool
235 {
237 }
238
242 public function getEmailAddressMode() : int
243 {
245 }
246
250 public function setEmailAddressMode(int $emailAddressMode) : void
251 {
252 $this->emailAddressMode = $emailAddressMode;
253 }
254
259 private static function lookupNotificationSetting(int $usrId) : int
260 {
261 global $DIC;
262
263 $row = $DIC->database()->fetchAssoc($DIC->database()->queryF(
264 'SELECT cronjob_notification FROM mail_options WHERE user_id = %s',
265 ['integer'],
266 [$usrId]
267 ));
268
269 return (int) $row['cronjob_notification'];
270 }
271
275 public function getExternalEmailAddresses() : array
276 {
277 $emailAddresses = [];
278
279 switch ($this->getEmailAddressMode()) {
281 if (strlen($this->secondEmailAddress)) {
282 $emailAddresses[] = $this->secondEmailAddress;
283 } elseif (strlen($this->firstEmailAddress)) {
284 // fallback, use first email address
285 $emailAddresses[] = $this->firstEmailAddress;
286 }
287 break;
288
289 case self::BOTH_EMAIL:
290 if (strlen($this->firstEmailAddress)) {
291 $emailAddresses[] = $this->firstEmailAddress;
292 }
293 if (strlen($this->secondEmailAddress)) {
294 $emailAddresses[] = $this->secondEmailAddress;
295 }
296 break;
297
299 default:
300 if (strlen($this->firstEmailAddress)) {
301 $emailAddresses[] = $this->firstEmailAddress;
302 } elseif (strlen($this->secondEmailAddress)) {
303 // fallback, use first email address
304 $emailAddresses[] = $this->secondEmailAddress;
305 }
306 break;
307 }
308
309 return $emailAddresses;
310 }
311}
An exception for terminatinating execution or to throw for unit testing.
Class ilMailOptions this class handles user mails.
setSignature(string $signature)
createMailOptionsEntry()
create entry in table_mail_options for a new user this method should only be called from createUser()
setEmailAddressMode(int $emailAddressMode)
static lookupNotificationSetting(int $usrId)
setLinebreak(int $linebreak)
setIsCronJobNotificationStatus(bool $isCronJobNotificationEnabled)
setIncomingType(int $incomingType)
__construct(int $usrId, ilMailTransportSettings $mailTransportSettings=null)
if(!file_exists(getcwd() . '/ilias.ini.php'))
registration confirmation script for ilias
Definition: confirmReg.php:12
$query
foreach($_POST as $key=> $value) $res
settings()
Definition: settings.php:2
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46