|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Confirmation.php */ |
|
11
|
|
|
namespace Applications\Mail; |
|
12
|
|
|
|
|
13
|
|
|
use Auth\Entity\AnonymousUser; |
|
14
|
|
|
use Auth\Entity\UserInterface; |
|
15
|
|
|
use Core\Mail\StringTemplateMessage; |
|
16
|
|
|
use Applications\Entity\ApplicationInterface; |
|
17
|
|
|
use Zend\Mvc\Router\RouteStackInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Sends an confirmation Mail to the applicant. |
|
21
|
|
|
* |
|
22
|
|
|
* @package Applications\Mail |
|
23
|
|
|
*/ |
|
24
|
|
|
class Confirmation extends StringTemplateMessage |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* @var ApplicationInterface |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $application; |
|
30
|
|
|
|
|
31
|
|
|
protected $callbacks = array( |
|
32
|
|
|
'anrede_formell' => 'getFormalSalutation', |
|
33
|
|
|
'salutation_formal' => 'getFormalSalutation', |
|
34
|
|
|
'anrede_informell' => 'getInformalSalutation', |
|
35
|
|
|
'salutation_informal' => 'getInformalSalutation', |
|
36
|
|
|
'job_title' => 'getJobTitle', |
|
37
|
|
|
'date' => 'getDate', |
|
38
|
|
|
'link' => 'getApplicationLink', |
|
39
|
|
|
); |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* |
|
43
|
|
|
* |
|
44
|
|
|
* @var RouteStackInterface |
|
45
|
|
|
*/ |
|
46
|
|
|
protected $router; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* |
|
50
|
|
|
* |
|
51
|
|
|
* @var UserInterface |
|
52
|
|
|
*/ |
|
53
|
|
|
protected $user; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param RouteStackInterface $router |
|
57
|
|
|
* |
|
58
|
|
|
* @return self |
|
59
|
|
|
*/ |
|
60
|
|
|
public function setRouter($router) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->router = $router; |
|
63
|
|
|
|
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @param UserInterface $user |
|
69
|
|
|
* |
|
70
|
|
|
* @return self |
|
71
|
|
|
*/ |
|
72
|
|
|
public function setUser($user) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->user = $user; |
|
75
|
|
|
|
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param ApplicationInterface $application |
|
84
|
|
|
* @return StringTemplateMessage |
|
85
|
|
|
*/ |
|
86
|
|
View Code Duplication |
public function setVariablesFromApplication(ApplicationInterface $application) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
$contact = $application->getContact(); |
|
89
|
|
|
$name = $contact->getDisplayName(); |
|
90
|
|
|
|
|
91
|
|
|
$variables = array( |
|
92
|
|
|
'name' => $name, |
|
93
|
|
|
); |
|
94
|
|
|
return $this->setVariables($variables); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param ApplicationInterface $application |
|
99
|
|
|
* @return $this |
|
100
|
|
|
*/ |
|
101
|
|
View Code Duplication |
public function setApplication(ApplicationInterface $application) |
|
|
|
|
|
|
102
|
|
|
{ |
|
103
|
|
|
$this->application = $application; |
|
104
|
|
|
$this->setTo($application->getContact()->getEmail(), $application->getContact()->getDisplayName()); |
|
105
|
|
|
$this->setVariablesFromApplication($application); |
|
106
|
|
|
return $this; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* @param $recruiter |
|
111
|
|
|
* @return $this |
|
112
|
|
|
*/ |
|
113
|
|
|
public function setRecruiter($recruiter) |
|
114
|
|
|
{ |
|
115
|
|
|
$this->recruiter = $recruiter; |
|
|
|
|
|
|
116
|
|
|
return $this; |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @return string |
|
121
|
|
|
*/ |
|
122
|
|
View Code Duplication |
protected function getFormalSalutation() |
|
|
|
|
|
|
123
|
|
|
{ |
|
124
|
|
|
$contact = $this->application->getContact(); |
|
125
|
|
|
$name = $contact->getDisplayName(); |
|
126
|
|
|
$gender = $contact->getGender(); |
|
127
|
|
|
$translator = $this->getTranslator(); |
|
128
|
|
|
|
|
129
|
|
|
$salutation = 'male' == $gender |
|
130
|
|
|
? $translator->translate('Dear Mr. %s') |
|
131
|
|
|
: $translator->translate('Dear Ms. %s'); |
|
132
|
|
|
|
|
133
|
|
|
return sprintf($salutation, $name); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @return string |
|
138
|
|
|
*/ |
|
139
|
|
View Code Duplication |
protected function getInformalSalutation() |
|
|
|
|
|
|
140
|
|
|
{ |
|
141
|
|
|
$contact = $this->application->getContact(); |
|
142
|
|
|
$name = $contact->getDisplayName(); |
|
143
|
|
|
|
|
144
|
|
|
$salutation = $this->getTranslator() |
|
145
|
|
|
->translate('Hello %s'); |
|
146
|
|
|
|
|
147
|
|
|
return sprintf($salutation, $name); |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @return mixed |
|
152
|
|
|
*/ |
|
153
|
|
|
protected function getJobTitle() |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->application->getJob()->getTitle(); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return string |
|
160
|
|
|
*/ |
|
161
|
|
|
protected function getDate() |
|
162
|
|
|
{ |
|
163
|
|
|
/** @var $date \DateTime */ |
|
164
|
|
|
$date = $this->application->getDateCreated(); |
|
165
|
|
|
return strftime('%x', $date->getTimestamp()); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
protected function getApplicationLink() |
|
169
|
|
|
{ |
|
170
|
|
|
$router = $this->router; |
|
171
|
|
|
$user = $this->user; |
|
172
|
|
|
|
|
173
|
|
|
if (!$router || !$user) { return ''; } |
|
174
|
|
|
|
|
175
|
|
|
$token = $user instanceOf AnonymousUser ? '?token=' . $user->getToken() : ''; |
|
176
|
|
|
$href = $router->assemble( |
|
177
|
|
|
['id' => $this->application->getId()], |
|
178
|
|
|
['name'=>'lang/applications/detail', 'force_canonical'=>true] |
|
179
|
|
|
) . $token; |
|
180
|
|
|
|
|
181
|
|
|
return $href; |
|
182
|
|
|
|
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* @param string $subject |
|
187
|
|
|
* @param bool $translate |
|
188
|
|
|
* @return \Zend\Mail\Message |
|
189
|
|
|
*/ |
|
190
|
|
|
public function setSubject($subject, $translate = true) |
|
191
|
|
|
{ |
|
192
|
|
|
$subject = $this->isTranslatorEnabled() && $translate |
|
193
|
|
|
? $this->getTranslator()->translate($subject, $this->getTranslatorTextDomain()) |
|
194
|
|
|
: $subject; |
|
195
|
|
|
return parent::setSubject($subject); |
|
196
|
|
|
} |
|
197
|
|
|
} |
|
198
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.