Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 15118 | Rev 15457 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1384 efrain 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;
1455 eleazar 13
use LeadersLinked\Form\RecruitmentSelectionVacancyForm;
1384 efrain 14
use LeadersLinked\Library\Functions;
1386 eleazar 15
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
1387 eleazar 16
use LeadersLinked\Model\RecruitmentSelectionVacancy;
1384 efrain 17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
18
use LeadersLinked\Model\Location;
19
use LeadersLinked\Mapper\LocationMapper;
20
use LeadersLinked\Mapper\IndustryMapper;
21
use LeadersLinked\Mapper\JobDescriptionMapper;
22
use LeadersLinked\Mapper\BehaviorMapper;
23
use LeadersLinked\Mapper\JobDescriptionBehaviorCompetencyMapper;
24
use LeadersLinked\Mapper\CompanyMapper;
25
use LeadersLinked\Model\Company;
26
use LeadersLinked\Mapper\JobCategoryMapper;
27
 
12314 stevensc 28
class RecruitmentSelectionVacancyController extends AbstractActionController
29
{
1384 efrain 30
 
31
    /**
32
     *
33
     * @var AdapterInterface
34
     */
35
    private $adapter;
36
 
37
    /**
38
     *
39
     * @var AbstractAdapter
40
     */
41
    private $cache;
42
 
43
    /**
44
     *
45
     * @var  LoggerInterface
46
     */
47
    private $logger;
48
 
49
    /**
50
     *
51
     * @var array
52
     */
53
    private $config;
54
 
55
    /**
56
     *
57
     * @param AdapterInterface $adapter
58
     * @param AbstractAdapter $cache
59
     * @param LoggerInterface $logger
60
     * @param array $config
61
     */
12314 stevensc 62
    public function __construct($adapter, $cache, $logger, $config)
63
    {
1384 efrain 64
        $this->adapter = $adapter;
65
        $this->cache = $cache;
66
        $this->logger = $logger;
67
        $this->config = $config;
68
    }
69
 
12314 stevensc 70
    public function indexAction()
71
    {
1384 efrain 72
        $request = $this->getRequest();
73
        $currentUserPlugin = $this->plugin('currentUserPlugin');
74
        $currentCompany = $currentUserPlugin->getCompany();
75
        $currentUser = $currentUserPlugin->getUser();
76
 
77
 
78
        $request = $this->getRequest();
79
        if ($request->isGet()) {
80
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
12314 stevensc 81
            if ($sandbox) {
1384 efrain 82
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
83
            } else {
84
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
85
            }
86
 
12314 stevensc 87
 
1384 efrain 88
            $headers = $request->getHeaders();
89
 
90
            $isJson = false;
91
            if ($headers->has('Accept')) {
92
                $accept = $headers->get('Accept');
93
 
94
                $prioritized = $accept->getPrioritized();
95
 
96
                foreach ($prioritized as $key => $value) {
97
                    $raw = trim($value->getRaw());
98
 
99
                    if (!$isJson) {
100
                        $isJson = strpos($raw, 'json');
101
                    }
102
                }
103
            }
104
 
105
            //$isJson = true;
106
            if ($isJson) {
10093 stevensc 107
                $search = $this->params()->fromQuery('search');
108
                $search = empty($search) ? '' : filter_var($search, FILTER_SANITIZE_STRING);
1384 efrain 109
 
15371 efrain 110
                $start = intval($this->params()->fromQuery('start', 0), 10);
1384 efrain 111
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
15371 efrain 112
                $page =  intval($start / $records_x_page);
113
                $page++;
114
 
1384 efrain 115
                $order = $this->params()->fromQuery('order', []);
116
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
117
                $order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
118
 
119
                $fields = ['name'];
120
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
121
 
122
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
123
                    $order_direction = 'ASC';
124
                }
125
 
1434 eleazar 126
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
1477 efrain 127
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/vacancies/delete');
12314 stevensc 128
 
1477 efrain 129
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/vacancies/edit');
1434 eleazar 130
 
12314 stevensc 131
 
1386 eleazar 132
                $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1544 eleazar 133
                $paginator = $recruitmentSelectionVacancyMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
1384 efrain 134
 
10100 stevensc 135
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
136
                $industryMapper = IndustryMapper::getInstance($this->adapter);
137
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
1384 efrain 138
 
139
                $items = [];
140
                $records = $paginator->getCurrentItems();
12314 stevensc 141
 
1384 efrain 142
                foreach ($records as $record) {
143
                    $jobDescription = $jobDescriptionMapper->fetchOne($record->job_description_id);
144
                    if ($jobDescription) {
145
 
146
                        $item = [
147
                            'id' => $record->id,
148
                            'name' => $record->name,
149
                            'job_description' => $jobDescription->name,
150
                            'status' => $record->status,
151
                            'actions' => [
1477 efrain 152
                                'link_edit' => $this->url()->fromRoute('recruitment-and-selection/vacancies/edit', ['id' => $record->uuid]),
153
                                'link_delete' => $this->url()->fromRoute('recruitment-and-selection/vacancies/delete', ['id' => $record->uuid])
1384 efrain 154
                            ]
155
                        ];
156
                    }
157
 
158
                    array_push($items, $item);
159
                }
160
 
161
                return new JsonModel([
162
                    'success' => true,
163
                    'data' => [
164
                        'items' => $items,
165
                        'total' => $paginator->getTotalItemCount(),
166
                    ]
167
                ]);
168
            } else {
169
 
1544 eleazar 170
                $form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
1384 efrain 171
 
1549 eleazar 172
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
173
                $industryMapper = industryMapper::getInstance($this->adapter);
12314 stevensc 174
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
175
 
176
                $jobDescritions = [];
177
                $industries = [];
178
                $jobCategories = [];
179
 
15087 efrain 180
                $records = $jobCategoryMapper->fetchAllActive();
12314 stevensc 181
 
182
                foreach ($records as $record) {
183
                    $jobCategories[$record->uuid] = $record->name;
184
                }
185
 
15087 efrain 186
                $records = $industryMapper->fetchAllActive();
12314 stevensc 187
 
188
                foreach ($records as $record) {
189
                    $industries[$record->uuid] = $record->name;
190
                }
191
 
192
                $records = $currentCompany ?
193
                    $jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id) :
15087 efrain 194
                    $jobDescriptionMapper->fetchAllActiveByDefault();
195
 
12314 stevensc 196
                foreach ($records as $record) {
197
                    $jobDescritions[$record->uuid] = $record->name;
198
                }
199
 
15087 efrain 200
 
201
                //print_r($jobDescritions); exit;
202
 
1384 efrain 203
                $this->layout()->setTemplate('layout/layout-backend');
204
                $viewModel = new ViewModel();
1396 eleazar 205
                $viewModel->setTemplate('leaders-linked/recruitment-and-selection-vacancies/index.phtml');
1384 efrain 206
                $viewModel->setVariable('form', $form);
10112 stevensc 207
                $viewModel->setVariable('google_map_key', $google_map_key);
12314 stevensc 208
                $viewModel->setVariable('jobDescritions', $jobDescritions);
209
                $viewModel->setVariable('industries', $industries);
210
                $viewModel->setVariable('jobCategories', $jobCategories);
1561 efrain 211
 
1384 efrain 212
                return $viewModel;
213
            }
214
        } else {
215
            return new JsonModel([
216
                'success' => false,
217
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
12314 stevensc 218
            ]);;
1384 efrain 219
        }
220
    }
221
 
12314 stevensc 222
    public function addAction()
223
    {
1384 efrain 224
        $request = $this->getRequest();
225
        $currentUserPlugin = $this->plugin('currentUserPlugin');
226
        $currentCompany = $currentUserPlugin->getCompany();
227
        $currentUser = $currentUserPlugin->getUser();
228
 
229
        $request = $this->getRequest();
230
 
231
 
232
        if ($request->isPost()) {
1544 eleazar 233
            $form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
1384 efrain 234
            $dataPost = $request->getPost()->toArray();
15087 efrain 235
 
236
 
237
 
238
 
1387 eleazar 239
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionVacancy::STATUS_INACTIVE;
1384 efrain 240
 
241
            $form->setData($dataPost);
242
 
243
            if ($form->isValid()) {
244
                $dataPost = (array) $form->getData();
245
 
15087 efrain 246
 
1384 efrain 247
                $hydrator = new ObjectPropertyHydrator();
248
 
1417 eleazar 249
                $location = new Location();
250
                $hydrator->hydrate($dataPost, $location);
12314 stevensc 251
 
252
                $locationMapper = LocationMapper::getInstance($this->adapter);
1452 eleazar 253
                $result = $locationMapper->insert($location);
1451 eleazar 254
 
1417 eleazar 255
 
1418 eleazar 256
                if (!$result) {
257
                    return new JsonModel([
258
                        'success'   => false,
12314 stevensc 259
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
1418 eleazar 260
                    ]);
261
                }
1417 eleazar 262
 
1539 eleazar 263
                $vacancy = new RecruitmentSelectionVacancy();
264
                $hydrator->hydrate($dataPost, $vacancy);
1427 eleazar 265
 
1539 eleazar 266
                $vacancy->location_id = $location->id;
1544 eleazar 267
                $vacancy->company_id = $currentCompany->id;
1384 efrain 268
 
1427 eleazar 269
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
270
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
1539 eleazar 271
                $vacancy->job_description_id = $jobDescription->id;
1427 eleazar 272
 
273
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
12314 stevensc 274
                $jobCategory = $jobCategoryMapper->fetchOneByUuid($dataPost['job_category_id']);
1539 eleazar 275
                $vacancy->job_category_id = $jobCategory->id;
1427 eleazar 276
 
1428 eleazar 277
                $industryMapper = IndustryMapper::getInstance($this->adapter);
278
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
1539 eleazar 279
                $vacancy->industry_id = $industry->id;
1425 eleazar 280
 
1539 eleazar 281
                $vacancy->description = $dataPost['description'];
282
                $vacancy->last_date = $dataPost['last_date'];
12314 stevensc 283
 
15087 efrain 284
                $dt = \DateTime::createFromFormat('m/d/Y', $vacancy->last_date);
12314 stevensc 285
                if ($dt) {
1539 eleazar 286
                    $vacancy->last_date = $dt->format('Y-m-d');
15087 efrain 287
 
288
 
289
 
1433 eleazar 290
                }
1428 eleazar 291
 
15087 efrain 292
 
1427 eleazar 293
                $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1430 eleazar 294
 
1539 eleazar 295
                $result = $recruitmentSelectionVacancyMapper->insert($vacancy);
1384 efrain 296
 
297
                if ($result) {
1539 eleazar 298
                    $this->logger->info('Se agrego el proceso de reclutamiento' . $vacancy->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1384 efrain 299
 
300
                    $data = [
301
                        'success' => true,
302
                        'data' => 'LABEL_RECORD_ADDED'
303
                    ];
304
                } else {
305
                    $data = [
306
                        'success' => false,
1412 eleazar 307
                        'data' => $recruitmentSelectionVacancyMapper->getError()
1384 efrain 308
                    ];
309
                }
310
 
311
                return new JsonModel($data);
312
            } else {
313
                $messages = [];
314
                $form_messages = (array) $form->getMessages();
315
                foreach ($form_messages as $fieldname => $field_messages) {
316
 
317
                    $messages[$fieldname] = array_values($field_messages);
318
                }
319
 
320
                return new JsonModel([
321
                    'success' => false,
322
                    'data' => $messages
323
                ]);
324
            }
325
        } else {
326
            $data = [
327
                'success' => false,
1575 eleazar 328
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1384 efrain 329
            ];
330
 
331
            return new JsonModel($data);
332
        }
333
 
334
        return new JsonModel($data);
335
    }
336
 
12314 stevensc 337
    public function editAction()
338
    {
1384 efrain 339
        $request = $this->getRequest();
340
        $currentUserPlugin = $this->plugin('currentUserPlugin');
341
        $currentCompany = $currentUserPlugin->getCompany();
342
        $currentUser = $currentUserPlugin->getUser();
343
 
344
        $request = $this->getRequest();
345
        $uuid = $this->params()->fromRoute('id');
346
 
347
 
348
        if (!$uuid) {
349
            $data = [
350
                'success' => false,
351
                'data' => 'ERROR_INVALID_PARAMETER'
352
            ];
353
 
354
            return new JsonModel($data);
355
        }
356
 
1386 eleazar 357
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1575 eleazar 358
        $vacancy = $recruitmentSelectionVacancyMapper->fetchOneByUuid($uuid);
359
        if (!$vacancy) {
1384 efrain 360
            $data = [
361
                'success' => false,
362
                'data' => 'ERROR_RECORD_NOT_FOUND'
363
            ];
364
 
365
            return new JsonModel($data);
366
        }
367
 
1575 eleazar 368
        if ($vacancy->company_id != $currentCompany->id) {
1384 efrain 369
            return new JsonModel([
370
                'success' => false,
371
                'data' => 'ERROR_UNAUTHORIZED'
372
            ]);
373
        }
374
 
375
 
376
        if ($request->isPost()) {
1544 eleazar 377
            $form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
1384 efrain 378
            $dataPost = $request->getPost()->toArray();
1387 eleazar 379
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionVacancy::STATUS_INACTIVE;
1384 efrain 380
 
381
            $form->setData($dataPost);
382
 
383
            if ($form->isValid()) {
384
                $dataPost = (array) $form->getData();
385
 
386
                $hydrator = new ObjectPropertyHydrator();
1575 eleazar 387
                $hydrator->hydrate($dataPost, $vacancy);
1384 efrain 388
 
1575 eleazar 389
                if (!$vacancy->status) {
390
                    $vacancy->status = RecruitmentSelectionVacancy::STATUS_INACTIVE;
1384 efrain 391
                }
15118 efrain 392
 
393
                $dt = \DateTime::createFromFormat('m/d/Y', $vacancy->last_date);
394
                if ($dt) {
395
                    $vacancy->last_date = $dt->format('Y-m-d');
396
                }
1384 efrain 397
 
1578 eleazar 398
                $locationMapper = LocationMapper::getInstance($this->adapter);
399
                $location = $locationMapper->fetchOne($vacancy->location_id);
400
                $hydrator->hydrate($dataPost, $location);
401
                $locationMapper->update($location);
402
 
1384 efrain 403
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
404
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
1575 eleazar 405
                $vacancy->job_description_id = $jobDescription->id;
1384 efrain 406
 
1439 eleazar 407
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
12314 stevensc 408
                $jobCategory = $jobCategoryMapper->fetchOneByUuid($dataPost['job_category_id']);
1575 eleazar 409
                $vacancy->job_category_id = $jobCategory->id;
1384 efrain 410
 
1439 eleazar 411
                $industryMapper = IndustryMapper::getInstance($this->adapter);
412
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
1575 eleazar 413
                $vacancy->industry_id = $industry->id;
1439 eleazar 414
 
1575 eleazar 415
                $vacancy->job_description_id = $jobDescription->id;
416
                $vacancy->job_category_id = $jobCategory->id;
1578 eleazar 417
                $vacancy->industry_id = $industry->id;
1577 eleazar 418
 
419
                $result = $recruitmentSelectionVacancyMapper->update($vacancy);
1439 eleazar 420
 
12314 stevensc 421
 
1384 efrain 422
                if ($result) {
1575 eleazar 423
                    $this->logger->info('Se agrego el proceso de reclutamiento' . $vacancy->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1384 efrain 424
                    $data = [
425
                        'success' => true,
426
                        'data' => 'LABEL_RECORD_UPDATED'
427
                    ];
428
                } else {
429
                    $data = [
430
                        'success' => false,
1386 eleazar 431
                        'data' => $recruitmentSelectionVacancyMapper->getError()
1384 efrain 432
                    ];
433
                }
434
 
435
                return new JsonModel($data);
436
            } else {
437
                $messages = [];
438
                $form_messages = (array) $form->getMessages();
439
                foreach ($form_messages as $fieldname => $field_messages) {
440
                    $messages[$fieldname] = array_values($field_messages);
441
                }
442
 
443
                return new JsonModel([
444
                    'success' => false,
445
                    'data' => $messages
446
                ]);
447
            }
448
        } else if ($request->isGet()) {
449
            $hydrator = new ObjectPropertyHydrator();
450
 
1441 eleazar 451
            $locationMapper = LocationMapper::getInstance($this->adapter);
1575 eleazar 452
            $location = $locationMapper->fetchOne($vacancy->location_id);
1441 eleazar 453
 
1384 efrain 454
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1575 eleazar 455
            $jobDescription = $jobDescriptionMapper->fetchOne($vacancy->job_description_id);
10258 stevensc 456
            $jobDescritions = [];
1445 eleazar 457
 
10258 stevensc 458
            $records = $currentCompany ?
12314 stevensc 459
                $jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id) :
460
                $jobDescriptionMapper->fetchAllByDefault();
461
 
462
            foreach ($records as $record) {
10258 stevensc 463
                $jobDescritions[$record->uuid] = $record->name;
464
            }
465
 
1445 eleazar 466
            $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
1575 eleazar 467
            $jobCategory = $jobCategoryMapper->fetchOne($vacancy->job_category_id);
10254 stevensc 468
            $jobCategories = [];
1445 eleazar 469
 
15087 efrain 470
            $records = $jobCategoryMapper->fetchAllActive();
12314 stevensc 471
 
472
            foreach ($records as $record) {
10254 stevensc 473
                $jobCategories[$record->uuid] = $record->name;
10112 stevensc 474
            }
475
 
1445 eleazar 476
            $industryMapper = IndustryMapper::getInstance($this->adapter);
1575 eleazar 477
            $industry = $industryMapper->fetchOne($vacancy->industry_id);
10254 stevensc 478
            $industries = [];
1445 eleazar 479
 
15087 efrain 480
            $records = $industryMapper->fetchAllActive();
12314 stevensc 481
 
482
            foreach ($records as $record) {
10254 stevensc 483
                $industries[$record->uuid] = $record->name;
484
            }
485
 
12314 stevensc 486
 
1384 efrain 487
            if (!$jobDescription) {
488
                $data = [
489
                    'success' => false,
490
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
491
                ];
492
 
493
                return new JsonModel($data);
494
            }
15087 efrain 495
 
1384 efrain 496
 
15087 efrain 497
            $dt = \DateTime::createFromFormat('Y-m-d', $vacancy->last_date);
498
            $last_date = $dt->format('m/d/Y');
499
 
1384 efrain 500
            $data = [
501
                'success' => true,
502
                'data' => [
1575 eleazar 503
                    'id' => $vacancy->uuid,
504
                    'name' => $vacancy->name,
10258 stevensc 505
                    'job_description' => [
506
                        'description_options' => $jobDescritions,
507
                        'current_description' => [
508
                            'description_id' => $jobDescription->uuid,
509
                            'description_name' => $jobDescription->name
510
                        ]
511
                    ],
1572 eleazar 512
                    'location_search' => $location->formatted_address,
1570 eleazar 513
                    'formatted_address' => $location->formatted_address,
1572 eleazar 514
                    'address1' => $location->address1,
515
                    'address2' => $location->address2,
1568 eleazar 516
                    'country' => $location->country,
517
                    'state' => $location->state,
12314 stevensc 518
                    'city1' => $location->city1,
1568 eleazar 519
                    'city2' => $location->city2,
520
                    'postal_code' => $location->postal_code,
521
                    'latitude' => $location->latitude,
522
                    'longitude' => $location->longitude,
10112 stevensc 523
                    'job_category' => [
10254 stevensc 524
                        'category_options' => $jobCategories,
525
                        'current_category' => [
10112 stevensc 526
                            'job_category_id' => $jobCategory->uuid,
527
                            'job_category_name' => $jobCategory->name,
528
                        ]
529
                    ],
1575 eleazar 530
                    'description' => $vacancy->description,
10254 stevensc 531
                    'industry' => [
532
                        'industry_options' => $industries,
533
                        'current_industry' => [
534
                            'industry_id' => $industry->uuid,
535
                            'industry_name' => $industry->name,
536
                        ]
12314 stevensc 537
                    ],
15087 efrain 538
                    'last_date' => $last_date,
1575 eleazar 539
                    'status' => $vacancy->status,
12314 stevensc 540
                    // 'content' => $vacancy->content ? json_decode($vacancy->content) : [],
1384 efrain 541
                ]
542
            ];
543
 
544
            return new JsonModel($data);
545
        } else {
546
            $data = [
547
                'success' => false,
1574 eleazar 548
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1384 efrain 549
            ];
550
 
551
            return new JsonModel($data);
552
        }
553
 
554
        return new JsonModel($data);
555
    }
556
 
12314 stevensc 557
    public function deleteAction()
558
    {
1384 efrain 559
        $request = $this->getRequest();
560
        $currentUserPlugin = $this->plugin('currentUserPlugin');
561
        $currentCompany = $currentUserPlugin->getCompany();
562
        $currentUser = $currentUserPlugin->getUser();
563
 
564
        $request = $this->getRequest();
565
        $uuid = $this->params()->fromRoute('id');
566
 
567
        if (!$uuid) {
568
            $data = [
569
                'success' => false,
570
                'data' => 'ERROR_INVALID_PARAMETER'
571
            ];
572
 
573
            return new JsonModel($data);
574
        }
575
 
1386 eleazar 576
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1539 eleazar 577
        $vacancyMapper = $recruitmentSelectionVacancyMapper->fetchOneByUuid($uuid);
578
        if (!$vacancyMapper) {
1384 efrain 579
            $data = [
580
                'success' => false,
581
                'data' => 'ERROR_RECORD_NOT_FOUND'
582
            ];
583
 
584
            return new JsonModel($data);
585
        }
586
 
1544 eleazar 587
        if ($vacancyMapper->company_id != $currentCompany->id) {
1384 efrain 588
            return new JsonModel([
589
                'success' => false,
590
                'data' => 'ERROR_UNAUTHORIZED'
591
            ]);
592
        }
593
 
594
        if ($request->isPost()) {
595
 
596
 
1539 eleazar 597
            $result = $recruitmentSelectionVacancyMapper->delete($vacancyMapper->id);
1384 efrain 598
            if ($result) {
1539 eleazar 599
                $this->logger->info('Se borro el formulario de reclutamiento ' . $vacancyMapper->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1384 efrain 600
 
601
                $data = [
602
                    'success' => true,
603
                    'data' => 'LABEL_RECORD_DELETED'
604
                ];
605
            } else {
606
 
607
                $data = [
608
                    'success' => false,
1386 eleazar 609
                    'data' => $recruitmentSelectionVacancyMapper->getError()
1384 efrain 610
                ];
611
 
612
                return new JsonModel($data);
613
            }
614
        } else {
615
            $data = [
616
                'success' => false,
617
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
618
            ];
619
 
620
            return new JsonModel($data);
621
        }
622
 
623
        return new JsonModel($data);
624
    }
625
}