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

Public Member Functions

 __construct ()
 
 useLangVariablesAsFallback (bool $a_status)
 
 areLangVariablesUsedAsFallback ()
 
 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, NewAccountMail $a_amail, string $a_lang)
 

Data Fields

string $u_password = ''
 
ilObjUser $user = null
 

Private Member Functions

 readAccountMail (string $a_lang)
 

Private Attributes

readonly ilSetting $settings
 
readonly ilTree $repository_tree
 
readonly ilMailMimeSenderFactory $sender_factory
 
bool $lang_variables_as_fallback = false
 
readonly ResourceStorage $irss
 
readonly NewAccountMailRepository $account_mail_repo
 
array $amail = []
 
string $permanent_link_target = null
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilAccountMail::__construct ( )

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

41 {
42 global $DIC;
43 $this->settings = $DIC->settings();
44 $this->repository_tree = $DIC->repositoryTree();
45 $this->sender_factory = $DIC->mail()->mime()->senderFactory();
46 $this->irss = $DIC->resourceStorage();
47 $this->account_mail_repo = new NewAccountMailRepository($DIC->database());
48 }
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ areLangVariablesUsedAsFallback()

ilAccountMail::areLangVariablesUsedAsFallback ( )

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

55 : bool
56 {
58 }

References $lang_variables_as_fallback.

◆ getUser()

ilAccountMail::getUser ( )

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

86 : ?ilObjUser
87 {
88 return $this->user;
89 }
User class.

References $user.

Referenced by send().

+ Here is the caller graph for this function:

◆ getUserPassword()

ilAccountMail::getUserPassword ( )

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

65 : string
66 {
67 return $this->u_password;
68 }

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 101 of file class.ilAccountMail.php.

101 : NewAccountMail
102 {
103 if (!isset($this->amail[$a_lang]) || !($this->amail[$a_lang] instanceof NewAccountMail)) {
104 $this->amail[$a_lang] = $this->account_mail_repo->getFor($a_lang);
105 }
106
107 return $this->amail[$a_lang];
108 }

Referenced by send().

+ Here is the caller graph for this function:

◆ replacePlaceholders()

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

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

188 : string
189 {
190 global $DIC;
191 $settings = $DIC->settings();
192 $mustache_factory = $DIC->mail()->mustacheFactory();
193
194 $replacements = [];
195
196 // determine salutation
197 $replacements['MAIL_SALUTATION'] = $mustache_factory->getBasicEngine()->render(
198 match ($a_user->getGender()) {
199 'f' => trim($a_amail->getSalutationFemale()),
200 'm' => trim($a_amail->getSalutationMale()),
201 default => trim($a_amail->getSalutationNoneSpecific()),
202 },
203 [
204 'FIRST_NAME' => $a_user->getFirstname(),
205 'LAST_NAME' => $a_user->getLastname(),
206 'LOGIN' => $a_user->getLogin(),
207 ]
208 );
209 $replacements['LOGIN'] = $a_user->getLogin();
210 $replacements['FIRST_NAME'] = $a_user->getFirstname();
211 $replacements['LAST_NAME'] = $a_user->getLastname();
212 // BEGIN Mail Include E-Mail Address in account mail
213 $replacements['EMAIL'] = $a_user->getEmail();
214 // END Mail Include E-Mail Address in account mail
215 $replacements['PASSWORD'] = $this->getUserPassword();
216 $replacements['ILIAS_URL'] = ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID;
217 $replacements['CLIENT_NAME'] = CLIENT_NAME;
218 $replacements['ADMIN_MAIL'] = $settings->get('admin_email');
219 $replacements['IF_PASSWORD'] = $this->getUserPassword() !== '';
220 $replacements['IF_NO_PASSWORD'] = $this->getUserPassword() === '';
221
222 // #13346
223 if (!$a_user->getTimeLimitUnlimited()) {
224 // #6098
225 $replacements['IF_TIMELIMIT'] = !$a_user->getTimeLimitUnlimited();
226 $timelimit_from = new ilDateTime($a_user->getTimeLimitFrom(), IL_CAL_UNIX);
227 $timelimit_until = new ilDateTime($a_user->getTimeLimitUntil(), IL_CAL_UNIX);
228 $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
229 $replacements['TIMELIMIT'] = $timelimit;
230 }
231
232 // target
233 $replacements['IF_TARGET'] = false;
234 if ($this->permanent_link_target !== null) {
235 $tarr = explode('_', $this->permanent_link_target);
236 if ($this->repository_tree->isInTree((int) $tarr[1])) {
237 $obj_id = ilObject::_lookupObjId((int) $tarr[1]);
238 $type = ilObject::_lookupType($obj_id);
239 if ($type === $tarr[0]) {
240 $replacements['TARGET_TITLE'] = ilObject::_lookupTitle($obj_id);
241 $replacements['TARGET'] = ILIAS_HTTP_PATH . '/goto.php?client_id=' . CLIENT_ID . '&target=' . $this->permanent_link_target;
242
243 // this looks complicated, but we may have no initilised $lng object here
244 // if mail is send during user creation in authentication
245 $replacements['TARGET_TYPE'] = ilLanguage::_lookupEntry($a_lang, 'common', 'obj_' . $tarr[0]);
246 $replacements['IF_TARGET'] = true;
247 }
248 }
249 }
250
251 return $mustache_factory->getBasicEngine()->render($a_string, $replacements);
252 }
const IL_CAL_UNIX
readonly ilSetting $settings
static formatPeriod(ilDateTime $start, ilDateTime $end, bool $a_skip_starting_day=false, ?ilObjUser $user=null)
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)
get(string $a_keyword, ?string $a_default_value=null)
get setting
const CLIENT_ID
Definition: constants.php:41
const CLIENT_NAME
Definition: constants.php:42

References $DIC, $permanent_link_target, $settings, ilLanguage\_lookupEntry(), ilObject\_lookupObjId(), ilObject\_lookupTitle(), ilObject\_lookupType(), CLIENT_ID, CLIENT_NAME, ilDatePresentation\formatPeriod(), ilSetting\get(), ilObjUser\getEmail(), ilObjUser\getFirstname(), ilObjUser\getGender(), ilObjUser\getLastname(), ilObjUser\getLogin(), ilObjUser\getTimeLimitFrom(), ilObjUser\getTimeLimitUnlimited(), ilObjUser\getTimeLimitUntil(), getUserPassword(), and IL_CAL_UNIX.

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 91 of file class.ilAccountMail.php.

91 : void
92 {
93 $this->user = null;
94 $this->u_password = '';
95 $this->permanent_link_target = null;
96 }

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.

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

116 : bool
117 {
118 $user = $this->getUser();
119 if (!$user instanceof ilObjUser) {
120 throw new RuntimeException('A user instance must be passed when sending emails');
121 }
122
123 if ($user->getEmail() === '') {
124 return false;
125 }
126
127 // determine language and get account mail data
128 // fall back to default language if acccount mail data is not given for user language.
131 if ($amail->getBody() === '' || $amail->getSubject() === '') {
132 $fallback_language = 'en';
133 $amail = $this->readAccountMail($this->settings->get('language', $fallback_language));
134 $lang = $this->settings->get('language', $fallback_language);
135 }
136
137 $mmail = new ilMimeMail();
138
139 // fallback if mail data is still not given
140 if (($amail->getBody() === '' || $amail->getSubject() === '') && $this->areLangVariablesUsedAsFallback()) {
142 $tmp_lang = new ilLanguage($lang);
143
144 $mail_subject = $tmp_lang->txt('reg_mail_subject');
145
146 $timelimit = '';
147 if (!$user->checkTimeLimit()) {
148 $tmp_lang->loadLanguageModule('registration');
149
150 // #6098
151 $timelimit_from = new ilDateTime($user->getTimeLimitFrom(), IL_CAL_UNIX);
152 $timelimit_until = new ilDateTime($user->getTimeLimitUntil(), IL_CAL_UNIX);
153 $timelimit = ilDatePresentation::formatPeriod($timelimit_from, $timelimit_until);
154 $timelimit = "\n" . sprintf($tmp_lang->txt('reg_mail_body_timelimit'), $timelimit) . "\n\n";
155 }
156
157 // mail body
158 $mail_body = $tmp_lang->txt('reg_mail_body_salutation') . ' ' . $user->getFullname() . ",\n\n" .
159 $tmp_lang->txt('reg_mail_body_text1') . "\n\n" .
160 $tmp_lang->txt('reg_mail_body_text2') . "\n" .
161 ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID . "\n";
162 $mail_body .= $tmp_lang->txt('login') . ': ' . $user->getLogin() . "\n";
163 $mail_body .= $tmp_lang->txt('passwd') . ': ' . $this->u_password . "\n";
164 $mail_body .= "\n" . $timelimit;
165 $mail_body .= $tmp_lang->txt('reg_mail_body_text3') . "\n\r";
166 $mail_body .= $user->getProfileAsString($tmp_lang);
167 } else {
168 $attachment = $amail->getAttachment($this->irss);
169 if ($attachment !== null) {
170 $mmail->Attach($attachment[0], '', 'attachment', $attachment[1]);
171 }
172
173 // replace placeholders
174 $mail_subject = $this->replacePlaceholders($amail->getSubject(), $user, $amail, $lang);
175 $mail_body = $this->replacePlaceholders($amail->getBody(), $user, $amail, $lang);
176 }
177
178 $mmail->From($this->sender_factory->system());
179 $mmail->Subject($mail_subject, true);
180 $mmail->To($user->getEmail());
181 $mmail->Body($mail_body);
182
183 $mmail->Send();
184
185 return true;
186 }
readAccountMail(string $a_lang)
replacePlaceholders(string $a_string, ilObjUser $a_user, NewAccountMail $a_amail, string $a_lang)
language handling
getProfileAsString(Language $language)
Get formatted mail body text of user profile data.
getFullname(int $max_strlen=0)
$lang
Definition: xapiexit.php:25

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

+ Here is the call graph for this function:

◆ setPermanentLinkTarget()

ilAccountMail::setPermanentLinkTarget ( ?string  $permanent_link_target)

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

75 : void
76 {
77 if ($permanent_link_target === '') {
78 throw new InvalidArgumentException(
79 'Permanent link target must not be empty'
80 );
81 }
82
83 $this->permanent_link_target = $permanent_link_target;
84 }

References $permanent_link_target.

◆ setUser()

ilAccountMail::setUser ( ilObjUser  $a_user)

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

70 : void
71 {
72 $this->user = $a_user;
73 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ setUserPassword()

ilAccountMail::setUserPassword ( string  $a_pwd)

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

60 : void
61 {
62 $this->u_password = $a_pwd;
63 }

◆ useLangVariablesAsFallback()

ilAccountMail::useLangVariablesAsFallback ( bool  $a_status)

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

50 : void
51 {
52 $this->lang_variables_as_fallback = $a_status;
53 }

Field Documentation

◆ $account_mail_repo

readonly NewAccountMailRepository ilAccountMail::$account_mail_repo
private

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

◆ $amail

array ilAccountMail::$amail = []
private

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

Referenced by send().

◆ $irss

readonly ResourceStorage ilAccountMail::$irss
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 34 of file class.ilAccountMail.php.

Referenced by areLangVariablesUsedAsFallback().

◆ $permanent_link_target

string ilAccountMail::$permanent_link_target = null
private

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

Referenced by replacePlaceholders(), and setPermanentLinkTarget().

◆ $repository_tree

readonly ilTree ilAccountMail::$repository_tree
private

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

◆ $sender_factory

readonly ilMailMimeSenderFactory ilAccountMail::$sender_factory
private

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

◆ $settings

readonly ilSetting ilAccountMail::$settings
private

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

Referenced by replacePlaceholders().

◆ $u_password

string ilAccountMail::$u_password = ''

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

Referenced by getUserPassword().

◆ $user

ilObjUser ilAccountMail::$user = null

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

Referenced by getUser(), and send().


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