ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
ilMailTemplateContext Class Reference
+ Inheritance diagram for ilMailTemplateContext:
+ Collaboration diagram for ilMailTemplateContext:

Public Member Functions

 __construct (?OrgUnitUserService $org_unit_user_service=null, ?ilMailEnvironmentHelper $environment_helper=null, ?ilMailUserHelper $user_helper=null, ?ilMailLanguageHelper $language_helper=null)
 
 getLanguage ()
 
 getId ()
 
 getTitle ()
 
 getDescription ()
 
 getNestedPlaceholders ()
 
 getPlaceholders ()
 
 getSpecificPlaceholders ()
 
 requiresRecipientByPlaceholderName (string $placeholder_name)
 
 resolveSpecificPlaceholder (string $placeholder_id, array $context_parameters, ?ilObjUser $recipient=null)
 
 resolvePlaceholder (string $placeholder_id, array $context_parameters, ?ilObjUser $recipient=null)
 

Protected Member Functions

 initLanguage (ilObjUser $user)
 
 initLanguageByIso2Code (string $iso_code)
 

Protected Attributes

ilLanguage $language
 
ilMailEnvironmentHelper $env_helper
 
ilMailLanguageHelper $language_helper
 
ilMailUserHelper $user_helper
 
OrgUnitUserService $org_unit_user_service
 

Private Member Functions

 getGenericPlaceholders ()
 
 findPlaceholderByMustacheName (string $placeholder_name)
 
 placeholderDefinitionRequiresRecipient (array $placeholder_definition)
 

Detailed Description

Definition at line 24 of file class.ilMailTemplateContext.php.

Constructor & Destructor Documentation

◆ __construct()

ilMailTemplateContext::__construct ( ?OrgUnitUserService  $org_unit_user_service = null,
?ilMailEnvironmentHelper  $environment_helper = null,
?ilMailUserHelper  $user_helper = null,
?ilMailLanguageHelper  $language_helper = null 
)

Member Function Documentation

◆ findPlaceholderByMustacheName()

ilMailTemplateContext::findPlaceholderByMustacheName ( string  $placeholder_name)
private
Returns
array{key: string, definition: array{ placeholder: string, label: string, requiresRecipient?: bool, supportsNestedPlaceholders?: bool }}|null

Definition at line 173 of file class.ilMailTemplateContext.php.

173 : ?array
174 {
175 foreach ($this->getPlaceholders() as $key => $placeholder_definition) {
176 if (strtoupper($placeholder_definition['placeholder']) !== strtoupper($placeholder_name)) {
177 continue;
178 }
179
180 return [
181 'key' => (string) $key,
182 'definition' => $placeholder_definition,
183 ];
184 }
185
186 return null;
187 }

References getPlaceholders().

Referenced by requiresRecipientByPlaceholderName().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getDescription()

◆ getGenericPlaceholders()

ilMailTemplateContext::getGenericPlaceholders ( )
private
Returns
array{ mail_salutation: array{placeholder: string, label: string, requiresRecipient: true, supportsNestedPlaceholders: true}, first_name: array{placeholder: string, label: string, requiresRecipient: true}, last_name: array{placeholder: string, label: string, requiresRecipient: true}, login: array{placeholder: string, label: string, requiresRecipient: true}, title: array{placeholder: string, label: string, requiresRecipient: true}, firstname_lastname_superior: array{placeholder: string, label: string, requiresRecipient: true}, ilias_url: array{placeholder: string, label: string}, installation_name: array{placeholder: string, label: string} }

Definition at line 67 of file class.ilMailTemplateContext.php.

67 : array
68 {
69 return [
70 'mail_salutation' => [
71 'placeholder' => 'MAIL_SALUTATION',
72 'label' => $this->getLanguage()->txt('mail_nacc_salutation'),
73 'requiresRecipient' => true,
74 'supportsNestedPlaceholders' => true,
75 ],
76 'first_name' => [
77 'placeholder' => 'FIRST_NAME',
78 'label' => $this->getLanguage()->txt('firstname'),
79 'requiresRecipient' => true,
80 ],
81 'last_name' => [
82 'placeholder' => 'LAST_NAME',
83 'label' => $this->getLanguage()->txt('lastname'),
84 'requiresRecipient' => true,
85 ],
86 'login' => [
87 'placeholder' => 'LOGIN',
88 'label' => $this->getLanguage()->txt('mail_nacc_login'),
89 'requiresRecipient' => true,
90 ],
91 'title' => [
92 'placeholder' => 'TITLE',
93 'label' => $this->getLanguage()->txt('mail_nacc_title'),
94 'requiresRecipient' => true,
95 ],
96 'firstname_lastname_superior' => [
97 'placeholder' => 'FIRSTNAME_LASTNAME_SUPERIOR',
98 'label' => $this->getLanguage()->txt('mail_firstname_last_name_superior'),
99 'requiresRecipient' => true,
100 ],
101 'ilias_url' => [
102 'placeholder' => 'ILIAS_URL',
103 'label' => $this->getLanguage()->txt('mail_nacc_ilias_url'),
104 'requiresRecipient' => false,
105 ],
106 'installation_name' => [
107 'placeholder' => 'INSTALLATION_NAME',
108 'label' => $this->getLanguage()->txt('mail_nacc_installation_name'),
109 'requiresRecipient' => false,
110 ],
111 ];
112 }

References getLanguage().

Referenced by getPlaceholders().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getId()

◆ getLanguage()

ilMailTemplateContext::getLanguage ( )

Definition at line 44 of file class.ilMailTemplateContext.php.

45 {
46 return $this->language ?? $this->language_helper->getCurrentLanguage();
47 }
language handling

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

Referenced by ilMailTemplateGenericContext\getDescription(), getGenericPlaceholders(), and ilMailTemplateGenericContext\getTitle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getNestedPlaceholders()

ilMailTemplateContext::getNestedPlaceholders ( )
Returns
list<string>

Definition at line 117 of file class.ilMailTemplateContext.php.

117 : array
118 {
119 $nested_placeholders = [];
120 foreach ($this->getPlaceholders() as $key => $ph) {
121 if (isset($ph['supportsNestedPlaceholders']) && $ph['supportsNestedPlaceholders']) {
122 $nested_placeholders[] = $ph['placeholder'];
123 }
124 }
125
126 return $nested_placeholders;
127 }

References getPlaceholders().

+ Here is the call graph for this function:

◆ getPlaceholders()

ilMailTemplateContext::getPlaceholders ( )
final
Returns
array<string, array{ placeholder: string, label: string, requiresRecipient?: bool, supportsNestedPlaceholders?: bool }>

Definition at line 137 of file class.ilMailTemplateContext.php.

137 : array
138 {
139 $placeholders = $this->getGenericPlaceholders();
140 $specific = $this->getSpecificPlaceholders();
141
142 return array_merge($placeholders, $specific);
143 }

References getGenericPlaceholders(), and getSpecificPlaceholders().

Referenced by findPlaceholderByMustacheName(), and getNestedPlaceholders().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getSpecificPlaceholders()

ilMailTemplateContext::getSpecificPlaceholders ( )
abstract
Returns
array<string, array{ placeholder: string, label: string, requiresRecipient?: bool, supportsNestedPlaceholders?: bool }>

Reimplemented in ilExcMailTemplateGradeReminderContext, ilExcMailTemplatePeerReminderContext, ilExcMailTemplateSubmitReminderContext, ilMailTemplateGenericContext, ilSessionMailTemplateParticipantContext, ilStudyProgrammeMailTemplateContext, and ilSurveyMailTemplateRaterInvitationContext.

Referenced by getPlaceholders().

+ Here is the caller graph for this function:

◆ getTitle()

◆ initLanguage()

ilMailTemplateContext::initLanguage ( ilObjUser  $user)
protected

Definition at line 298 of file class.ilMailTemplateContext.php.

298 : void
299 {
300 $this->initLanguageByIso2Code($user->getLanguage());
301 }

References ilObjUser\getLanguage().

Referenced by resolvePlaceholder().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initLanguageByIso2Code()

ilMailTemplateContext::initLanguageByIso2Code ( string  $iso_code)
protected

Definition at line 303 of file class.ilMailTemplateContext.php.

303 : void
304 {
305 $this->language = $this->language_helper->getLanguageByIsoCode($iso_code);
306 $this->language->loadLanguageModule('mail');
307 }

References ILIAS\UI\examples\Symbol\Glyph\Language\language().

+ Here is the call graph for this function:

◆ placeholderDefinitionRequiresRecipient()

ilMailTemplateContext::placeholderDefinitionRequiresRecipient ( array  $placeholder_definition)
private
Parameters
array{placeholder: string, label: string, requiresRecipient?: bool, supportsNestedPlaceholders?: bool } $placeholder_definition

Definition at line 197 of file class.ilMailTemplateContext.php.

197 : bool
198 {
199 return $placeholder_definition['requiresRecipient'] ?? false;
200 }

Referenced by requiresRecipientByPlaceholderName().

+ Here is the caller graph for this function:

◆ requiresRecipientByPlaceholderName()

ilMailTemplateContext::requiresRecipientByPlaceholderName ( string  $placeholder_name)

Definition at line 155 of file class.ilMailTemplateContext.php.

155 : bool
156 {
157 $found = $this->findPlaceholderByMustacheName($placeholder_name);
158 if ($found === null) {
159 return false;
160 }
161
162 return $this->placeholderDefinitionRequiresRecipient($found['definition']);
163 }
placeholderDefinitionRequiresRecipient(array $placeholder_definition)
findPlaceholderByMustacheName(string $placeholder_name)

References findPlaceholderByMustacheName(), and placeholderDefinitionRequiresRecipient().

+ Here is the call graph for this function:

◆ resolvePlaceholder()

ilMailTemplateContext::resolvePlaceholder ( string  $placeholder_id,
array  $context_parameters,
?ilObjUser  $recipient = null 
)
Parameters
array<string,mixed>$context_parameters

Definition at line 214 of file class.ilMailTemplateContext.php.

218 : string {
219 if ($recipient !== null) {
220 $this->initLanguage($recipient);
221 }
222
223 $placeholder_id = strtolower($placeholder_id);
224 $resolved = '';
225 switch (true) {
226 case ($placeholder_id === 'mail_salutation' && $recipient !== null):
227 $resolved = $this->getLanguage()->txt('mail_salutation_n');
228 switch ($recipient->getGender()) {
229 case 'f':
230 $resolved = $this->getLanguage()->txt('mail_salutation_f');
231 break;
232
233 case 'm':
234 $resolved = $this->getLanguage()->txt('mail_salutation_m');
235 break;
236
237 case 'n':
238 $resolved = $this->getLanguage()->txt('mail_salutation_n');
239 break;
240 }
241 break;
242
243 case ($placeholder_id === 'first_name' && $recipient !== null):
244 $resolved = $recipient->getFirstname();
245 break;
246
247 case ($placeholder_id === 'last_name' && $recipient !== null):
248 $resolved = $recipient->getLastname();
249 break;
250
251 case ($placeholder_id === 'login' && $recipient !== null):
252 $resolved = $recipient->getLogin();
253 break;
254
255 case ($placeholder_id === 'title' && $recipient !== null):
256 $resolved = $recipient->getUTitle();
257 break;
258
259 case $placeholder_id === 'ilias_url':
260 $resolved = $this->env_helper->getHttpPath() . ' ';
261 break;
262
263 case $placeholder_id === 'installation_name':
264 $resolved = $this->env_helper->getClientId();
265 break;
266
267 case $placeholder_id === 'firstname_lastname_superior' && $recipient !== null:
268 $ou_users = $this->org_unit_user_service->getUsers([$recipient->getId()], true);
269 foreach ($ou_users as $ou_user) {
270 $superiors = $ou_user->getSuperiors();
271
272 $superior_usr_ids = array_map(static fn(ilOrgUnitUser $ou_user): int => $ou_user->getUserId(), $superiors);
273
274 $usr_id_by_name_map = $this->user_helper->getUsernameMapForIds($superior_usr_ids);
275
276 $resolved = implode(', ', $usr_id_by_name_map);
277 break;
278 }
279 break;
280
281 case !array_key_exists($placeholder_id, $this->getGenericPlaceholders()):
282 $date_presentation_language = ilDatePresentation::getLanguage();
284
285 $resolved = $this->resolveSpecificPlaceholder(
286 $placeholder_id,
287 $context_parameters,
288 $recipient
289 );
290
291 ilDatePresentation::setLanguage($date_presentation_language);
292 break;
293 }
294
295 return $resolved;
296 }
Class for date presentation.
static setLanguage(ilLanguage $a_lng)
resolveSpecificPlaceholder(string $placeholder_id, array $context_parameters, ?ilObjUser $recipient=null)

References initLanguage().

+ Here is the call graph for this function:

◆ resolveSpecificPlaceholder()

ilMailTemplateContext::resolveSpecificPlaceholder ( string  $placeholder_id,
array  $context_parameters,
?ilObjUser  $recipient = null 
)
abstract

Field Documentation

◆ $env_helper

ilMailEnvironmentHelper ilMailTemplateContext::$env_helper
protected

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

◆ $language

ilLanguage ilMailTemplateContext::$language
protected

Definition at line 26 of file class.ilMailTemplateContext.php.

◆ $language_helper

ilMailLanguageHelper ilMailTemplateContext::$language_helper
protected

Definition at line 28 of file class.ilMailTemplateContext.php.

Referenced by __construct().

◆ $org_unit_user_service

OrgUnitUserService ilMailTemplateContext::$org_unit_user_service
protected

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

Referenced by __construct().

◆ $user_helper

ilMailUserHelper ilMailTemplateContext::$user_helper
protected

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

Referenced by __construct().


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