|
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 Applications\Listener\Events\ApplicationEvent; |
|
14
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
15
|
|
|
use Zend\View\Model\ViewModel; |
|
16
|
|
|
use Zend\View\Model\JsonModel; |
|
17
|
|
|
use Applications\Entity\StatusInterface as Status; |
|
18
|
|
|
use Applications\Entity\Application; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @method \Core\Controller\Plugin\Notification notification() |
|
22
|
|
|
* @method \Core\Controller\Plugin\Mailer mailer() |
|
23
|
|
|
* @method \Acl\Controller\Plugin\Acl acl() |
|
24
|
|
|
* @method \Auth\Controller\Plugin\Auth auth() |
|
25
|
|
|
* |
|
26
|
|
|
* Handles managing actions on applications |
|
27
|
|
|
*/ |
|
28
|
|
|
class ManageController extends AbstractActionController |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* attaches further Listeners for generating / processing the output |
|
32
|
|
|
* |
|
33
|
|
|
* @return $this |
|
34
|
|
|
*/ |
|
35
|
|
View Code Duplication |
public function attachDefaultListeners() |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
parent::attachDefaultListeners(); |
|
38
|
|
|
$serviceLocator = $this->serviceLocator; |
|
39
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
|
40
|
|
|
$events = $this->getEventManager(); |
|
41
|
|
|
$events->attach($defaultServices); |
|
|
|
|
|
|
42
|
|
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* (non-PHPdoc) |
|
47
|
|
|
* @see \Zend\Mvc\Controller\AbstractActionController::onDispatch() |
|
48
|
|
|
*/ |
|
49
|
|
|
public function onDispatch(\Zend\Mvc\MvcEvent $e) |
|
50
|
|
|
{ |
|
51
|
|
|
$routeMatch = $e->getRouteMatch(); |
|
52
|
|
|
$action = $this->params()->fromQuery('action'); |
|
53
|
|
|
|
|
54
|
|
|
if ($routeMatch && $action) { |
|
55
|
|
|
$routeMatch->setParam('action', $action); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return parent::onDispatch($e); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* List applications |
|
63
|
|
|
*/ |
|
64
|
|
|
public function indexAction() |
|
65
|
|
|
{ |
|
66
|
|
|
$services = $this->serviceLocator; |
|
67
|
|
|
/* @var \Jobs\Repository\Job $jobRepository */ |
|
68
|
|
|
$jobRepository = $services->get('repositories')->get('Jobs/Job'); |
|
69
|
|
|
/* @var \Applications\Repository\Application $applicationRepository */ |
|
70
|
|
|
$applicationRepository = $services->get('repositories')->get('Applications/Application'); |
|
71
|
|
|
$services_form = $services->get('forms'); |
|
|
|
|
|
|
72
|
|
|
/* @var \Applications\Form\FilterApplication $form */ |
|
73
|
|
|
$form = $services_form->get('Applications/Filter'); |
|
|
|
|
|
|
74
|
|
|
$params = $this->getRequest()->getQuery(); |
|
|
|
|
|
|
75
|
|
|
/* @var \Zend\Form\Element\Select $statusElement */ |
|
76
|
|
|
$statusElement = $form->get('status'); |
|
77
|
|
|
|
|
78
|
|
|
$states = $applicationRepository->getStates()->toArray(); |
|
79
|
|
|
$states = array_merge(array(/*@translate*/ 'all'), $states); |
|
80
|
|
|
|
|
81
|
|
|
$statesForSelections = array(); |
|
82
|
|
|
foreach ($states as $state) { |
|
83
|
|
|
$statesForSelections[$state] = $state; |
|
84
|
|
|
} |
|
85
|
|
|
$statusElement->setValueOptions($statesForSelections); |
|
86
|
|
|
|
|
87
|
|
|
$job = $params->job ? $jobRepository->find($params->job) : null; |
|
88
|
|
|
$paginator = $this->paginator('Applications'); |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
if ($job) { |
|
91
|
|
|
$params['job_title'] = '[' . $job->getApplyId() . '] ' . $job->getTitle(); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
$form->bind($params); |
|
95
|
|
|
|
|
96
|
|
|
return array( |
|
97
|
|
|
'form' => $form, |
|
98
|
|
|
'applications' => $paginator, |
|
99
|
|
|
'byJobs' => 'jobs' == $params->get('by', 'me'), |
|
100
|
|
|
'sort' => $params->get('sort', 'none'), |
|
101
|
|
|
'search' => $params->get('search', ''), |
|
102
|
|
|
'job' => $job, |
|
103
|
|
|
'applicationStates' => $states, |
|
104
|
|
|
'applicationState' => $params->get('status', '') |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
/** |
|
109
|
|
|
* Detail view of an application |
|
110
|
|
|
* |
|
111
|
|
|
* @return array|JsonModel|ViewModel |
|
112
|
|
|
*/ |
|
113
|
|
|
public function detailAction() |
|
114
|
|
|
{ |
|
115
|
|
|
if ('refresh-rating' == $this->params()->fromQuery('do')) { |
|
116
|
|
|
return $this->refreshRatingAction(); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$nav = $this->serviceLocator->get('Core/Navigation'); |
|
120
|
|
|
$page = $nav->findByRoute('lang/applications'); |
|
121
|
|
|
$page->setActive(); |
|
122
|
|
|
|
|
123
|
|
|
/* @var \Applications\Repository\Application$repository */ |
|
124
|
|
|
$repository = $this->serviceLocator->get('repositories')->get('Applications/Application'); |
|
125
|
|
|
/* @var Application $application */ |
|
126
|
|
|
$application = $repository->find($this->params('id')); |
|
127
|
|
|
|
|
128
|
|
|
if (!$application) { |
|
129
|
|
|
$this->response->setStatusCode(410); |
|
|
|
|
|
|
130
|
|
|
$model = new ViewModel( |
|
131
|
|
|
array( |
|
132
|
|
|
'content' => /*@translate*/ 'Invalid apply id' |
|
133
|
|
|
) |
|
134
|
|
|
); |
|
135
|
|
|
$model->setTemplate('applications/error/not-found'); |
|
136
|
|
|
return $model; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
$this->acl($application, 'read'); |
|
|
|
|
|
|
140
|
|
|
|
|
141
|
|
|
$applicationIsUnread = false; |
|
142
|
|
|
if ($application->isUnreadBy($this->auth('id')) && $application->getStatus()) { |
|
|
|
|
|
|
143
|
|
|
$application->addReadBy($this->auth('id')); |
|
|
|
|
|
|
144
|
|
|
$applicationIsUnread = true; |
|
145
|
|
|
$application->changeStatus( |
|
146
|
|
|
$application->getStatus(), |
|
147
|
|
|
sprintf(/*@translate*/ 'Application was read by %s', |
|
148
|
|
|
$this->auth()->getUser()->getInfo()->getDisplayName())); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
$format=$this->params()->fromQuery('format'); |
|
154
|
|
|
|
|
155
|
|
|
if ($application->isDraft()) { |
|
156
|
|
|
$list = false; |
|
157
|
|
|
} else { |
|
158
|
|
|
$list = $this->paginationParams('Applications\Index', $repository); |
|
|
|
|
|
|
159
|
|
|
$list->setCurrent($application->id); |
|
|
|
|
|
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
$return = array( |
|
163
|
|
|
'application'=> $application, |
|
164
|
|
|
'list' => $list, |
|
165
|
|
|
'isUnread' => $applicationIsUnread, |
|
166
|
|
|
'format' => 'html' |
|
167
|
|
|
); |
|
168
|
|
|
switch ($format) { |
|
169
|
|
|
case 'json': |
|
170
|
|
|
/*@deprecated - must be refactored */ |
|
171
|
|
|
$viewModel = new JsonModel(); |
|
172
|
|
|
$viewModel->setVariables( |
|
173
|
|
|
/*array( |
|
|
|
|
|
|
174
|
|
|
'application' => */$this->serviceLocator |
|
175
|
|
|
->get('builders') |
|
176
|
|
|
->get('JsonApplication') |
|
177
|
|
|
->unbuild($application) |
|
178
|
|
|
); |
|
179
|
|
|
$viewModel->setVariable('isUnread', $applicationIsUnread); |
|
180
|
|
|
$return = $viewModel; |
|
181
|
|
|
break; |
|
182
|
|
|
case 'pdf': |
|
183
|
|
|
$pdf = $this->serviceLocator->get('Core/html2pdf'); |
|
|
|
|
|
|
184
|
|
|
$return['format'] = $format; |
|
185
|
|
|
break; |
|
186
|
|
|
default: |
|
187
|
|
|
$contentCollector = $this->getPluginManager()->get('Core/ContentCollector'); |
|
188
|
|
|
$contentCollector->setTemplate('applications/manage/details/action-buttons'); |
|
|
|
|
|
|
189
|
|
|
$actionButtons = $contentCollector->trigger('application.detail.actionbuttons', $application); |
|
|
|
|
|
|
190
|
|
|
|
|
191
|
|
|
$return = new ViewModel($return); |
|
192
|
|
|
$return->addChild($actionButtons, 'externActionButtons'); |
|
193
|
|
|
|
|
194
|
|
|
$allowSubsequentAttachmentUpload = $this->serviceLocator->get('Applications/Options') |
|
195
|
|
|
->getAllowSubsequentAttachmentUpload(); |
|
196
|
|
|
|
|
197
|
|
|
if ($allowSubsequentAttachmentUpload |
|
198
|
|
|
&& $this->acl($application, Application::PERMISSION_SUBSEQUENT_ATTACHMENT_UPLOAD, 'test') |
|
|
|
|
|
|
199
|
|
|
) { |
|
200
|
|
|
$attachmentsForm = $this->serviceLocator->get('forms') |
|
201
|
|
|
->get('Applications/Attachments'); |
|
202
|
|
|
$attachmentsForm->bind($application->getAttachments()); |
|
203
|
|
|
|
|
204
|
|
|
/* @var $request \Zend\Http\PhpEnvironment\Request */ |
|
205
|
|
|
$request = $this->getRequest(); |
|
206
|
|
|
|
|
207
|
|
|
if ($request->isPost() && $attachmentsForm->get('return')->getValue() === $request->getPost('return')) { |
|
208
|
|
|
$data = array_merge( |
|
209
|
|
|
$attachmentsForm->getOption('use_post_array') ? $request->getPost()->toArray() : [], |
|
210
|
|
|
$attachmentsForm->getOption('use_files_array') ? $request->getFiles()->toArray() : [] |
|
211
|
|
|
); |
|
212
|
|
|
$attachmentsForm->setData($data); |
|
213
|
|
|
|
|
214
|
|
|
if (!$attachmentsForm->isValid()) { |
|
215
|
|
|
return new JsonModel([ |
|
216
|
|
|
'valid' => false, |
|
217
|
|
|
'errors' => $attachmentsForm->getMessages() |
|
218
|
|
|
]); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
$content = $attachmentsForm->getHydrator() |
|
222
|
|
|
->getLastUploadedFile() |
|
223
|
|
|
->getUri(); |
|
224
|
|
|
|
|
225
|
|
|
return new JsonModel([ |
|
226
|
|
|
'valid' => $attachmentsForm->isValid(), |
|
227
|
|
|
'content' => $content |
|
228
|
|
|
]); |
|
229
|
|
|
} |
|
230
|
|
|
|
|
231
|
|
|
$return->setVariable('attachmentsForm', $attachmentsForm); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
break; |
|
235
|
|
|
} |
|
236
|
|
|
|
|
237
|
|
|
return $return; |
|
238
|
|
|
} |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* Refreshes the rating of an application |
|
242
|
|
|
* |
|
243
|
|
|
* @throws \DomainException |
|
244
|
|
|
* @return \Zend\View\Model\ViewModel |
|
245
|
|
|
*/ |
|
246
|
|
|
public function refreshRatingAction() |
|
247
|
|
|
{ |
|
248
|
|
|
$model = new ViewModel(); |
|
249
|
|
|
$model->setTemplate('applications/manage/_rating'); |
|
250
|
|
|
|
|
251
|
|
|
$application = $this->serviceLocator->get('repositories')->get('Applications/Application') |
|
252
|
|
|
->find($this->params('id', 0)); |
|
253
|
|
|
|
|
254
|
|
|
if (!$application) { |
|
255
|
|
|
throw new \DomainException('Invalid application id.'); |
|
256
|
|
|
} |
|
257
|
|
|
|
|
258
|
|
|
$model->setVariable('application', $application); |
|
259
|
|
|
return $model; |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Attaches a social profile to an application |
|
264
|
|
|
* @throws \InvalidArgumentException |
|
265
|
|
|
* |
|
266
|
|
|
* @return array |
|
267
|
|
|
*/ |
|
268
|
|
|
public function socialProfileAction() |
|
269
|
|
|
{ |
|
270
|
|
|
if ($spId = $this->params()->fromQuery('spId')) { |
|
|
|
|
|
|
271
|
|
|
$repositories = $this->serviceLocator->get('repositories'); |
|
272
|
|
|
$repo = $repositories->get('Applications/Application'); |
|
273
|
|
|
$profile = $repo->findProfile($this->params()->fromQuery('spId')); |
|
274
|
|
|
if (!$profile) { |
|
275
|
|
|
throw new \InvalidArgumentException('Could not find profile.'); |
|
276
|
|
|
} |
|
277
|
|
|
} elseif ($this->getRequest()->isPost() |
|
|
|
|
|
|
278
|
|
|
&& ($network = $this->params()->fromQuery('network')) |
|
279
|
|
|
&& ($data = $this->params()->fromPost('data')) |
|
280
|
|
|
) { |
|
281
|
|
|
$profileClass = '\\Auth\\Entity\\SocialProfiles\\' . $network; |
|
282
|
|
|
$profile = new $profileClass(); |
|
283
|
|
|
$profile->setData(\Zend\Json\Json::decode($data, \Zend\Json\Json::TYPE_ARRAY)); |
|
284
|
|
|
} else { |
|
285
|
|
|
throw new \RuntimeException( |
|
286
|
|
|
'Missing arguments. Either provide "spId" as Get or "network" and "data" as Post.' |
|
287
|
|
|
); |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
return array( |
|
291
|
|
|
'profile' => $profile |
|
292
|
|
|
); |
|
293
|
|
|
} |
|
294
|
|
|
|
|
295
|
|
|
/** |
|
296
|
|
|
* Changes the status of an application |
|
297
|
|
|
* |
|
298
|
|
|
* @return array |
|
|
|
|
|
|
299
|
|
|
*/ |
|
300
|
|
|
public function statusAction() |
|
301
|
|
|
{ |
|
302
|
|
|
$applicationId = $this->params('id'); |
|
303
|
|
|
/* @var \Applications\Repository\Application $repository */ |
|
304
|
|
|
$repository = $this->serviceLocator->get('repositories')->get('Applications/Application'); |
|
305
|
|
|
/* @var Application $application */ |
|
306
|
|
|
$application = $repository->find($applicationId); |
|
307
|
|
|
|
|
308
|
|
|
/* @var Request $request */ |
|
309
|
|
|
$request = $this->getRequest(); |
|
310
|
|
|
|
|
311
|
|
|
if (!$application) { |
|
312
|
|
|
throw new \InvalidArgumentException('Could not find application.'); |
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
$this->acl($application, 'change'); |
|
|
|
|
|
|
316
|
|
|
|
|
317
|
|
|
$jsonFormat = 'json' == $this->params()->fromQuery('format'); |
|
318
|
|
|
$status = $this->params('status', Status::CONFIRMED); |
|
319
|
|
|
$settings = $this->settings(); |
|
|
|
|
|
|
320
|
|
|
|
|
321
|
|
|
if (in_array($status, array(Status::INCOMING))) { |
|
322
|
|
|
$application->changeStatus($status); |
|
323
|
|
|
if ($request->isXmlHttpRequest()) { |
|
324
|
|
|
$response = $this->getResponse(); |
|
325
|
|
|
$response->setContent('ok'); |
|
326
|
|
|
return $response; |
|
327
|
|
|
} |
|
328
|
|
|
if ($jsonFormat) { |
|
329
|
|
|
return array( |
|
330
|
|
|
'status' => 'success', |
|
331
|
|
|
); |
|
332
|
|
|
} |
|
333
|
|
|
return $this->redirect()->toRoute('lang/applications/detail', array(), true); |
|
|
|
|
|
|
334
|
|
|
} |
|
335
|
|
|
|
|
336
|
|
|
$events = $this->serviceLocator->get('Applications/Events'); |
|
337
|
|
|
|
|
338
|
|
|
/* @var ApplicationEvent $event */ |
|
339
|
|
|
$event = $events->getEvent(ApplicationEvent::EVENT_APPLICATION_STATUS_CHANGE, |
|
340
|
|
|
$this, |
|
341
|
|
|
[ |
|
342
|
|
|
'application' => $application, |
|
343
|
|
|
'status' => $status, |
|
344
|
|
|
'user' => $this->auth()->getUser(), |
|
345
|
|
|
] |
|
346
|
|
|
); |
|
347
|
|
|
|
|
348
|
|
|
$event->setIsPostRequest($request->isPost()); |
|
349
|
|
|
$event->setPostData($request->getPost()); |
|
350
|
|
|
$events->trigger($event); |
|
351
|
|
|
|
|
352
|
|
|
$params = $event->getFormData(); |
|
353
|
|
|
|
|
354
|
|
|
|
|
355
|
|
|
if ($request->isPost()) { |
|
356
|
|
|
|
|
357
|
|
|
if ($jsonFormat) { |
|
358
|
|
|
return array( |
|
359
|
|
|
'status' => 'success', |
|
360
|
|
|
); |
|
361
|
|
|
} |
|
362
|
|
|
$this->notification()->success($event->getNotification()); |
|
363
|
|
|
return $this->redirect()->toRoute('lang/applications/detail', array(), true); |
|
|
|
|
|
|
364
|
|
|
} |
|
365
|
|
|
|
|
366
|
|
|
if ($jsonFormat) { |
|
367
|
|
|
return $params; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/* @var \Applications\Form\Mail $form */ |
|
371
|
|
|
$form = $this->serviceLocator->get('FormElementManager')->get('Applications/Mail'); |
|
372
|
|
|
$form->populateValues($params); |
|
373
|
|
|
|
|
374
|
|
|
|
|
375
|
|
|
|
|
376
|
|
|
$reciptient = $params['to']; |
|
377
|
|
|
|
|
378
|
|
|
return [ |
|
379
|
|
|
'recipient' => $reciptient, |
|
380
|
|
|
'form' => $form |
|
381
|
|
|
]; |
|
382
|
|
|
} |
|
383
|
|
|
|
|
384
|
|
|
/** |
|
385
|
|
|
* Forwards an application via Email |
|
386
|
|
|
* |
|
387
|
|
|
* @throws \InvalidArgumentException |
|
388
|
|
|
* @return \Zend\View\Model\JsonModel |
|
389
|
|
|
*/ |
|
390
|
|
|
public function forwardAction() |
|
391
|
|
|
{ |
|
392
|
|
|
$services = $this->serviceLocator; |
|
393
|
|
|
$emailAddress = $this->params()->fromQuery('email'); |
|
394
|
|
|
/* @var \Applications\Entity\Application $application */ |
|
395
|
|
|
$application = $services->get('repositories')->get('Applications/Application') |
|
396
|
|
|
->find($this->params('id')); |
|
397
|
|
|
|
|
398
|
|
|
$this->acl($application, 'forward'); |
|
|
|
|
|
|
399
|
|
|
|
|
400
|
|
|
$translator = $services->get('translator'); |
|
401
|
|
|
|
|
402
|
|
|
if (!$emailAddress) { |
|
403
|
|
|
throw new \InvalidArgumentException('An email address must be supplied.'); |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
$params = array( |
|
407
|
|
|
'ok' => true, |
|
408
|
|
|
'text' => sprintf($translator->translate('Forwarded application to %s'), $emailAddress) |
|
409
|
|
|
); |
|
410
|
|
|
|
|
411
|
|
|
try { |
|
412
|
|
|
$userName = $this->auth('info')->displayName; |
|
|
|
|
|
|
413
|
|
|
$fromAddress = $application->getJob()->getContactEmail(); |
|
414
|
|
|
$mailOptions = array( |
|
415
|
|
|
'application' => $application, |
|
416
|
|
|
'to' => $emailAddress, |
|
417
|
|
|
'from' => array($fromAddress => $userName) |
|
418
|
|
|
); |
|
419
|
|
|
$this->mailer('Applications/Forward', $mailOptions, true); |
|
|
|
|
|
|
420
|
|
|
$this->notification()->success($params['text']); |
|
421
|
|
|
} catch (\Exception $ex) { |
|
422
|
|
|
$params = array( |
|
423
|
|
|
'ok' => false, |
|
424
|
|
|
'text' => sprintf($translator->translate('Forward application to %s failed.'), $emailAddress) |
|
425
|
|
|
); |
|
426
|
|
|
$this->notification()->error($params['text']); |
|
427
|
|
|
} |
|
428
|
|
|
$application->changeStatus($application->getStatus(), $params['text']); |
|
|
|
|
|
|
429
|
|
|
return new JsonModel($params); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* Deletes an application |
|
434
|
|
|
* |
|
435
|
|
|
* @return array|\Zend\Http\Response |
|
436
|
|
|
*/ |
|
437
|
|
|
public function deleteAction() |
|
438
|
|
|
{ |
|
439
|
|
|
$id = $this->params('id'); |
|
440
|
|
|
$services = $this->serviceLocator; |
|
441
|
|
|
$repositories= $services->get('repositories'); |
|
442
|
|
|
$repository = $repositories->get('Applications/Application'); |
|
443
|
|
|
$application = $repository->find($id); |
|
444
|
|
|
|
|
445
|
|
|
if (!$application) { |
|
446
|
|
|
throw new \DomainException('Application not found.'); |
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
$this->acl($application, 'delete'); |
|
|
|
|
|
|
450
|
|
|
|
|
451
|
|
|
$events = $services->get('Applications/Events'); |
|
452
|
|
|
$events->trigger(ApplicationEvent::EVENT_APPLICATION_PRE_DELETE, $this, [ 'application' => $application ]); |
|
453
|
|
|
|
|
454
|
|
|
$repositories->remove($application); |
|
455
|
|
|
|
|
456
|
|
|
if ('json' == $this->params()->fromQuery('format')) { |
|
457
|
|
|
return ['status' => 'success']; |
|
458
|
|
|
} |
|
459
|
|
|
|
|
460
|
|
|
return $this->redirect()->toRoute('lang/applications', array(), true); |
|
|
|
|
|
|
461
|
|
|
} |
|
462
|
|
|
|
|
463
|
|
|
/** |
|
464
|
|
|
* Move an application to talent pool |
|
465
|
|
|
* |
|
466
|
|
|
* @return \Zend\Http\Response |
|
467
|
|
|
* @since 0.26 |
|
468
|
|
|
*/ |
|
469
|
|
|
public function moveAction() |
|
470
|
|
|
{ |
|
471
|
|
|
$id = $this->params('id'); |
|
472
|
|
|
$serviceManager = $this->serviceLocator; |
|
473
|
|
|
$repositories = $serviceManager->get('repositories'); |
|
474
|
|
|
$application = $repositories->get('Applications/Application')->find($id); |
|
475
|
|
|
|
|
476
|
|
|
if (!$application) { |
|
477
|
|
|
throw new \DomainException('Application not found.'); |
|
478
|
|
|
} |
|
479
|
|
|
|
|
480
|
|
|
$this->acl($application, 'move'); |
|
|
|
|
|
|
481
|
|
|
|
|
482
|
|
|
$user = $this->auth()->getUser(); |
|
483
|
|
|
$cv = $repositories->get('Cv/Cv')->createFromApplication($application, $user); |
|
484
|
|
|
|
|
485
|
|
|
$repositories->store($cv); |
|
486
|
|
|
$repositories->remove($application); |
|
487
|
|
|
|
|
488
|
|
|
$this->notification()->success( |
|
489
|
|
|
/*@translate*/ 'Application has been successfully moved to Talent Pool'); |
|
490
|
|
|
|
|
491
|
|
|
return $this->redirect()->toRoute('lang/applications', array(), true); |
|
|
|
|
|
|
492
|
|
|
} |
|
493
|
|
|
} |
|
494
|
|
|
|
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.