ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilMailOptions Class Reference

Class ilMailOptions this class handles user mails. More...

+ Collaboration diagram for ilMailOptions:

Public Member Functions

 __construct ($a_user_id, ilMailTransportSettings $mailTransportSettings=null)
 
 createMailOptionsEntry ()
 create entry in table_mail_options for a new user this method should only be called from createUser() More...
 
 updateOptions ()
 
 getLinebreak ()
 
 getSignature ()
 
 getIncomingType ()
 
 setLinebreak ($linebreak)
 
 setSignature ($signature)
 
 setIncomingType ($incoming_type)
 
 setCronjobNotification ($cronjob_notification)
 
 getCronjobNotification ()
 
 getMailAddressOption ()
 
 setMailAddressOption ($mail_address_option)
 

Static Public Member Functions

static getExternalEmailsByUser (ilObjUser $user, ilMailOptions $mail_options=null)
 
static getExternalEmailsByUserId ($user_id, ilMailOptions $mail_options=null)
 

Data Fields

const INCOMING_LOCAL = 0
 
const INCOMING_EMAIL = 1
 
const INCOMING_BOTH = 2
 
const FIRST_EMAIL = 3
 
const SECOND_EMAIL = 4
 
const BOTH_EMAIL = 5
 
const DEFAULT_LINE_BREAK = 60
 

Protected Member Functions

 read ()
 

Static Protected Member Functions

static lookupNotificationSetting ($usr_id)
 
static lookupExternalEmails (ilObjUser $user, ilMailOptions $mail_options)
 

Protected Attributes

 $ilias
 
 $db
 
 $user_id
 
 $settings
 
 $table_mail_options = 'mail_options'
 
 $linebreak = self::DEFAULT_LINE_BREAK
 
 $signature
 
 $cronjob_notification = 0
 
 $incoming_type = self::INCOMING_LOCAL
 
 $mail_address_option = self::FIRST_EMAIL
 

Private Attributes

 $mailTransportSettings
 

Detailed Description

Class ilMailOptions this class handles user mails.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 10 of file class.ilMailOptions.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailOptions::__construct (   $a_user_id,
ilMailTransportSettings  $mailTransportSettings = null 
)
Parameters
int$a_user_id
ilMailTransportSettings | null$mailTransportSettings

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

50 {
51 global $DIC;
52
53 $this->user_id = $a_user_id;
54
55 $this->db = $DIC->database();
56 $this->settings = $DIC->settings();
57
58 if ($mailTransportSettings === null) {
60 }
61 $this->mailTransportSettings = $mailTransportSettings;
62
63 $this->read();
64 }
global $DIC
Definition: saml.php:7
settings()
Definition: settings.php:2

References $DIC, $mailTransportSettings, read(), and settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ createMailOptionsEntry()

ilMailOptions::createMailOptionsEntry ( )

create entry in table_mail_options for a new user this method should only be called from createUser()

Definition at line 70 of file class.ilMailOptions.php.

71 {
72 $this->incoming_type = self::INCOMING_LOCAL;
73 if (strlen($this->settings->get('mail_incoming_mail', '')) > 0) {
74 $this->incoming_type = (int) $this->settings->get('mail_incoming_mail');
75 }
76
77 $this->mail_address_option = self::FIRST_EMAIL;
78 if (strlen($this->settings->get('mail_address_option', '')) > 0) {
79 $this->mail_address_option = (int) $this->settings->get('mail_address_option');
80 }
81
82 $this->linebreak = self::DEFAULT_LINE_BREAK;
83 $this->cronjob_notification = 0;
84 $this->signature = null;
85
86 $this->db->replace(
87 $this->table_mail_options,
88 [
89 'user_id' => ['integer', $this->user_id],
90 ],
91 [
92 'linebreak' => ['integer', $this->linebreak],
93 'signature' => ['text', $this->signature],
94 'incoming_type' => ['integer', $this->incoming_type],
95 'mail_address_option' => ['integer', $this->mail_address_option],
96 'cronjob_notification' => ['integer', $this->cronjob_notification]
97 ]
98 );
99 }

References DEFAULT_LINE_BREAK, FIRST_EMAIL, INCOMING_LOCAL, and settings().

+ Here is the call graph for this function:

◆ getCronjobNotification()

ilMailOptions::getCronjobNotification ( )
Returns
int

Definition at line 236 of file class.ilMailOptions.php.

237 {
239 }

References $cronjob_notification.

Referenced by updateOptions().

+ Here is the caller graph for this function:

◆ getExternalEmailsByUser()

static ilMailOptions::getExternalEmailsByUser ( ilObjUser  $user,
ilMailOptions  $mail_options = null 
)
static
Parameters
ilObjUser$user
ilMailOptions$mail_options
Returns
string[]

Definition at line 317 of file class.ilMailOptions.php.

318 {
319 if (!($mail_options instanceof ilMailOptions)) {
320 $mail_options = new self($user->getId());
321 }
322
323 return self::lookupExternalEmails($user, $mail_options);
324 }
Class ilMailOptions this class handles user mails.
static lookupExternalEmails(ilObjUser $user, ilMailOptions $mail_options)
$user
Definition: migrateto20.php:57

References $user, and lookupExternalEmails().

Referenced by ilMail\distributeMail(), and getExternalEmailsByUserId().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExternalEmailsByUserId()

static ilMailOptions::getExternalEmailsByUserId (   $user_id,
ilMailOptions  $mail_options = null 
)
static
Parameters
int$user_id
ilMailOptions | NULL$mail_options
Returns
string[]

Definition at line 331 of file class.ilMailOptions.php.

332 {
333 return self::getExternalEmailsByUser(new ilObjUser($user_id), $mail_options);
334 }
static getExternalEmailsByUser(ilObjUser $user, ilMailOptions $mail_options=null)

References $user_id, and getExternalEmailsByUser().

+ Here is the call graph for this function:

◆ getIncomingType()

ilMailOptions::getIncomingType ( )
Returns
int

Definition at line 196 of file class.ilMailOptions.php.

197 {
199 }

References $incoming_type.

Referenced by updateOptions().

+ Here is the caller graph for this function:

◆ getLinebreak()

ilMailOptions::getLinebreak ( )
Returns
string

Definition at line 180 of file class.ilMailOptions.php.

181 {
182 return $this->linebreak;
183 }

References $linebreak.

Referenced by updateOptions().

+ Here is the caller graph for this function:

◆ getMailAddressOption()

ilMailOptions::getMailAddressOption ( )
Returns
int

Definition at line 244 of file class.ilMailOptions.php.

245 {
247 }

References $mail_address_option.

Referenced by lookupExternalEmails(), and updateOptions().

+ Here is the caller graph for this function:

◆ getSignature()

ilMailOptions::getSignature ( )
Returns
string

Definition at line 188 of file class.ilMailOptions.php.

189 {
190 return $this->signature;
191 }

References $signature.

Referenced by updateOptions().

+ Here is the caller graph for this function:

◆ lookupExternalEmails()

static ilMailOptions::lookupExternalEmails ( ilObjUser  $user,
ilMailOptions  $mail_options 
)
staticprotected
Parameters
ilObjUser$user
ilMailOptions$mail_options
Returns
string[]

Definition at line 275 of file class.ilMailOptions.php.

276 {
277 $emailAddresses = array();
278
279 switch ($mail_options->getMailAddressOption()) {
281 if (strlen($user->getSecondEmail())) {
282 $emailAddresses[] = $user->getSecondEmail();
283 } elseif (strlen($user->getEmail())) {
284 // fallback, use first email address
285 $emailAddresses[] = $user->getEmail();
286 }
287 break;
288
289 case self::BOTH_EMAIL:
290 if (strlen($user->getEmail())) {
291 $emailAddresses[] = $user->getEmail();
292 }
293 if (strlen($user->getSecondEmail())) {
294 $emailAddresses[] = $user->getSecondEmail();
295 }
296 break;
297
299 default:
300 if (strlen($user->getEmail())) {
301 $emailAddresses[] = $user->getEmail();
302 } elseif (strlen($user->getSecondEmail())) {
303 // fallback, use first email address
304 $emailAddresses[] = $user->getSecondEmail();
305 }
306 break;
307 }
308
309 return $emailAddresses;
310 }

References $user, BOTH_EMAIL, FIRST_EMAIL, getMailAddressOption(), and SECOND_EMAIL.

Referenced by getExternalEmailsByUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupNotificationSetting()

static ilMailOptions::lookupNotificationSetting (   $usr_id)
staticprotected
Parameters
int$usr_id
Returns
int

Definition at line 261 of file class.ilMailOptions.php.

262 {
263 global $DIC;
264
265 $query = "SELECT cronjob_notification FROM mail_options WHERE user_id = " . $DIC->database()->quote($usr_id, 'integer');
266 $row = $DIC->database()->fetchAssoc($DIC->database()->query($query));
267 return (int) $row['cronjob_notification'];
268 }
$row
$query

References $DIC, $query, and $row.

◆ read()

ilMailOptions::read ( )
protected

Definition at line 101 of file class.ilMailOptions.php.

102 {
103 $res = $this->db->queryF(
104 'SELECT mail_options.cronjob_notification,
105 mail_options.signature,
106 mail_options.linebreak,
107 mail_options.incoming_type,
108 mail_options.mail_address_option,
109 usr_data.email,
110 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 array('integer'),
115 array($this->user_id)
116 );
117 $row = $this->db->fetchObject($res);
118
119 if ($row !== null) {
120 $this->cronjob_notification = (int) $row->cronjob_notification;
121 $this->signature = $row->signature;
122 $this->linebreak = (int) $row->linebreak;
123 $this->incoming_type = (int) $row->incoming_type;
124 $this->mail_address_option = (int) $row->mail_address_option;
125
126 if (
127 filter_var(
128 $this->incoming_type,
129 FILTER_VALIDATE_INT,
130 ['options' => ['min_range' => self::INCOMING_LOCAL, 'max_range' => self::INCOMING_BOTH]]
131 ) === false
132 ) {
133 $this->incoming_type = self::INCOMING_LOCAL;
134 }
135
136 if (
137 filter_var(
138 $this->mail_address_option,
139 FILTER_VALIDATE_INT,
140 ['options' => ['min_range' => self::FIRST_EMAIL, 'max_range' => self::BOTH_EMAIL]]
141 ) === false
142 ) {
143 $this->mail_address_option = self::FIRST_EMAIL;
144 }
145
146 $firstMailAddress = (string) $row->email;
147 $secondMailAddress = (string) $row->second_email;
148
149 $this->mailTransportSettings->adjust($firstMailAddress, $secondMailAddress);
150 }
151 }
foreach($_POST as $key=> $value) $res

References $res, $row, FIRST_EMAIL, and INCOMING_LOCAL.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setCronjobNotification()

ilMailOptions::setCronjobNotification (   $cronjob_notification)
Returns
int

Definition at line 228 of file class.ilMailOptions.php.

229 {
230 $this->cronjob_notification = $cronjob_notification;
231 }

References $cronjob_notification.

◆ setIncomingType()

ilMailOptions::setIncomingType (   $incoming_type)
Parameters
int$incoming_type

Definition at line 220 of file class.ilMailOptions.php.

221 {
222 $this->incoming_type = $incoming_type;
223 }

References $incoming_type.

◆ setLinebreak()

ilMailOptions::setLinebreak (   $linebreak)
Parameters
int$linebreak

Definition at line 204 of file class.ilMailOptions.php.

205 {
206 $this->linebreak = $linebreak;
207 }

References $linebreak.

◆ setMailAddressOption()

ilMailOptions::setMailAddressOption (   $mail_address_option)
Parameters
int$mail_address_option

Definition at line 252 of file class.ilMailOptions.php.

253 {
254 $this->mail_address_option = $mail_address_option;
255 }

References $mail_address_option.

◆ setSignature()

ilMailOptions::setSignature (   $signature)
Parameters
string$signature

Definition at line 212 of file class.ilMailOptions.php.

213 {
214 $this->signature = $signature;
215 }

References $signature.

◆ updateOptions()

ilMailOptions::updateOptions ( )

Definition at line 153 of file class.ilMailOptions.php.

154 {
155 $data = [
156 'signature' => ['text', $this->getSignature()],
157 'linebreak' => ['integer', (int) $this->getLinebreak()],
158 'incoming_type' => ['integer', $this->getIncomingType()],
159 'mail_address_option' => ['integer', $this->getMailAddressOption()]
160 ];
161
162 if ($this->settings->get('mail_notification')) {
163 $data['cronjob_notification'] = ['integer', (int) $this->getCronjobNotification()];
164 } else {
165 $data['cronjob_notification'] = ['integer', (int) self::lookupNotificationSetting($this->user_id)];
166 }
167
168 return $this->db->replace(
169 $this->table_mail_options,
170 [
171 'user_id' => ['integer', $this->user_id]
172 ],
173 $data
174 );
175 }
$data
Definition: bench.php:6

References $data, getCronjobNotification(), getIncomingType(), getLinebreak(), getMailAddressOption(), getSignature(), and settings().

+ Here is the call graph for this function:

Field Documentation

◆ $cronjob_notification

ilMailOptions::$cronjob_notification = 0
protected

Definition at line 37 of file class.ilMailOptions.php.

Referenced by getCronjobNotification(), and setCronjobNotification().

◆ $db

ilMailOptions::$db
protected

Definition at line 25 of file class.ilMailOptions.php.

◆ $ilias

ilMailOptions::$ilias
protected

Definition at line 23 of file class.ilMailOptions.php.

◆ $incoming_type

ilMailOptions::$incoming_type = self::INCOMING_LOCAL
protected

Definition at line 39 of file class.ilMailOptions.php.

Referenced by getIncomingType(), and setIncomingType().

◆ $linebreak

ilMailOptions::$linebreak = self::DEFAULT_LINE_BREAK
protected

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

Referenced by getLinebreak(), and setLinebreak().

◆ $mail_address_option

ilMailOptions::$mail_address_option = self::FIRST_EMAIL
protected

Definition at line 41 of file class.ilMailOptions.php.

Referenced by getMailAddressOption(), and setMailAddressOption().

◆ $mailTransportSettings

ilMailOptions::$mailTransportSettings
private

Definition at line 43 of file class.ilMailOptions.php.

Referenced by __construct().

◆ $settings

ilMailOptions::$settings
protected

Definition at line 29 of file class.ilMailOptions.php.

◆ $signature

ilMailOptions::$signature
protected

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

Referenced by getSignature(), and setSignature().

◆ $table_mail_options

ilMailOptions::$table_mail_options = 'mail_options'
protected

Definition at line 31 of file class.ilMailOptions.php.

◆ $user_id

ilMailOptions::$user_id
protected

Definition at line 27 of file class.ilMailOptions.php.

Referenced by getExternalEmailsByUserId().

◆ BOTH_EMAIL

const ilMailOptions::BOTH_EMAIL = 5

◆ DEFAULT_LINE_BREAK

const ilMailOptions::DEFAULT_LINE_BREAK = 60

Definition at line 20 of file class.ilMailOptions.php.

Referenced by createMailOptionsEntry().

◆ FIRST_EMAIL

◆ INCOMING_BOTH

const ilMailOptions::INCOMING_BOTH = 2

◆ INCOMING_EMAIL

const ilMailOptions::INCOMING_EMAIL = 1

◆ INCOMING_LOCAL

◆ SECOND_EMAIL

const ilMailOptions::SECOND_EMAIL = 4

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