ILIAS  release_8 Revision v8.24
class.ilMailTemplateContext.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
30{
36
37 public function __construct(
40 ilMailUserHelper $usernameHelper = null,
42 ) {
43 $this->orgUnitUserService = $orgUnitUserService ?? new OrgUnitUserService();
44 $this->envHelper = $envHelper ?? new ilMailEnvironmentHelper();
45 $this->userHelper = $usernameHelper ?? new ilMailUserHelper();
46 $this->languageHelper = $languageHelper ?? new ilMailLanguageHelper();
47 }
48
49 public function getLanguage(): ilLanguage
50 {
51 return $this->language ?? $this->languageHelper->getCurrentLanguage();
52 }
53
54 abstract public function getId(): string;
55
56 abstract public function getTitle(): string;
57
58 abstract public function getDescription(): string;
59
60 private function getGenericPlaceholders(): array
61 {
62 return [
63 'mail_salutation' => [
64 'placeholder' => 'MAIL_SALUTATION',
65 'label' => $this->getLanguage()->txt('mail_nacc_salutation'),
66 ],
67 'first_name' => [
68 'placeholder' => 'FIRST_NAME',
69 'label' => $this->getLanguage()->txt('firstname'),
70 ],
71 'last_name' => [
72 'placeholder' => 'LAST_NAME',
73 'label' => $this->getLanguage()->txt('lastname'),
74 ],
75 'login' => [
76 'placeholder' => 'LOGIN',
77 'label' => $this->getLanguage()->txt('mail_nacc_login'),
78 ],
79 'title' => [
80 'placeholder' => 'TITLE',
81 'label' => $this->getLanguage()->txt('mail_nacc_title'),
82 'supportsCondition' => true,
83 ],
84 'firstname_last_name_superior' => [
85 'placeholder' => 'FIRSTNAME_LASTNAME_SUPERIOR',
86 'label' => $this->getLanguage()->txt('mail_firstname_last_name_superior'),
87 ],
88 'ilias_url' => [
89 'placeholder' => 'ILIAS_URL',
90 'label' => $this->getLanguage()->txt('mail_nacc_ilias_url'),
91 ],
92 'installation_name' => [
93 'placeholder' => 'INSTALLATION_NAME',
94 'label' => $this->getLanguage()->txt('mail_nacc_installation_name'),
95 ],
96 ];
97 }
98
99 final public function getPlaceholders(): array
100 {
101 $placeholders = $this->getGenericPlaceholders();
102 $specific = $this->getSpecificPlaceholders();
103
104 return array_merge($placeholders, $specific);
105 }
106
107 abstract public function getSpecificPlaceholders(): array;
108
109 abstract public function resolveSpecificPlaceholder(
110 string $placeholder_id,
111 array $context_parameters,
112 ilObjUser $recipient = null,
113 bool $html_markup = false
114 ): string;
115
116 public function resolvePlaceholder(
117 string $placeholder_id,
118 array $context_parameters,
119 ilObjUser $recipient = null,
120 bool $html_markup = false
121 ): string {
122 if ($recipient !== null) {
123 $this->initLanguage($recipient);
124 }
125
126 $resolved = '';
127
128 switch (true) {
129 case ('mail_salutation' === $placeholder_id && $recipient !== null):
130 $resolved = $this->getLanguage()->txt('mail_salutation_n');
131 switch ($recipient->getGender()) {
132 case 'f':
133 $resolved = $this->getLanguage()->txt('mail_salutation_f');
134 break;
135
136 case 'm':
137 $resolved = $this->getLanguage()->txt('mail_salutation_m');
138 break;
139
140 case 'n':
141 $resolved = $this->getLanguage()->txt('mail_salutation_n');
142 break;
143 }
144 break;
145
146 case ('first_name' === $placeholder_id && $recipient !== null):
147 $resolved = $recipient->getFirstname();
148 break;
149
150 case ('last_name' === $placeholder_id && $recipient !== null):
151 $resolved = $recipient->getLastname();
152 break;
153
154 case ('login' === $placeholder_id && $recipient !== null):
155 $resolved = $recipient->getLogin();
156 break;
157
158 case ('title' === $placeholder_id && $recipient !== null):
159 $resolved = $recipient->getUTitle();
160 break;
161
162 case 'ilias_url' === $placeholder_id:
163 $resolved = $this->envHelper->getHttpPath() . ' ';
164 break;
165
166 case 'installation_name' === $placeholder_id:
167 $resolved = $this->envHelper->getClientId();
168 break;
169
170 case 'firstname_last_name_superior' === $placeholder_id && $recipient !== null:
171 $ouUsers = $this->orgUnitUserService->getUsers([$recipient->getId()], true);
172 foreach ($ouUsers as $ouUser) {
173 $superiors = $ouUser->getSuperiors();
174
175 $superiorUsrIds = array_map(static function (ilOrgUnitUser $ouUser): int {
176 return $ouUser->getUserId();
177 }, $superiors);
178
179 $usrIdByNameMap = $this->userHelper->getUsernameMapForIds($superiorUsrIds);
180
181 $resolved = implode(', ', $usrIdByNameMap);
182 break;
183 }
184 break;
185
186 case !array_key_exists($placeholder_id, $this->getGenericPlaceholders()):
187 $datePresentationLanguage = ilDatePresentation::getLanguage();
189
190 $resolved = $this->resolveSpecificPlaceholder(
191 $placeholder_id,
192 $context_parameters,
193 $recipient,
194 $html_markup
195 );
196
197 ilDatePresentation::setLanguage($datePresentationLanguage);
198 break;
199 }
200
201 return $resolved;
202 }
203
204 protected function initLanguage(ilObjUser $user): void
205 {
206 $this->initLanguageByIso2Code($user->getLanguage());
207 }
208
209 protected function initLanguageByIso2Code(string $isoCode): void
210 {
211 $this->language = $this->languageHelper->getLanguageByIsoCode($isoCode);
212 $this->language->loadLanguageModule('mail');
213 }
214}
Class for date presentation.
static setLanguage(ilLanguage $a_lng)
language handling
Class ilMailEnvironmentHelper.
Class ilMailLanguageHelper.
Class ilMailTemplateContext.
resolvePlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
ilMailLanguageHelper $languageHelper
OrgUnitUserService $orgUnitUserService
ilMailEnvironmentHelper $envHelper
__construct(OrgUnitUserService $orgUnitUserService=null, ilMailEnvironmentHelper $envHelper=null, ilMailUserHelper $usernameHelper=null, ilMailLanguageHelper $languageHelper=null)
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ilObjUser $recipient=null, bool $html_markup=false)
Class ilMailUserHelper.
User class.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20