ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMailTemplateContext.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2015 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once './Services/Language/classes/class.ilLanguageFactory.php';
5
12{
16 protected $language;
17
21 public function getLanguage()
22 {
26 global $lng;
27
28 return $this->language ? $this->language : $lng;
29 }
30
34 public function setLanguage($language)
35 {
36 $this->language = $language;
37 }
38
43 abstract public function getId();
44
49 abstract public function getTitle();
50
55 abstract public function getDescription();
56
57 final private static function getGenericPlaceholders()
58 {
62 global $lng;
63
64 return array(
65 'mail_salutation' => array(
66 'placeholder' => 'MAIL_SALUTATION',
67 'label' => $lng->txt('mail_nacc_salutation')
68 ),
69 'first_name' => array(
70 'placeholder' => 'FIRST_NAME',
71 'label' => $lng->txt('firstname')
72 ),
73 'last_name' => array(
74 'placeholder' => 'LAST_NAME',
75 'label' => $lng->txt('lastname')
76 ),
77 'login' => array(
78 'placeholder' => 'LOGIN',
79 'label' => $lng->txt('mail_nacc_login')
80 ),
81 'ilias_url' => array(
82 'placeholder' => 'ILIAS_URL',
83 'label' => $lng->txt('mail_nacc_ilias_url')
84 ),
85 'client_name' => array(
86 'placeholder' => 'CLIENT_NAME',
87 'label' => $lng->txt('mail_nacc_client_name')
88 )
89 );
90 }
91
96 final public function getPlaceholders()
97 {
98 $placeholders = self::getGenericPlaceholders();
99 $specific = $this->getSpecificPlaceholders();
100
101 return $placeholders + $specific;
102 }
103
108 abstract public function getSpecificPlaceholders();
109
117 abstract public function resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient = null, $html_markup = false);
118
126 public function resolvePlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient = null, $html_markup = false)
127 {
128 if($recipient !== null)
129 {
130 $this->initLanguage($recipient);
131 }
132
134 ilDatePresentation::setLanguage($this->getLanguage());
135
136 $resolved = '';
137
138 switch(true)
139 {
140 case ('mail_salutation' == $placeholder_id && $recipient !== null):
141 switch($recipient->getGender())
142 {
143 case 'f':
144 $resolved = $this->getLanguage()->txt('salutation_f');
145 break;
146
147 case 'm':
148 $resolved = $this->getLanguage()->txt('salutation_m');
149 break;
150
151 default:
152 $resolved = $this->getLanguage()->txt('salutation');
153 }
154 break;
155
156 case ('first_name' == $placeholder_id && $recipient !== null):
157 $resolved = $recipient->getFirstname();
158 break;
159
160 case ('last_name' == $placeholder_id && $recipient !== null):
161 $resolved = $recipient->getLastname();
162 break;
163
164 case ('login' == $placeholder_id && $recipient !== null):
165 $resolved = $recipient->getLogin();
166 break;
167
168 case 'ilias_url' == $placeholder_id:
169 $resolved = ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID;
170 break;
171
172 case 'client_name' == $placeholder_id:
173 $resolved = CLIENT_NAME;
174 break;
175
176 case !in_array($placeholder_id, array_keys(self::getGenericPlaceholders())):
177 $resolved = $this->resolveSpecificPlaceholder($placeholder_id, $context_parameters, $recipient, $html_markup);
178 break;
179 }
180
182
183 return $resolved;
184 }
185
189 protected function initLanguage(ilObjUser $user)
190 {
191 $this->initLanguageByIso2Code($user->getLanguage());
192 }
193
198 protected function initLanguageByIso2Code($a_code)
199 {
200 $this->language = ilLanguageFactory::_getLanguage($a_code);
201 $this->language->loadLanguageModule('mail');
202 }
203}
static getLanguage()
set language
static setLanguage($a_lng)
set language
static _getLanguage($a_lang_key='')
Get langauge object.
Class ilMailTemplateContext.
getSpecificPlaceholders()
Return an array of placeholders.
initLanguageByIso2Code($a_code)
Init language by ISO2 code.
getId()
Returns a unique (in the context of mail template contexts) id.
resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient=null, $html_markup=false)
getTitle()
Returns a translated title (depending on the current language) which is displayed in the user interfa...
resolvePlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient=null, $html_markup=false)
getPlaceholders()
Return an array of placeholders.
getDescription()
Returns a translated description (depending on the current language) which is displayed in the user i...
getLanguage()
returns a 2char-language-string @access public
global $lng
Definition: privfeed.php:40