forked from spiegel/seminars
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.tx_seminars_EmailSalutation.php
143 lines (127 loc) · 4.53 KB
/
class.tx_seminars_EmailSalutation.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009-2013 Bernd Schönbach <bernd@oliverklee.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* This class creates a salutation for e-mails.
*
* @package TYPO3
* @subpackage tx_seminars
*
* @author Bernd Schönbach <bernd@oliverklee.de>
*/
class tx_seminars_EmailSalutation {
/**
* @var Tx_Oelib_Translator
*/
private $translator = NULL;
/**
* the constructor
*/
public function __construct() {
$this->translator = Tx_Oelib_TranslatorRegistry::getInstance()->get('seminars');
}
/**
* The destructor. Frees as much memory as possible.
*/
public function __destruct() {
unset($this->translator);
}
/**
* Creates the salutation for the given user.
*
* The salutation is localized and gender-specific and contains the name of
* the user.
*
* @param tx_seminars_Model_FrontEndUser $user
* the user to create the salutation for
*
* @return string the localized, gender-specific salutation with a trailing comma, will not be empty
*/
public function getSalutation(tx_seminars_Model_FrontEndUser $user) {
$salutationParts = array();
$salutationMode = Tx_Oelib_ConfigurationRegistry::get('plugin.tx_seminars')->getAsString('salutation');
switch ($salutationMode) {
case 'informal':
$salutationParts['dear'] = $this->translator->translate('email_hello_informal');
$salutationParts['name'] = $user->getFirstOrFullName();
break;
default:
$gender = $user->getGender();
$salutationParts['dear'] = $this->translator->translate('email_hello_formal_' . $gender);
$salutationParts['title'] = $this->translator->translate('email_salutation_title_' . $gender);
$salutationParts['name'] = $user->getLastOrFullName();
}
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'modifySalutation')) {
$hook->modifySalutation($salutationParts);
}
}
return implode(' ', $salutationParts) . ',';
}
/**
* Gets all hooks for this class.
*
* @return array the hook objects in an array, will be empty if no hooks have been set
*/
private function getHooks() {
$result = array();
$hooks = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['seminars']['modifyEmailSalutation'];
if (is_array($hooks)) {
foreach ($hooks as $classReference) {
$result[] = t3lib_div::getUserObj($classReference);
}
}
return $result;
}
/**
* Creates an e-mail introduction with the given event's title, date and
* time prepended with the given introduction string.
*
* @param string $introductionBegin
* the start of the introduction, must not be empty and contain %s as
* place to fill the title of the event in
* @param tx_seminars_seminar $event the event the introduction is for
*
* @return string the introduction with the event's title and if available
* date and time, will not be empty
*/
public function createIntroduction($introductionBegin, tx_seminars_seminar $event) {
$result = sprintf($introductionBegin, $event->getTitle());
if (!$event->hasDate()) {
return $result;
}
$result .= ' ' . sprintf($this->translator->translate('email_eventDate'), $event->getDate('-'));
if ($event->hasTime() && !$event->hasTimeslots()) {
$timeToLabel = $this->translator->translate('email_timeTo');
$time = $event->getTime(' ' . $timeToLabel . ' ');
$label = ' ' . (!$event->isOpenEnded()
? $this->translator->translate('email_timeFrom')
: $this->translator->translate('email_timeAt'));
$result .= sprintf($label, $time);
}
return $result;
}
}
if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/seminars/class.tx_seminars_EmailSalutation.php']) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/seminars/class.tx_seminars_EmailSalutation.php']);
}