ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilAccountMail Class Reference
+ Collaboration diagram for ilAccountMail:

Public Member Functions

 __construct ()
 
 useLangVariablesAsFallback (bool $a_status)
 
 areLangVariablesUsedAsFallback ()
 
 shouldAttachConfiguredFiles ()
 
 setAttachConfiguredFiles (bool $attach_configured_files)
 
 setUserPassword (string $a_pwd)
 
 getUserPassword ()
 
 setUser (ilObjUser $a_user)
 
 setPermanentLinkTarget (?string $permanent_link_target)
 
 getUser ()
 
 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
 

Private Member Functions

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

Private Attributes

readonly ilSetting $settings
 
readonly ilTree $repository_tree
 
readonly ilMailMimeSenderFactory $sender_factory
 
bool $lang_variables_as_fallback = false
 
array $attachments = []
 
bool $attach_configured_files = false
 
array $amail = []
 
string $permanent_link_target = null
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilAccountMail::__construct ( )

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

References $DIC, and ILIAS\Repository\settings().

39  {
40  global $DIC;
41  $this->settings = $DIC->settings();
42  $this->repository_tree = $DIC->repositoryTree();
43  $this->sender_factory = $DIC->mail()->mime()->senderFactory();
44  }
global $DIC
Definition: shib_login.php:26
+ Here is the call graph for this function:

Member Function Documentation

◆ addAttachment()

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

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

Referenced by addAttachments().

311  : void
312  {
313  $this->attachments[$a_filename] = $a_display_name;
314  }
+ Here is the caller graph for this function:

◆ addAttachments()

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

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

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

Referenced by send().

146  : void
147  {
148  if (isset($mail_data['att_file']) && $this->shouldAttachConfiguredFiles()) {
150  $fs->create();
151 
152  $path_to_tile = '/' . implode(
153  '/',
154  array_map(
155  static fn(string $path_part): string => trim($path_part, '/'),
156  [
157  $fs->getAbsolutePath(),
158  $mail_data['lang'],
159  ]
160  )
161  );
162 
163  $this->addAttachment($path_to_tile, $mail_data['att_file']);
164  }
165  }
const USER_FOLDER_ID
Definition: constants.php:33
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAttachment(string $a_filename, string $a_display_name)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ areLangVariablesUsedAsFallback()

ilAccountMail::areLangVariablesUsedAsFallback ( )

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

References $lang_variables_as_fallback.

Referenced by send().

51  : bool
52  {
54  }
+ Here is the caller graph for this function:

◆ ensureValidMailDataShape()

ilAccountMail::ensureValidMailDataShape ( array  $mail_data)
private
Parameters
array{lang?string, subject?: string, body?: string, sal_f?: string, sal_g?: string, sal_m?: string, type?: string, att_file?: string} $mail_data
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 115 of file class.ilAccountMail.php.

Referenced by readAccountMail().

115  : array
116  {
117  foreach (['lang', 'subject', 'body', 'sal_f', 'sal_g', 'sal_m', 'type'] as $key) {
118  if (!isset($mail_data[$key])) {
119  $mail_data[$key] = '';
120  }
121  }
122 
123  $mail_data['subject'] = trim($mail_data['subject']);
124  $mail_data['body'] = trim($mail_data['body']);
125 
126  return $mail_data;
127  }
+ Here is the caller graph for this function:

◆ getUser()

ilAccountMail::getUser ( )

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

References $user.

Referenced by send().

99  : ?ilObjUser
100  {
101  return $this->user;
102  }
+ Here is the caller graph for this function:

◆ getUserPassword()

ilAccountMail::getUserPassword ( )

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

References $u_password.

Referenced by replacePlaceholders().

71  : string
72  {
73  return $this->u_password;
74  }
+ 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 132 of file class.ilAccountMail.php.

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

Referenced by send().

132  : array
133  {
134  if (!isset($this->amail[$a_lang]) || !is_array($this->amail[$a_lang])) {
135  $this->amail[$a_lang] = $this->ensureValidMailDataShape(
137  );
138  }
139 
140  return $this->amail[$a_lang];
141  }
ensureValidMailDataShape(array $mail_data)
static _lookupNewAccountMail(string $a_lang)
+ 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 245 of file class.ilAccountMail.php.

References $DIC, $permanent_link_target, 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(), IL_CAL_UNIX, and null.

Referenced by send().

245  : string
246  {
247  global $DIC;
248  $settings = $DIC->settings();
249  $mustache_factory = $DIC->mail()->mustacheFactory();
250 
251  $replacements = [];
252 
253  // determine salutation
254  $replacements['MAIL_SALUTATION'] = $mustache_factory->getBasicEngine()->render(
255  match ($a_user->getGender()) {
256  'f' => trim((string) $a_amail['sal_f']),
257  'm' => trim((string) $a_amail['sal_m']),
258  default => trim((string) $a_amail['sal_g']),
259  },
260  [
261  'FIRST_NAME' => $a_user->getFirstname(),
262  'LAST_NAME' => $a_user->getLastname(),
263  'LOGIN' => $a_user->getLogin(),
264  ]
265  );
266  $replacements['LOGIN'] = $a_user->getLogin();
267  $replacements['FIRST_NAME'] = $a_user->getFirstname();
268  $replacements['LAST_NAME'] = $a_user->getLastname();
269  // BEGIN Mail Include E-Mail Address in account mail
270  $replacements['EMAIL'] = $a_user->getEmail();
271  // END Mail Include E-Mail Address in account mail
272  $replacements['PASSWORD'] = $this->getUserPassword();
273  $replacements['ILIAS_URL'] = ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID;
274  $replacements['CLIENT_NAME'] = CLIENT_NAME;
275  $replacements['ADMIN_MAIL'] = $settings->get('admin_email');
276  $replacements['IF_PASSWORD'] = $this->getUserPassword() !== '';
277  $replacements['IF_NO_PASSWORD'] = $this->getUserPassword() === '';
278 
279  // #13346
280  if (!$a_user->getTimeLimitUnlimited()) {
281  // #6098
282  $replacements['IF_TIMELIMIT'] = !$a_user->getTimeLimitUnlimited();
283  $timelimit_from = new ilDateTime($a_user->getTimeLimitFrom(), IL_CAL_UNIX);
284  $timelimit_until = new ilDateTime($a_user->getTimeLimitUntil(), IL_CAL_UNIX);
285  $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
286  $replacements['TIMELIMIT'] = $timelimit;
287  }
288 
289  // target
290  $replacements['IF_TARGET'] = false;
291  if ($this->permanent_link_target !== null) {
292  $tarr = explode('_', $this->permanent_link_target);
293  if ($this->repository_tree->isInTree((int) $tarr[1])) {
294  $obj_id = ilObject::_lookupObjId((int) $tarr[1]);
295  $type = ilObject::_lookupType($obj_id);
296  if ($type === $tarr[0]) {
297  $replacements['TARGET_TITLE'] = ilObject::_lookupTitle($obj_id);
298  $replacements['TARGET'] = ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . '&target=' . $this->permanent_link_target;
299 
300  // this looks complicated, but we may have no initilised $lng object here
301  // if mail is send during user creation in authentication
302  $replacements['TARGET_TYPE'] = ilLanguage::_lookupEntry($a_lang, 'common', 'obj_' . $tarr[0]);
303  $replacements['IF_TARGET'] = true;
304  }
305  }
306  }
307 
308  return $mustache_factory->getBasicEngine()->render($a_string, $replacements);
309  }
get(string $a_keyword, ?string $a_default_value=null)
get setting
const CLIENT_NAME
Definition: constants.php:42
const IL_CAL_UNIX
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static _lookupTitle(int $obj_id)
const CLIENT_ID
Definition: constants.php:41
global $DIC
Definition: shib_login.php:26
readonly ilSetting $settings
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _lookupType(int $id, bool $reference=false)
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
Format a period of two dates Shows: 14.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ reset()

ilAccountMail::reset ( )

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

References null, and ILIAS\Repository\user().

104  : void
105  {
106  $this->user = null;
107  $this->u_password = '';
108  $this->permanent_link_target = null;
109  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ 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.

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

References $filename, $lang, 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().

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

◆ setAttachConfiguredFiles()

ilAccountMail::setAttachConfiguredFiles ( bool  $attach_configured_files)

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

References $attach_configured_files.

61  : void
62  {
63  $this->attach_configured_files = $attach_configured_files;
64  }

◆ setPermanentLinkTarget()

ilAccountMail::setPermanentLinkTarget ( ?string  $permanent_link_target)

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

References $permanent_link_target.

88  : void
89  {
90  if ($permanent_link_target === '') {
91  throw new InvalidArgumentException(
92  'Permanent link target must not be empty'
93  );
94  }
95 
96  $this->permanent_link_target = $permanent_link_target;
97  }

◆ setUser()

ilAccountMail::setUser ( ilObjUser  $a_user)

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

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

76  : void
77  {
78  if (
79  $this->user instanceof ilObjUser &&
80  $a_user->getId() !== $this->user->getId()
81  ) {
82  $this->attachments = [];
83  }
84 
85  $this->user = $a_user;
86  }
+ Here is the call graph for this function:

◆ setUserPassword()

ilAccountMail::setUserPassword ( string  $a_pwd)

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

66  : void
67  {
68  $this->u_password = $a_pwd;
69  }

◆ shouldAttachConfiguredFiles()

ilAccountMail::shouldAttachConfiguredFiles ( )

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

References $attach_configured_files.

Referenced by addAttachments().

56  : bool
57  {
59  }
+ Here is the caller graph for this function:

◆ useLangVariablesAsFallback()

ilAccountMail::useLangVariablesAsFallback ( bool  $a_status)

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

46  : void
47  {
48  $this->lang_variables_as_fallback = $a_status;
49  }

Field Documentation

◆ $amail

array ilAccountMail::$amail = []
private

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

◆ $attach_configured_files

bool ilAccountMail::$attach_configured_files = false
private

◆ $attachments

array ilAccountMail::$attachments = []
private

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

◆ $lang_variables_as_fallback

bool ilAccountMail::$lang_variables_as_fallback = false
private

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

Referenced by areLangVariablesUsedAsFallback().

◆ $permanent_link_target

string ilAccountMail::$permanent_link_target = null
private

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

Referenced by replacePlaceholders(), and setPermanentLinkTarget().

◆ $repository_tree

readonly ilTree ilAccountMail::$repository_tree
private

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

◆ $sender_factory

readonly ilMailMimeSenderFactory ilAccountMail::$sender_factory
private

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

◆ $settings

readonly ilSetting ilAccountMail::$settings
private

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

◆ $u_password

string ilAccountMail::$u_password = ''

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

Referenced by getUserPassword().

◆ $user

ilObjUser ilAccountMail::$user = null

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

Referenced by getUser().


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