Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 16766 | Rev 16769 | 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;
16768 efrain 8
 
1384 efrain 9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
15457 efrain 13
use LeadersLinked\Form\RecruitmentSelection\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;
15461 efrain 19
use LeadersLinked\Mapper\BehaviorMapper;
20
use LeadersLinked\Mapper\CompetencyMapper;
21
use LeadersLinked\Mapper\CompetencyTypeMapper;
22
use LeadersLinked\Mapper\JobDescriptionCompetencyBehaviorMapper;
23
use LeadersLinked\Mapper\JobDescriptionCompetencyMapper;
24
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
1384 efrain 25
use LeadersLinked\Mapper\LocationMapper;
26
use LeadersLinked\Mapper\IndustryMapper;
27
use LeadersLinked\Mapper\JobDescriptionMapper;
28
use LeadersLinked\Mapper\JobCategoryMapper;
15457 efrain 29
use Laminas\Paginator\Adapter\DbSelect;
30
use Laminas\Paginator\Paginator;
31
use LeadersLinked\Mapper\QueryMapper;
32
use Laminas\Hydrator\ArraySerializableHydrator;
33
use Laminas\Db\ResultSet\HydratingResultSet;
1384 efrain 34
 
12314 stevensc 35
class RecruitmentSelectionVacancyController extends AbstractActionController
36
{
1384 efrain 37
 
38
    /**
39
     *
40
     * @var AdapterInterface
41
     */
42
    private $adapter;
16768 efrain 43
 
1384 efrain 44
    /**
45
     *
46
     * @var  LoggerInterface
47
     */
48
    private $logger;
16768 efrain 49
 
1384 efrain 50
    /**
51
     *
52
     * @var array
53
     */
54
    private $config;
16768 efrain 55
 
1384 efrain 56
    /**
57
     *
58
     * @param AdapterInterface $adapter
59
     * @param LoggerInterface $logger
60
     * @param array $config
61
     */
16768 efrain 62
    public function __construct($adapter, $logger, $config)
12314 stevensc 63
    {
1384 efrain 64
        $this->adapter = $adapter;
65
        $this->logger = $logger;
66
        $this->config = $config;
67
    }
68
 
12314 stevensc 69
    public function indexAction()
70
    {
1384 efrain 71
        $request = $this->getRequest();
72
        $currentUserPlugin = $this->plugin('currentUserPlugin');
73
        $currentCompany = $currentUserPlugin->getCompany();
74
        $currentUser = $currentUserPlugin->getUser();
75
 
76
 
77
        $request = $this->getRequest();
78
        if ($request->isGet()) {
79
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
12314 stevensc 80
            if ($sandbox) {
1384 efrain 81
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
82
            } else {
83
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
84
            }
85
 
12314 stevensc 86
 
1384 efrain 87
            $headers = $request->getHeaders();
88
 
89
            $isJson = false;
90
            if ($headers->has('Accept')) {
91
                $accept = $headers->get('Accept');
92
 
93
                $prioritized = $accept->getPrioritized();
94
 
95
                foreach ($prioritized as $key => $value) {
96
                    $raw = trim($value->getRaw());
97
 
98
                    if (!$isJson) {
99
                        $isJson = strpos($raw, 'json');
100
                    }
101
                }
102
            }
103
 
104
            //$isJson = true;
105
            if ($isJson) {
10093 stevensc 106
                $search = $this->params()->fromQuery('search');
16766 efrain 107
                $search = empty($search) ? '' : Functions::sanitizeFilterString($search);
1384 efrain 108
 
15371 efrain 109
                $start = intval($this->params()->fromQuery('start', 0), 10);
1384 efrain 110
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
15371 efrain 111
                $page =  intval($start / $records_x_page);
112
                $page++;
113
 
1384 efrain 114
                $order = $this->params()->fromQuery('order', []);
115
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
16766 efrain 116
                $order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
1384 efrain 117
 
118
                $fields = ['name'];
119
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
120
 
121
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
122
                    $order_direction = 'ASC';
123
                }
124
 
1434 eleazar 125
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
1477 efrain 126
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/vacancies/delete');
127
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'recruitment-and-selection/vacancies/edit');
1434 eleazar 128
 
12314 stevensc 129
 
15457 efrain 130
                $queryMapper = QueryMapper::getInstance($this->adapter);
131
                $select = $queryMapper->getSql()->select();
132
                $select->from(['tb1' => RecruitmentSelectionVacancyMapper::_TABLE]);
133
                $select->columns(['uuid', 'name', 'last_date', 'status']);
134
                $select->join(['tb2' => JobDescriptionMapper::_TABLE], 'tb1.job_description_id = tb2.id AND tb1.company_id = tb2.company_id', ['job_description' => 'name']);
135
 
136
                $select->where->equalTo('tb1.company_id', $currentCompany->network_id);
137
 
138
                if($search) {
139
                    $select->where->like('tb1.name', '%' . $search . '%');
140
                }
141
                $select->order($order_field . ' ' . $order_direction);
142
 
143
                //echo $select->getSqlString($this->adapter->platform); exit;
144
 
145
                $hydrator   = new ArraySerializableHydrator();
146
                $resultset  = new HydratingResultSet($hydrator);
147
 
148
                $adapter = new DbSelect($select, $queryMapper->getSql(), $resultset);
149
                $paginator = new Paginator($adapter);
150
                $paginator->setItemCountPerPage($records_x_page);
151
                $paginator->setCurrentPageNumber($page);
152
 
153
 
1384 efrain 154
 
155
                $items = [];
156
                $records = $paginator->getCurrentItems();
12314 stevensc 157
 
1384 efrain 158
                foreach ($records as $record) {
15457 efrain 159
                    $dt = \DateTime::createFromFormat('Y-m-d', $record['last_date']);
160
 
15461 efrain 161
 
162
 
15457 efrain 163
                    switch($record['status'])
164
                    {
165
                        case RecruitmentSelectionVacancy::STATUS_ACTIVE :
166
                            $status = 'LABEL_ACTIVE';
167
                            break;
168
 
169
                        case RecruitmentSelectionVacancy::STATUS_INACTIVE :
170
                            $status = 'LABEL_INACTIVE';
171
                            break;
172
 
173
                        case RecruitmentSelectionVacancy::STATUS_EXPIRED :
174
                            $status = 'LABEL_EXPIRED';
175
                            break;
176
 
177
                        case RecruitmentSelectionVacancy::STATUS_COMPLETED :
178
                            $status = 'LABEL_COMPLETED';
179
                            break;
180
 
181
                        default :
182
                            $status = 'LABEL_UNKNOWN';
183
                            break;
184
 
1384 efrain 185
                    }
15457 efrain 186
 
15461 efrain 187
 
188
                    if($record['status'] == RecruitmentSelectionVacancy::STATUS_ACTIVE || $record['status'] ==  RecruitmentSelectionVacancy::STATUS_INACTIVE) {
189
                        $actions = [
190
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('recruitment-and-selection/vacancies/edit', ['id' => $record['uuid']]) : '',
191
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('recruitment-and-selection/vacancies/delete', ['id' => $record['uuid']]) : ''
192
                        ];
193
                    } else {
194
 
195
                        $actions = [
196
                            'link_edit' => '',
197
                            'link_delete' => '',
198
                        ];
199
                    }
200
 
15457 efrain 201
                    $item = [
202
                      'name' => $record['name'],
203
                      'job_description' => $record['job_description'],
204
                      'last_date' => $dt->format('d/m/Y'),
15461 efrain 205
                      'status' => $status,
206
                      'actions' =>  $actions,
15457 efrain 207
                    ];
208
 
1384 efrain 209
 
210
                    array_push($items, $item);
211
                }
212
 
213
                return new JsonModel([
214
                    'success' => true,
215
                    'data' => [
216
                        'items' => $items,
217
                        'total' => $paginator->getTotalItemCount(),
218
                    ]
219
                ]);
220
            } else {
221
 
1544 eleazar 222
                $form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
1384 efrain 223
 
1549 eleazar 224
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
225
                $industryMapper = industryMapper::getInstance($this->adapter);
12314 stevensc 226
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
227
 
228
                $jobDescritions = [];
229
                $industries = [];
230
                $jobCategories = [];
231
 
15087 efrain 232
                $records = $jobCategoryMapper->fetchAllActive();
12314 stevensc 233
 
234
                foreach ($records as $record) {
235
                    $jobCategories[$record->uuid] = $record->name;
236
                }
237
 
15087 efrain 238
                $records = $industryMapper->fetchAllActive();
12314 stevensc 239
 
240
                foreach ($records as $record) {
241
                    $industries[$record->uuid] = $record->name;
242
                }
243
 
244
                $records = $currentCompany ?
245
                    $jobDescriptionMapper->fetchAllActiveByCompanyId($currentCompany->id) :
15087 efrain 246
                    $jobDescriptionMapper->fetchAllActiveByDefault();
247
 
12314 stevensc 248
                foreach ($records as $record) {
249
                    $jobDescritions[$record->uuid] = $record->name;
250
                }
251
 
15087 efrain 252
 
253
                //print_r($jobDescritions); exit;
254
 
1384 efrain 255
                $this->layout()->setTemplate('layout/layout-backend');
256
                $viewModel = new ViewModel();
1396 eleazar 257
                $viewModel->setTemplate('leaders-linked/recruitment-and-selection-vacancies/index.phtml');
1384 efrain 258
                $viewModel->setVariable('form', $form);
10112 stevensc 259
                $viewModel->setVariable('google_map_key', $google_map_key);
12314 stevensc 260
                $viewModel->setVariable('jobDescritions', $jobDescritions);
261
                $viewModel->setVariable('industries', $industries);
262
                $viewModel->setVariable('jobCategories', $jobCategories);
1561 efrain 263
 
1384 efrain 264
                return $viewModel;
265
            }
266
        } else {
267
            return new JsonModel([
268
                'success' => false,
269
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
12314 stevensc 270
            ]);;
1384 efrain 271
        }
272
    }
273
 
12314 stevensc 274
    public function addAction()
275
    {
1384 efrain 276
        $request = $this->getRequest();
277
        $currentUserPlugin = $this->plugin('currentUserPlugin');
278
        $currentCompany = $currentUserPlugin->getCompany();
279
        $currentUser = $currentUserPlugin->getUser();
280
 
281
        $request = $this->getRequest();
282
 
283
 
284
        if ($request->isPost()) {
1544 eleazar 285
            $form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
1384 efrain 286
            $dataPost = $request->getPost()->toArray();
15087 efrain 287
 
288
 
15461 efrain 289
            if(!empty($dataPost['last_date'])) {
290
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
291
                if($dt) {
292
                    $dataPost['last_date'] = $dt->format('Y-m-d');
293
                } else {
294
                    $dataPost['last_date'] = date('Y-m-d');
295
                }
296
            }
297
 
15087 efrain 298
 
299
 
1387 eleazar 300
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionVacancy::STATUS_INACTIVE;
1384 efrain 301
 
302
            $form->setData($dataPost);
303
 
304
            if ($form->isValid()) {
305
                $dataPost = (array) $form->getData();
306
 
15087 efrain 307
 
1384 efrain 308
                $hydrator = new ObjectPropertyHydrator();
309
 
1417 eleazar 310
                $location = new Location();
311
                $hydrator->hydrate($dataPost, $location);
12314 stevensc 312
 
313
                $locationMapper = LocationMapper::getInstance($this->adapter);
1452 eleazar 314
                $result = $locationMapper->insert($location);
1451 eleazar 315
 
1417 eleazar 316
 
1418 eleazar 317
                if (!$result) {
318
                    return new JsonModel([
319
                        'success'   => false,
15461 efrain 320
                        'data' => $locationMapper->getError()
1418 eleazar 321
                    ]);
322
                }
1417 eleazar 323
 
1539 eleazar 324
                $vacancy = new RecruitmentSelectionVacancy();
325
                $hydrator->hydrate($dataPost, $vacancy);
1427 eleazar 326
 
1539 eleazar 327
                $vacancy->location_id = $location->id;
1544 eleazar 328
                $vacancy->company_id = $currentCompany->id;
1384 efrain 329
 
1427 eleazar 330
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
331
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
1539 eleazar 332
                $vacancy->job_description_id = $jobDescription->id;
15461 efrain 333
                $vacancy->content =  $this->serialize($jobDescription);
1427 eleazar 334
 
335
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
12314 stevensc 336
                $jobCategory = $jobCategoryMapper->fetchOneByUuid($dataPost['job_category_id']);
1539 eleazar 337
                $vacancy->job_category_id = $jobCategory->id;
1427 eleazar 338
 
1428 eleazar 339
                $industryMapper = IndustryMapper::getInstance($this->adapter);
340
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
1539 eleazar 341
                $vacancy->industry_id = $industry->id;
1425 eleazar 342
 
1539 eleazar 343
                $vacancy->description = $dataPost['description'];
12314 stevensc 344
 
1428 eleazar 345
 
15087 efrain 346
 
1427 eleazar 347
                $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1539 eleazar 348
                $result = $recruitmentSelectionVacancyMapper->insert($vacancy);
1384 efrain 349
 
350
                if ($result) {
15461 efrain 351
                    $this->logger->info('Se agrego la vacante : ' . $vacancy->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1384 efrain 352
 
353
                    $data = [
354
                        'success' => true,
355
                        'data' => 'LABEL_RECORD_ADDED'
356
                    ];
357
                } else {
358
                    $data = [
359
                        'success' => false,
1412 eleazar 360
                        'data' => $recruitmentSelectionVacancyMapper->getError()
1384 efrain 361
                    ];
362
                }
363
 
364
                return new JsonModel($data);
365
            } else {
366
                $messages = [];
367
                $form_messages = (array) $form->getMessages();
368
                foreach ($form_messages as $fieldname => $field_messages) {
369
 
370
                    $messages[$fieldname] = array_values($field_messages);
371
                }
372
 
373
                return new JsonModel([
374
                    'success' => false,
375
                    'data' => $messages
376
                ]);
377
            }
378
        } else {
379
            $data = [
380
                'success' => false,
1575 eleazar 381
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1384 efrain 382
            ];
383
 
384
            return new JsonModel($data);
385
        }
386
 
387
        return new JsonModel($data);
388
    }
389
 
12314 stevensc 390
    public function editAction()
391
    {
1384 efrain 392
        $request = $this->getRequest();
393
        $currentUserPlugin = $this->plugin('currentUserPlugin');
394
        $currentCompany = $currentUserPlugin->getCompany();
395
        $currentUser = $currentUserPlugin->getUser();
396
 
397
        $request = $this->getRequest();
398
        $uuid = $this->params()->fromRoute('id');
399
 
400
 
401
        if (!$uuid) {
402
            $data = [
403
                'success' => false,
404
                'data' => 'ERROR_INVALID_PARAMETER'
405
            ];
406
 
407
            return new JsonModel($data);
408
        }
409
 
1386 eleazar 410
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1575 eleazar 411
        $vacancy = $recruitmentSelectionVacancyMapper->fetchOneByUuid($uuid);
412
        if (!$vacancy) {
1384 efrain 413
            $data = [
414
                'success' => false,
415
                'data' => 'ERROR_RECORD_NOT_FOUND'
416
            ];
417
 
418
            return new JsonModel($data);
419
        }
420
 
1575 eleazar 421
        if ($vacancy->company_id != $currentCompany->id) {
1384 efrain 422
            return new JsonModel([
423
                'success' => false,
424
                'data' => 'ERROR_UNAUTHORIZED'
425
            ]);
426
        }
427
 
428
 
429
        if ($request->isPost()) {
1544 eleazar 430
            $form = new RecruitmentSelectionVacancyForm($this->adapter, $currentCompany->id);
1384 efrain 431
            $dataPost = $request->getPost()->toArray();
15461 efrain 432
 
433
            if(!empty($dataPost['last_date'])) {
434
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
435
                if($dt) {
436
                    $dataPost['last_date'] = $dt->format('Y-m-d');
437
                } else {
438
                    $dataPost['last_date'] = date('Y-m-d');
439
                }
440
            }
441
 
1387 eleazar 442
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : RecruitmentSelectionVacancy::STATUS_INACTIVE;
1384 efrain 443
 
444
            $form->setData($dataPost);
445
 
446
            if ($form->isValid()) {
447
                $dataPost = (array) $form->getData();
448
 
449
                $hydrator = new ObjectPropertyHydrator();
1575 eleazar 450
                $hydrator->hydrate($dataPost, $vacancy);
1384 efrain 451
 
1575 eleazar 452
                if (!$vacancy->status) {
453
                    $vacancy->status = RecruitmentSelectionVacancy::STATUS_INACTIVE;
1384 efrain 454
                }
15118 efrain 455
 
1578 eleazar 456
                $locationMapper = LocationMapper::getInstance($this->adapter);
457
                $location = $locationMapper->fetchOne($vacancy->location_id);
458
                $hydrator->hydrate($dataPost, $location);
459
                $locationMapper->update($location);
460
 
1384 efrain 461
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
462
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
1575 eleazar 463
                $vacancy->job_description_id = $jobDescription->id;
1384 efrain 464
 
1439 eleazar 465
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
12314 stevensc 466
                $jobCategory = $jobCategoryMapper->fetchOneByUuid($dataPost['job_category_id']);
1575 eleazar 467
                $vacancy->job_category_id = $jobCategory->id;
1384 efrain 468
 
1439 eleazar 469
                $industryMapper = IndustryMapper::getInstance($this->adapter);
470
                $industry = $industryMapper->fetchOneByUuid($dataPost['industry_id']);
1575 eleazar 471
                $vacancy->industry_id = $industry->id;
15461 efrain 472
 
1439 eleazar 473
 
1577 eleazar 474
                $result = $recruitmentSelectionVacancyMapper->update($vacancy);
1439 eleazar 475
 
12314 stevensc 476
 
1384 efrain 477
                if ($result) {
15461 efrain 478
                    $this->logger->info('Se actualizo la vancante : ' . $vacancy->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1384 efrain 479
                    $data = [
480
                        'success' => true,
481
                        'data' => 'LABEL_RECORD_UPDATED'
482
                    ];
483
                } else {
484
                    $data = [
485
                        'success' => false,
1386 eleazar 486
                        'data' => $recruitmentSelectionVacancyMapper->getError()
1384 efrain 487
                    ];
488
                }
489
 
490
                return new JsonModel($data);
491
            } else {
492
                $messages = [];
493
                $form_messages = (array) $form->getMessages();
494
                foreach ($form_messages as $fieldname => $field_messages) {
495
                    $messages[$fieldname] = array_values($field_messages);
496
                }
497
 
498
                return new JsonModel([
499
                    'success' => false,
500
                    'data' => $messages
501
                ]);
502
            }
503
        } else if ($request->isGet()) {
504
            $hydrator = new ObjectPropertyHydrator();
505
 
1441 eleazar 506
            $locationMapper = LocationMapper::getInstance($this->adapter);
1575 eleazar 507
            $location = $locationMapper->fetchOne($vacancy->location_id);
1441 eleazar 508
 
1384 efrain 509
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
1575 eleazar 510
            $jobDescription = $jobDescriptionMapper->fetchOne($vacancy->job_description_id);
15461 efrain 511
 
512
            $jobCategoryMapper =  JobCategoryMapper::getInstance($this->adapter);
1575 eleazar 513
            $jobCategory = $jobCategoryMapper->fetchOne($vacancy->job_category_id);
15461 efrain 514
 
1445 eleazar 515
            $industryMapper = IndustryMapper::getInstance($this->adapter);
1575 eleazar 516
            $industry = $industryMapper->fetchOne($vacancy->industry_id);
15087 efrain 517
 
15461 efrain 518
 
15087 efrain 519
            $dt = \DateTime::createFromFormat('Y-m-d', $vacancy->last_date);
15461 efrain 520
            $last_date = $dt->format('d/m/Y');
15087 efrain 521
 
1384 efrain 522
            $data = [
523
                'success' => true,
524
                'data' => [
1575 eleazar 525
                    'name' => $vacancy->name,
15461 efrain 526
                    'job_description_id' =>  $jobDescription->uuid,
527
                    'job_category_id' => $jobCategory->uuid,
528
                    'industry_id' => $industry->uuid,
1572 eleazar 529
                    'location_search' => $location->formatted_address,
1570 eleazar 530
                    'formatted_address' => $location->formatted_address,
1572 eleazar 531
                    'address1' => $location->address1,
532
                    'address2' => $location->address2,
1568 eleazar 533
                    'country' => $location->country,
534
                    'state' => $location->state,
12314 stevensc 535
                    'city1' => $location->city1,
1568 eleazar 536
                    'city2' => $location->city2,
537
                    'postal_code' => $location->postal_code,
538
                    'latitude' => $location->latitude,
539
                    'longitude' => $location->longitude,
1575 eleazar 540
                    'description' => $vacancy->description,
15087 efrain 541
                    'last_date' => $last_date,
1575 eleazar 542
                    'status' => $vacancy->status,
15461 efrain 543
 
1384 efrain 544
                ]
545
            ];
546
 
15461 efrain 547
 
1384 efrain 548
        } else {
549
            $data = [
550
                'success' => false,
1574 eleazar 551
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
1384 efrain 552
            ];
553
 
15461 efrain 554
 
1384 efrain 555
        }
556
 
557
        return new JsonModel($data);
558
    }
559
 
12314 stevensc 560
    public function deleteAction()
561
    {
1384 efrain 562
        $request = $this->getRequest();
563
        $currentUserPlugin = $this->plugin('currentUserPlugin');
564
        $currentCompany = $currentUserPlugin->getCompany();
565
        $currentUser = $currentUserPlugin->getUser();
566
 
567
        $request = $this->getRequest();
568
        $uuid = $this->params()->fromRoute('id');
569
 
570
        if (!$uuid) {
571
            $data = [
572
                'success' => false,
573
                'data' => 'ERROR_INVALID_PARAMETER'
574
            ];
575
 
576
            return new JsonModel($data);
577
        }
578
 
1386 eleazar 579
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
1539 eleazar 580
        $vacancyMapper = $recruitmentSelectionVacancyMapper->fetchOneByUuid($uuid);
581
        if (!$vacancyMapper) {
1384 efrain 582
            $data = [
583
                'success' => false,
584
                'data' => 'ERROR_RECORD_NOT_FOUND'
585
            ];
586
 
587
            return new JsonModel($data);
588
        }
589
 
1544 eleazar 590
        if ($vacancyMapper->company_id != $currentCompany->id) {
1384 efrain 591
            return new JsonModel([
592
                'success' => false,
593
                'data' => 'ERROR_UNAUTHORIZED'
594
            ]);
595
        }
596
 
597
        if ($request->isPost()) {
598
 
599
 
1539 eleazar 600
            $result = $recruitmentSelectionVacancyMapper->delete($vacancyMapper->id);
1384 efrain 601
            if ($result) {
1539 eleazar 602
                $this->logger->info('Se borro el formulario de reclutamiento ' . $vacancyMapper->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1384 efrain 603
 
604
                $data = [
605
                    'success' => true,
606
                    'data' => 'LABEL_RECORD_DELETED'
607
                ];
608
            } else {
609
 
610
                $data = [
611
                    'success' => false,
1386 eleazar 612
                    'data' => $recruitmentSelectionVacancyMapper->getError()
1384 efrain 613
                ];
614
 
615
                return new JsonModel($data);
616
            }
617
        } else {
618
            $data = [
619
                'success' => false,
620
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
621
            ];
622
 
623
            return new JsonModel($data);
624
        }
625
 
626
        return new JsonModel($data);
627
    }
15461 efrain 628
 
629
 
630
 
631
    public function serialize($jobDescription)
632
    {
633
 
634
 
635
 
636
 
637
        $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
638
        $competencyMapper = CompetencyMapper::getInstance($this->adapter);
639
        $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
640
 
641
        $competencyTypes = [];
642
        $competencies = [];
643
        $behaviors = [];
644
        $competencies_selected = [];
645
        $subordinates_selected = [];
646
 
647
        $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
648
        $jobDescriptionCompetencyBehaviorMapper = JobDescriptionCompetencyBehaviorMapper::getInstance($this->adapter);
649
 
650
        $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchAllByJobDescriptionId($jobDescription->id);
651
        foreach($jobDescriptionCompetencies as $jobDescriptionCompetency)
652
        {
653
 
654
            if(isset($competencies[$jobDescriptionCompetency->competency_id])) {
655
                $competency = $competencies[$jobDescriptionCompetency->competency_id];
656
            } else {
657
 
658
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
659
                if(!$competency) {
660
                    continue;
661
                }
662
 
663
 
664
 
665
                $competencies[$jobDescriptionCompetency->competency_id] = new \stdClass();
666
                $competencies[$jobDescriptionCompetency->competency_id]->uuid = $competency->uuid;
667
                $competencies[$jobDescriptionCompetency->competency_id]->name = $competency->name;
668
                $competencies[$jobDescriptionCompetency->competency_id]->description = $competency->description;
669
 
670
            }
671
 
672
 
673
            if(isset($competencyTypes[$competency->competency_type_id])) {
674
                $competencyType = $competencyTypes[$competency->competency_type_id];
675
            } else {
676
 
677
                $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
678
                if(!$competencyType) {
679
                    continue;
680
                }
681
 
682
                $competencyTypes[$competency->competency_type_id] = new \stdClass();
683
                $competencyTypes[$competency->competency_type_id]->uuid = $competencyType->uuid;
684
                $competencyTypes[$competency->competency_type_id]->name = $competencyType->name;
685
                $competencyTypes[$competency->competency_type_id]->description = $competencyType->description;
686
 
687
            }
688
 
689
            $competency_selected = [
690
                'uuid' => $competency->uuid,
691
                'competency_type_uuid' => $competencyType->uuid,
692
                'behaviors' => []
693
            ];
694
 
695
 
696
            $jobDescriptionCompetencyBehaviors = $jobDescriptionCompetencyBehaviorMapper->fetchAllByJobDescriptionIdAndCompetencyId($jobDescriptionCompetency->job_description_id, $jobDescriptionCompetency->competency_id);
697
            foreach($jobDescriptionCompetencyBehaviors as $jobDescriptionCompetencyBehavior)
698
            {
699
 
700
 
701
                if(isset($behaviors[$jobDescriptionCompetencyBehavior->behavior_id])) {
702
                    $behavior = $behaviors[$jobDescriptionCompetencyBehavior->behavior_id];
703
                } else {
704
 
705
                    $behavior = $behaviorMapper->fetchOne($jobDescriptionCompetencyBehavior->behavior_id);
706
                    if(!$behavior) {
707
 
708
                        continue;
709
                    }
710
 
711
                    $behaviors[$jobDescriptionCompetencyBehavior->behavior_id] = new \stdClass();
712
                    $behaviors[$jobDescriptionCompetencyBehavior->behavior_id]->uuid = $behavior->uuid;
713
                    $behaviors[$jobDescriptionCompetencyBehavior->behavior_id]->description = $behavior->description;
714
 
715
                }
716
 
717
 
718
 
719
 
720
                array_push($competency_selected['behaviors'], ['uuid' => $behavior->uuid, 'level' => $jobDescriptionCompetencyBehavior->level]);
721
 
722
 
723
            }
724
 
725
            array_push($competencies_selected, $competency_selected);
726
 
727
 
728
 
729
        }
730
 
731
 
732
        $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
733
 
734
        $jobDescriptionSubordinateMapper = JobDescriptionSubordinateMapper::getInstance($this->adapter);
735
        $jobDescriptionSubordinates = $jobDescriptionSubordinateMapper->fetchAllByJobDescriptionIdTopLevel($jobDescription->id);
736
 
737
        foreach($jobDescriptionSubordinates as $jobDescriptionSubordinate)
738
        {
739
            $jobDescriptionForSubordinate = $jobDescriptionMapper->fetchOne($jobDescriptionSubordinate->job_description_id_low_level);
740
            if($jobDescriptionForSubordinate) {
741
                array_push($subordinates_selected, ['uuid' => $jobDescriptionForSubordinate->uuid ]);
742
            }
743
 
744
 
745
 
746
        }
747
 
748
        if($jobDescription->job_description_id_boss) {
749
 
750
            $jobDescriptionBoss = $jobDescriptionMapper->fetchOne($jobDescription->job_description_id_boss);
751
            if($jobDescriptionBoss) {
752
                $job_description_id_boss = $jobDescriptionBoss->uuid;
753
            }
754
        } else {
755
            $job_description_id_boss = '';
756
        }
757
 
758
        $content = [
759
            'uuid' => $jobDescription->uuid,
760
            'name' => $jobDescription->name,
761
            'functions' => $jobDescription->functions,
762
            'objectives' => $jobDescription->objectives,
763
            'job_description_id_boss' => $job_description_id_boss,
764
            'competency_types' => $competencyTypes,
765
            'competencies' => $competencies,
766
            'behaviors' => $behaviors,
767
            'competencies_selected' => $competencies_selected,
768
            'subordinates_selected' => $subordinates_selected,
769
 
770
        ];
771
 
772
        return json_encode($content);
773
    }
1384 efrain 774
}