|
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
|
|
|
/** Applications controller */ |
|
11
|
|
|
namespace Applications\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Auth\Entity\Info; |
|
14
|
|
|
use Applications\Entity\Application; |
|
15
|
|
|
use Zend\Http\Request; |
|
16
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
17
|
|
|
use Zend\View\Model\ViewModel; |
|
18
|
|
|
use Zend\View\Model\JsonModel; |
|
19
|
|
|
use Applications\Entity\Status; |
|
20
|
|
|
use Applications\Entity\StatusInterface; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Main Action Controller for Applications module. |
|
24
|
|
|
* |
|
25
|
|
|
* @method \Core\Controller\Plugin\Notification notification() |
|
26
|
|
|
* @method \Core\Controller\Plugin\CreatePaginator paginator() |
|
27
|
|
|
* @method \Auth\Controller\Plugin\Auth auth() |
|
28
|
|
|
* @method \Acl\Controller\Plugin\Acl acl() |
|
29
|
|
|
*/ |
|
30
|
|
|
class IndexController extends AbstractActionController |
|
31
|
|
|
{ |
|
32
|
|
|
/** |
|
33
|
|
|
* attaches further Listeners for generating / processing the output |
|
34
|
|
|
* @return $this |
|
35
|
|
|
*/ |
|
36
|
|
|
public function attachDefaultListeners() |
|
37
|
|
|
{ |
|
38
|
|
|
parent::attachDefaultListeners(); |
|
39
|
|
|
$serviceLocator = $this->getServiceLocator(); |
|
40
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
|
41
|
|
|
$events = $this->getEventManager(); |
|
42
|
|
|
$events->attach($defaultServices); |
|
|
|
|
|
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Processes formular data of the application form |
|
49
|
|
|
* |
|
50
|
|
|
* @return \Zend\View\Model\ViewModel |
|
51
|
|
|
*/ |
|
52
|
|
|
public function indexAction() |
|
53
|
|
|
{ |
|
54
|
|
|
$services = $this->getServiceLocator(); |
|
55
|
|
|
/** @var Request $request */ |
|
56
|
|
|
$request = $this->getRequest(); |
|
57
|
|
|
|
|
58
|
|
|
$jobId = $this->params()->fromPost('jobId', 0); |
|
59
|
|
|
$applyId = (int) $this->params()->fromPost('applyId', 0); |
|
60
|
|
|
|
|
61
|
|
|
// subscriber comes from the form |
|
62
|
|
|
$subscriberUri = $this->params()->fromPost('subscriberUri', ''); |
|
63
|
|
|
if (empty($subscriberUri)) { |
|
64
|
|
|
// subscriber comes with the request of the form |
|
65
|
|
|
// which implies that the backlink in the job-offer had such an link in the query |
|
66
|
|
|
$subscriberUri = $this->params()->fromQuery('subscriberUri', ''); |
|
67
|
|
|
} |
|
68
|
|
|
if (empty($subscriberUri)) { |
|
69
|
|
|
// the subscriber comes from an external module, maybe after interpreting the backlink, or the referer |
|
70
|
|
|
$e = $this->getEvent(); |
|
71
|
|
|
$subscriberResponseCollection = $this->getEventManager()->trigger('subscriber.getUri', $e); |
|
72
|
|
|
if (!$subscriberResponseCollection->isEmpty()) { |
|
73
|
|
|
$subscriberUri = $subscriberResponseCollection->last(); |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
$job = ($request->isPost() && !empty($jobId)) |
|
79
|
|
|
? $services->get('repositories')->get('Jobs/Job')->find($jobId) |
|
80
|
|
|
: $services->get('repositories')->get('Jobs/Job')->findOneBy(array("applyId"=>(0 == $applyId)?$this->params('jobId'):$applyId)); |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
View Code Duplication |
if (!$job) { |
|
|
|
|
|
|
84
|
|
|
$this->response->setStatusCode(410); |
|
|
|
|
|
|
85
|
|
|
$model = new ViewModel( |
|
86
|
|
|
array( |
|
87
|
|
|
'content' => /*@translate*/ 'Invalid apply id' |
|
88
|
|
|
) |
|
89
|
|
|
); |
|
90
|
|
|
$model->setTemplate('auth/index/job-not-found.phtml'); |
|
91
|
|
|
return $model; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/* @var $form \Zend\Form\Form */ |
|
95
|
|
|
$form = $services->get('FormElementManager')->get('Application/Create'); |
|
96
|
|
|
$form->setValidate(); |
|
97
|
|
|
|
|
98
|
|
|
$viewModel = new ViewModel(); |
|
99
|
|
|
$viewModel->setVariables( |
|
100
|
|
|
array( |
|
101
|
|
|
'job' => $job, |
|
102
|
|
|
'form' => $form, |
|
103
|
|
|
'isApplicationSaved' => false, |
|
104
|
|
|
'subscriberUri' => $subscriberUri, |
|
105
|
|
|
) |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
$applicationEntity = new Application(); |
|
109
|
|
|
$applicationEntity->setJob($job); |
|
110
|
|
|
|
|
111
|
|
|
if ($this->auth()->isLoggedIn()) { |
|
112
|
|
|
// copy the contact info into the application |
|
113
|
|
|
$contact = new Info(); |
|
114
|
|
|
$contact->fromArray(Info::toArray($this->auth()->get('info'))); |
|
|
|
|
|
|
115
|
|
|
$applicationEntity->setContact($contact); |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
$form->bind($applicationEntity); |
|
119
|
|
|
$form->get('jobId')->setValue($job->id); |
|
120
|
|
|
$form->get('subscriberUri')->setValue($subscriberUri); |
|
121
|
|
|
|
|
122
|
|
|
if ($request->isPost()) { |
|
123
|
|
|
if ($returnTo = $this->params()->fromPost('returnTo', false)) { |
|
124
|
|
|
$returnTo = \Zend\Uri\UriFactory::factory($returnTo); |
|
125
|
|
|
} |
|
126
|
|
|
$services = $this->getServiceLocator(); |
|
127
|
|
|
|
|
128
|
|
|
$data = array_merge_recursive( |
|
129
|
|
|
$this->request->getPost()->toArray(), |
|
|
|
|
|
|
130
|
|
|
$this->request->getFiles()->toArray() |
|
|
|
|
|
|
131
|
|
|
); |
|
132
|
|
|
|
|
133
|
|
|
if (!empty($subscriberUri) && $request->isPost()) { |
|
134
|
|
|
$subscriber = $services->get('repositories')->get('Applications/Subscriber')->findbyUriOrCreate($subscriberUri); |
|
135
|
|
|
$applicationEntity->subscriber = $subscriber; |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
$form->setData($data); |
|
139
|
|
|
|
|
140
|
|
|
if (!$form->isValid()) { |
|
141
|
|
|
if ($request->isXmlHttpRequest()) { |
|
142
|
|
|
return new JsonModel( |
|
143
|
|
|
array( |
|
144
|
|
|
'ok' => false, |
|
145
|
|
|
'messages' => $form->getMessages() |
|
146
|
|
|
) |
|
147
|
|
|
); |
|
148
|
|
|
} |
|
149
|
|
View Code Duplication |
if ($returnTo) { |
|
|
|
|
|
|
150
|
|
|
$returnTo->setQuery($returnTo->getQueryAsArray() + array('status' => 'failure')); |
|
151
|
|
|
return $this->redirect()->toUrl((string) $returnTo); |
|
152
|
|
|
} |
|
153
|
|
|
$this->notification()->error(/*@translate*/ 'There were errors in the form.'); |
|
154
|
|
|
|
|
155
|
|
|
} else { |
|
156
|
|
|
$auth = $this->auth(); |
|
157
|
|
|
|
|
158
|
|
|
if ($auth->isLoggedIn()) { |
|
159
|
|
|
// in instance user is logged in, |
|
160
|
|
|
// and no image is uploaded |
|
161
|
|
|
// take his profile-image as copy |
|
162
|
|
|
$applicationEntity->setUser($auth->getUser()); |
|
163
|
|
|
$imageData = $form->get('contact')->get('image')->getValue(); |
|
|
|
|
|
|
164
|
|
|
if (UPLOAD_ERR_NO_FILE == $imageData['error']) { |
|
165
|
|
|
// has the user an image |
|
166
|
|
|
$image = $auth->getUser()->info->image; |
|
|
|
|
|
|
167
|
|
|
if ($image) { |
|
168
|
|
|
$repositoryAttachment = $services->get('repositories')->get('Applications/Attachment'); |
|
169
|
|
|
|
|
170
|
|
|
// this should provide a real copy, not just a reference |
|
171
|
|
|
$contactImage = $repositoryAttachment->copy($image); |
|
172
|
|
|
$applicationEntity->contact->setImage($contactImage); |
|
|
|
|
|
|
173
|
|
|
} else { |
|
174
|
|
|
$applicationEntity->contact->setImage(null); //explicitly remove image. |
|
|
|
|
|
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
if (!$request->isXmlHttpRequest()) { |
|
180
|
|
|
$applicationEntity->setStatus(new Status()); |
|
181
|
|
|
$permissions = $applicationEntity->getPermissions(); |
|
182
|
|
|
$permissions->inherit($job->getPermissions()); |
|
183
|
|
|
|
|
184
|
|
|
/* |
|
185
|
|
|
* New Application alert Mails to job recruiter |
|
186
|
|
|
* This is temporary until Companies are implemented. |
|
187
|
|
|
*/ |
|
188
|
|
|
$recruiter = $services->get('repositories')->get('Auth/User')->findOneByEmail($job->contactEmail); |
|
189
|
|
View Code Duplication |
if (!$recruiter) { |
|
|
|
|
|
|
190
|
|
|
$recruiter = $job->user; |
|
|
|
|
|
|
191
|
|
|
$admin = false; |
|
|
|
|
|
|
192
|
|
|
} else { |
|
193
|
|
|
$admin = $job->user; |
|
|
|
|
|
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
$services->get('repositories')->store($applicationEntity); |
|
197
|
|
|
/* |
|
198
|
|
|
* New Application alert Mails to job recruiter |
|
199
|
|
|
* This is temporary until Companies are implemented. |
|
200
|
|
|
*/ |
|
201
|
|
|
$recruiter = $services->get('repositories')->get('Auth/User')->findOneByEmail($job->contactEmail); |
|
202
|
|
View Code Duplication |
if (!$recruiter) { |
|
|
|
|
|
|
203
|
|
|
$recruiter = $job->user; |
|
204
|
|
|
$admin = false; |
|
205
|
|
|
} else { |
|
206
|
|
|
$admin = $job->user; |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
if ($recruiter->getSettings('Applications')->getMailAccess()) { |
|
210
|
|
|
$this->mailer('Applications/NewApplication', array('job' => $job, 'user' => $recruiter, 'admin' => $admin), /*send*/ true); |
|
|
|
|
|
|
211
|
|
|
} |
|
212
|
|
View Code Duplication |
if ($recruiter->getSettings('Applications')->getAutoConfirmMail()) { |
|
|
|
|
|
|
213
|
|
|
$ackBody = $recruiter->getSettings('Applications')->getMailConfirmationText(); |
|
214
|
|
|
if (empty($ackBody)) { |
|
215
|
|
|
$ackBody = $job->user->getSettings('Applications')->getMailConfirmationText(); |
|
216
|
|
|
} |
|
217
|
|
|
if (!empty($ackBody)) { |
|
218
|
|
|
/* Acknowledge mail to the applicant */ |
|
219
|
|
|
$ackMail = $this->mailer( |
|
|
|
|
|
|
220
|
|
|
'Applications/Confirmation', |
|
221
|
|
|
array('application' => $applicationEntity, |
|
222
|
|
|
'body' => $ackBody, |
|
223
|
|
|
) |
|
224
|
|
|
); |
|
225
|
|
|
// Must be called after initializers in creation |
|
226
|
|
|
$ackMail->setSubject(/*@translate*/ 'Application confirmation'); |
|
227
|
|
|
$ackMail->setFrom($recruiter->getInfo()->getEmail()); |
|
228
|
|
|
$this->mailer($ackMail); |
|
|
|
|
|
|
229
|
|
|
$applicationEntity->changeStatus(StatusInterface::CONFIRMED, sprintf('Mail was sent to %s', $applicationEntity->contact->email)); |
|
|
|
|
|
|
230
|
|
|
} |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
// send carbon copy of the application |
|
234
|
|
|
|
|
235
|
|
|
$paramsCC = $this->getRequest()->getPost('carboncopy', 0); |
|
|
|
|
|
|
236
|
|
|
if (isset($paramsCC) && array_key_exists('carboncopy', $paramsCC)) { |
|
237
|
|
|
$wantCarbonCopy = (int) $paramsCC['carboncopy']; |
|
238
|
|
|
if ($wantCarbonCopy) { |
|
239
|
|
|
$mail = $this->mailer( |
|
|
|
|
|
|
240
|
|
|
'Applications/CarbonCopy', |
|
241
|
|
|
array( |
|
242
|
|
|
'application' => $applicationEntity, |
|
243
|
|
|
'to' => $applicationEntity->contact->email, |
|
|
|
|
|
|
244
|
|
|
), /*send*/ |
|
245
|
|
|
true |
|
246
|
|
|
); |
|
247
|
|
|
} |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
if ($request->isXmlHttpRequest()) { |
|
252
|
|
|
return new JsonModel( |
|
253
|
|
|
array( |
|
254
|
|
|
'ok' => true, |
|
255
|
|
|
'id' => $applicationEntity->id, |
|
|
|
|
|
|
256
|
|
|
'jobId' => $applicationEntity->job->id, |
|
|
|
|
|
|
257
|
|
|
) |
|
258
|
|
|
); |
|
259
|
|
|
} |
|
260
|
|
View Code Duplication |
if ($returnTo) { |
|
|
|
|
|
|
261
|
|
|
$returnTo->setQuery($returnTo->getQueryAsArray() + array('status' => 'success')); |
|
262
|
|
|
return $this->redirect()->toUrl((string) $returnTo); |
|
263
|
|
|
} |
|
264
|
|
|
$this->notification()->success(/*@translate*/ 'your application was sent successfully'); |
|
265
|
|
|
$viewModel->setVariable('isApplicationSaved', true); |
|
266
|
|
|
} |
|
267
|
|
|
} |
|
268
|
|
|
return $viewModel; |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
/** |
|
272
|
|
|
* Handles dashboard listings of applications |
|
273
|
|
|
* |
|
274
|
|
|
* @return array |
|
275
|
|
|
*/ |
|
276
|
|
View Code Duplication |
public function dashboardAction() |
|
|
|
|
|
|
277
|
|
|
{ |
|
278
|
|
|
$params = $this->getRequest()->getQuery(); |
|
|
|
|
|
|
279
|
|
|
$isRecruiter = $this->acl()->isRole('recruiter'); |
|
280
|
|
|
if ($isRecruiter) { |
|
281
|
|
|
$params->set('by', 'me'); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
//default sorting |
|
285
|
|
|
if (!isset($params['sort'])) { |
|
286
|
|
|
$params['sort']="-date"; |
|
287
|
|
|
} |
|
288
|
|
|
$params->count = 5; |
|
289
|
|
|
$params->pageRange=5; |
|
290
|
|
|
|
|
291
|
|
|
$this->paginationParams()->setParams('Applications\Index', $params); |
|
|
|
|
|
|
292
|
|
|
|
|
293
|
|
|
$paginator = $this->paginator('Applications/Application', $params); |
|
|
|
|
|
|
294
|
|
|
|
|
295
|
|
|
return array( |
|
296
|
|
|
'script' => 'applications/index/dashboard', |
|
297
|
|
|
'applications' => $paginator |
|
298
|
|
|
); |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
/** |
|
302
|
|
|
* sends a test-mail with all application-data to the applicant |
|
303
|
|
|
* @return JsonModel |
|
304
|
|
|
*/ |
|
305
|
|
|
public function mailAction() |
|
306
|
|
|
{ |
|
307
|
|
|
$services = $this->getServiceLocator(); |
|
308
|
|
|
$config = $services->get('Config'); |
|
309
|
|
|
$applicationId = $this->getRequest() |
|
|
|
|
|
|
310
|
|
|
->getQuery('id'); |
|
311
|
|
|
$status = $this->params('status'); |
|
312
|
|
|
$repositories = $services->get('repositories'); |
|
313
|
|
|
$entityApplication = $repositories->get('Applications/Application')->find($applicationId); |
|
314
|
|
|
if (empty($entityApplication)) { |
|
315
|
|
|
$this->notification()->error(/*@translate*/ 'Application has been deleted.'); |
|
316
|
|
|
} else { |
|
317
|
|
|
$jobEntity = $entityApplication->job; |
|
318
|
|
|
$applicantEmail = $entityApplication->contact->email; |
|
319
|
|
|
$organizationEmail = $jobEntity->contactEmail; |
|
320
|
|
|
$mailAddress = null; |
|
|
|
|
|
|
321
|
|
|
switch ($status == 'test') { |
|
322
|
|
|
case 'company': |
|
323
|
|
|
$mailAddress = $organizationEmail; |
|
324
|
|
|
break; |
|
325
|
|
|
case 'test': |
|
326
|
|
|
default: |
|
327
|
|
|
$mailAddress = $applicantEmail; |
|
328
|
|
|
break; |
|
329
|
|
|
} |
|
330
|
|
|
if (!empty($mailAddress)) { |
|
331
|
|
|
$mailData = array( |
|
332
|
|
|
'application' => $entityApplication, |
|
333
|
|
|
'to' => $mailAddress |
|
334
|
|
|
); |
|
335
|
|
View Code Duplication |
if (array_key_exists('mails', $config) && array_key_exists('from', $config['mails']) && array_key_exists('email', $config['mails']['from'])) { |
|
|
|
|
|
|
336
|
|
|
$mailData['from'] = $config['mails']['from']['email']; |
|
337
|
|
|
} |
|
338
|
|
|
|
|
339
|
|
|
$mail = $this->mailer('Applications/CarbonCopy', $mailData, true); |
|
|
|
|
|
|
340
|
|
|
$this->notification() |
|
341
|
|
|
->success(/*@translate*/ 'Mail has been send'); |
|
342
|
|
|
if ($status == 'company') { |
|
343
|
|
|
$repositories->remove($entityApplication); |
|
344
|
|
|
$this->notification()->info(/*@translate*/ 'Application data has been deleted'); |
|
345
|
|
|
} |
|
346
|
|
|
} else { |
|
347
|
|
|
$this->notification()->error(/*@translate*/ 'No mail adress available'); |
|
348
|
|
|
} |
|
349
|
|
|
} |
|
350
|
|
|
return new JsonModel(array()); |
|
351
|
|
|
} |
|
352
|
|
|
} |
|
353
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: