Proyectos de Subversion LeadersLinked - Backend

Rev

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