ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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 GlobalHttpState $http
 
readonly ilSetting $settings
 
readonly Refinery $refinery
 
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 42 of file class.ilAccountMail.php.

43 {
44 global $DIC;
45 $this->http = $DIC->http();
46 $this->refinery = $DIC->refinery();
47 $this->settings = $DIC->settings();
48 $this->repository_tree = $DIC->repositoryTree();
49 $this->sender_factory = $DIC->mail()->mime()->senderFactory();
50 $this->irss = $DIC->resourceStorage();
51 $this->account_mail_repo = new NewAccountMailRepository($DIC->database());
52 }
static http()
Fetches the global http state from ILIAS.
global $DIC
Definition: shib_login.php:26

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

+ Here is the call graph for this function:

Member Function Documentation

◆ areLangVariablesUsedAsFallback()

ilAccountMail::areLangVariablesUsedAsFallback ( )

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

59 : bool
60 {
62 }

References $lang_variables_as_fallback.

◆ getUser()

ilAccountMail::getUser ( )

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

90 : ?ilObjUser
91 {
92 return $this->user;
93 }
User class.

References $user.

Referenced by send().

+ Here is the caller graph for this function:

◆ getUserPassword()

ilAccountMail::getUserPassword ( )

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

69 : string
70 {
71 return $this->u_password;
72 }

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

105 : NewAccountMail
106 {
107 if (!isset($this->amail[$a_lang]) || !($this->amail[$a_lang] instanceof NewAccountMail)) {
108 $this->amail[$a_lang] = $this->account_mail_repo->getFor($a_lang);
109 }
110
111 return $this->amail[$a_lang];
112 }

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

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

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

95 : void
96 {
97 $this->user = null;
98 $this->u_password = '';
99 $this->permanent_link_target = null;
100 }

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

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

References $amail, $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 79 of file class.ilAccountMail.php.

79 : void
80 {
81 if ($permanent_link_target === '') {
82 throw new InvalidArgumentException(
83 'Permanent link target must not be empty'
84 );
85 }
86
87 $this->permanent_link_target = $permanent_link_target;
88 }

References $permanent_link_target.

◆ setUser()

ilAccountMail::setUser ( ilObjUser  $a_user)

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

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

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ setUserPassword()

ilAccountMail::setUserPassword ( string  $a_pwd)

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

64 : void
65 {
66 $this->u_password = $a_pwd;
67 }

◆ useLangVariablesAsFallback()

ilAccountMail::useLangVariablesAsFallback ( bool  $a_status)

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

54 : void
55 {
56 $this->lang_variables_as_fallback = $a_status;
57 }

Field Documentation

◆ $account_mail_repo

readonly NewAccountMailRepository ilAccountMail::$account_mail_repo
private

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

◆ $amail

array ilAccountMail::$amail = []
private

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

Referenced by send().

◆ $http

readonly GlobalHttpState ilAccountMail::$http
private

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

◆ $irss

readonly ResourceStorage ilAccountMail::$irss
private

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

◆ $lang_variables_as_fallback

bool ilAccountMail::$lang_variables_as_fallback = false
private

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

Referenced by areLangVariablesUsedAsFallback().

◆ $permanent_link_target

string ilAccountMail::$permanent_link_target = null
private

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

Referenced by replacePlaceholders(), and setPermanentLinkTarget().

◆ $refinery

readonly Refinery ilAccountMail::$refinery
private

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

◆ $repository_tree

readonly ilTree ilAccountMail::$repository_tree
private

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

◆ $sender_factory

readonly ilMailMimeSenderFactory ilAccountMail::$sender_factory
private

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

◆ $settings

readonly ilSetting ilAccountMail::$settings
private

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

Referenced by replacePlaceholders().

◆ $u_password

string ilAccountMail::$u_password = ''

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

Referenced by getUserPassword().

◆ $user

ilObjUser ilAccountMail::$user = null

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

Referenced by getUser(), and send().


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