|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* YAWIK |
|
4
|
|
|
* |
|
5
|
|
|
* @filesource |
|
6
|
|
|
* @copyright (c) 2013 Cross Solution (http://cross-solution.de) |
|
7
|
|
|
* @license MIT |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
/** Applications controller */ |
|
11
|
|
|
namespace Applications\Controller; |
|
12
|
|
|
|
|
13
|
|
|
use Zend\Mvc\Controller\AbstractActionController; |
|
14
|
|
|
use Zend\View\Model\JsonModel; |
|
15
|
|
|
use Applications\Entity\StatusInterface as Status; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Handles multiple actions on applications |
|
19
|
|
|
*/ |
|
20
|
|
|
class MultimanageController extends AbstractActionController |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* attaches further Listeners for generating / processing the output |
|
25
|
|
|
* @return $this |
|
26
|
|
|
*/ |
|
27
|
|
View Code Duplication |
public function attachDefaultListeners() |
|
|
|
|
|
|
28
|
|
|
{ |
|
29
|
|
|
parent::attachDefaultListeners(); |
|
30
|
|
|
$serviceLocator = $this->serviceLocator; |
|
31
|
|
|
$defaultServices = $serviceLocator->get('DefaultListeners'); |
|
32
|
|
|
$events = $this->getEventManager(); |
|
33
|
|
|
$events->attach($defaultServices); |
|
|
|
|
|
|
34
|
|
|
return $this; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* some Action on a set of applications, |
|
39
|
|
|
* as there are invite, decline, postpone, confirm |
|
40
|
|
|
* |
|
41
|
|
|
* @return \Zend\View\Model\JsonModel |
|
42
|
|
|
*/ |
|
43
|
|
|
public function multimodalAction() |
|
44
|
|
|
{ |
|
45
|
|
|
return new JsonModel( |
|
46
|
|
|
array( |
|
47
|
|
|
'ok' => true, |
|
48
|
|
|
'action' => 'multimodal' |
|
49
|
|
|
) |
|
50
|
|
|
); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* |
|
55
|
|
|
* @TODO consolidate with Manage::status - a lot of shared code |
|
56
|
|
|
* @return \Zend\View\Model\JsonModel |
|
57
|
|
|
*/ |
|
58
|
|
|
public function rejectApplicationAction() |
|
59
|
|
|
{ |
|
60
|
|
|
$translator = $this->serviceLocator->get('translator'); |
|
61
|
|
|
$viewHelperManager = $this->serviceLocator->get('viewHelperManager'); |
|
62
|
|
|
$actionUrl = $viewHelperManager->get('url') |
|
63
|
|
|
->__invoke('lang/applications/applications-list', array('action' => 'rejectApproval')); |
|
64
|
|
|
$repository = $this->serviceLocator->get('repositories')->get('Applications/Application'); |
|
65
|
|
|
$settings = $this->settings(); |
|
|
|
|
|
|
66
|
|
|
$mailService = $this->serviceLocator->get('Core/MailService'); |
|
67
|
|
|
|
|
68
|
|
|
// re-inject the Application-ids to the formular |
|
69
|
|
|
$elements = $this->params()->fromPost('elements', array()); |
|
70
|
|
|
$hidden = ''; |
|
71
|
|
|
$displayNames = array(); |
|
72
|
|
|
foreach ($elements as $element) { |
|
73
|
|
|
$hidden .= '<input type="hidden" name="elements[]" value="' . $element . '">'; |
|
74
|
|
|
$application = $repository->find($element); |
|
75
|
|
|
$isAllowed = $this->acl()->test($application, 'change'); |
|
|
|
|
|
|
76
|
|
|
if ($isAllowed) { |
|
77
|
|
|
$contact = $application->contact; |
|
78
|
|
|
$displayNames[] = $contact->displayName; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$mailService->get('Applications/StatusChange'); |
|
83
|
|
|
|
|
84
|
|
|
$mailText = $settings->mailRejectionText ? $settings->mailRejectionText : ''; |
|
85
|
|
|
$mailSubject = $translator->translate('Your application dated %s'); |
|
86
|
|
|
|
|
87
|
|
|
// @TODO transfer into form class |
|
88
|
|
|
return new JsonModel( |
|
89
|
|
|
array( |
|
90
|
|
|
'ok' => true, |
|
91
|
|
|
'header' => $translator->translate('reject the applicants'), |
|
92
|
|
|
'content' => '<form action="' . $actionUrl . '">' . |
|
93
|
|
|
$hidden . |
|
94
|
|
|
'<input class=" form-control " name="mail-subject" value="' |
|
95
|
|
|
. $mailSubject . '"><br /><br />' . |
|
96
|
|
|
'<textarea class=" form-control " id="mail-content" name="mail-content">' |
|
97
|
|
|
. $mailText . '</textarea></form>' |
|
98
|
|
|
) |
|
99
|
|
|
); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* |
|
104
|
|
|
* @return \Zend\View\Model\JsonModel |
|
105
|
|
|
*/ |
|
106
|
|
|
public function rejectApprovalAction() |
|
107
|
|
|
{ |
|
108
|
|
|
$translator = $this->serviceLocator->get('translator'); |
|
109
|
|
|
$repositoryService = $this->serviceLocator->get('repositories'); |
|
110
|
|
|
$repository = $repositoryService->get('Applications/Application'); |
|
111
|
|
|
$mailService = $this->serviceLocator->get('Core/MailService'); |
|
112
|
|
|
$elements = $this->params()->fromPost('elements', array()); |
|
113
|
|
|
foreach ($elements as $element) { |
|
114
|
|
|
$mail = $mailService->get('Applications/StatusChange'); |
|
115
|
|
|
/* @var \Applications\Entity\Application $application */ |
|
116
|
|
|
$application = $repository->find($element); |
|
117
|
|
|
$mail->setApplication($application); |
|
118
|
|
|
$mail->setBody($this->params()->fromPost('mail-content')); |
|
119
|
|
|
$mailSubject = sprintf( |
|
120
|
|
|
$translator->translate($this->params()->fromPost('mail-subject')), |
|
121
|
|
|
strftime('%x', $application->dateCreated->getTimestamp()) |
|
|
|
|
|
|
122
|
|
|
); |
|
123
|
|
|
$mail->setSubject($mailSubject); |
|
124
|
|
|
|
|
125
|
|
|
if ($from = $application->job->contactEmail) { |
|
|
|
|
|
|
126
|
|
|
$mail->setFrom($from, $application->job->company); |
|
|
|
|
|
|
127
|
|
|
} |
|
128
|
|
|
if ($this->settings()->mailBCC) { |
|
|
|
|
|
|
129
|
|
|
$user = $this->auth()->getUser(); |
|
|
|
|
|
|
130
|
|
|
$mail->addBcc($user->info->email, $user->info->displayName); |
|
131
|
|
|
} |
|
132
|
|
|
$mailService->send($mail); |
|
133
|
|
|
|
|
134
|
|
|
// update the Application-History |
|
135
|
|
|
$application->changeStatus( |
|
136
|
|
|
Status::REJECTED, |
|
137
|
|
|
sprintf( |
|
138
|
|
|
/*@translate */ 'Mail was sent to %s', |
|
139
|
|
|
$application->contact->email |
|
|
|
|
|
|
140
|
|
|
) |
|
141
|
|
|
); |
|
142
|
|
|
$repositoryService->store($application); |
|
143
|
|
|
unset($mail); |
|
144
|
|
|
} |
|
145
|
|
|
return new JsonModel(array('ok' => true, )); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* Move given applications to Talent Pool |
|
150
|
|
|
* |
|
151
|
|
|
* @since 0.26 |
|
152
|
|
|
*/ |
|
153
|
|
|
public function moveAction() |
|
154
|
|
|
{ |
|
155
|
|
|
$ids = (array)$this->params()->fromPost('ids'); |
|
156
|
|
|
$moved = 0; |
|
157
|
|
|
|
|
158
|
|
|
if ($ids) { |
|
|
|
|
|
|
159
|
|
|
$serviceManager = $this->serviceLocator; |
|
160
|
|
|
$repositories = $serviceManager->get('repositories'); |
|
161
|
|
|
$applicationRepository = $repositories->get('Applications/Application'); |
|
162
|
|
|
$cvRepository = $repositories->get('Cv/Cv'); |
|
163
|
|
|
$user = $this->auth()->getUser(); |
|
|
|
|
|
|
164
|
|
|
|
|
165
|
|
|
foreach ($ids as $id) { |
|
166
|
|
|
$application = $applicationRepository->find($id); |
|
167
|
|
|
|
|
168
|
|
|
if (!$application) { |
|
169
|
|
|
continue; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
if (!$this->acl($application, 'move', 'test')) { |
|
|
|
|
|
|
173
|
|
|
continue; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
$cv = $cvRepository->createFromApplication($application, $user); |
|
177
|
|
|
$repositories->store($cv); |
|
178
|
|
|
$repositories->remove($application); |
|
179
|
|
|
$moved++; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
$this->notification()->success( |
|
|
|
|
|
|
184
|
|
|
sprintf( |
|
185
|
|
|
/*@translate */ '%d Application(s) has been successfully moved to Talent Pool', |
|
186
|
|
|
$moved |
|
187
|
|
|
)); |
|
188
|
|
|
|
|
189
|
|
|
return $this->redirect()->toRoute('lang/applications'); |
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
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.