|
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 Auth\Entity\UserInterface; |
|
14
|
|
|
use Jobs\Entity\JobInterface; |
|
15
|
|
|
use Core\Mail\StringTemplateMessage; |
|
16
|
|
|
use Organizations\Entity\EmployeeInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Sends Information about a new Application to the recruiter |
|
20
|
|
|
* |
|
21
|
|
|
* Class NewApplication |
|
22
|
|
|
* @package Applications\Mail |
|
23
|
|
|
*/ |
|
24
|
|
|
class NewApplication extends StringTemplateMessage |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Job posting |
|
28
|
|
|
* |
|
29
|
|
|
* @var \Jobs\Entity\Job $job |
|
30
|
|
|
*/ |
|
31
|
|
|
protected $job; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Owner of the job posting |
|
35
|
|
|
* |
|
36
|
|
|
* @var \Auth\Entity\User $user |
|
37
|
|
|
*/ |
|
38
|
|
|
protected $user; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Organization Admin |
|
42
|
|
|
* |
|
43
|
|
|
* @var bool|\Auth\Entity\User $admin |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $admin; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @var bool |
|
49
|
|
|
*/ |
|
50
|
|
|
private $callInitOnSetJob = false; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @param array $options |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(array $options = array()) |
|
56
|
|
|
{ |
|
57
|
|
|
parent::__construct($options); |
|
58
|
|
|
$this->callInitOnSetJob = true; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function init() |
|
62
|
|
|
{ |
|
63
|
|
|
if (!$this->job) { |
|
64
|
|
|
return false; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/* @var \Auth\Entity\Info $userInfo */ |
|
68
|
|
|
$userInfo = $this->user->getInfo(); |
|
69
|
|
|
$name = $userInfo->getDisplayName(); |
|
70
|
|
|
if ('' == trim($name)) { |
|
71
|
|
|
$name = $userInfo->getEmail(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$variables = array( |
|
75
|
|
|
'name' => $name, |
|
76
|
|
|
'title' => $this->job->getTitle() |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
$this->setReciptient(); |
|
80
|
|
|
|
|
81
|
|
|
$this->setVariables($variables); |
|
82
|
|
|
$subject = /*@translate*/ 'New application for your vacancy "%s"'; |
|
83
|
|
|
|
|
84
|
|
|
if ($this->isTranslatorEnabled()) { |
|
85
|
|
|
$subject = $this->getTranslator()->translate($subject); |
|
86
|
|
|
} |
|
87
|
|
|
$this->setSubject(sprintf($subject, $this->job->getTitle())); |
|
88
|
|
|
|
|
89
|
|
|
/* @var \Applications\Entity\Settings $settings */ |
|
90
|
|
|
$settings = $this->user->getSettings('Applications'); |
|
91
|
|
|
|
|
92
|
|
|
$body = $settings->getMailAccessText(); |
|
|
|
|
|
|
93
|
|
|
if ('' == $body) { |
|
94
|
|
|
$body = /*@translate*/ "Hello ##name##,\n\nThere is a new application for your vacancy:\n\"##title##\"\n\n"; |
|
95
|
|
|
if ($this->isTranslatorEnabled()) { |
|
96
|
|
|
$body = $this->getTranslator()->translate($body); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
$this->setBody($body); |
|
101
|
|
|
return $this; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* @param JobInterface $job |
|
106
|
|
|
* @param bool $init |
|
107
|
|
|
* @return $this |
|
108
|
|
|
*/ |
|
109
|
|
|
public function setJob(JobInterface $job, $init = true) |
|
|
|
|
|
|
110
|
|
|
{ |
|
111
|
|
|
$this->job = $job; |
|
|
|
|
|
|
112
|
|
|
if ($this->callInitOnSetJob) { |
|
113
|
|
|
$this->init(); |
|
114
|
|
|
} |
|
115
|
|
|
return $this; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* @param \Auth\Entity\User $user |
|
120
|
|
|
* @return $this |
|
121
|
|
|
*/ |
|
122
|
|
|
public function setUser($user) |
|
123
|
|
|
{ |
|
124
|
|
|
$this->user=$user; |
|
125
|
|
|
return $this; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @param \Auth\Entity\User $admin |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setAdmin($admin) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->admin = $admin; |
|
135
|
|
|
return $this; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
protected function setReciptient() { |
|
139
|
|
|
$workflowSettings = $this->getWorkflowSettings(); |
|
140
|
|
|
if ($workflowSettings->getAcceptApplicationByDepartmentManager()){ |
|
141
|
|
|
$departmentManagers = $this->getDepartmentManagers(); |
|
142
|
|
|
foreach ($departmentManagers as $employee) { /* @var \Organizations\Entity\Employee $employee */ |
|
|
|
|
|
|
143
|
|
|
$this->setTo($employee->getUser()->getInfo()->getEmail(), $employee->getUser()->getInfo()->getDisplayName()); |
|
144
|
|
|
} |
|
145
|
|
|
} else { |
|
146
|
|
|
$this->setTo($this->user->getInfo()->getEmail(), $this->user->getInfo()->getDisplayName()); |
|
147
|
|
|
} |
|
148
|
|
|
if (true === $this->admin && $this->user->getSettings('Applications')->getMailBCC()) { |
|
149
|
|
|
$this->addBcc($this->user->getInfo()->getEmail(), $this->user->getInfo()->getDisplayName()); |
|
150
|
|
|
} elseif($this->admin instanceof UserInterface && $this->admin->getSettings('Applications')->getMailBCC()) { |
|
151
|
|
|
$this->addBcc($this->admin->getInfo()->getEmail(), $this->admin->getInfo()->getDisplayName()); |
|
152
|
|
|
} |
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* @return bool|\Doctrine\Common\Collections\Collection |
|
157
|
|
|
*/ |
|
158
|
|
|
protected function getDepartmentManagers(){ |
|
159
|
|
|
if (true === $this->admin) { |
|
160
|
|
|
return $this->user->getOrganization()->getOrganization()->getEmployeesByRole(EmployeeInterface::ROLE_DEPARTMENT_MANAGER); |
|
161
|
|
|
} elseif($this->admin) { |
|
162
|
|
|
return $this->admin->getOrganization()->getOrganization()->getEmployeesByRole(EmployeeInterface::ROLE_DEPARTMENT_MANAGER); |
|
163
|
|
|
} else { |
|
164
|
|
|
return false; |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @return bool|\Organizations\Entity\WorkflowSettings |
|
170
|
|
|
*/ |
|
171
|
|
|
protected function getWorkflowSettings() |
|
172
|
|
|
{ |
|
173
|
|
|
if ($this->user->getOrganization()->hasAssociation()) { |
|
174
|
|
|
return $this->user->getOrganization()->getOrganization()->getWorkflowSettings(); |
|
175
|
|
|
} else { |
|
176
|
|
|
return false; |
|
177
|
|
|
} |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
} |
|
181
|
|
|
|
If you implement
__calland you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__callis implemented by a parent class and only the child class knows which methods exist: