ILIAS  release_8 Revision v8.24
ilAccountMail Class Reference

Class ilAccountMail. More...

+ Collaboration diagram for ilAccountMail:

Public Member Functions

 __construct ()
 
 useLangVariablesAsFallback (bool $a_status)
 
 areLangVariablesUsedAsFallback ()
 
 shouldAttachConfiguredFiles ()
 
 setAttachConfiguredFiles (bool $attachConfiguredFiles)
 
 setUserPassword (string $a_pwd)
 
 getUserPassword ()
 
 setUser (ilObjUser $a_user)
 
 getUser ()
 
 getTarget ()
 
 reset ()
 
 send ()
 Sends the mail with its object properties as MimeMail It first tries to read the mail body, subject and sender address from posted named formular fields. More...
 
 replacePlaceholders (string $a_string, ilObjUser $a_user, array $a_amail, string $a_lang)
 
 addAttachment (string $a_filename, string $a_display_name)
 

Data Fields

string $u_password = ''
 
ilObjUser $user = null
 
string $target = ''
 

Private Member Functions

 ensureValidMailDataShape (array $mailData)
 
 readAccountMail (string $a_lang)
 
 addAttachments (array $mailData)
 

Private Attributes

GlobalHttpState $http
 
ilSetting $settings
 
Refinery $refinery
 
ilTree $repositoryTree
 
ilMailMimeSenderFactory $senderFactory
 
bool $lang_variables_as_fallback = false
 
array $attachments = []
 
bool $attachConfiguredFiles = false
 
array $amail = []
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

ilAccountMail::__construct ( )

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

50 {
51 global $DIC;
52 $this->http = $DIC->http();
53 $this->refinery = $DIC->refinery();
54 $this->settings = $DIC->settings();
55 $this->repositoryTree = $DIC->repositoryTree();
56 $this->senderFactory = $DIC['mail.mime.sender.factory'];
57 }
global $DIC
Definition: feed.php:28
static http()
Fetches the global http state from ILIAS.

References $DIC, ILIAS\FileDelivery\http(), ILIAS\Repository\refinery(), ILIAS\Repository\repositoryTree(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

Member Function Documentation

◆ addAttachment()

ilAccountMail::addAttachment ( string  $a_filename,
string  $a_display_name 
)

Definition at line 381 of file class.ilAccountMail.php.

381 : void
382 {
383 $this->attachments[$a_filename] = $a_display_name;
384 }

Referenced by addAttachments().

+ Here is the caller graph for this function:

◆ addAttachments()

ilAccountMail::addAttachments ( array  $mailData)
private
Parameters
array{lang?string, subject?: string, body?: string, sal_f?: string, sal_g?: string, sal_m?: string, type?: string, att_file?: string} $mailData
Returns
void
Exceptions

ILIAS\Filesystem\Exception\IOException

Definition at line 155 of file class.ilAccountMail.php.

155 : void
156 {
157 if (isset($mailData['att_file']) && $this->shouldAttachConfiguredFiles()) {
159 $fs->create();
160
161 $pathToFile = '/' . implode('/', array_map(static function (string $pathPart): string {
162 return trim($pathPart, '/');
163 }, [
164 $fs->getAbsolutePath(),
165 $mailData['lang'],
166 ]));
167
168 $this->addAttachment($pathToFile, $mailData['att_file']);
169 }
170 }
addAttachment(string $a_filename, string $a_display_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const USER_FOLDER_ID
Definition: constants.php:33

References addAttachment(), shouldAttachConfiguredFiles(), and USER_FOLDER_ID.

Referenced by send().

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

◆ areLangVariablesUsedAsFallback()

ilAccountMail::areLangVariablesUsedAsFallback ( )

Definition at line 64 of file class.ilAccountMail.php.

64 : bool
65 {
67 }

References $lang_variables_as_fallback.

Referenced by send().

+ Here is the caller graph for this function:

◆ ensureValidMailDataShape()

ilAccountMail::ensureValidMailDataShape ( array  $mailData)
private
Parameters
array{lang?string, subject?: string, body?: string, sal_f?: string, sal_g?: string, sal_m?: string, type?: string, att_file?: string} $mailData
Returns
array{lang?: string, subject?: string, body?: string, sal_f?: string, sal_g?: string, sal_m?: string, type?: string, att_file?: string}

Definition at line 122 of file class.ilAccountMail.php.

122 : array
123 {
124 foreach (['lang', 'subject', 'body', 'sal_f', 'sal_g', 'sal_m', 'type'] as $key) {
125 if (!isset($mailData[$key])) {
126 $mailData[$key] = '';
127 }
128 }
129
130 $mailData['subject'] = trim($mailData['subject']);
131 $mailData['body'] = trim($mailData['body']);
132
133 return $mailData;
134 }
string $key
Consumer key/client ID value.
Definition: System.php:193

References ILIAS\LTI\ToolProvider\$key.

Referenced by readAccountMail().

+ Here is the caller graph for this function:

◆ getTarget()

ilAccountMail::getTarget ( )

Definition at line 106 of file class.ilAccountMail.php.

106 : string
107 {
108 return $this->target;
109 }

References $target.

◆ getUser()

ilAccountMail::getUser ( )

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

101 : ?ilObjUser
102 {
103 return $this->user;
104 }
User class.

References $user.

Referenced by send().

+ Here is the caller graph for this function:

◆ getUserPassword()

ilAccountMail::getUserPassword ( )

Definition at line 84 of file class.ilAccountMail.php.

84 : string
85 {
86 return $this->u_password;
87 }

References $u_password.

Referenced by replacePlaceholders().

+ Here is the caller graph for this function:

◆ readAccountMail()

ilAccountMail::readAccountMail ( string  $a_lang)
private
Returns
array{lang?: string, subject?: string, body?: string, sal_f?: string, sal_g?: string, sal_m?: string, type?: string}

Definition at line 139 of file class.ilAccountMail.php.

139 : array
140 {
141 if (!isset($this->amail[$a_lang]) || !is_array($this->amail[$a_lang])) {
142 $this->amail[$a_lang] = $this->ensureValidMailDataShape(
144 );
145 }
146
147 return $this->amail[$a_lang];
148 }
ensureValidMailDataShape(array $mailData)
static _lookupNewAccountMail(string $a_lang)

References ilObjUserFolder\_lookupNewAccountMail(), and ensureValidMailDataShape().

Referenced by send().

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

◆ replacePlaceholders()

ilAccountMail::replacePlaceholders ( string  $a_string,
ilObjUser  $a_user,
array  $a_amail,
string  $a_lang 
)

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

252 : string
253 {
254 switch ($a_user->getGender()) {
255 case 'f':
256 $gender_salut = $a_amail['sal_f'];
257 break;
258 case 'm':
259 $gender_salut = $a_amail['sal_m'];
260 break;
261 default:
262 $gender_salut = $a_amail['sal_g'];
263 }
264 $gender_salut = trim($gender_salut);
265
266 $a_string = str_replace(
267 [
268 '[MAIL_SALUTATION]',
269 '[LOGIN]',
270 '[FIRST_NAME]',
271 '[LAST_NAME]',
272 '[EMAIL]',
273 '[PASSWORD]',
274 '[ILIAS_URL]',
275 '[INSTALLATION_NAME]',
276 '[ADMIN_MAIL]',
277 ],
278 [
279 $gender_salut,
280 $a_user->getLogin(),
281 $a_user->getFirstname(),
282 $a_user->getLastname(),
283 $a_user->getEmail(),
284 $this->getUserPassword(),
285 ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID,
287 $this->settings->get('admin_email', ''),
288 ],
289 $a_string
290 );
291
292 // (no) password sections
293 if ($this->getUserPassword() === '') {
294 // #12232
295 $a_string = preg_replace(
296 "/\[IF_PASSWORD\].*\[\/IF_PASSWORD\]/imsU",
297 "",
298 $a_string
299 );
300 $a_string = preg_replace(
301 "/\[IF_NO_PASSWORD\](.*)\[\/IF_NO_PASSWORD\]/imsU",
302 "$1",
303 $a_string
304 );
305 } else {
306 $a_string = preg_replace(
307 "/\[IF_NO_PASSWORD\].*\[\/IF_NO_PASSWORD\]/imsU",
308 "",
309 $a_string
310 );
311 $a_string = preg_replace(
312 "/\[IF_PASSWORD\](.*)\[\/IF_PASSWORD\]/imsU",
313 "$1",
314 $a_string
315 );
316 }
317
318 // #13346
319 if (!$a_user->getTimeLimitUnlimited()) {
320 // #6098
321 $a_string = preg_replace(
322 "/\[IF_TIMELIMIT\](.*)\[\/IF_TIMELIMIT\]/imsU",
323 "$1",
324 $a_string
325 );
326 $timelimit_from = new ilDateTime($a_user->getTimeLimitFrom(), IL_CAL_UNIX);
327 $timelimit_until = new ilDateTime($a_user->getTimeLimitUntil(), IL_CAL_UNIX);
328 $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
329 $a_string = str_replace("[TIMELIMIT]", $timelimit, $a_string);
330 } else {
331 $a_string = preg_replace(
332 "/\[IF_TIMELIMIT\](.*)\[\/IF_TIMELIMIT\]/imsU",
333 "",
334 $a_string
335 );
336 }
337
338 // target
339 $tar = false;
340 if ($this->http->wrapper()->query()->has('target') &&
341 $this->http->wrapper()->query()->retrieve('target', $this->refinery->kindlyTo()->string()) !== ''
342 ) {
343 $target = $this->http->wrapper()->query()->retrieve('target', $this->refinery->kindlyTo()->string());
344 $tarr = explode('_', $target);
345 if ($this->repositoryTree->isInTree((int) $tarr[1])) {
346 $obj_id = ilObject::_lookupObjId((int) $tarr[1]);
347 $type = ilObject::_lookupType($obj_id);
348 if ($type === $tarr[0]) {
349 $a_string = str_replace(
350 ['[TARGET_TITLE]', '[TARGET]'],
351 [
352 ilObject::_lookupTitle($obj_id),
353 ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . '&target=' . $target
354 ],
355 $a_string
356 );
357
358 // this looks complicated, but we may have no initiliased $lng object here
359 // if mail is send during user creation in authentication
360 $a_string = str_replace(
361 '[TARGET_TYPE]',
362 ilLanguage::_lookupEntry($a_lang, 'common', 'obj_' . $tarr[0]),
363 $a_string
364 );
365
366 $tar = true;
367 }
368 }
369 }
370
371 // (no) target section
372 if (!$tar) {
373 $a_string = preg_replace("/\[IF_TARGET\].*\[\/IF_TARGET\]/imsU", '', $a_string);
374 } else {
375 $a_string = preg_replace("/\[IF_TARGET\](.*)\[\/IF_TARGET\]/imsU", "$1", $a_string);
376 }
377
378 return $a_string;
379 }
const IL_CAL_UNIX
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false)
Format a period of two dates Shows: 14.
@classDescription Date and time handling
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
const CLIENT_ID
Definition: constants.php:41
const CLIENT_NAME
Definition: constants.php:42
$type

References $target, $type, ilLanguage\_lookupEntry(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), ilObject\_lookupType(), CLIENT_ID, CLIENT_NAME, ilDatePresentation\formatPeriod(), ilObjUser\getEmail(), ilObjUser\getFirstname(), ilObjUser\getGender(), ilObjUser\getLastname(), ilObjUser\getLogin(), ilObjUser\getTimeLimitFrom(), ilObjUser\getTimeLimitUnlimited(), ilObjUser\getTimeLimitUntil(), getUserPassword(), ILIAS\FileDelivery\http(), IL_CAL_UNIX, ILIAS\Repository\refinery(), and ILIAS\Repository\repositoryTree().

Referenced by send().

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

◆ reset()

ilAccountMail::reset ( )

Definition at line 111 of file class.ilAccountMail.php.

111 : void
112 {
113 $this->user = null;
114 $this->u_password = '';
115 $this->target = '';
116 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ send()

ilAccountMail::send ( )

Sends the mail with its object properties as MimeMail It first tries to read the mail body, subject and sender address from posted named formular fields.

If no field values found the defaults are used. Placehoders will be replaced by the appropriate data.

Returns
bool
Exceptions
RuntimeException

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

180 : bool
181 {
182 $user = $this->getUser();
183 if (null === $user) {
184 throw new RuntimeException('A user instance must be passed when sending emails');
185 }
186
187 if (!$user->getEmail()) {
188 return false;
189 }
190
191 // determine language and get account mail data
192 // fall back to default language if acccount mail data is not given for user language.
195 if ($amail['body'] === '' || $amail['subject'] === '') {
196 $fallback_language = 'en';
197 $amail = $this->readAccountMail($this->settings->get('language', $fallback_language));
198 $lang = $this->settings->get('language', $fallback_language);
199 }
200
201 // fallback if mail data is still not given
202 if (($amail['body'] === '' || $amail['subject'] === '') && $this->areLangVariablesUsedAsFallback()) {
204 $tmp_lang = new ilLanguage($lang);
205
206 $mail_subject = $tmp_lang->txt('reg_mail_subject');
207
208 $timelimit = "";
209 if (!$user->checkTimeLimit()) {
210 $tmp_lang->loadLanguageModule("registration");
211
212 // #6098
213 $timelimit_from = new ilDateTime($user->getTimeLimitFrom(), IL_CAL_UNIX);
214 $timelimit_until = new ilDateTime($user->getTimeLimitUntil(), IL_CAL_UNIX);
215 $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
216 $timelimit = "\n" . sprintf($tmp_lang->txt('reg_mail_body_timelimit'), $timelimit) . "\n\n";
217 }
218
219 // mail body
220 $mail_body = $tmp_lang->txt('reg_mail_body_salutation') . ' ' . $user->getFullname() . ",\n\n" .
221 $tmp_lang->txt('reg_mail_body_text1') . "\n\n" .
222 $tmp_lang->txt('reg_mail_body_text2') . "\n" .
223 ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID . "\n";
224 $mail_body .= $tmp_lang->txt('login') . ': ' . $user->getLogin() . "\n";
225 $mail_body .= $tmp_lang->txt('passwd') . ': ' . $this->u_password . "\n";
226 $mail_body .= "\n" . $timelimit;
227 $mail_body .= $tmp_lang->txt('reg_mail_body_text3') . "\n\r";
228 $mail_body .= $user->getProfileAsString($tmp_lang);
229 } else {
230 $this->addAttachments($amail);
231
232 // replace placeholders
233 $mail_subject = $this->replacePlaceholders($amail['subject'], $user, $amail, $lang);
234 $mail_body = $this->replacePlaceholders($amail['body'], $user, $amail, $lang);
235 }
236
237 $mmail = new ilMimeMail();
238 $mmail->From($this->senderFactory->system());
239 $mmail->Subject($mail_subject, true);
240 $mmail->To($user->getEmail());
241 $mmail->Body($mail_body);
242
243 foreach ($this->attachments as $filename => $display_name) {
244 $mmail->Attach($filename, '', 'attachment', $display_name);
245 }
246
247 $mmail->Send();
248
249 return true;
250 }
$filename
Definition: buildRTE.php:78
readAccountMail(string $a_lang)
replacePlaceholders(string $a_string, ilObjUser $a_user, array $a_amail, string $a_lang)
addAttachments(array $mailData)
language handling
getFullname(int $a_max_strlen=0)
$lang
Definition: xapiexit.php:26

References $amail, $filename, $lang, $user, addAttachments(), areLangVariablesUsedAsFallback(), ilObjUser\checkTimeLimit(), CLIENT_ID, ilDatePresentation\formatPeriod(), ilObjUser\getEmail(), ilObjUser\getFullname(), ilObjUser\getLanguage(), ilObjUser\getLogin(), ilObjUser\getTimeLimitFrom(), ilObjUser\getTimeLimitUntil(), getUser(), IL_CAL_UNIX, readAccountMail(), replacePlaceholders(), and ILIAS\Repository\settings().

+ Here is the call graph for this function:

◆ setAttachConfiguredFiles()

ilAccountMail::setAttachConfiguredFiles ( bool  $attachConfiguredFiles)

Definition at line 74 of file class.ilAccountMail.php.

74 : void
75 {
76 $this->attachConfiguredFiles = $attachConfiguredFiles;
77 }

References $attachConfiguredFiles.

◆ setUser()

ilAccountMail::setUser ( ilObjUser  $a_user)

Definition at line 89 of file class.ilAccountMail.php.

89 : void
90 {
91 if (
92 $this->user instanceof ilObjUser &&
93 $a_user->getId() !== $this->user->getId()
94 ) {
95 $this->attachments = [];
96 }
97
98 $this->user = $a_user;
99 }

References ilObject\getId(), and ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ setUserPassword()

ilAccountMail::setUserPassword ( string  $a_pwd)

Definition at line 79 of file class.ilAccountMail.php.

79 : void
80 {
81 $this->u_password = $a_pwd;
82 }

◆ shouldAttachConfiguredFiles()

ilAccountMail::shouldAttachConfiguredFiles ( )

Definition at line 69 of file class.ilAccountMail.php.

69 : bool
70 {
72 }

References $attachConfiguredFiles.

Referenced by addAttachments().

+ Here is the caller graph for this function:

◆ useLangVariablesAsFallback()

ilAccountMail::useLangVariablesAsFallback ( bool  $a_status)

Definition at line 59 of file class.ilAccountMail.php.

59 : void
60 {
61 $this->lang_variables_as_fallback = $a_status;
62 }

Field Documentation

◆ $amail

array ilAccountMail::$amail = []
private

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

Referenced by send().

◆ $attachConfiguredFiles

bool ilAccountMail::$attachConfiguredFiles = false
private

◆ $attachments

array ilAccountMail::$attachments = []
private

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

◆ $http

GlobalHttpState ilAccountMail::$http
private

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

◆ $lang_variables_as_fallback

bool ilAccountMail::$lang_variables_as_fallback = false
private

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

Referenced by areLangVariablesUsedAsFallback().

◆ $refinery

Refinery ilAccountMail::$refinery
private

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

◆ $repositoryTree

ilTree ilAccountMail::$repositoryTree
private

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

◆ $senderFactory

ilMailMimeSenderFactory ilAccountMail::$senderFactory
private

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

◆ $settings

ilSetting ilAccountMail::$settings
private

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

◆ $target

string ilAccountMail::$target = ''

Definition at line 42 of file class.ilAccountMail.php.

Referenced by getTarget(), and replacePlaceholders().

◆ $u_password

string ilAccountMail::$u_password = ''

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

Referenced by getUserPassword().

◆ $user

ilObjUser ilAccountMail::$user = null

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

Referenced by getUser(), and send().


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