| 1468 |
eleazar |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
declare(strict_types=1);
|
|
|
4 |
|
|
|
5 |
namespace LeadersLinked\Controller;
|
|
|
6 |
|
|
|
7 |
use Laminas\Db\Adapter\AdapterInterface;
|
|
|
8 |
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
|
|
|
9 |
use Laminas\Mvc\Controller\AbstractActionController;
|
|
|
10 |
use Laminas\Log\LoggerInterface;
|
|
|
11 |
use Laminas\View\Model\ViewModel;
|
|
|
12 |
use Laminas\View\Model\JsonModel;
|
| 1471 |
eleazar |
13 |
use LeadersLinked\Form\RecruitmentSelectionCandidateFormForm;
|
| 1468 |
eleazar |
14 |
use LeadersLinked\Library\Functions;
|
| 1479 |
eleazar |
15 |
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
|
| 1468 |
eleazar |
16 |
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
|
|
|
17 |
use LeadersLinked\Model\RecruitmentSelectionCandidate;
|
|
|
18 |
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
|
|
|
19 |
use LeadersLinked\Model\RecruitmentSelectionVacancy;
|
|
|
20 |
use LeadersLinked\Mapper\BehaviorMapper;
|
| 1473 |
eleazar |
21 |
use LeadersLinked\Mapper\UserMapper;
|
| 1468 |
eleazar |
22 |
use LeadersLinked\Mapper\CompanyMapper;
|
|
|
23 |
use LeadersLinked\Model\Company;
|
| 1601 |
eleazar |
24 |
use Laminas\Hydrator\ArraySerializableHydrator;
|
|
|
25 |
use Laminas\Db\ResultSet\HydratingResultSet;
|
|
|
26 |
use LeadersLinked\Mapper\QueryMapper;
|
|
|
27 |
use Laminas\Paginator\Adapter\DbSelect;
|
|
|
28 |
use Laminas\Paginator\Paginator;
|
| 1468 |
eleazar |
29 |
|
| 1470 |
eleazar |
30 |
class RecruitmentSelectionCandidateController extends AbstractActionController{
|
|
|
31 |
|
|
|
32 |
/**
|
| 1468 |
eleazar |
33 |
*
|
|
|
34 |
* @var AdapterInterface
|
|
|
35 |
*/
|
|
|
36 |
private $adapter;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
*
|
|
|
40 |
* @var AbstractAdapter
|
|
|
41 |
*/
|
|
|
42 |
private $cache;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
*
|
|
|
46 |
* @var LoggerInterface
|
|
|
47 |
*/
|
|
|
48 |
private $logger;
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
*
|
|
|
52 |
* @var array
|
|
|
53 |
*/
|
|
|
54 |
private $config;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
*
|
|
|
58 |
* @param AdapterInterface $adapter
|
|
|
59 |
* @param AbstractAdapter $cache
|
|
|
60 |
* @param LoggerInterface $logger
|
|
|
61 |
* @param array $config
|
|
|
62 |
*/
|
|
|
63 |
public function __construct($adapter, $cache, $logger, $config) {
|
|
|
64 |
$this->adapter = $adapter;
|
|
|
65 |
$this->cache = $cache;
|
|
|
66 |
$this->logger = $logger;
|
|
|
67 |
$this->config = $config;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
public function indexAction() {
|
|
|
71 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
72 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
73 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
74 |
|
|
|
75 |
$request = $this->getRequest();
|
|
|
76 |
|
|
|
77 |
if ($request->isGet()) {
|
|
|
78 |
|
|
|
79 |
$headers = $request->getHeaders();
|
|
|
80 |
|
|
|
81 |
$isJson = false;
|
|
|
82 |
if ($headers->has('Accept')) {
|
|
|
83 |
$accept = $headers->get('Accept');
|
|
|
84 |
|
|
|
85 |
$prioritized = $accept->getPrioritized();
|
|
|
86 |
|
|
|
87 |
foreach ($prioritized as $key => $value) {
|
|
|
88 |
$raw = trim($value->getRaw());
|
|
|
89 |
|
|
|
90 |
if (!$isJson) {
|
|
|
91 |
$isJson = strpos($raw, 'json');
|
|
|
92 |
}
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
if ($isJson) {
|
| 1477 |
efrain |
97 |
//$form_uuid = filter_var($this->params()->fromQuery('form_uuid'), FILTER_SANITIZE_STRING);
|
| 1468 |
eleazar |
98 |
|
| 1502 |
eleazar |
99 |
$vacancy_uuid = $this->params()->fromRoute('vacancy_uuid');
|
| 1501 |
eleazar |
100 |
|
| 1468 |
eleazar |
101 |
$data = [
|
|
|
102 |
'items' => [],
|
|
|
103 |
'total' => 0,
|
|
|
104 |
];
|
|
|
105 |
|
|
|
106 |
|
| 1477 |
efrain |
107 |
if (!$vacancy_uuid) {
|
| 1468 |
eleazar |
108 |
return new JsonModel([
|
|
|
109 |
'success' => true,
|
|
|
110 |
'data' => $data
|
|
|
111 |
]);
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
|
| 1477 |
efrain |
115 |
$vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
|
|
|
116 |
$vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
|
|
|
117 |
if (! $vacancy) {
|
| 1468 |
eleazar |
118 |
return new JsonModel([
|
|
|
119 |
'success' => true,
|
|
|
120 |
'data' => 'ERROR_FORM_NOT_FOUND'
|
|
|
121 |
]);
|
|
|
122 |
}
|
|
|
123 |
|
| 1477 |
efrain |
124 |
if ( $vacancy->company_id != $currentCompany->id) {
|
| 1468 |
eleazar |
125 |
return new JsonModel([
|
|
|
126 |
'success' => true,
|
|
|
127 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
128 |
]);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
$search = $this->params()->fromQuery('search', []);
|
|
|
133 |
$search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
|
|
|
134 |
|
|
|
135 |
$page = intval($this->params()->fromQuery('start', 1), 10);
|
|
|
136 |
$records_x_page = intval($this->params()->fromQuery('length', 10), 10);
|
|
|
137 |
$order = $this->params()->fromQuery('order', []);
|
|
|
138 |
$order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
|
|
|
139 |
$order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
|
|
|
140 |
|
|
|
141 |
$fields = ['uuid', 'first_name', 'last_name', 'email'];
|
|
|
142 |
$order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
|
|
|
143 |
|
|
|
144 |
if (!in_array($order_direction, ['ASC', 'DESC'])) {
|
|
|
145 |
$order_direction = 'ASC';
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
$acl = $this->getEvent()->getViewModel()->getVariable('acl');
|
|
|
149 |
$allowAdd = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/candidates/add');
|
| 1614 |
eleazar |
150 |
$allowEdit = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/candidates/edit');
|
| 1468 |
eleazar |
151 |
$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/candidates/delete');
|
| 1636 |
eleazar |
152 |
$allowEmail = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/user-by-email');
|
| 1468 |
eleazar |
153 |
|
| 1600 |
eleazar |
154 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
|
|
155 |
$sql = $queryMapper->getSql();
|
|
|
156 |
$select = $sql->select();
|
| 6235 |
eleazar |
157 |
$select->columns(['id', 'uuid', 'first_name', 'last_name', 'email', 'file']);
|
| 1600 |
eleazar |
158 |
$select->from(['tb1' => RecruitmentSelectionCandidateMapper::_TABLE]);
|
| 2681 |
eleazar |
159 |
$select->where->equalTo('tb1.vacancy_id', $vacancy->id);
|
| 1468 |
eleazar |
160 |
|
| 1600 |
eleazar |
161 |
if($search) {
|
|
|
162 |
$select->where->nest()
|
|
|
163 |
->like('first_name', '%' . $search . '%')
|
|
|
164 |
->or->like('last_name', '%' . $search . '%')
|
|
|
165 |
->or->like('email', '%' . $search . '%')
|
|
|
166 |
->unnest();
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
$select->order($order_field . ' ' . $order_direction);
|
|
|
170 |
|
| 1468 |
eleazar |
171 |
$hydrator = new ArraySerializableHydrator();
|
|
|
172 |
$resultset = new HydratingResultSet($hydrator);
|
|
|
173 |
|
|
|
174 |
$adapter = new DbSelect($select, $sql, $resultset);
|
|
|
175 |
$paginator = new Paginator($adapter);
|
|
|
176 |
$paginator->setItemCountPerPage($records_x_page);
|
|
|
177 |
$paginator->setCurrentPageNumber($page);
|
|
|
178 |
|
|
|
179 |
|
|
|
180 |
$items = [];
|
|
|
181 |
$records = $paginator->getCurrentItems();
|
| 4503 |
eleazar |
182 |
|
| 6237 |
eleazar |
183 |
|
| 1468 |
eleazar |
184 |
foreach ($records as $record) {
|
|
|
185 |
$params = [
|
| 1608 |
eleazar |
186 |
'vacancy_uuid' => $vacancy->uuid,
|
|
|
187 |
'id' => $record['uuid'],
|
| 1468 |
eleazar |
188 |
];
|
|
|
189 |
|
| 1624 |
eleazar |
190 |
$link_delete = $this->url()->fromRoute('recruitment-and-selection/candidates/delete', $params);
|
|
|
191 |
|
|
|
192 |
$link_edit = $this->url()->fromRoute('recruitment-and-selection/candidates/edit', $params);
|
|
|
193 |
|
| 1468 |
eleazar |
194 |
$item = [
|
|
|
195 |
'uuid' => $record['uuid'],
|
|
|
196 |
'first_name' => $record['first_name'],
|
|
|
197 |
'last_name' => $record['last_name'],
|
|
|
198 |
'email' => $record['email'],
|
| 1611 |
eleazar |
199 |
// 'file' => $this->url()->fromRoute('storage', ['type' => 'recruitment_selection', 'code' => $record['uuid'], 'filename' => $record['file']]),
|
| 1468 |
eleazar |
200 |
'actions' => [
|
| 1614 |
eleazar |
201 |
'link_edit' => $allowEdit ? $link_edit : '',
|
| 1468 |
eleazar |
202 |
'link_delete' => $allowDelete ? $link_delete : '',
|
|
|
203 |
]
|
|
|
204 |
];
|
|
|
205 |
|
|
|
206 |
array_push($items, $item);
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
$data['items'] = $items;
|
|
|
210 |
$data['total'] = $paginator->getTotalItemCount();
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
return new JsonModel([
|
|
|
214 |
'success' => true,
|
|
|
215 |
'data' => $data
|
|
|
216 |
]);
|
|
|
217 |
} else {
|
|
|
218 |
$form = new RecruitmentSelectionCandidateFormForm($this->adapter, $currentCompany->id);
|
|
|
219 |
|
|
|
220 |
$this->layout()->setTemplate('layout/layout-backend');
|
|
|
221 |
$viewModel = new ViewModel();
|
| 1475 |
eleazar |
222 |
$viewModel->setTemplate('leaders-linked/recruitment-and-selection-candidates/index.phtml');
|
| 1598 |
eleazar |
223 |
$viewModel->setVariables(['form' => $form]);
|
| 1468 |
eleazar |
224 |
|
|
|
225 |
return $viewModel;
|
|
|
226 |
}
|
|
|
227 |
} else {
|
|
|
228 |
return new JsonModel([
|
|
|
229 |
'success' => false,
|
|
|
230 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
231 |
]);
|
|
|
232 |
;
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
| 1485 |
eleazar |
236 |
public function addAction()
|
|
|
237 |
{
|
|
|
238 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
239 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
240 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
241 |
|
|
|
242 |
$request = $this->getRequest();
|
|
|
243 |
|
| 1515 |
eleazar |
244 |
$vacancy_uuid = $this->params()->fromRoute('vacancy_uuid');
|
|
|
245 |
|
| 1485 |
eleazar |
246 |
if($request->isPost()) {
|
| 1513 |
eleazar |
247 |
$form = new RecruitmentSelectionCandidateFormForm($this->adapter, $currentCompany->id);
|
| 1516 |
eleazar |
248 |
$dataPost = array_merge(
|
|
|
249 |
$request->getPost()->toArray(),
|
|
|
250 |
$request->getFiles()->toArray(),
|
|
|
251 |
['form_uuid' => $vacancy_uuid],
|
|
|
252 |
);
|
| 1485 |
eleazar |
253 |
|
|
|
254 |
$form->setData($dataPost);
|
|
|
255 |
|
|
|
256 |
if($form->isValid()) {
|
|
|
257 |
$dataPost = (array) $form->getData();
|
|
|
258 |
|
| 1592 |
eleazar |
259 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
260 |
|
| 1485 |
eleazar |
261 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
262 |
$candidate = new RecruitmentSelectionCandidate();
|
|
|
263 |
$hydrator->hydrate($dataPost, $candidate);
|
|
|
264 |
|
|
|
265 |
$candidate->company_id = $currentCompany->id;
|
| 1586 |
eleazar |
266 |
$candidate->file = null;
|
| 1520 |
eleazar |
267 |
|
|
|
268 |
$vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
|
|
|
269 |
$vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
|
|
|
270 |
|
| 2680 |
eleazar |
271 |
$candidate->vacancy_id = $vacancy->id;
|
| 1494 |
eleazar |
272 |
$candidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
|
| 1518 |
eleazar |
273 |
|
| 1534 |
eleazar |
274 |
if($candidateMapper->insert($candidate)) {
|
| 1593 |
eleazar |
275 |
$candidate = $candidateMapper->fetchOne($candidate->id);
|
| 1485 |
eleazar |
276 |
|
|
|
277 |
//leaderslinked.fullpath.recruitment_selection/uuid vacante/uuid candidato
|
|
|
278 |
|
| 6245 |
eleazar |
279 |
$target_path = $this->config['leaderslinked.fullpath.recruitment_selection'].$vacancy->uuid.'/'.$candidate->uuid;
|
| 1582 |
eleazar |
280 |
if(!file_exists($target_path)) {
|
|
|
281 |
mkdir($target_path, 0755, true);
|
|
|
282 |
}
|
|
|
283 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
284 |
if(isset($files['file']) && empty($files['file']['error'])) {
|
|
|
285 |
$tmp_filename = $files['file']['tmp_name'];
|
| 1592 |
eleazar |
286 |
$original_filename = trim(strtolower($files['file']['name']));
|
| 1582 |
eleazar |
287 |
try {
|
| 1592 |
eleazar |
288 |
$parts = explode('.', $original_filename);
|
|
|
289 |
$filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
|
|
|
290 |
|
|
|
291 |
$full_filename = $target_path . DIRECTORY_SEPARATOR .$filename;
|
|
|
292 |
if(move_uploaded_file($tmp_filename, $full_filename)) {
|
| 1582 |
eleazar |
293 |
$candidate->file = $filename;
|
|
|
294 |
$candidateMapper->update($candidate);
|
|
|
295 |
}
|
|
|
296 |
} catch(\Throwable $e) {
|
|
|
297 |
error_log($e->getTraceAsString());
|
|
|
298 |
}
|
|
|
299 |
}
|
| 1518 |
eleazar |
300 |
|
| 1588 |
eleazar |
301 |
$this->logger->info('Se agrego el candidato ' . $candidate->first_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 1485 |
eleazar |
302 |
|
|
|
303 |
$data = [
|
|
|
304 |
'success' => true,
|
|
|
305 |
'data' => 'LABEL_RECORD_ADDED'
|
|
|
306 |
];
|
|
|
307 |
} else {
|
|
|
308 |
$data = [
|
|
|
309 |
'success' => false,
|
| 1494 |
eleazar |
310 |
'data' => $candidateMapper->getError()
|
| 1485 |
eleazar |
311 |
];
|
|
|
312 |
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
return new JsonModel($data);
|
|
|
316 |
|
|
|
317 |
} else {
|
|
|
318 |
$messages = [];
|
|
|
319 |
$form_messages = (array) $form->getMessages();
|
|
|
320 |
foreach($form_messages as $fieldname => $field_messages)
|
|
|
321 |
{
|
|
|
322 |
|
|
|
323 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
324 |
}
|
|
|
325 |
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
} else {
|
|
|
329 |
$data = [
|
|
|
330 |
'success' => false,
|
|
|
331 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
332 |
];
|
|
|
333 |
|
|
|
334 |
return new JsonModel($data);
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
return new JsonModel($data);
|
|
|
338 |
}
|
| 1614 |
eleazar |
339 |
|
|
|
340 |
public function editAction() {
|
|
|
341 |
$request = $this->getRequest();
|
|
|
342 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
343 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
344 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
345 |
|
|
|
346 |
$request = $this->getRequest();
|
| 1623 |
eleazar |
347 |
$id = $this->params()->fromRoute('id');
|
| 1614 |
eleazar |
348 |
|
| 1625 |
eleazar |
349 |
if (!$id) {
|
| 1614 |
eleazar |
350 |
$data = [
|
|
|
351 |
'success' => false,
|
|
|
352 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
353 |
];
|
|
|
354 |
|
|
|
355 |
return new JsonModel($data);
|
|
|
356 |
}
|
|
|
357 |
|
|
|
358 |
$recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
|
| 1625 |
eleazar |
359 |
$candidate = $recruitmentSelectionCandidateMapper->fetchOneByUuid($id);
|
|
|
360 |
|
|
|
361 |
if (!$candidate) {
|
| 1614 |
eleazar |
362 |
$data = [
|
|
|
363 |
'success' => false,
|
|
|
364 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
365 |
];
|
|
|
366 |
|
|
|
367 |
return new JsonModel($data);
|
|
|
368 |
}
|
|
|
369 |
|
| 1625 |
eleazar |
370 |
if ($candidate->company_id != $currentCompany->id) {
|
| 1614 |
eleazar |
371 |
return new JsonModel([
|
|
|
372 |
'success' => false,
|
|
|
373 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
374 |
]);
|
|
|
375 |
}
|
|
|
376 |
|
|
|
377 |
if ($request->isPost()) {
|
| 1626 |
eleazar |
378 |
$vacancy_uuid = $this->params()->fromRoute('vacancy_uuid');
|
| 1614 |
eleazar |
379 |
$form = new RecruitmentSelectionCandidateFormForm($this->adapter, $currentCompany->id);
|
|
|
380 |
$dataPost = $request->getPost()->toArray();
|
| 3879 |
eleazar |
381 |
$dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionCandidate::STATUS_REJECTED;
|
| 1626 |
eleazar |
382 |
$dataPost['form_uuid'] = $vacancy_uuid;
|
| 1614 |
eleazar |
383 |
|
|
|
384 |
$form->setData($dataPost);
|
|
|
385 |
|
|
|
386 |
if ($form->isValid()) {
|
|
|
387 |
$dataPost = (array) $form->getData();
|
|
|
388 |
|
|
|
389 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
390 |
$hydrator->hydrate($dataPost, $candidate);
|
|
|
391 |
|
| 1625 |
eleazar |
392 |
if($recruitmentSelectionCandidateMapper->update($candidate)) {
|
|
|
393 |
$candidate = $recruitmentSelectionCandidateMapper->fetchOne($candidate->id);
|
| 1623 |
eleazar |
394 |
|
|
|
395 |
//leaderslinked.fullpath.recruitment_selection/uuid vacante/uuid candidato
|
|
|
396 |
|
| 6245 |
eleazar |
397 |
$target_path = $this->config['leaderslinked.fullpath.recruitment_selection'].$vacancy_uuid.'/'.$candidate->uuid;
|
| 1623 |
eleazar |
398 |
if(!file_exists($target_path)) {
|
|
|
399 |
mkdir($target_path, 0755, true);
|
|
|
400 |
}
|
| 1625 |
eleazar |
401 |
|
|
|
402 |
$files = $this->getRequest()->getFiles()->toArray();
|
|
|
403 |
|
| 1623 |
eleazar |
404 |
if(isset($files['file']) && empty($files['file']['error'])) {
|
|
|
405 |
$tmp_filename = $files['file']['tmp_name'];
|
|
|
406 |
$original_filename = trim(strtolower($files['file']['name']));
|
| 1625 |
eleazar |
407 |
|
|
|
408 |
try {
|
|
|
409 |
$parts = explode('.', $original_filename);
|
|
|
410 |
$filename = 'document-' . uniqid() . '.' . $parts[ count($parts) - 1 ];
|
|
|
411 |
|
|
|
412 |
$full_filename = $target_path . DIRECTORY_SEPARATOR .$filename;
|
|
|
413 |
if(move_uploaded_file($tmp_filename, $full_filename)) {
|
| 1623 |
eleazar |
414 |
$candidate->file = $filename;
|
| 1625 |
eleazar |
415 |
$recruitmentSelectionCandidateMapper->update($candidate);
|
| 1623 |
eleazar |
416 |
}
|
|
|
417 |
} catch(\Throwable $e) {
|
|
|
418 |
error_log($e->getTraceAsString());
|
|
|
419 |
}
|
|
|
420 |
}
|
|
|
421 |
|
|
|
422 |
$this->logger->info('Se agrego el candidato ' . $candidate->first_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
|
|
423 |
|
|
|
424 |
$data = [
|
|
|
425 |
'success' => true,
|
| 1628 |
eleazar |
426 |
'data' => 'LABEL_RECORD_UPDATED'
|
| 1623 |
eleazar |
427 |
];
|
|
|
428 |
} else {
|
|
|
429 |
$data = [
|
|
|
430 |
'success' => false,
|
| 1625 |
eleazar |
431 |
'data' => $recruitmentSelectionCandidateMapper->getError()
|
| 1623 |
eleazar |
432 |
];
|
|
|
433 |
|
|
|
434 |
}
|
|
|
435 |
|
| 1614 |
eleazar |
436 |
return new JsonModel($data);
|
|
|
437 |
} else {
|
|
|
438 |
$messages = [];
|
|
|
439 |
$form_messages = (array) $form->getMessages();
|
|
|
440 |
foreach ($form_messages as $fieldname => $field_messages) {
|
|
|
441 |
$messages[$fieldname] = array_values($field_messages);
|
|
|
442 |
}
|
|
|
443 |
|
|
|
444 |
return new JsonModel([
|
|
|
445 |
'success' => false,
|
|
|
446 |
'data' => $messages
|
|
|
447 |
]);
|
|
|
448 |
}
|
|
|
449 |
} else if ($request->isGet()) {
|
|
|
450 |
$hydrator = new ObjectPropertyHydrator();
|
|
|
451 |
|
|
|
452 |
$data = [
|
|
|
453 |
'success' => true,
|
|
|
454 |
'data' => [
|
|
|
455 |
'id' => $candidate->uuid,
|
| 1660 |
eleazar |
456 |
'user_id' => $candidate->user_id,
|
| 1614 |
eleazar |
457 |
'first_name' => $candidate->first_name,
|
|
|
458 |
'last_name' => $candidate->last_name,
|
|
|
459 |
'email' => $candidate->email,
|
| 1658 |
eleazar |
460 |
'evaluation' => $candidate->evaluation,
|
| 1655 |
eleazar |
461 |
'coment' => $candidate->coment,
|
| 1614 |
eleazar |
462 |
'status' => $candidate->status,
|
|
|
463 |
]
|
|
|
464 |
];
|
|
|
465 |
|
|
|
466 |
return new JsonModel($data);
|
|
|
467 |
} else {
|
|
|
468 |
$data = [
|
|
|
469 |
'success' => false,
|
| 1619 |
eleazar |
470 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
| 1614 |
eleazar |
471 |
];
|
|
|
472 |
|
|
|
473 |
return new JsonModel($data);
|
|
|
474 |
}
|
|
|
475 |
|
|
|
476 |
return new JsonModel($data);
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
public function deleteAction() {
|
|
|
480 |
$request = $this->getRequest();
|
|
|
481 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
482 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
483 |
$currentUser = $currentUserPlugin->getUser();
|
|
|
484 |
|
|
|
485 |
$request = $this->getRequest();
|
|
|
486 |
$uuid = $this->params()->fromRoute('id');
|
|
|
487 |
|
|
|
488 |
if (!$uuid) {
|
|
|
489 |
$data = [
|
|
|
490 |
'success' => false,
|
|
|
491 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
492 |
];
|
|
|
493 |
|
|
|
494 |
return new JsonModel($data);
|
|
|
495 |
}
|
|
|
496 |
|
|
|
497 |
$recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
|
|
|
498 |
$candidateMapper = $recruitmentSelectionCandidateMapper->fetchOneByUuid($uuid);
|
|
|
499 |
if (!$candidateMapper) {
|
|
|
500 |
$data = [
|
|
|
501 |
'success' => false,
|
|
|
502 |
'data' => 'ERROR_RECORD_NOT_FOUND'
|
|
|
503 |
];
|
|
|
504 |
|
|
|
505 |
return new JsonModel($data);
|
|
|
506 |
}
|
|
|
507 |
|
|
|
508 |
if ($candidateMapper->company_id != $currentCompany->id) {
|
|
|
509 |
return new JsonModel([
|
|
|
510 |
'success' => false,
|
|
|
511 |
'data' => 'ERROR_UNAUTHORIZED'
|
|
|
512 |
]);
|
|
|
513 |
}
|
|
|
514 |
|
|
|
515 |
if ($request->isPost()) {
|
|
|
516 |
|
|
|
517 |
|
|
|
518 |
$result = $recruitmentSelectionCandidateMapper->delete($candidateMapper->id);
|
|
|
519 |
if ($result) {
|
| 1615 |
eleazar |
520 |
$this->logger->info('Se borro el candidato ' . $candidateMapper->first_name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
|
| 1614 |
eleazar |
521 |
|
|
|
522 |
$data = [
|
|
|
523 |
'success' => true,
|
|
|
524 |
'data' => 'LABEL_RECORD_DELETED'
|
|
|
525 |
];
|
|
|
526 |
} else {
|
|
|
527 |
|
|
|
528 |
$data = [
|
|
|
529 |
'success' => false,
|
|
|
530 |
'data' => $recruitmentSelectionCandidateMapper->getError()
|
|
|
531 |
];
|
|
|
532 |
|
|
|
533 |
return new JsonModel($data);
|
|
|
534 |
}
|
|
|
535 |
} else {
|
|
|
536 |
$data = [
|
|
|
537 |
'success' => false,
|
|
|
538 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
539 |
];
|
|
|
540 |
|
|
|
541 |
return new JsonModel($data);
|
|
|
542 |
}
|
|
|
543 |
|
|
|
544 |
return new JsonModel($data);
|
|
|
545 |
}
|
|
|
546 |
|
| 1632 |
eleazar |
547 |
public function emailAction() {
|
| 1630 |
eleazar |
548 |
$request = $this->getRequest();
|
|
|
549 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
|
|
550 |
$currentCompany = $currentUserPlugin->getCompany();
|
|
|
551 |
$currentUser = $currentUserPlugin->getUser();
|
| 1640 |
eleazar |
552 |
|
|
|
553 |
$email = $request->getQuery('email');
|
| 1643 |
eleazar |
554 |
|
|
|
555 |
if(!$email){
|
|
|
556 |
$data = [
|
|
|
557 |
'success' => false,
|
|
|
558 |
'data' => 'ERROR_INVALID_PARAMETER'
|
|
|
559 |
];
|
|
|
560 |
|
|
|
561 |
return new JsonModel($data);
|
|
|
562 |
}
|
|
|
563 |
|
|
|
564 |
$userMapper = UserMapper::getInstance($this->adapter);
|
|
|
565 |
$user = $userMapper->fetchOneByEmail($email);
|
|
|
566 |
|
|
|
567 |
if (!$user) {
|
|
|
568 |
return new JsonModel([
|
|
|
569 |
'success' => false,
|
|
|
570 |
'data' => 'ERROR_USER_NOT_FOUND',
|
|
|
571 |
]);
|
| 1644 |
eleazar |
572 |
} else if($request->isGet()){
|
|
|
573 |
$data = [
|
|
|
574 |
'success' => true,
|
|
|
575 |
'data' => [
|
| 1663 |
eleazar |
576 |
'user_id' => $user->id,
|
| 1644 |
eleazar |
577 |
'first_name' => $user->first_name,
|
|
|
578 |
'last_name' => $user->last_name,
|
|
|
579 |
|
|
|
580 |
]
|
|
|
581 |
];
|
|
|
582 |
return new JsonModel($data);
|
|
|
583 |
|
|
|
584 |
}else {
|
|
|
585 |
$data = [
|
| 1643 |
eleazar |
586 |
'success' => false,
|
| 1644 |
eleazar |
587 |
'data' => 'ERROR_METHOD_NOT_ALLOWED'
|
|
|
588 |
];
|
|
|
589 |
|
|
|
590 |
return new JsonModel($data);
|
| 1643 |
eleazar |
591 |
}
|
| 1630 |
eleazar |
592 |
}
|
| 1468 |
eleazar |
593 |
}
|