19declare(strict_types=1);
37 private readonly ResourceStorage
$irss;
45 $this->
http = $DIC->http();
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());
56 $this->lang_variables_as_fallback = $a_status;
66 $this->u_password = $a_pwd;
76 $this->
user = $a_user;
82 throw new InvalidArgumentException(
83 'Permanent link target must not be empty'
98 $this->u_password =
'';
99 $this->permanent_link_target =
null;
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);
111 return $this->amail[$a_lang];
124 throw new RuntimeException(
'A user instance must be passed when sending emails');
135 if (
$amail->getBody() ===
'' ||
$amail->getSubject() ===
'') {
136 $fallback_language =
'en';
138 $lang = $this->
settings->get(
'language', $fallback_language);
144 if ((
$amail->getBody() ===
'' ||
$amail->getSubject() ===
'') && $this->areLangVariablesUsedAsFallback()) {
148 $mail_subject = $tmp_lang->txt(
'reg_mail_subject');
152 $tmp_lang->loadLanguageModule(
'registration');
158 $timelimit =
"\n" . sprintf($tmp_lang->txt(
'reg_mail_body_timelimit'), $timelimit) .
"\n\n";
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";
172 $attachment =
$amail->getAttachment($this->irss);
173 if ($attachment !==
null) {
174 $mmail->Attach($attachment[0],
'',
'attachment', $attachment[1]);
182 $mmail->From($this->sender_factory->system());
183 $mmail->Subject($mail_subject,
true);
185 $mmail->Body($mail_body);
196 $mustache_factory =
$DIC->mail()->mustacheFactory();
201 $replacements[
'MAIL_SALUTATION'] = $mustache_factory->getBasicEngine()->render(
203 'f' => trim($a_amail->getSalutationFemale()),
204 'm' => trim($a_amail->getSalutationMale()),
205 default => trim($a_amail->getSalutationNoneSpecific()),
213 $replacements[
'LOGIN'] = $a_user->
getLogin();
215 $replacements[
'LAST_NAME'] = $a_user->
getLastname();
217 $replacements[
'EMAIL'] = $a_user->
getEmail();
220 $replacements[
'ILIAS_URL'] = ILIAS_HTTP_PATH .
'/login.php?client_id=' .
CLIENT_ID;
222 $replacements[
'ADMIN_MAIL'] = $this->
settings->get(
'admin_email');
233 $replacements[
'TIMELIMIT'] = $timelimit;
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])) {
243 if ($type === $tarr[0]) {
250 $replacements[
'IF_TARGET'] =
true;
255 return $mustache_factory->getBasicEngine()->render($a_string, $replacements);
areLangVariablesUsedAsFallback()
useLangVariablesAsFallback(bool $a_status)
readAccountMail(string $a_lang)
readonly ilTree $repository_tree
send()
Sends the mail with its object properties as MimeMail It first tries to read the mail body,...
readonly ilSetting $settings
readonly ResourceStorage $irss
setUser(ilObjUser $a_user)
readonly ilMailMimeSenderFactory $sender_factory
string $permanent_link_target
setPermanentLinkTarget(?string $permanent_link_target)
setUserPassword(string $a_pwd)
bool $lang_variables_as_fallback
readonly NewAccountMailRepository $account_mail_repo
replacePlaceholders(string $a_string, ilObjUser $a_user, NewAccountMail $a_amail, string $a_lang)
readonly Refinery $refinery
readonly GlobalHttpState $http
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)
getProfileAsString(Language $language)
Get formatted mail body text of user profile data.
getFullname(int $max_strlen=0)
static _lookupType(int $id, bool $reference=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Interface GlobalHttpState.
static http()
Fetches the global http state from ILIAS.