|
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
|
|
|
/** NewApplication.php */ |
|
11
|
|
|
namespace Applications\Mail; |
|
12
|
|
|
|
|
13
|
|
|
use Applications\Entity\ApplicationInterface; |
|
14
|
|
|
use Auth\Entity\UserInterface; |
|
15
|
|
|
use Core\Exception\MissingDependencyException; |
|
16
|
|
|
use Jobs\Entity\JobInterface; |
|
17
|
|
|
use Core\Mail\StringTemplateMessage; |
|
18
|
|
|
use Organizations\Entity\EmployeeInterface; |
|
19
|
|
|
use Zend\Mvc\Router\RouteStackInterface; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Sends Information about a new Application to the recruiter |
|
23
|
|
|
* |
|
24
|
|
|
* Class NewApplication |
|
25
|
|
|
* @package Applications\Mail |
|
26
|
|
|
*/ |
|
27
|
|
|
class NewApplication extends StringTemplateMessage |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Job posting |
|
31
|
|
|
* |
|
32
|
|
|
* @var ApplicationInterface |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $application; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Owner of the job posting |
|
38
|
|
|
* |
|
39
|
|
|
* @var \Auth\Entity\User $user |
|
40
|
|
|
*/ |
|
41
|
|
|
protected $user; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Organization Admin |
|
45
|
|
|
* |
|
46
|
|
|
* @var bool|\Auth\Entity\User $admin |
|
47
|
|
|
*/ |
|
48
|
|
|
protected $admin; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @var bool |
|
52
|
|
|
*/ |
|
53
|
|
|
private $callInitOnSetJob = false; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* |
|
57
|
|
|
* |
|
58
|
|
|
* @var RouteStackInterface |
|
59
|
|
|
*/ |
|
60
|
|
|
private $router; |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @param array $options |
|
64
|
|
|
*/ |
|
65
|
|
|
public function __construct($options = array()) |
|
66
|
|
|
{ |
|
67
|
|
|
if (!is_array($options)) { |
|
68
|
|
|
$this->router = $options; |
|
69
|
|
|
$options = []; |
|
70
|
|
View Code Duplication |
} else if (isset($options['router'])) { |
|
|
|
|
|
|
71
|
|
|
$this->router = $options['router']; |
|
72
|
|
|
unset($options['router']); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
if (!$this->router) { |
|
76
|
|
|
throw new MissingDependencyException('Router', $this); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
parent::__construct($options); |
|
80
|
|
|
$this->callInitOnSetJob = true; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function init() |
|
84
|
|
|
{ |
|
85
|
|
|
if (!$this->application) { |
|
86
|
|
|
return false; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/* @var \Auth\Entity\Info $userInfo */ |
|
90
|
|
|
$job = $this->application->getJob(); |
|
91
|
|
|
$userInfo = $this->user->getInfo(); |
|
92
|
|
|
$name = $userInfo->getDisplayName(); |
|
93
|
|
|
if ('' == trim($name)) { |
|
94
|
|
|
$name = $userInfo->getEmail(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$variables = [ |
|
98
|
|
|
'name' => $name, |
|
99
|
|
|
'title' => $job->getTitle(), |
|
100
|
|
|
'link' => $this->router->assemble( |
|
101
|
|
|
['id' => $this->application->getId()], |
|
102
|
|
|
['name'=>'lang/applications/detail', 'force_canonical'=>true] |
|
103
|
|
|
), |
|
104
|
|
|
]; |
|
105
|
|
|
|
|
106
|
|
|
$this->setTo($this->user->getInfo()->getEmail(), $this->user->getInfo()->getDisplayName(false)); |
|
107
|
|
|
|
|
108
|
|
|
$this->setVariables($variables); |
|
109
|
|
|
$subject = /*@translate*/ 'New application for your vacancy "%s"'; |
|
110
|
|
|
|
|
111
|
|
|
if ($this->isTranslatorEnabled()) { |
|
112
|
|
|
$subject = $this->getTranslator()->translate($subject); |
|
113
|
|
|
} |
|
114
|
|
|
$this->setSubject(sprintf($subject, $job->getTitle())); |
|
115
|
|
|
|
|
116
|
|
|
/* @var \Applications\Entity\Settings $settings */ |
|
117
|
|
|
$settings = $this->user->getSettings('Applications'); |
|
118
|
|
|
|
|
119
|
|
|
$body = $settings->getMailAccessText(); |
|
|
|
|
|
|
120
|
|
|
if ('' == $body) { |
|
121
|
|
|
$body = /*@translate*/ "Hello ##name##,\n\nThere is a new application for your vacancy:\n\"##title##\"\n\n"; |
|
122
|
|
|
|
|
123
|
|
|
if ($this->isTranslatorEnabled()) { |
|
124
|
|
|
$body = $this->getTranslator()->translate($body); |
|
125
|
|
|
} |
|
126
|
|
|
$body .= "##link##\n\n"; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
$this->setBody($body); |
|
130
|
|
|
return $this; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* @param ApplicationInterface $application |
|
135
|
|
|
* @param bool $init |
|
136
|
|
|
* @return $this |
|
137
|
|
|
*/ |
|
138
|
|
|
public function setApplication(ApplicationInterface $application, $init = true) |
|
139
|
|
|
{ |
|
140
|
|
|
$this->application = $application; |
|
141
|
|
|
if ($this->callInitOnSetApplication) { |
|
|
|
|
|
|
142
|
|
|
$this->init(); |
|
143
|
|
|
} |
|
144
|
|
|
return $this; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @param \Auth\Entity\User $user |
|
149
|
|
|
* @return $this |
|
150
|
|
|
*/ |
|
151
|
|
|
public function setUser($user) |
|
152
|
|
|
{ |
|
153
|
|
|
$this->user=$user; |
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
} |
|
157
|
|
|
|
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.