ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
4 require_once './Services/Language/classes/class.ilLanguageFactory.php';
5 
11 abstract class ilMailTemplateContext
12 {
16  protected $language;
17 
21  public function getLanguage()
22  {
23  global $DIC;
24 
25  return $this->language ? $this->language : $DIC->language();
26  }
27 
31  public function setLanguage($language)
32  {
33  $this->language = $language;
34  }
35 
40  abstract public function getId();
41 
46  abstract public function getTitle();
47 
52  abstract public function getDescription();
53 
57  final private static function getGenericPlaceholders()
58  {
59  global $DIC;
60 
61  return array(
62  'mail_salutation' => array(
63  'placeholder' => 'MAIL_SALUTATION',
64  'label' => $DIC->language()->txt('mail_nacc_salutation')
65  ),
66  'first_name' => array(
67  'placeholder' => 'FIRST_NAME',
68  'label' => $DIC->language()->txt('firstname')
69  ),
70  'last_name' => array(
71  'placeholder' => 'LAST_NAME',
72  'label' => $DIC->language()->txt('lastname')
73  ),
74  'login' => array(
75  'placeholder' => 'LOGIN',
76  'label' => $DIC->language()->txt('mail_nacc_login')
77  ),
78  'title' => array(
79  'placeholder' => 'TITLE',
80  'label' => $DIC->language()->txt('mail_nacc_title'),
81  'supportsCondition' => true
82  ),
83  'ilias_url' => array(
84  'placeholder' => 'ILIAS_URL',
85  'label' => $DIC->language()->txt('mail_nacc_ilias_url')
86  ),
87  'client_name' => array(
88  'placeholder' => 'CLIENT_NAME',
89  'label' => $DIC->language()->txt('mail_nacc_client_name')
90  )
91  );
92  }
93 
98  final public function getPlaceholders()
99  {
100  $placeholders = self::getGenericPlaceholders();
101  $specific = $this->getSpecificPlaceholders();
102 
103  return $placeholders + $specific;
104  }
105 
110  abstract public function getSpecificPlaceholders();
111 
119  abstract public function resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient = null, $html_markup = false);
120 
128  public function resolvePlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient = null, $html_markup = false)
129  {
130  if ($recipient !== null) {
131  $this->initLanguage($recipient);
132  }
133 
134  $old_lang = ilDatePresentation::getLanguage();
136 
137  $resolved = '';
138 
139  switch (true) {
140  case ('mail_salutation' == $placeholder_id && $recipient !== null):
141  switch ($recipient->getGender()) {
142  case 'f':
143  $resolved = $this->getLanguage()->txt('mail_salutation_f');
144  break;
145 
146  case 'm':
147  $resolved = $this->getLanguage()->txt('mail_salutation_m');
148  break;
149 
150  case 'n':
151  $resolved = $this->getLanguage()->txt('mail_salutation_n');
152  break;
153 
154  default:
155  $resolved = $this->getLanguage()->txt('mail_salutation_n');
156  }
157  break;
158 
159  case ('first_name' == $placeholder_id && $recipient !== null):
160  $resolved = $recipient->getFirstname();
161  break;
162 
163  case ('last_name' == $placeholder_id && $recipient !== null):
164  $resolved = $recipient->getLastname();
165  break;
166 
167  case ('login' == $placeholder_id && $recipient !== null):
168  $resolved = $recipient->getLogin();
169  break;
170 
171  case ('title' == $placeholder_id && $recipient !== null):
172  $resolved = $recipient->getUTitle();
173  break;
174 
175  case 'ilias_url' == $placeholder_id:
176  $resolved = ILIAS_HTTP_PATH . '/login.php?client_id=' . CLIENT_ID;
177  break;
178 
179  case 'client_name' == $placeholder_id:
180  $resolved = CLIENT_NAME;
181  break;
182 
183  case !in_array($placeholder_id, array_keys(self::getGenericPlaceholders())):
184  $resolved = $this->resolveSpecificPlaceholder($placeholder_id, $context_parameters, $recipient, $html_markup);
185  break;
186  }
187 
189 
190  return $resolved;
191  }
192 
196  protected function initLanguage(ilObjUser $user)
197  {
198  $this->initLanguageByIso2Code($user->getLanguage());
199  }
200 
205  protected function initLanguageByIso2Code($a_code)
206  {
207  $this->language = ilLanguageFactory::_getLanguage($a_code);
208  $this->language->loadLanguageModule('mail');
209  }
210 }
global $DIC
Definition: saml.php:7
resolveSpecificPlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient=null, $html_markup=false)
getSpecificPlaceholders()
Return an array of placeholders.
getId()
Returns a unique (in the context of mail template contexts) id.
static setLanguage($a_lng)
set language
resolvePlaceholder($placeholder_id, array $context_parameters, ilObjUser $recipient=null, $html_markup=false)
static _getLanguage($a_lang_key='')
Get langauge object.
getTitle()
Returns a translated title (depending on the current language) which is displayed in the user interfa...
initLanguageByIso2Code($a_code)
Init language by ISO2 code.
Class ilMailTemplateContext.
Create styles array
The data for the language used.
getPlaceholders()
Return an array of placeholders.
getDescription()
Returns a translated description (depending on the current language) which is displayed in the user i...
static getLanguage()
set language
getLanguage()
returns a 2char-language-string public