ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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 28 of file class.ilAccountMail.php.

Constructor & Destructor Documentation

◆ __construct()

ilAccountMail::__construct ( )

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

44 {
45 global $DIC;
46 $this->http = $DIC->http();
47 $this->refinery = $DIC->refinery();
48 $this->settings = $DIC->settings();
49 $this->repository_tree = $DIC->repositoryTree();
50 $this->sender_factory = $DIC->mail()->mime()->senderFactory();
51 $this->irss = $DIC->resourceStorage();
52 $this->account_mail_repo = new NewAccountMailRepository($DIC->database());
53 }
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 60 of file class.ilAccountMail.php.

60 : bool
61 {
63 }

References $lang_variables_as_fallback.

◆ getUser()

ilAccountMail::getUser ( )

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

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

References $user.

Referenced by send().

+ Here is the caller graph for this function:

◆ getUserPassword()

ilAccountMail::getUserPassword ( )

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

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

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

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

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

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

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

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

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

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

References $permanent_link_target.

◆ setUser()

ilAccountMail::setUser ( ilObjUser  $a_user)

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

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

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ setUserPassword()

ilAccountMail::setUserPassword ( string  $a_pwd)

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

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

◆ useLangVariablesAsFallback()

ilAccountMail::useLangVariablesAsFallback ( bool  $a_status)

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

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

Field Documentation

◆ $account_mail_repo

readonly NewAccountMailRepository ilAccountMail::$account_mail_repo
private

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

◆ $amail

array ilAccountMail::$amail = []
private

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

Referenced by send().

◆ $http

readonly GlobalHttpState ilAccountMail::$http
private

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

◆ $irss

readonly ResourceStorage ilAccountMail::$irss
private

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

◆ $lang_variables_as_fallback

bool ilAccountMail::$lang_variables_as_fallback = false
private

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

Referenced by areLangVariablesUsedAsFallback().

◆ $permanent_link_target

string ilAccountMail::$permanent_link_target = null
private

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

Referenced by replacePlaceholders(), and setPermanentLinkTarget().

◆ $refinery

readonly Refinery ilAccountMail::$refinery
private

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

◆ $repository_tree

readonly ilTree ilAccountMail::$repository_tree
private

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

◆ $sender_factory

readonly ilMailMimeSenderFactory ilAccountMail::$sender_factory
private

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

◆ $settings

readonly ilSetting ilAccountMail::$settings
private

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

Referenced by replacePlaceholders().

◆ $u_password

string ilAccountMail::$u_password = ''

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

Referenced by getUserPassword().

◆ $user

ilObjUser ilAccountMail::$user = null

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

Referenced by getUser(), and send().


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