ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilMailOptions Class Reference

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

+ Collaboration diagram for ilMailOptions:

Public Member Functions

 __construct (int $usrId, ilMailTransportSettings $mailTransportSettings=null, ilSetting $settings=null, ilDBInterface $db=null)
 
 createMailOptionsEntry ()
 create entry in table_mail_options for a new user this method should only be called from createUser() More...
 
 mayModifyIndividualTransportSettings ()
 
 maySeeIndividualTransportSettings ()
 
 mayManageInvididualSettings ()
 
 updateOptions ()
 
 getLinebreak ()
 
 getSignature ()
 
 getIncomingType ()
 
 setLinebreak (int $linebreak)
 
 setSignature (string $signature)
 
 setIncomingType (int $incomingType)
 
 setIsCronJobNotificationStatus (bool $isCronJobNotificationEnabled)
 
 isCronJobNotificationEnabled ()
 
 getEmailAddressMode ()
 
 setEmailAddressMode (int $emailAddressMode)
 
 getExternalEmailAddresses ()
 

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 ()
 

Protected Attributes

ILIAS $ilias
 
ilDBInterface $db
 
int $usrId = 0
 
ilSetting $settings
 
string $table_mail_options = 'mail_options'
 
int $linebreak = 0
 
string $signature = ''
 
bool $isCronJobNotificationEnabled = false
 
int $incomingType = self::INCOMING_LOCAL
 
int $default_incoming_type = self::INCOMING_LOCAL
 
int $emailAddressMode = self::FIRST_EMAIL
 
int $default_email_address_mode = self::FIRST_EMAIL
 
ilMailTransportSettings $mailTransportSettings
 
string $firstEmailAddress = ''
 
string $secondEmailAddress = ''
 

Static Private Member Functions

static lookupNotificationSetting (int $usrId)
 

Detailed Description

Class ilMailOptions this class handles user mails.

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

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

Constructor & Destructor Documentation

◆ __construct()

ilMailOptions::__construct ( int  $usrId,
ilMailTransportSettings  $mailTransportSettings = null,
ilSetting  $settings = null,
ilDBInterface  $db = null 
)

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

References $default_email_address_mode, $default_incoming_type, $DIC, $usrId, ILIAS\Repository\int(), isCronJobNotificationEnabled(), read(), and ILIAS\Repository\settings().

56  {
57  global $DIC;
58  $this->usrId = $usrId;
59  $this->db = $db ?? $DIC->database();
60  $this->settings = $settings ?? $DIC->settings();
61  $this->mailTransportSettings = $mailTransportSettings ?? new ilMailTransportSettings($this);
62 
63  $this->incomingType = self::INCOMING_LOCAL;
64  $default_incoming_type = $this->settings->get('mail_incoming_mail', '');
65  if ($default_incoming_type !== '') {
66  $this->default_incoming_type = (int) $default_incoming_type;
67  $this->incomingType = $this->default_incoming_type;
68  }
69 
70  $this->emailAddressMode = self::FIRST_EMAIL;
71  $default_email_address_mode = $this->settings->get('mail_address_option', '');
72  if ($default_email_address_mode !== '') {
73  $this->default_email_address_mode = (int) $default_email_address_mode;
74  $this->emailAddressMode = $this->default_email_address_mode;
75  }
76 
77  $this->linebreak = self::DEFAULT_LINE_BREAK;
78  $this->isCronJobNotificationEnabled = false;
79  $this->signature = '';
80 
81  $this->read();
82  }
global $DIC
Definition: feed.php:28
+ 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 88 of file class.ilMailOptions.php.

References isCronJobNotificationEnabled().

88  : void
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->default_incoming_type],
99  'mail_address_option' => ['integer', $this->default_email_address_mode],
100  'cronjob_notification' => ['integer', (int) $this->isCronJobNotificationEnabled]
101  ]
102  );
103  }
+ Here is the call graph for this function:

◆ getEmailAddressMode()

ilMailOptions::getEmailAddressMode ( )

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

References $emailAddressMode.

Referenced by getExternalEmailAddresses(), and updateOptions().

241  : int
242  {
244  }
+ Here is the caller graph for this function:

◆ getExternalEmailAddresses()

ilMailOptions::getExternalEmailAddresses ( )
Returns
string[]

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

References $firstEmailAddress, $secondEmailAddress, and getEmailAddressMode().

267  : array
268  {
269  $emailAddresses = [];
270 
271  switch ($this->getEmailAddressMode()) {
272  case self::SECOND_EMAIL:
273  if ($this->secondEmailAddress !== '') {
274  $emailAddresses[] = $this->secondEmailAddress;
275  } elseif ($this->firstEmailAddress !== '') {
276  // fallback, use first email address
277  $emailAddresses[] = $this->firstEmailAddress;
278  }
279  break;
280 
281  case self::BOTH_EMAIL:
282  if ($this->firstEmailAddress !== '') {
283  $emailAddresses[] = $this->firstEmailAddress;
284  }
285  if ($this->secondEmailAddress !== '') {
286  $emailAddresses[] = $this->secondEmailAddress;
287  }
288  break;
289 
290  case self::FIRST_EMAIL:
291  default:
292  if ($this->firstEmailAddress !== '') {
293  $emailAddresses[] = $this->firstEmailAddress;
294  } elseif ($this->secondEmailAddress !== '') {
295  // fallback, use first email address
296  $emailAddresses[] = $this->secondEmailAddress;
297  }
298  break;
299  }
300 
301  return $emailAddresses;
302  }
+ Here is the call graph for this function:

◆ getIncomingType()

ilMailOptions::getIncomingType ( )

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

References $incomingType.

Referenced by updateOptions().

211  : int
212  {
213  return $this->incomingType;
214  }
+ Here is the caller graph for this function:

◆ getLinebreak()

ilMailOptions::getLinebreak ( )

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

References $linebreak.

Referenced by updateOptions().

201  : int
202  {
203  return $this->linebreak;
204  }
+ Here is the caller graph for this function:

◆ getSignature()

ilMailOptions::getSignature ( )

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

References $signature.

Referenced by updateOptions().

206  : string
207  {
208  return $this->signature;
209  }
+ Here is the caller graph for this function:

◆ isCronJobNotificationEnabled()

ilMailOptions::isCronJobNotificationEnabled ( )

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

References $isCronJobNotificationEnabled.

Referenced by __construct(), createMailOptionsEntry(), read(), setIsCronJobNotificationStatus(), and updateOptions().

236  : bool
237  {
239  }
bool $isCronJobNotificationEnabled
+ Here is the caller graph for this function:

◆ lookupNotificationSetting()

static ilMailOptions::lookupNotificationSetting ( int  $usrId)
staticprivate

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

References $DIC.

Referenced by updateOptions().

251  : int
252  {
253  global $DIC;
254 
255  $row = $DIC->database()->fetchAssoc($DIC->database()->queryF(
256  'SELECT cronjob_notification FROM mail_options WHERE user_id = %s',
257  ['integer'],
258  [$usrId]
259  ));
260 
261  return (int) $row['cronjob_notification'];
262  }
global $DIC
Definition: feed.php:28
+ Here is the caller graph for this function:

◆ mayManageInvididualSettings()

ilMailOptions::mayManageInvididualSettings ( )

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

References ILIAS\Repository\settings().

Referenced by mayModifyIndividualTransportSettings(), and read().

119  : bool
120  {
121  return $this->settings->get('show_mail_settings') === '1';
122  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mayModifyIndividualTransportSettings()

ilMailOptions::mayModifyIndividualTransportSettings ( )

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

References mayManageInvididualSettings(), maySeeIndividualTransportSettings(), and ILIAS\Repository\settings().

Referenced by read().

105  : bool
106  {
107  return (
108  $this->mayManageInvididualSettings() &&
110  $this->settings->get('usr_settings_disable_mail_incoming_mail') !== '1'
111  );
112  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ maySeeIndividualTransportSettings()

ilMailOptions::maySeeIndividualTransportSettings ( )

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

References ILIAS\Repository\settings().

Referenced by mayModifyIndividualTransportSettings().

114  : bool
115  {
116  return $this->settings->get('usr_settings_hide_mail_incoming_mail') !== '1';
117  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ read()

ilMailOptions::read ( )
protected

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

References $query, $res, ILIAS\Repository\int(), isCronJobNotificationEnabled(), mayManageInvididualSettings(), and mayModifyIndividualTransportSettings().

Referenced by __construct().

124  : void
125  {
126  $query = implode(' ', [
127  'SELECT mail_options.cronjob_notification,',
128  'mail_options.signature, mail_options.linebreak, mail_options.incoming_type,',
129  'mail_options.mail_address_option, usr_data.email, usr_data.second_email',
130  'FROM mail_options',
131  'INNER JOIN usr_data ON mail_options.user_id = usr_data.usr_id',
132  'WHERE mail_options.user_id = %s',
133  ]);
134  $res = $this->db->queryF(
135  $query,
136  ['integer'],
137  [$this->usrId]
138  );
139  $row = $this->db->fetchObject($res);
140  if ($row === null) {
141  $this->mailTransportSettings->adjust($this->firstEmailAddress, $this->secondEmailAddress, false);
142  return;
143  }
144 
145  $this->firstEmailAddress = (string) $row->email;
146  $this->secondEmailAddress = (string) $row->second_email;
147  if ($this->mayManageInvididualSettings()) {
148  $this->signature = (string) $row->signature;
149  $this->linebreak = (int) $row->linebreak;
150  $this->isCronJobNotificationEnabled = (bool) $row->cronjob_notification;
151  }
152 
154  $this->incomingType = (int) $row->incoming_type;
155  $this->emailAddressMode = (int) $row->mail_address_option;
156 
157  if (false === filter_var(
158  $this->incomingType,
159  FILTER_VALIDATE_INT,
160  ['options' => ['min_range' => self::INCOMING_LOCAL, 'max_range' => self::INCOMING_BOTH]]
161  )) {
162  $this->incomingType = self::INCOMING_LOCAL;
163  }
164 
165  if (false === filter_var(
166  $this->emailAddressMode,
167  FILTER_VALIDATE_INT,
168  ['options' => ['min_range' => self::FIRST_EMAIL, 'max_range' => self::BOTH_EMAIL]]
169  )) {
170  $this->emailAddressMode = self::FIRST_EMAIL;
171  }
172  }
173 
174  $this->mailTransportSettings->adjust($this->firstEmailAddress, $this->secondEmailAddress);
175  }
$res
Definition: ltiservices.php:69
$query
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setEmailAddressMode()

ilMailOptions::setEmailAddressMode ( int  $emailAddressMode)

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

References $emailAddressMode.

246  : void
247  {
248  $this->emailAddressMode = $emailAddressMode;
249  }

◆ setIncomingType()

ilMailOptions::setIncomingType ( int  $incomingType)

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

References $incomingType.

226  : void
227  {
228  $this->incomingType = $incomingType;
229  }

◆ setIsCronJobNotificationStatus()

ilMailOptions::setIsCronJobNotificationStatus ( bool  $isCronJobNotificationEnabled)

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

References $isCronJobNotificationEnabled, and isCronJobNotificationEnabled().

231  : void
232  {
234  }
bool $isCronJobNotificationEnabled
+ Here is the call graph for this function:

◆ setLinebreak()

ilMailOptions::setLinebreak ( int  $linebreak)

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

References $linebreak.

216  : void
217  {
218  $this->linebreak = $linebreak;
219  }

◆ setSignature()

ilMailOptions::setSignature ( string  $signature)

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

References $signature.

221  : void
222  {
223  $this->signature = $signature;
224  }

◆ updateOptions()

ilMailOptions::updateOptions ( )

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

References $data, getEmailAddressMode(), getIncomingType(), getLinebreak(), getSignature(), ILIAS\Repository\int(), isCronJobNotificationEnabled(), lookupNotificationSetting(), and ILIAS\Repository\settings().

177  : int
178  {
179  $data = [
180  'signature' => ['text', $this->getSignature()],
181  'linebreak' => ['integer', $this->getLinebreak()],
182  'incoming_type' => ['integer', $this->getIncomingType()],
183  'mail_address_option' => ['integer', $this->getEmailAddressMode()],
184  ];
185 
186  if ($this->settings->get('mail_notification', '0')) {
187  $data['cronjob_notification'] = ['integer', (int) $this->isCronJobNotificationEnabled()];
188  } else {
189  $data['cronjob_notification'] = ['integer', $this->lookupNotificationSetting($this->usrId)];
190  }
191 
192  return $this->db->replace(
193  $this->table_mail_options,
194  [
195  'user_id' => ['integer', $this->usrId],
196  ],
197  $data
198  );
199  }
static lookupNotificationSetting(int $usrId)
+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilMailOptions::$db
protected

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

◆ $default_email_address_mode

int ilMailOptions::$default_email_address_mode = self::FIRST_EMAIL
protected

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

Referenced by __construct().

◆ $default_incoming_type

int ilMailOptions::$default_incoming_type = self::INCOMING_LOCAL
protected

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

Referenced by __construct().

◆ $emailAddressMode

int ilMailOptions::$emailAddressMode = self::FIRST_EMAIL
protected

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

Referenced by getEmailAddressMode(), and setEmailAddressMode().

◆ $firstEmailAddress

string ilMailOptions::$firstEmailAddress = ''
protected

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

Referenced by getExternalEmailAddresses().

◆ $ilias

ILIAS ilMailOptions::$ilias
protected

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

◆ $incomingType

int ilMailOptions::$incomingType = self::INCOMING_LOCAL
protected

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

Referenced by getIncomingType(), and setIncomingType().

◆ $isCronJobNotificationEnabled

bool ilMailOptions::$isCronJobNotificationEnabled = false
protected

◆ $linebreak

int ilMailOptions::$linebreak = 0
protected

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

Referenced by getLinebreak(), and setLinebreak().

◆ $mailTransportSettings

ilMailTransportSettings ilMailOptions::$mailTransportSettings
protected

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

◆ $secondEmailAddress

string ilMailOptions::$secondEmailAddress = ''
protected

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

Referenced by getExternalEmailAddresses().

◆ $settings

ilSetting ilMailOptions::$settings
protected

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

◆ $signature

string ilMailOptions::$signature = ''
protected

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

Referenced by getSignature(), and setSignature().

◆ $table_mail_options

string ilMailOptions::$table_mail_options = 'mail_options'
protected

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

◆ $usrId

int ilMailOptions::$usrId = 0
protected

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

Referenced by __construct().

◆ BOTH_EMAIL

const ilMailOptions::BOTH_EMAIL = 5

◆ DEFAULT_LINE_BREAK

const ilMailOptions::DEFAULT_LINE_BREAK = 60

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

Referenced by ilMailOptionsTest\testConstructor().

◆ FIRST_EMAIL

◆ INCOMING_BOTH

const ilMailOptions::INCOMING_BOTH = 2

◆ INCOMING_EMAIL

◆ INCOMING_LOCAL

◆ SECOND_EMAIL

const ilMailOptions::SECOND_EMAIL = 4

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