Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
/**
3
 *
4
 * Controlador: Mis Perfiles
5
 *
6
 */
7
declare(strict_types=1);
8
 
9
namespace LeadersLinked\Controller;
10
 
11
use Laminas\Db\Adapter\AdapterInterface;
12
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
13
use Laminas\Mvc\Controller\AbstractActionController;
14
use Laminas\Log\LoggerInterface;
15
use Laminas\View\Model\ViewModel;
16
use Laminas\View\Model\JsonModel;
17
 
18
use LeadersLinked\Library\Functions;
19
 
20
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
21
use LeadersLinked\Mapper\CompanyUserMapper;
22
use LeadersLinked\Model\Job;
23
use LeadersLinked\Model\Location;
24
use LeadersLinked\Mapper\LocationMapper;
25
use LeadersLinked\Mapper\JobMapper;
26
use LeadersLinked\Mapper\CompanyMapper;
27
use LeadersLinked\Model\CompanyUser;
28
use LeadersLinked\Mapper\QueryMapper;
29
 
30
use LeadersLinked\Mapper\JobCategoryMapper;
31
use LeadersLinked\Form\CompanyJobExtendedForm;
32
use LeadersLinked\Form\CompanyJobLocationForm;
33
use LeadersLinked\Form\CompanyJobCreateForm;
34
use LeadersLinked\Form\CompanyJobCategoryForm;
35
use LeadersLinked\Form\CompanyJobEmploymentTypeForm;
36
use LeadersLinked\Form\CompanyJobExperienceForm;
37
use LeadersLinked\Form\CompanyJobSalaryForm;
38
use LeadersLinked\Form\CompanyJobDegreeForm;
39
use LeadersLinked\Form\CompanyJobLanguageForm;
40
use LeadersLinked\Form\CompanyJobSkillForm;
41
use LeadersLinked\Form\CompanyJobLastDateOfApplicationForm;
42
use LeadersLinked\Mapper\JobSkillMapper;
43
use LeadersLinked\Model\JobSkill;
44
use LeadersLinked\Model\JobDegree;
45
use LeadersLinked\Mapper\JobDegreeMapper;
46
use LeadersLinked\Model\JobLanguage;
47
use LeadersLinked\Mapper\JobLanguageMapper;
48
use LeadersLinked\Mapper\DegreeMapper;
49
use LeadersLinked\Mapper\LanguageMapper;
50
use LeadersLinked\Mapper\SkillMapper;
51
use LeadersLinked\Mapper\UserMapper;
52
use LeadersLinked\Model\User;
53
use Laminas\Paginator\Adapter\DbSelect;
54
use Laminas\Paginator\Paginator;
55
use LeadersLinked\Mapper\JobApplicationMapper;
56
use LeadersLinked\Mapper\UserProfileMapper;
57
use LeadersLinked\Mapper\IndustryMapper;
58
use LeadersLinked\Mapper\CurrencyMapper;
59
use LeadersLinked\Form\CompanyJobTitleForm;
60
use LeadersLinked\Form\CompanyJobStatusForm;
61
 
62
class JobController extends AbstractActionController
63
{
64
    /**
65
     *
66
     * @var AdapterInterface
67
     */
68
    private $adapter;
69
 
70
 
71
    /**
72
     *
73
     * @var AbstractAdapter
74
     */
75
    private $cache;
76
 
77
    /**
78
     *
79
     * @var  LoggerInterface
80
     */
81
    private $logger;
82
 
83
 
84
    /**
85
     *
86
     * @var array
87
     */
88
    private $config;
89
 
90
    /**
91
     *
92
     * @param AdapterInterface $adapter
93
     * @param AbstractAdapter $cache
94
     * @param LoggerInterface $logger
95
     * @param array $config
96
     */
97
    public function __construct($adapter, $cache , $logger,  $config)
98
    {
99
        $this->adapter      = $adapter;
100
        $this->cache        = $cache;
101
        $this->logger       = $logger;
102
        $this->config       = $config;
103
 
104
    }
105
 
106
    /**
107
     *
108
     * Generación del listado de perfiles
109
     * {@inheritDoc}
110
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
111
     */
112
    public function indexAction()
113
    {
114
        $currentUserPlugin = $this->plugin('currentUserPlugin');
115
        $currentUser = $currentUserPlugin->getUser();
116
        $currentCompany = $currentUserPlugin->getCompany();
117
 
118
 
119
 
120
 
121
        $request = $this->getRequest();
122
        if($request->isGet()) {
123
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
124
            if($sandbox) {
125
                $google_map_key  = $this->config['leaderslinked.google_map.sandbox_api_key'];
126
            } else {
127
                $google_map_key  = $this->config['leaderslinked.google_map.production_api_key'];
128
            }
129
 
130
            $headers  = $request->getHeaders();
131
 
132
            $isJson = false;
133
            if($headers->has('Accept')) {
134
                $accept = $headers->get('Accept');
135
 
136
                $prioritized = $accept->getPrioritized();
137
 
138
                foreach($prioritized as $key => $value) {
139
                    $raw = trim($value->getRaw());
140
 
141
                    if(!$isJson) {
142
                        $isJson = strpos($raw, 'json');
143
                    }
144
 
145
                }
146
            }
147
 
148
            if($isJson) {
7135 stevensc 149
                $search = $this->params()->fromQuery('search');
150
                $search = empty($search) ? '' : filter_var($search, FILTER_SANITIZE_STRING);
1 www 151
 
152
                $page               = intval($this->params()->fromQuery('start', 1), 10);
153
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
154
                $order =  $this->params()->fromQuery('order', []);
155
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
156
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
157
 
158
                $fields =  ['last_date_of_application', 'titlte'];
159
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'last_date_of_application';
160
 
161
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
162
                    $order_direction = 'ASC';
163
                }
164
 
165
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
166
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'jobs/delete');
167
 
168
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'jobs/edit');
169
                $allowUsersWhoApplied = $acl->isAllowed($currentUser->usertype_id, 'jobs/users-who-applied');
170
 
171
 
172
 
173
                $jobMapper = JobMapper::getInstance($this->adapter);
174
                $jobApplicationMapper = JobApplicationMapper::getInstance($this->adapter);
175
                $paginator = $jobMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
176
 
177
 
178
                $records = $paginator->getCurrentItems();
179
 
180
                $items = [];
181
                foreach($records as $record)
182
                {
183
 
184
                    switch($record->status) {
185
                        case  Job::STATUS_ACTIVE :
186
                            $status = 'LABEL_ACTIVE';
187
                            break;
188
 
189
                        case  Job::STATUS_INACTIVE :
190
                            $status = 'LABEL_INACTIVE';
191
                            break;
192
 
193
 
194
                        case  Job::STATUS_DELETED :
195
                            $status = 'LABEL_DELETED';
196
                            break;
197
 
198
                        default :
199
                            $status = '';
200
                            break;
201
                    }
202
 
203
                    switch($record->employment_type)
204
                    {
205
                        case Job::EMPLOYMENT_TYPE_FULL_TIME :
206
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
207
                            break;
208
                        case Job::EMPLOYMENT_TYPE_PART_TIME :
209
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
210
                            break;
211
 
212
                        case Job::EMPLOYMENT_TYPE_CONTRACT :
213
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
214
                            break;
215
 
216
                        case Job::EMPLOYMENT_TYPE_TEMPORARY :
217
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
218
                            break;
219
 
220
                        default :
221
                            $employment_type = '';
222
                            break;
223
                    }
224
 
225
                    $users_who_applied = $jobApplicationMapper->fetchTotalApplicationsByJobId($record->id);
226
 
227
 
228
                    $dt = \DateTime::createFromFormat('Y-m-d', $record->last_date_of_application );
229
 
230
 
231
                    $item = [
232
                        'last_date_of_application' => $dt->format('d/m/Y') ,
233
                        'title' => $record->title,
234
 
235
 
236
                        'details' => [
237
                            'status' => $status,
238
                            'employment_type' => $employment_type,
239
                            'users_who_applied' => $users_who_applied,
240
                        ],
241
                        'actions' => [
242
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('jobs/edit', ['id' => $record->uuid  ]) : '' ,
243
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('jobs/delete', [ 'id' => $record->uuid  ]) : '',
244
                            'link_users_who_applied'  => $allowUsersWhoApplied && $users_who_applied  ? $this->url()->fromRoute('jobs/users-who-applied', ['id' => $record->uuid ]) : '',
245
                         ]
246
                    ];
247
 
248
                    array_push($items, $item);
249
                }
250
 
251
 
252
 
253
 
254
                $response = [
255
                    'success' => true,
256
                    'data' => [
257
                        'items' => $items,
258
                        'total' => $paginator->getTotalItemCount(),
259
                    ]
260
                ];
261
 
262
                return new JsonModel($response);
263
 
264
 
265
            } else {
266
 
267
 
268
                $formAdd = new CompanyJobCreateForm($this->adapter);
269
                $formExtended = new CompanyJobExtendedForm();
270
                $formLocation = new CompanyJobLocationForm();
271
                $formEmploymentType = new CompanyJobEmploymentTypeForm();
272
                $formJobCategory = new CompanyJobCategoryForm($this->adapter);
273
                $formExperience = new CompanyJobExperienceForm();
274
                $formSalary = new CompanyJobSalaryForm($this->adapter);
275
                $fromLastDateOfApplication = new CompanyJobLastDateOfApplicationForm();
276
                $formDegree = new CompanyJobDegreeForm($this->adapter);
277
                $formLanguage = new CompanyJobLanguageForm($this->adapter);
278
                $formSkill = new CompanyJobSkillForm($this->adapter);
279
                $formStatus = new CompanyJobStatusForm();
280
                $formTitle = new CompanyJobTitleForm();
281
 
282
 
283
                $this->layout()->setTemplate('layout/layout-backend');
284
                $viewModel = new ViewModel();
285
                $viewModel->setTemplate('leaders-linked/jobs/index.phtml');
286
                $viewModel->setVariables([
287
                    'formAdd'                   => $formAdd,
288
                    'formLocation'              => $formLocation,
289
                    'formExtended'              => $formExtended,
290
                    'formEmploymentType'        => $formEmploymentType,
291
                    'formJobCategory'           => $formJobCategory,
292
                    'formExperience'            => $formExperience,
293
                    'formSalary'                => $formSalary,
294
                    'fromLastDateOfApplication' => $fromLastDateOfApplication,
295
                    'formDegree'                => $formDegree,
296
                    'formLanguage'              => $formLanguage,
297
                    'formSkill'                 => $formSkill,
298
                    'formStatus'                => $formStatus,
299
                    'formTitle'                 => $formTitle,
300
 
301
                    'google_map_key'    => $google_map_key,
302
 
303
                ]);
304
                return $viewModel ;
305
            }
306
 
307
        } else {
308
            return new JsonModel([
309
                'success' => false,
310
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
311
            ]);
312
        }
313
    }
314
 
315
    /**
316
     *
317
     * Agregar un nuevo perfil
318
     * @return \Laminas\View\Model\JsonModel
319
     */
320
    public function addAction()
321
    {
322
        $request = $this->getRequest();
323
 
324
 
325
        $currentUserPlugin = $this->plugin('currentUserPlugin');
326
        $currentUser = $currentUserPlugin->getUser();
327
        $currentCompany = $currentUserPlugin->getCompany();
328
 
329
 
330
 
331
        if($request->isPost()) {
332
            $form = new  CompanyJobCreateForm($this->adapter);
333
            $dataPost = $request->getPost()->toArray();
334
 
335
            $form->setData($dataPost);
336
 
337
            if($form->isValid()) {
338
                $companyMapper = CompanyMapper::getInstance($this->adapter);
339
                $company = $companyMapper->fetchOne($currentCompany->id);
340
 
341
 
342
                $dataPost = (array) $form->getData();
343
 
344
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
345
                $jobCategory = $jobCategoryMapper->fetchOneByUuid( $dataPost['job_category_id']);
346
 
347
 
348
 
349
                $hydrator = new ObjectPropertyHydrator();
350
                $location = new Location();
351
                $hydrator->hydrate($dataPost, $location);
352
 
353
 
354
                $locationMapper= LocationMapper::getInstance($this->adapter);
355
                $result = $locationMapper->insert($location);
356
 
357
                if($result) {
358
 
359
                    $job = new Job();
360
                    $hydrator->hydrate($dataPost, $job);
361
 
362
                    $job->location_id = $location->id;
363
                    $job->status = Job::STATUS_INACTIVE;
364
                    $job->company_id = $company->id;
365
                    $job->job_category_id = $jobCategory->id;
366
                    $job->description = '';
367
 
368
                    $last_date_of_application = $job->last_date_of_application;
369
 
370
                    $dt = \DateTime::createFromFormat('d/m/Y', $last_date_of_application);
371
                    if($dt) {
372
                        $job->last_date_of_application = $dt->format('Y-m-d');
373
                    }
374
 
375
 
376
 
377
                    $jobMapper = JobMapper::getInstance($this->adapter);
378
                    $result = $jobMapper->insert($job);
379
 
380
                    if($result) {
381
 
382
                        $this->logger->info('Se agrego el empleo : ' . $job->title . ' a  la empresa ' . $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
383
 
384
                        switch($job->employment_type)
385
                        {
386
                            case Job::EMPLOYMENT_TYPE_FULL_TIME :
387
                                $employment_type = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
388
                                break;
389
                            case Job::EMPLOYMENT_TYPE_PART_TIME :
390
                                $employment_type = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
391
                                break;
392
 
393
                            case Job::EMPLOYMENT_TYPE_CONTRACT :
394
                                $employment_type = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
395
                                break;
396
 
397
                            case Job::EMPLOYMENT_TYPE_TEMPORARY :
398
                                $employment_type = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
399
                                break;
400
 
401
                            default :
402
                                $employment_type = '';
403
                                break;
404
                        }
405
 
406
                        $months = [
407
                            1 => 'LABEL_MONTH_JANUARY',
408
                            2 => 'LABEL_MONTH_FEBRUARY',
409
                            3 => 'LABEL_MONTH_MARCH',
410
                            4 => 'LABEL_MONTH_APRIL',
411
                            5 => 'LABEL_MONTH_MAY',
412
                            6 => 'LABEL_MONTH_JUNE',
413
                            7 => 'LABEL_MONTH_JULY',
414
                            8 => 'LABEL_MONTH_AUGUST',
415
                            9 => 'LABEL_MONTH_SEPTEMBER',
416
                            10 => 'LABEL_MONTH_OCTOBER',
417
                            11 => 'LABEL_MONTH_NOVEMBER',
418
                            12 => 'LABEL_MONTH_DECEMBER',
419
                        ];
420
 
421
                        $dt = \DateTime::createFromFormat('Y-m-d', $job->last_date_of_application);
422
                        $last_date_of_application = $dt->format('d') . ' de ' . $months[$dt->format('n')] . ' de ' . $dt->format('Y');
423
 
424
                        $job = $jobMapper->fetchOne($job->id);
425
 
426
 
427
                        //'LABEL_RECORD_ADDED'
428
                        $response = [
429
                            'success'   => true,
430
                            'data'   => [
431
                                'title' => $job->title,
432
                                'status' => 'LABEL_INACTIVE',
433
                                'employment_type' => $employment_type,
434
                                'job_category' => $jobCategory->name,
435
                                'last_date_of_application' => $last_date_of_application,
436
                                'location'  => $location->formatted_address,
437
                                'route_status' => $this->url()->fromRoute('jobs/edit/status', [ 'id' => $job->uuid ]),
438
                                'route_title' => $this->url()->fromRoute('jobs/edit/title', [ 'id' => $job->uuid ]),
439
                                'route_extended' => $this->url()->fromRoute('jobs/edit/extended', [ 'id' => $job->uuid ]),
440
                                'route_location' => $this->url()->fromRoute('jobs/edit/location', [ 'id' => $job->uuid ]),
441
                                'route_job_category' => $this->url()->fromRoute('jobs/edit/job-category', [ 'id' => $job->uuid ]),
442
                                'route_employment_type' => $this->url()->fromRoute('jobs/edit/employment-type', [ 'id' => $job->uuid ]),
443
                                'route_salary' => $this->url()->fromRoute('jobs/edit/salary', [ 'id' => $job->uuid ]),
444
                                'route_experience' => $this->url()->fromRoute('jobs/edit/experience', [ 'id' => $job->uuid ]),
445
                                'route_languages' => $this->url()->fromRoute('jobs/edit/languages', [ 'id' => $job->uuid ]),
446
                                'route_degrees' => $this->url()->fromRoute('jobs/edit/degrees', [ 'id' => $job->uuid ]),
447
                                'route_skills' => $this->url()->fromRoute('jobs/edit/skills', [ 'id' => $job->uuid ]),
448
                                'route_last_date_of_application' => $this->url()->fromRoute('jobs/edit/last-date-of-application', [ 'id' => $job->uuid ]),
449
 
450
                            ]
451
                        ];
452
                    } else {
453
                        $response = [
454
                            'success'   => false,
455
                            'data' => 'ERROR_THERE_WAS_AN_ERROR'
456
                        ];
457
                    }
458
 
459
                } else {
460
                    $response = [
461
                        'success'   => false,
462
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
463
                    ];
464
                }
465
 
466
 
467
 
468
            } else {
469
                $messages = [];
470
                $form_messages = (array) $form->getMessages();
471
                foreach($form_messages  as $fieldname => $field_messages)
472
                {
473
 
474
                    $messages[$fieldname] = array_values($field_messages);
475
                }
476
 
477
                return new JsonModel([
478
                    'success'   => false,
479
                    'data'   => $messages
480
                ]);
481
            }
482
 
483
        } else {
484
            $response = [
485
                'success' => false,
486
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
487
            ];
488
 
489
 
490
        }
491
 
492
        return new JsonModel($response);
493
    }
494
 
495
    /**
496
     *
497
     * Borrar un perfil excepto el público
498
     * @return \Laminas\View\Model\JsonModel
499
     */
500
    public function deleteAction()
501
    {
502
 
503
        $currentUserPlugin = $this->plugin('currentUserPlugin');
504
        $currentUser = $currentUserPlugin->getUser();
505
        $currentCompany = $currentUserPlugin->getCompany();
506
 
507
 
508
        $request = $this->getRequest();
509
        $id = $this->params()->fromRoute('id');
510
 
511
        if(!$id) {
512
            $data = [
513
                'success'   => false,
514
                'data'   => 'ERROR_INVALID_PARAMETER'
515
            ];
516
 
517
            return new JsonModel($data);
518
        }
519
 
520
        $jobMapper = JobMapper::getInstance($this->adapter);
521
        $job = $jobMapper->fetchOneByUuid($id);
522
        if(!$job) {
523
            $data = [
524
                'success'   => false,
525
                'data'   => 'ERROR_JOB_NOT_FOUND'
526
            ];
527
 
528
            return new JsonModel($data);
529
        }
530
 
531
        if($job->company_id != $currentCompany->id) {
532
            $data = [
533
                'success'   => false,
534
                'data'   => 'ERROR_UNAUTHORIZED'
535
            ];
536
 
537
            return new JsonModel($data);
538
        }
539
 
540
 
541
 
542
        if($request->isPost()) {
543
            $companyMapper = CompanyMapper::getInstance($this->adapter);
544
            $company = $companyMapper->fetchOne($currentCompany->id);
545
 
546
            $result = $jobMapper->delete($job);
547
            if($result) {
548
                $this->logger->info('Se borro el empleo : ' . $job->title . ' de la empresa : ' .  $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
549
 
550
                $data = [
551
                    'success' => true,
552
                    'data' => 'LABEL_RECORD_DELETED'
553
                ];
554
            } else {
555
 
556
                $data = [
557
                    'success'   => false,
558
                    'data'      => $job->getError()
559
                ];
560
 
561
                return new JsonModel($data);
562
            }
563
 
564
        } else {
565
            $data = [
566
                'success' => false,
567
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
568
            ];
569
 
570
            return new JsonModel($data);
571
        }
572
 
573
        return new JsonModel($data);
574
    }
575
 
576
    /**
577
     * Presenta el perfil con las opciónes de edición de cada sección
578
     * @return \Laminas\Http\Response|\Laminas\View\Model\ViewModel|\Laminas\View\Model\JsonModel
579
     */
580
    public function editAction()
581
    {
582
        $currentUserPlugin = $this->plugin('currentUserPlugin');
583
        $currentUser = $currentUserPlugin->getUser();
584
        $currentCompany = $currentUserPlugin->getCompany();
585
 
586
 
587
        $request = $this->getRequest();
588
        $id = $this->params()->fromRoute('id');
589
 
590
        if(!$id) {
591
            $data = [
592
                'success'   => false,
593
                'data'   => 'ERROR_INVALID_PARAMETER'
594
            ];
595
 
596
            return new JsonModel($data);
597
        }
598
 
599
        $jobMapper = JobMapper::getInstance($this->adapter);
600
        $job = $jobMapper->fetchOneByUuid($id);
601
        if(!$job) {
602
            $data = [
603
                'success'   => false,
604
                'data'   => 'ERROR_JOB_NOT_FOUND'
605
            ];
606
 
607
            return new JsonModel($data);
608
        }
609
 
610
        if($job->company_id != $currentCompany->id) {
611
            $data = [
612
                'success'   => false,
613
                'data'   => 'ERROR_UNAUTHORIZED'
614
            ];
615
 
616
            return new JsonModel($data);
617
        }
618
 
619
 
620
        if($request->isGet()) {
621
            $months = [
622
                1 => 'LABEL_MONTH_JANUARY',
623
                2 => 'LABEL_MONTH_FEBRUARY',
624
                3 => 'LABEL_MONTH_MARCH',
625
                4 => 'LABEL_MONTH_APRIL',
626
                5 => 'LABEL_MONTH_MAY',
627
                6 => 'LABEL_MONTH_JUNE',
628
                7 => 'LABEL_MONTH_JULY',
629
                8 => 'LABEL_MONTH_AUGUST',
630
                9 => 'LABEL_MONTH_SEPTEMBER',
631
                10 => 'LABEL_MONTH_OCTOBER',
632
                11 => 'LABEL_MONTH_NOVEMBER',
633
                12 => 'LABEL_MONTH_DECEMBER',
634
            ];
635
 
636
            $dt = \DateTime::createFromFormat('Y-m-d', $job->last_date_of_application);
637
            $last_date_of_application = $dt->format('d') . ' de ' . $months[$dt->format('n')] . ' de ' . $dt->format('Y');
638
 
639
 
640
 
641
            $locationMapper = LocationMapper::getInstance($this->adapter);
642
            $location = $locationMapper->fetchOne($job->location_id);
643
 
644
            $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
645
            $jobCategory = $jobCategoryMapper->fetchOne($job->job_category_id);
646
 
647
            switch($job->employment_type)
648
            {
649
                case Job::EMPLOYMENT_TYPE_FULL_TIME :
650
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
651
                    break;
652
                case Job::EMPLOYMENT_TYPE_PART_TIME :
653
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
654
                    break;
655
 
656
                case Job::EMPLOYMENT_TYPE_CONTRACT :
657
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
658
                    break;
659
 
660
                case Job::EMPLOYMENT_TYPE_TEMPORARY :
661
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
662
                    break;
663
 
664
                default :
665
                    $employment_type = '';
666
                    break;
667
            }
668
 
669
            switch($job->status)
670
            {
671
                case Job::STATUS_ACTIVE :
672
                    $status = 'LABEL_ACTIVE';
673
                    break;
674
 
675
                case Job::STATUS_INACTIVE :
676
                    $status = 'LABEL_INACTIVE';
677
                    break;
678
 
679
                default :
680
                    $status = '';
681
                    break;
682
            }
683
 
684
 
685
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
686
 
687
            $jobDegreeMapper = JobDegreeMapper::getInstance($this->adapter);
688
            $records = $jobDegreeMapper->fetchAllByJobId($job->id);
689
 
690
            $job_degrees = [];
691
            foreach($records as $record)
692
            {
693
                $degree = $degreeMapper->fetchOne($record->degree_id);
694
                array_push($job_degrees, $degree->name);
695
            }
696
 
697
 
698
            $languageMapper = LanguageMapper::getInstance($this->adapter);
699
            $jobLanguageMapper = JobLanguageMapper::getInstance($this->adapter);
700
            $records = $jobLanguageMapper->fetchAllByJobId($job->id);
701
 
702
            $job_languages = [];
703
            foreach($records as $record)
704
            {
705
                $language = $languageMapper->fetchOne($record->language_id);
706
                array_push($job_languages, $language->name);
707
            }
708
 
709
            $skillMapper = SkillMapper::getInstance($this->adapter);
710
 
711
            $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
712
            $records = $jobSkillMapper->fetchAllByJobId($job->id);
713
 
714
            $job_skills = [];
715
            foreach($records as $record)
716
            {
717
                $skill = $skillMapper->fetchOne($record->skill_id);
718
                array_push($job_skills, $skill->name);
719
            }
720
 
721
 
722
 
723
            return new JsonModel([
724
                'success' => true,
725
                'data' => [
726
                    'title'                     => $job->title,
727
                    'status'                    => $status,
728
                    'description'               => $job->description,
729
                    'location'                  => $location->formatted_address,
730
                    'employment_type'           => $employment_type,
731
                    'last_date_of_application'  => $last_date_of_application,
732
                    'job_category'              => $jobCategory->name,
733
                    'experience'                => $job->experience_visible ? $job->experience_min . '-' . $job->experience_max : '',
734
                    'salary'                    => $job->salary_visible ==  Job::SALARY_VISIBLE_YES ? $job->salary_min . '-' . $job->salary_max . ' ' . $job->salary_currency : '',
735
                    'degrees'                   => $job_degrees,
736
                    'languages'                 => $job_languages,
737
                    'skills'                    => $job_skills,
738
 
739
                    'route_status'              => $this->url()->fromRoute('jobs/edit/status', [ 'id' => $job->uuid ]),
740
                    'route_title'               => $this->url()->fromRoute('jobs/edit/title', [ 'id' => $job->uuid ]),
741
                    'route_extended'            => $this->url()->fromRoute('jobs/edit/extended', [ 'id' => $job->uuid ]),
742
                    'route_location'            => $this->url()->fromRoute('jobs/edit/location', [ 'id' => $job->uuid ]),
743
                    'route_job_category'        => $this->url()->fromRoute('jobs/edit/job-category', [ 'id' => $job->uuid ]),
744
                    'route_employment_type'     => $this->url()->fromRoute('jobs/edit/employment-type', [ 'id' => $job->uuid ]),
745
                    'route_salary'              => $this->url()->fromRoute('jobs/edit/salary', [ 'id' => $job->uuid ]),
746
                    'route_experience'          => $this->url()->fromRoute('jobs/edit/experience', [ 'id' => $job->uuid ]),
747
                    'route_languages'           => $this->url()->fromRoute('jobs/edit/languages', [ 'id' => $job->uuid ]),
748
                    'route_degrees'             => $this->url()->fromRoute('jobs/edit/degrees', [ 'id' => $job->uuid ]),
749
                    'route_skills'              => $this->url()->fromRoute('jobs/edit/skills', [ 'id' => $job->uuid ]),
750
                    'route_last_date_of_application'    => $this->url()->fromRoute('jobs/edit/last-date-of-application', [ 'id' => $job->uuid ]),
751
                ]
752
            ]);
753
 
754
        } else {
755
            $data = [
756
                'success' => false,
757
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
758
            ];
759
 
760
            return new JsonModel($data);
761
        }
762
 
763
        return new JsonModel($data);
764
    }
765
 
766
 
767
 
768
    /**
769
     * Actualización de la descripción y cualquier otro campo extendido del perfil a futuro
770
     * @return \Laminas\View\Model\JsonModel
771
     */
772
    public function extendedAction()
773
    {
774
        $currentUserPlugin = $this->plugin('currentUserPlugin');
775
        $currentUser = $currentUserPlugin->getUser();
776
        $currentCompany = $currentUserPlugin->getCompany();
777
 
778
 
779
        $request = $this->getRequest();
780
        $id = $this->params()->fromRoute('id');
781
 
782
 
783
        if(!$id) {
784
            $response = [
785
                'success' => false,
786
                'data' => 'ERROR_INVALID_PARAMETER'
787
            ];
788
 
789
            return new JsonModel($response);
790
 
791
        }
792
 
793
        $jobMapper = JobMapper::getInstance($this->adapter);
794
        $job = $jobMapper->fetchOneByUuid($id);
795
 
796
        if(!$job) {
797
            $response = [
798
                'success' => false,
799
                'data' => 'ERROR_JOB_NOT_FOUND'
800
            ];
801
 
802
            return new JsonModel($response);
803
        }
804
 
805
        if($job->company_id != $currentCompany->id) {
806
            $response = [
807
                'success' => false,
808
                'data' => 'ERROR_UNAUTHORIZED'
809
            ];
810
 
811
            return new JsonModel($response);
812
        }
813
 
814
 
815
        $companyMapper = CompanyMapper::getInstance($this->adapter);
816
        $company = $companyMapper->fetchOne($currentCompany->id);
817
        if(!$company) {
818
            $response = [
819
                'success' => false,
820
                'data' => 'ERROR_COMPANY_NOT_FOUND'
821
            ];
822
 
823
            return new JsonModel($response);
824
        }
825
 
826
 
827
 
828
 
829
        $request = $this->getRequest();
830
        if($request->isGet()) {
831
            $data = [
832
                'success' => true,
833
                'data' => [
7136 stevensc 834
                    'description' => strip_tags($job->description, 'p'),
1 www 835
                ]
836
            ];
837
 
838
            return new JsonModel($data);
839
 
840
 
841
        } else if($request->isPost()) {
842
 
843
 
844
            $form = new CompanyJobExtendedForm();
845
            $dataPost = $request->getPost()->toArray();
846
 
847
            $form->setData($dataPost);
848
 
849
            if($form->isValid()) {
850
                $dataPost = (array) $form->getData();
851
 
852
                $hydrator = new ObjectPropertyHydrator();
853
                $hydrator->hydrate($dataPost, $job);
854
 
855
                $jobMapper->updateExtended($job);
856
 
857
                $this->logger->info('Se actualizo las descripción del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
858
 
859
                return new JsonModel([
860
                    'success'   => true,
861
                    'data' => [
7136 stevensc 862
                        'description' => strip_tags($job->description, 'p'),
1 www 863
                    ]
864
                ]);
865
 
866
            } else {
867
                $messages = [];
868
                $form_messages = (array) $form->getMessages();
869
                foreach($form_messages  as $fieldname => $field_messages)
870
                {
871
                    $messages[$fieldname] = array_values($field_messages);
872
                }
873
 
874
                return new JsonModel([
875
                    'success'   => false,
876
                    'data'   => $messages
877
                ]);
878
            }
879
        }
880
 
881
 
882
        $data = [
883
            'success' => false,
884
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
885
        ];
886
 
887
 
888
        return new JsonModel($data);
889
    }
890
 
891
 
892
    public function locationAction()
893
    {
894
 
895
        $currentUserPlugin = $this->plugin('currentUserPlugin');
896
        $currentUser = $currentUserPlugin->getUser();
897
        $currentCompany = $currentUserPlugin->getCompany();
898
 
899
 
900
        $request = $this->getRequest();
901
        $id = $this->params()->fromRoute('id');
902
 
903
 
904
        if(!$id) {
905
            $response = [
906
                'success' => false,
907
                'data' => 'ERROR_INVALID_PARAMETER'
908
            ];
909
 
910
            return new JsonModel($response);
911
 
912
        }
913
 
914
        $jobMapper = JobMapper::getInstance($this->adapter);
915
        $job = $jobMapper->fetchOneByUuid($id);
916
 
917
        if(!$job) {
918
            $response = [
919
                'success' => false,
920
                'data' => 'ERROR_JOB_NOT_FOUND'
921
            ];
922
 
923
            return new JsonModel($response);
924
        }
925
 
926
        if($job->company_id != $currentCompany->id) {
927
            $response = [
928
                'success' => false,
929
                'data' => 'ERROR_UNAUTHORIZED'
930
            ];
931
 
932
            return new JsonModel($response);
933
        }
934
 
935
 
936
        $companyMapper = CompanyMapper::getInstance($this->adapter);
937
        $company = $companyMapper->fetchOne($currentCompany->id);
938
        if(!$company) {
939
            $response = [
940
                'success' => false,
941
                'data' => 'ERROR_COMPANY_NOT_FOUND'
942
            ];
943
 
944
            return new JsonModel($response);
945
        }
946
 
947
 
948
        $request = $this->getRequest();
949
        if($request->isPost()) {
950
            $form = new CompanyJobLocationForm();
951
            $dataPost = $request->getPost()->toArray();
952
 
953
            $form->setData($dataPost);
954
            if($form->isValid()) {
955
                $dataPost = (array) $form->getData();
956
 
957
                $locationMapper = LocationMapper::getInstance($this->adapter);
958
                $location = $locationMapper->fetchOne($job->location_id);
959
 
960
                $hydrator = new ObjectPropertyHydrator();
961
                $hydrator->hydrate($dataPost, $location);
962
 
963
                if($locationMapper->update($location)) {
964
                     $this->logger->info('Se actualizo una ubicación del empleo: '. $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
965
 
966
                     $response = [
967
                         'success' => true,
968
                         'data' =>  $location->formatted_address
969
                     ];
970
                } else {
971
                    $response = [
972
                        'success'   => false,
973
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
974
                    ];
975
                }
976
            } else {
977
                $response = [
978
                    'success'   => false,
979
                    'data'   =>   'ERROR_PLACED_AUTOCOMPLETE_DOES_NOT_CONTAIN_GEOMETRY'
980
                ];
981
            }
982
 
983
            return new JsonModel($response);
984
 
985
        }
986
 
987
        $response = [
988
            'success' => false,
989
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
990
        ];
991
 
992
 
993
        return new JsonModel($response);
994
    }
995
 
996
    public function employmentTypeAction()
997
    {
998
 
999
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1000
        $currentUser = $currentUserPlugin->getUser();
1001
        $currentCompany = $currentUserPlugin->getCompany();
1002
 
1003
 
1004
        $request = $this->getRequest();
1005
        $id = $this->params()->fromRoute('id');
1006
 
1007
 
1008
        if(!$id) {
1009
            $response = [
1010
                'success' => false,
1011
                'data' => 'ERROR_INVALID_PARAMETER'
1012
            ];
1013
 
1014
            return new JsonModel($response);
1015
 
1016
        }
1017
 
1018
        $jobMapper = JobMapper::getInstance($this->adapter);
1019
        $job = $jobMapper->fetchOneByUuid($id);
1020
 
1021
        if(!$job) {
1022
            $response = [
1023
                'success' => false,
1024
                'data' => 'ERROR_JOB_NOT_FOUND'
1025
            ];
1026
 
1027
            return new JsonModel($response);
1028
        }
1029
 
1030
        if($job->company_id != $currentCompany->id) {
1031
            $response = [
1032
                'success' => false,
1033
                'data' => 'ERROR_UNAUTHORIZED'
1034
            ];
1035
 
1036
            return new JsonModel($response);
1037
        }
1038
 
1039
 
1040
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1041
        $company = $companyMapper->fetchOne($currentCompany->id);
1042
        if(!$company) {
1043
            $response = [
1044
                'success' => false,
1045
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1046
            ];
1047
 
1048
            return new JsonModel($response);
1049
        }
1050
 
1051
 
1052
 
1053
        $request = $this->getRequest();
1054
        if($request->isGet()) {
1055
            $data = [
1056
                'success' => true,
1057
                'data' => $job->employment_type
1058
            ];
1059
 
1060
            return new JsonModel($data);
1061
 
1062
 
1063
        } else if($request->isPost()) {
1064
 
1065
            $form = new CompanyJobEmploymentTypeForm();
1066
            $dataPost = $request->getPost()->toArray();
1067
 
1068
            $form->setData($dataPost);
1069
 
1070
            if($form->isValid()) {
1071
 
1072
                $dataPost = (array) $form->getData();
1073
 
1074
                $hydrator = new ObjectPropertyHydrator();
1075
                $hydrator->hydrate($dataPost, $job);
1076
 
1077
                if($jobMapper->updateEmploymentType($job)) {
1078
                    $this->logger->info('Se actualizo tipo de empleo: '. $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1079
 
1080
                    switch($job->employment_type)
1081
                    {
1082
                        case Job::EMPLOYMENT_TYPE_FULL_TIME :
1083
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
1084
                            break;
1085
                        case Job::EMPLOYMENT_TYPE_PART_TIME :
1086
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
1087
                            break;
1088
 
1089
                        case Job::EMPLOYMENT_TYPE_CONTRACT :
1090
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
1091
                            break;
1092
 
1093
                        case Job::EMPLOYMENT_TYPE_TEMPORARY :
1094
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
1095
                            break;
1096
 
1097
                        default :
1098
                            $employment_type = '';
1099
                            break;
1100
                    }
1101
 
1102
 
1103
 
1104
                    return new JsonModel([
1105
                        'success'   => true,
1106
                        'data' => $employment_type
1107
                    ]);
1108
                }  else {
1109
                    return new JsonModel([
1110
                        'success'   => false,
1111
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
1112
                    ]);
1113
                }
1114
 
1115
 
1116
            } else {
1117
                $messages = [];
1118
                $form_messages = (array) $form->getMessages();
1119
                foreach($form_messages  as $fieldname => $field_messages)
1120
                {
1121
                    $messages[$fieldname] = array_values($field_messages);
1122
                }
1123
 
1124
                return new JsonModel([
1125
                    'success'   => false,
1126
                    'data'   => $messages
1127
                ]);
1128
            }
1129
        }
1130
 
1131
 
1132
        $data = [
1133
            'success' => false,
1134
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1135
        ];
1136
 
1137
 
1138
        return new JsonModel($data);
1139
    }
1140
 
1141
    public function jobCategoryAction()
1142
    {
1143
 
1144
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1145
        $currentUser = $currentUserPlugin->getUser();
1146
        $currentCompany = $currentUserPlugin->getCompany();
1147
 
1148
 
1149
        $request = $this->getRequest();
1150
        $id = $this->params()->fromRoute('id');
1151
 
1152
 
1153
        if(!$id) {
1154
            $response = [
1155
                'success' => false,
1156
                'data' => 'ERROR_INVALID_PARAMETER'
1157
            ];
1158
 
1159
            return new JsonModel($response);
1160
 
1161
        }
1162
 
1163
        $jobMapper = JobMapper::getInstance($this->adapter);
1164
        $job = $jobMapper->fetchOneByUuid($id);
1165
 
1166
        if(!$job) {
1167
            $response = [
1168
                'success' => false,
1169
                'data' => 'ERROR_JOB_NOT_FOUND'
1170
            ];
1171
 
1172
            return new JsonModel($response);
1173
        }
1174
 
1175
        if($job->company_id != $currentCompany->id) {
1176
            $response = [
1177
                'success' => false,
1178
                'data' => 'ERROR_UNAUTHORIZED'
1179
            ];
1180
 
1181
            return new JsonModel($response);
1182
        }
1183
 
1184
 
1185
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1186
        $company = $companyMapper->fetchOne($currentCompany->id);
1187
        if(!$company) {
1188
            $response = [
1189
                'success' => false,
1190
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1191
            ];
1192
 
1193
            return new JsonModel($response);
1194
        }
1195
 
1196
        $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
1197
        $jobCategory = $jobCategoryMapper->fetchOne( $job->job_category_id );
1198
 
1199
 
1200
        $request = $this->getRequest();
1201
        if($request->isGet()) {
1202
            $data = [
1203
                'success' => true,
1204
                'data' => $jobCategory->uuid,
1205
            ];
1206
 
1207
            return new JsonModel($data);
1208
 
1209
 
1210
        } else if($request->isPost()) {
1211
 
1212
            $form = new CompanyJobCategoryForm($this->adapter);
1213
            $dataPost = $request->getPost()->toArray();
1214
 
1215
            $form->setData($dataPost);
1216
 
1217
            if($form->isValid()) {
1218
                $this->logger->info('Se actualizaron la categoría de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1219
 
1220
                $dataPost = (array) $form->getData();
1221
 
1222
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
1223
                $jobCategory = $jobCategoryMapper->fetchOneByUuid( $dataPost['job_category_id'] );
1224
 
1225
                $job->job_category_id = $jobCategory->id;
1226
 
1227
                if($jobMapper->updateJobCategory($job)) {
1228
 
1229
 
1230
                    return new JsonModel([
1231
                        'success'   => true,
1232
                        'data' => $jobCategory->name
1233
                    ]);
1234
                }  else {
1235
                    return new JsonModel([
1236
                        'success'   => false,
1237
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
1238
                    ]);
1239
                }
1240
 
1241
 
1242
            } else {
1243
                $messages = [];
1244
                $form_messages = (array) $form->getMessages();
1245
                foreach($form_messages  as $fieldname => $field_messages)
1246
                {
1247
                    $messages[$fieldname] = array_values($field_messages);
1248
                }
1249
 
1250
                return new JsonModel([
1251
                    'success'   => false,
1252
                    'data'   => $messages
1253
                ]);
1254
            }
1255
        }
1256
 
1257
 
1258
        $data = [
1259
            'success' => false,
1260
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1261
        ];
1262
 
1263
 
1264
        return new JsonModel($data);
1265
    }
1266
 
1267
 
1268
    public function salaryAction()
1269
    {
1270
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1271
        $currentUser = $currentUserPlugin->getUser();
1272
        $currentCompany = $currentUserPlugin->getCompany();
1273
 
1274
 
1275
        $request = $this->getRequest();
1276
        $id = $this->params()->fromRoute('id');
1277
 
1278
 
1279
        if(!$id) {
1280
            $response = [
1281
                'success' => false,
1282
                'data' => 'ERROR_INVALID_PARAMETER'
1283
            ];
1284
 
1285
            return new JsonModel($response);
1286
 
1287
        }
1288
 
1289
        $jobMapper = JobMapper::getInstance($this->adapter);
1290
        $job = $jobMapper->fetchOneByUuid($id);
1291
 
1292
        if(!$job) {
1293
            $response = [
1294
                'success' => false,
1295
                'data' => 'ERROR_JOB_NOT_FOUND'
1296
            ];
1297
 
1298
            return new JsonModel($response);
1299
        }
1300
 
1301
        if($job->company_id != $currentCompany->id) {
1302
            $response = [
1303
                'success' => false,
1304
                'data' => 'ERROR_UNAUTHORIZED'
1305
            ];
1306
 
1307
            return new JsonModel($response);
1308
        }
1309
 
1310
 
1311
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1312
        $company = $companyMapper->fetchOne($currentCompany->id);
1313
        if(!$company) {
1314
            $response = [
1315
                'success' => false,
1316
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1317
            ];
1318
 
1319
            return new JsonModel($response);
1320
        }
1321
 
1322
 
1323
 
1324
        $request = $this->getRequest();
1325
        if($request->isGet()) {
1326
            $data = [
1327
                'success' => true,
1328
                'data' => [
1329
                    'salary_visible' => $job->salary_visible,
1330
                    'salary_currency' => $job->salary_currency,
1331
                    'salary_min' => $job->salary_min,
1332
                    'salary_max' =>  $job->salary_max
1333
                ]
1334
            ];
1335
 
1336
            return new JsonModel($data);
1337
 
1338
 
1339
        } else if($request->isPost()) {
1340
 
1341
 
1342
            $form = new CompanyJobSalaryForm($this->adapter);
1343
            $dataPost = $request->getPost()->toArray();
1344
 
1345
            $dataPost['salary_visible'] = empty( $dataPost['salary_visible']) ? Job::SALARY_VISIBLE_NO :  $dataPost['salary_visible'];
1346
            $dataPost['salary_currency'] = empty( $dataPost['salary_currency']) ? 'USD' :  $dataPost['salary_currency'];
1347
 
1348
 
1349
            $form->setData($dataPost);
1350
 
1351
            if($form->isValid()) {
1352
                $dataPost = (array) $form->getData();
1353
 
1354
                $hydrator = new ObjectPropertyHydrator();
1355
                $hydrator->hydrate($dataPost, $job);
1356
 
1357
                $jobMapper->updateSalary($job);
1358
 
1359
                $this->logger->info('Se actualizo el salario del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1360
 
1361
                return new JsonModel([
1362
                    'success'   => true,
1363
                    'data' =>  $job->salary_visible == Job::SALARY_VISIBLE_YES ?  $job->salary_min . '-' . $job->salary_max . ' ' . $job->salary_currency: ''
1364
                ]);
1365
 
1366
            } else {
1367
                $messages = [];
1368
                $form_messages = (array) $form->getMessages();
1369
                foreach($form_messages  as $fieldname => $field_messages)
1370
                {
1371
                    $messages[$fieldname] = array_values($field_messages);
1372
                }
1373
 
1374
                return new JsonModel([
1375
                    'success'   => false,
1376
                    'data'   => $messages
1377
                ]);
1378
            }
1379
        }
1380
 
1381
 
1382
        $data = [
1383
            'success' => false,
1384
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1385
        ];
1386
 
1387
 
1388
        return new JsonModel($data);
1389
    }
1390
 
1391
    public function experienceAction()
1392
    {
1393
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1394
        $currentUser = $currentUserPlugin->getUser();
1395
        $currentCompany = $currentUserPlugin->getCompany();
1396
 
1397
 
1398
        $request = $this->getRequest();
1399
        $id = $this->params()->fromRoute('id');
1400
 
1401
 
1402
        if(!$id) {
1403
            $response = [
1404
                'success' => false,
1405
                'data' => 'ERROR_INVALID_PARAMETER'
1406
            ];
1407
 
1408
            return new JsonModel($response);
1409
 
1410
        }
1411
 
1412
        $jobMapper = JobMapper::getInstance($this->adapter);
1413
        $job = $jobMapper->fetchOneByUuid($id);
1414
 
1415
        if(!$job) {
1416
            $response = [
1417
                'success' => false,
1418
                'data' => 'ERROR_JOB_NOT_FOUND'
1419
            ];
1420
 
1421
            return new JsonModel($response);
1422
        }
1423
 
1424
        if($job->company_id != $currentCompany->id) {
1425
            $response = [
1426
                'success' => false,
1427
                'data' => 'ERROR_UNAUTHORIZED'
1428
            ];
1429
 
1430
            return new JsonModel($response);
1431
        }
1432
 
1433
 
1434
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1435
        $company = $companyMapper->fetchOne($currentCompany->id);
1436
        if(!$company) {
1437
            $response = [
1438
                'success' => false,
1439
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1440
            ];
1441
 
1442
            return new JsonModel($response);
1443
        }
1444
 
1445
        $request = $this->getRequest();
1446
        if($request->isGet()) {
1447
            $data = [
1448
                'success' => true,
1449
                'data' =>  [
1450
                    'experience_visible' => $job->experience_visible,
1451
                    'experience_min' => $job->experience_min,
1452
                    'experience_max' => $job->experience_max
1453
                ]
1454
            ];
1455
 
1456
            return new JsonModel($data);
1457
 
1458
 
1459
        } else if($request->isPost()) {
1460
 
1461
 
1462
            $form = new CompanyJobExperienceForm();
1463
            $dataPost = $request->getPost()->toArray();
1464
 
1465
            $form->setData($dataPost);
1466
 
1467
            if($form->isValid()) {
1468
                $dataPost = (array) $form->getData();
1469
 
1470
                $hydrator = new ObjectPropertyHydrator();
1471
                $hydrator->hydrate($dataPost, $job);
1472
 
1473
                $jobMapper->updateExperience($job);
1474
 
1475
                $this->logger->info('Se actualizo el experiencia del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1476
 
1477
                return new JsonModel([
1478
                    'success'   => true,
1479
                    'data' => $job->experience_visible ? $job->experience_min . '-' . $job->experience_max . ' LABEL_YEARS' : ''
1480
                ]);
1481
 
1482
            } else {
1483
                $messages = [];
1484
                $form_messages = (array) $form->getMessages();
1485
                foreach($form_messages  as $fieldname => $field_messages)
1486
                {
1487
                    $messages[$fieldname] = array_values($field_messages);
1488
                }
1489
 
1490
                return new JsonModel([
1491
                    'success'   => false,
1492
                    'data'   => $messages
1493
                ]);
1494
            }
1495
        }
1496
 
1497
 
1498
        $data = [
1499
            'success' => false,
1500
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1501
        ];
1502
 
1503
 
1504
        return new JsonModel($data);
1505
    }
1506
 
1507
    public function skillAction()
1508
    {
1509
 
1510
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1511
        $currentUser = $currentUserPlugin->getUser();
1512
        $currentCompany = $currentUserPlugin->getCompany();
1513
 
1514
 
1515
        $request = $this->getRequest();
1516
        $id = $this->params()->fromRoute('id');
1517
 
1518
 
1519
        if(!$id) {
1520
            $response = [
1521
                'success' => false,
1522
                'data' => 'ERROR_INVALID_PARAMETER'
1523
            ];
1524
 
1525
            return new JsonModel($response);
1526
 
1527
        }
1528
 
1529
        $jobMapper = JobMapper::getInstance($this->adapter);
1530
        $job = $jobMapper->fetchOneByUuid($id);
1531
 
1532
        if(!$job) {
1533
            $response = [
1534
                'success' => false,
1535
                'data' => 'ERROR_JOB_NOT_FOUND'
1536
            ];
1537
 
1538
            return new JsonModel($response);
1539
        }
1540
 
1541
        if($job->company_id != $currentCompany->id) {
1542
            $response = [
1543
                'success' => false,
1544
                'data' => 'ERROR_UNAUTHORIZED'
1545
            ];
1546
 
1547
            return new JsonModel($response);
1548
        }
1549
 
1550
 
1551
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1552
        $company = $companyMapper->fetchOne($currentCompany->id);
1553
        if(!$company) {
1554
            $response = [
1555
                'success' => false,
1556
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1557
            ];
1558
 
1559
            return new JsonModel($response);
1560
        }
1561
 
1562
 
1563
 
1564
        $request = $this->getRequest();
1565
        if($request->isGet()) {
1566
 
1567
            $skillMapper = SkillMapper::getInstance($this->adapter);
1568
 
1569
            $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
1570
            $skills  = $jobSkillMapper->fetchAllByJobId($job->id);
1571
 
1572
            $items = [];
1573
            foreach($skills as $skill)
1574
            {
1575
                $skill = $skillMapper->fetchOne( $skill->skill_id );
1576
 
1577
 
1578
                array_push($items, $skill->uuid );
1579
            }
1580
 
1581
            $data = [
1582
                'success' => true,
1583
                'data' => $items
1584
            ];
1585
 
1586
            return new JsonModel($data);
1587
 
1588
 
1589
        } else if($request->isPost()) {
1590
 
1591
            $form = new CompanyJobSkillForm($this->adapter);
1592
            $dataPost = $request->getPost()->toArray();
1593
 
1594
            $form->setData($dataPost);
1595
 
1596
            if($form->isValid()) {
1597
                $this->logger->info('Se actualizaron las habilidades requeridas del empleo : ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1598
 
1599
                $skillMapper = SkillMapper::getInstance($this->adapter);
1600
 
1601
                $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
1602
                $jobSkillMapper->deleteByJobId($job->id);
1603
 
1604
                $dataPost = (array) $form->getData();
1605
                $skills = $dataPost['skills'];
1606
                foreach($skills as $skill_id)
1607
                {
1608
                    $skill = $skillMapper->fetchOneByUuid( $skill_id );
1609
 
1610
                    $jobSkill = new JobSkill();
1611
                    $jobSkill->job_id = $job->id;
1612
                    $jobSkill->skill_id = $skill->id;
1613
 
1614
                    $jobSkillMapper->insert($jobSkill);
1615
                }
1616
 
1617
                $items = [];
1618
                $records = $jobSkillMapper->fetchAllByJobId( $job->id );
1619
                foreach($records as $record)
1620
                {
1621
                    $skill = $skillMapper->fetchOne($record->skill_id);
1622
 
1623
                    array_push($items,  ['value' => $skill->uuid, 'label' => $skill->name ]);
1624
                }
1625
 
1626
                return new JsonModel([
1627
                    'success'   => true,
1628
                    'data'   => $items
1629
                ]);
1630
 
1631
            } else {
1632
                $messages = [];
1633
                $form_messages = (array) $form->getMessages();
1634
                foreach($form_messages  as $fieldname => $field_messages)
1635
                {
1636
                    $messages[$fieldname] = array_values($field_messages);
1637
                }
1638
 
1639
                return new JsonModel([
1640
                    'success'   => false,
1641
                    'data'   => $messages
1642
                ]);
1643
            }
1644
 
1645
            $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
1646
 
1647
        }
1648
 
1649
 
1650
        $data = [
1651
            'success' => false,
1652
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1653
        ];
1654
 
1655
 
1656
        return new JsonModel($data);
1657
    }
1658
 
1659
 
1660
    public function languageAction()
1661
    {
1662
 
1663
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1664
        $currentUser = $currentUserPlugin->getUser();
1665
        $currentCompany = $currentUserPlugin->getCompany();
1666
 
1667
 
1668
        $request = $this->getRequest();
1669
        $id = $this->params()->fromRoute('id');
1670
 
1671
 
1672
        if(!$id) {
1673
            $response = [
1674
                'success' => false,
1675
                'data' => 'ERROR_INVALID_PARAMETER'
1676
            ];
1677
 
1678
            return new JsonModel($response);
1679
 
1680
        }
1681
 
1682
        $jobMapper = JobMapper::getInstance($this->adapter);
1683
        $job = $jobMapper->fetchOneByUuid($id);
1684
 
1685
        if(!$job) {
1686
            $response = [
1687
                'success' => false,
1688
                'data' => 'ERROR_JOB_NOT_FOUND'
1689
            ];
1690
 
1691
            return new JsonModel($response);
1692
        }
1693
 
1694
        if($job->company_id != $currentCompany->id) {
1695
            $response = [
1696
                'success' => false,
1697
                'data' => 'ERROR_UNAUTHORIZED'
1698
            ];
1699
 
1700
            return new JsonModel($response);
1701
        }
1702
 
1703
 
1704
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1705
        $company = $companyMapper->fetchOne($currentCompany->id);
1706
        if(!$company) {
1707
            $response = [
1708
                'success' => false,
1709
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1710
            ];
1711
 
1712
            return new JsonModel($response);
1713
        }
1714
 
1715
 
1716
 
1717
        $request = $this->getRequest();
1718
        if($request->isGet()) {
1719
            $this->logger->info('Se actualizaron los idiomas requeridos del empleo : ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1720
 
1721
            $jobLanguageMapper = JobLanguageMapper::getInstance($this->adapter);
1722
            $languages  = $jobLanguageMapper->fetchAllByJobId($job->id);
1723
 
1724
            $items = [];
1725
            foreach($languages as $language)
1726
            {
1727
                array_push($items, $language->language_id);
1728
            }
1729
 
1730
            $data = [
1731
                'success' => true,
1732
                'data' => $items
1733
            ];
1734
 
1735
            return new JsonModel($data);
1736
 
1737
 
1738
        } else if($request->isPost()) {
1739
 
1740
            $form = new CompanyJobLanguageForm($this->adapter);
1741
            $dataPost = $request->getPost()->toArray();
1742
 
1743
            $form->setData($dataPost);
1744
 
1745
            if($form->isValid()) {
1746
                $languageMapper = LanguageMapper::getInstance($this->adapter);
1747
 
1748
                $jobLanguageMapper = JobLanguageMapper::getInstance($this->adapter);
1749
                $jobLanguageMapper->deleteByJobId($job->id);
1750
 
1751
                $dataPost = (array) $form->getData();
1752
                $languages = $dataPost['languages'];
1753
                foreach($languages as $language_id)
1754
                {
1755
                    $language = $languageMapper->fetchOne($language_id);
1756
 
1757
                    $jobLanguage = new JobLanguage();
1758
                    $jobLanguage->job_id = $job->id;
1759
                    $jobLanguage->language_id = $language->id;
1760
 
1761
                    $jobLanguageMapper->insert($jobLanguage);
1762
                }
1763
 
1764
                $items = [];
1765
                $records = $jobLanguageMapper->fetchAllByJobId($job->id);
1766
                foreach($records as $record)
1767
                {
1768
                    $language = $languageMapper->fetchOne($record->language_id);
1769
 
1770
                    array_push($items,  ['value' => $language->id, 'label' => $language->name]);
1771
                }
1772
 
1773
                return new JsonModel([
1774
                    'success'   => true,
1775
                    'data'   => $items
1776
                ]);
1777
 
1778
            } else {
1779
                $messages = [];
1780
                $form_messages = (array) $form->getMessages();
1781
                foreach($form_messages  as $fieldname => $field_messages)
1782
                {
1783
                    $messages[$fieldname] = array_values($field_messages);
1784
                }
1785
 
1786
                return new JsonModel([
1787
                    'success'   => false,
1788
                    'data'   => $messages
1789
                ]);
1790
            }
1791
        }
1792
 
1793
 
1794
        $data = [
1795
            'success' => false,
1796
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1797
        ];
1798
 
1799
 
1800
        return new JsonModel($data);
1801
    }
1802
 
1803
    public function degreeAction()
1804
    {
1805
 
1806
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1807
        $currentUser = $currentUserPlugin->getUser();
1808
        $currentCompany = $currentUserPlugin->getCompany();
1809
 
1810
 
1811
        $request = $this->getRequest();
1812
        $id = $this->params()->fromRoute('id');
1813
 
1814
 
1815
        if(!$id) {
1816
            $response = [
1817
                'success' => false,
1818
                'data' => 'ERROR_INVALID_PARAMETER'
1819
            ];
1820
 
1821
            return new JsonModel($response);
1822
 
1823
        }
1824
 
1825
        $jobMapper = JobMapper::getInstance($this->adapter);
1826
        $job = $jobMapper->fetchOneByUuid($id);
1827
 
1828
        if(!$job) {
1829
            $response = [
1830
                'success' => false,
1831
                'data' => 'ERROR_JOB_NOT_FOUND'
1832
            ];
1833
 
1834
            return new JsonModel($response);
1835
        }
1836
 
1837
        if($job->company_id != $currentCompany->id) {
1838
            $response = [
1839
                'success' => false,
1840
                'data' => 'ERROR_UNAUTHORIZED'
1841
            ];
1842
 
1843
            return new JsonModel($response);
1844
        }
1845
 
1846
 
1847
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1848
        $company = $companyMapper->fetchOne($currentCompany->id);
1849
        if(!$company) {
1850
            $response = [
1851
                'success' => false,
1852
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1853
            ];
1854
 
1855
            return new JsonModel($response);
1856
        }
1857
 
1858
 
1859
 
1860
        $request = $this->getRequest();
1861
        if($request->isGet()) {
1862
            $this->logger->info('Se actualizaron los idiomas requeridos del empleo : ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1863
 
1864
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
1865
            $jobDegreeMapper = JobDegreeMapper::getInstance($this->adapter);
1866
            $records  = $jobDegreeMapper->fetchAllByJobId($job->id);
1867
 
1868
            $items = [];
1869
            foreach($records as $record)
1870
            {
1871
                $degree = $degreeMapper->fetchOne($record->degree_id);
1872
 
1873
                array_push($items, $degree->uuid);
1874
 
1875
            }
1876
 
1877
            $data = [
1878
                'success' => true,
1879
                'data' => $items
1880
            ];
1881
 
1882
            return new JsonModel($data);
1883
 
1884
 
1885
        } else if($request->isPost()) {
1886
 
1887
            $form = new CompanyJobDegreeForm($this->adapter);
1888
            $dataPost = $request->getPost()->toArray();
1889
 
1890
            $form->setData($dataPost);
1891
 
1892
            if($form->isValid()) {
1893
                $degreeMapper = DegreeMapper::getInstance($this->adapter);
1894
 
1895
                $jobDegreeMapper = JobDegreeMapper::getInstance($this->adapter);
1896
                $jobDegreeMapper->deleteByJobId($job->id);
1897
 
1898
                $dataPost = (array) $form->getData();
1899
                $degrees = $dataPost['degrees'];
1900
                foreach($degrees as $degree_id)
1901
                {
1902
                    $degree = $degreeMapper->fetchOneByUuid($degree_id);
1903
 
1904
                    $jobDegree = new JobDegree();
1905
                    $jobDegree->job_id = $job->id;
1906
                    $jobDegree->degree_id = $degree->id;
1907
                    $jobDegreeMapper->insert($jobDegree);
1908
                }
1909
 
1910
                $items = [];
1911
                $records = $jobDegreeMapper->fetchAllByJobId($job->id);
1912
                foreach($records as $record)
1913
                {
1914
                    $degree = $degreeMapper->fetchOne($record->degree_id);
1915
                    array_push($items,  ['value' => $degree->uuid, 'label' => $degree->name]);
1916
                }
1917
 
1918
                return new JsonModel([
1919
                    'success'   => true,
1920
                    'data'   => $items
1921
                ]);
1922
 
1923
            } else {
1924
                $messages = [];
1925
                $form_messages = (array) $form->getMessages();
1926
                foreach($form_messages  as $fieldname => $field_messages)
1927
                {
1928
                    $messages[$fieldname] = array_values($field_messages);
1929
                }
1930
 
1931
                return new JsonModel([
1932
                    'success'   => false,
1933
                    'data'   => $messages
1934
                ]);
1935
            }
1936
 
1937
        }
1938
 
1939
 
1940
        $data = [
1941
            'success' => false,
1942
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1943
        ];
1944
 
1945
 
1946
        return new JsonModel($data);
1947
    }
1948
 
1949
    public function lastDateOfApplicationAction()
1950
    {
1951
 
1952
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1953
        $currentUser = $currentUserPlugin->getUser();
1954
        $currentCompany = $currentUserPlugin->getCompany();
1955
 
1956
 
1957
        $request = $this->getRequest();
1958
        $id = $this->params()->fromRoute('id');
1959
 
1960
 
1961
        if(!$id) {
1962
            $response = [
1963
                'success' => false,
1964
                'data' => 'ERROR_INVALID_PARAMETER'
1965
            ];
1966
 
1967
            return new JsonModel($response);
1968
 
1969
        }
1970
 
1971
        $jobMapper = JobMapper::getInstance($this->adapter);
1972
        $job = $jobMapper->fetchOneByUuid($id);
1973
 
1974
        if(!$job) {
1975
            $response = [
1976
                'success' => false,
1977
                'data' => 'ERROR_JOB_NOT_FOUND'
1978
            ];
1979
 
1980
            return new JsonModel($response);
1981
        }
1982
 
1983
        if($job->company_id != $currentCompany->id) {
1984
            $response = [
1985
                'success' => false,
1986
                'data' => 'ERROR_UNAUTHORIZED'
1987
            ];
1988
 
1989
            return new JsonModel($response);
1990
        }
1991
 
1992
 
1993
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1994
        $company = $companyMapper->fetchOne($currentCompany->id);
1995
        if(!$company) {
1996
            $response = [
1997
                'success' => false,
1998
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1999
            ];
2000
 
2001
            return new JsonModel($response);
2002
        }
2003
 
2004
 
2005
 
2006
        $request = $this->getRequest();
2007
        if($request->isGet()) {
2008
            $dt = \DateTime::createFromFormat('Y-m-d', $job->last_date_of_application);
2009
 
2010
            $data = [
2011
                'success' => true,
2012
                'data' => $dt->format('d/m/Y'),
2013
            ];
2014
 
2015
            return new JsonModel($data);
2016
 
2017
 
2018
        } else if($request->isPost()) {
2019
 
2020
            $form = new CompanyJobLastDateOfApplicationForm();
2021
            $dataPost = $request->getPost()->toArray();
2022
 
2023
            $form->setData($dataPost);
2024
 
2025
            if($form->isValid()) {
2026
                $this->logger->info('Se actualizo la última fecha de aplicación de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2027
 
2028
                $dt = \DateTime::createFromFormat('d/m/Y', $form->get('last_date_of_application')->getValue());
2029
                $job->last_date_of_application = $dt->format('Y-m-d');
2030
 
2031
                if($jobMapper->updateLastDateOfApplication($job)) {
2032
                    $months = [
2033
                        1 => 'LABEL_MONTH_JANUARY',
2034
                        2 => 'LABEL_MONTH_FEBRUARY',
2035
                        3 => 'LABEL_MONTH_MARCH',
2036
                        4 => 'LABEL_MONTH_APRIL',
2037
                        5 => 'LABEL_MONTH_MAY',
2038
                        6 => 'LABEL_MONTH_JUNE',
2039
                        7 => 'LABEL_MONTH_JULY',
2040
                        8 => 'LABEL_MONTH_AUGUST',
2041
                        9 => 'LABEL_MONTH_SEPTEMBER',
2042
                        10 => 'LABEL_MONTH_OCTOBER',
2043
                        11 => 'LABEL_MONTH_NOVEMBER',
2044
                        12 => 'LABEL_MONTH_DECEMBER',
2045
                    ];
2046
 
2047
                   $last_date_of_application = $dt->format('d') . ' de ' . $months[$dt->format('n')] . ' de ' . $dt->format('Y');
2048
 
2049
 
2050
                    return new JsonModel([
2051
                        'success'   => true,
2052
                        'data' => $last_date_of_application
2053
                    ]);
2054
                }  else {
2055
                    return new JsonModel([
2056
                        'success'   => false,
2057
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
2058
                    ]);
2059
                }
2060
 
2061
 
2062
            } else {
2063
                $messages = [];
2064
                $form_messages = (array) $form->getMessages();
2065
                foreach($form_messages  as $fieldname => $field_messages)
2066
                {
2067
                    $messages[$fieldname] = array_values($field_messages);
2068
                }
2069
 
2070
                return new JsonModel([
2071
                    'success'   => false,
2072
                    'data'   => $messages
2073
                ]);
2074
            }
2075
        }
2076
 
2077
 
2078
        $data = [
2079
            'success' => false,
2080
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2081
        ];
2082
 
2083
 
2084
        return new JsonModel($data);
2085
    }
2086
 
2087
    public function usersWhoAppliedAction()
2088
    {
2089
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2090
        $currentUser = $currentUserPlugin->getUser();
2091
        $currentCompany = $currentUserPlugin->getCompany();
2092
 
2093
 
2094
        $request = $this->getRequest();
2095
        $id = $this->params()->fromRoute('id');
2096
 
2097
        if(!$id) {
2098
            $data = [
2099
                'success'   => false,
2100
                'data'   => 'ERROR_INVALID_PARAMETER'
2101
            ];
2102
 
2103
            return new JsonModel($data);
2104
        }
2105
 
2106
        $jobMapper = JobMapper::getInstance($this->adapter);
2107
        $job = $jobMapper->fetchOneByUuid($id);
2108
        if(!$job) {
2109
            $data = [
2110
                'success'   => false,
2111
                'data'   => 'ERROR_JOB_NOT_FOUND'
2112
            ];
2113
 
2114
            return new JsonModel($data);
2115
        }
2116
 
2117
        if($job->company_id != $currentCompany->id) {
2118
            $data = [
2119
                'success'   => false,
2120
                'data'   => 'ERROR_UNAUTHORIZED'
2121
            ];
2122
 
2123
            return new JsonModel($data);
2124
        }
2125
 
2126
 
2127
        $request = $this->getRequest();
2128
        if($request->isGet()) {
2129
 
2130
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
2131
            if($sandbox) {
2132
                $user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
2133
            } else {
2134
                $user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
2135
            }
2136
 
2137
 
2138
            $queryMapper = QueryMapper::getInstance($this->adapter);
2139
            $select = $queryMapper->getSql()->select();
2140
            $select->columns(['id',  'user_uuid' => 'uuid', 'first_name','last_name', 'email']);
2141
            $select->from(['u' => UserMapper::_TABLE]);
2142
            $select->join(['ja' => JobApplicationMapper::_TABLE], 'ja.user_id = u.id', ['user_profile_id']);
2143
            $select->join(['up' => UserProfileMapper::_TABLE], 'ja.user_profile_id = up.id', ['user_profile_uuid' => 'uuid']);
2144
            $select->where->equalTo('u.status', User::STATUS_ACTIVE);
2145
            $select->order(['first_name', 'last_name']);
2146
 
2147
            $items = [];
2148
            $records = $queryMapper->fetchAll($select);
2149
 
2150
            foreach($records as $record)
2151
            {
2152
                $item = [
2153
                    'first_name' => $record['first_name'],
2154
                    'last_name' => $record['last_name'],
2155
                    'email' => $record['email'],
2156
                    'link_view' => str_replace('[uuid]', $record['user_profile_uuid'], $user_profile_url),
2157
 
2158
                ];
2159
 
2160
                array_push($items, $item);
2161
            }
2162
 
2163
 
2164
            $response = [
2165
                'success' => true,
2166
                'data' => $items
2167
            ];
2168
 
2169
            return new JsonModel($response);
2170
 
2171
 
2172
        } else {
2173
            return new JsonModel([
2174
                'success' => false,
2175
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2176
            ]);
2177
        }
2178
    }
2179
 
2180
 
2181
    public function statusAction()
2182
    {
2183
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2184
        $currentUser = $currentUserPlugin->getUser();
2185
        $currentCompany = $currentUserPlugin->getCompany();
2186
 
2187
 
2188
        $request = $this->getRequest();
2189
        $id = $this->params()->fromRoute('id');
2190
 
2191
 
2192
        if(!$id) {
2193
            $response = [
2194
                'success' => false,
2195
                'data' => 'ERROR_INVALID_PARAMETER'
2196
            ];
2197
 
2198
            return new JsonModel($response);
2199
 
2200
        }
2201
 
2202
        $jobMapper = JobMapper::getInstance($this->adapter);
2203
        $job = $jobMapper->fetchOneByUuid($id);
2204
 
2205
        if(!$job) {
2206
            $response = [
2207
                'success' => false,
2208
                'data' => 'ERROR_JOB_NOT_FOUND'
2209
            ];
2210
 
2211
            return new JsonModel($response);
2212
        }
2213
 
2214
        if($job->company_id != $currentCompany->id) {
2215
            $response = [
2216
                'success' => false,
2217
                'data' => 'ERROR_UNAUTHORIZED'
2218
            ];
2219
 
2220
            return new JsonModel($response);
2221
        }
2222
 
2223
 
2224
        $companyMapper = CompanyMapper::getInstance($this->adapter);
2225
        $company = $companyMapper->fetchOne($currentCompany->id);
2226
        if(!$company) {
2227
            $response = [
2228
                'success' => false,
2229
                'data' => 'ERROR_COMPANY_NOT_FOUND'
2230
            ];
2231
 
2232
            return new JsonModel($response);
2233
        }
2234
 
2235
 
2236
 
2237
 
2238
        $request = $this->getRequest();
2239
        if($request->isGet()) {
2240
            $data = [
2241
                'success' => true,
2242
                'data' => [
2243
                    'status' => $job->status,
2244
                ]
2245
            ];
2246
 
2247
            return new JsonModel($data);
2248
 
2249
 
2250
        } else if($request->isPost()) {
2251
 
2252
 
2253
            $form = new CompanyJobStatusForm();
2254
            $dataPost = $request->getPost()->toArray();
2255
 
2256
            $form->setData($dataPost);
2257
 
2258
            if($form->isValid()) {
2259
                $dataPost = (array) $form->getData();
2260
 
2261
                $hydrator = new ObjectPropertyHydrator();
2262
                $hydrator->hydrate($dataPost, $job);
2263
 
2264
                $jobMapper->updateStatus($job);
2265
 
2266
                $this->logger->info('Se actualizo el estatus del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2267
 
2268
                switch($job->status) {
2269
                    case  Job::STATUS_ACTIVE :
2270
                        $status = 'LABEL_ACTIVE';
2271
                        break;
2272
 
2273
                    case  Job::STATUS_INACTIVE :
2274
                        $status = 'LABEL_INACTIVE';
2275
                        break;
2276
 
2277
 
2278
                    case  Job::STATUS_DELETED :
2279
                        $status = 'LABEL_DELETED';
2280
                        break;
2281
 
2282
                    default :
2283
                        $status = '';
2284
                        break;
2285
                }
2286
 
2287
 
2288
                return new JsonModel([
2289
                    'success'   => true,
2290
                    'data' => [
2291
                        'status' => $status,
2292
                    ]
2293
                ]);
2294
 
2295
            } else {
2296
                $messages = [];
2297
                $form_messages = (array) $form->getMessages();
2298
                foreach($form_messages  as $fieldname => $field_messages)
2299
                {
2300
                    $messages[$fieldname] = array_values($field_messages);
2301
                }
2302
 
2303
                return new JsonModel([
2304
                    'success'   => false,
2305
                    'data'   => $messages
2306
                ]);
2307
            }
2308
        }
2309
 
2310
 
2311
        $data = [
2312
            'success' => false,
2313
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2314
        ];
2315
 
2316
 
2317
        return new JsonModel($data);
2318
    }
2319
 
2320
 
2321
    public function titleAction()
2322
    {
2323
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2324
        $currentUser = $currentUserPlugin->getUser();
2325
        $currentCompany = $currentUserPlugin->getCompany();
2326
 
2327
 
2328
        $request = $this->getRequest();
2329
        $id = $this->params()->fromRoute('id');
2330
 
2331
 
2332
        if(!$id) {
2333
            $response = [
2334
                'success' => false,
2335
                'data' => 'ERROR_INVALID_PARAMETER'
2336
            ];
2337
 
2338
            return new JsonModel($response);
2339
 
2340
        }
2341
 
2342
        $jobMapper = JobMapper::getInstance($this->adapter);
2343
        $job = $jobMapper->fetchOneByUuid($id);
2344
 
2345
        if(!$job) {
2346
            $response = [
2347
                'success' => false,
2348
                'data' => 'ERROR_JOB_NOT_FOUND'
2349
            ];
2350
 
2351
            return new JsonModel($response);
2352
        }
2353
 
2354
        if($job->company_id != $currentCompany->id) {
2355
            $response = [
2356
                'success' => false,
2357
                'data' => 'ERROR_UNAUTHORIZED'
2358
            ];
2359
 
2360
            return new JsonModel($response);
2361
        }
2362
 
2363
 
2364
        $companyMapper = CompanyMapper::getInstance($this->adapter);
2365
        $company = $companyMapper->fetchOne($currentCompany->id);
2366
        if(!$company) {
2367
            $response = [
2368
                'success' => false,
2369
                'data' => 'ERROR_COMPANY_NOT_FOUND'
2370
            ];
2371
 
2372
            return new JsonModel($response);
2373
        }
2374
 
2375
 
2376
 
2377
 
2378
        $request = $this->getRequest();
2379
        if($request->isGet()) {
2380
            $data = [
2381
                'success' => true,
2382
                'data' => [
2383
                    'title' => $job->title,
2384
                ]
2385
            ];
2386
 
2387
            return new JsonModel($data);
2388
 
2389
 
2390
        } else if($request->isPost()) {
2391
 
2392
 
2393
            $form = new CompanyJobTitleForm();
2394
            $dataPost = $request->getPost()->toArray();
2395
 
2396
            $form->setData($dataPost);
2397
 
2398
            if($form->isValid()) {
2399
                $dataPost = (array) $form->getData();
2400
 
2401
                $hydrator = new ObjectPropertyHydrator();
2402
                $hydrator->hydrate($dataPost, $job);
2403
 
2404
                $jobMapper->updateTitle($job);
2405
 
2406
                $this->logger->info('Se actualizo el título del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2407
 
2408
                return new JsonModel([
2409
                    'success'   => true,
2410
                    'data' => [
2411
                        'title' => $job->title,
2412
                    ]
2413
                ]);
2414
 
2415
            } else {
2416
                $messages = [];
2417
                $form_messages = (array) $form->getMessages();
2418
                foreach($form_messages  as $fieldname => $field_messages)
2419
                {
2420
                    $messages[$fieldname] = array_values($field_messages);
2421
                }
2422
 
2423
                return new JsonModel([
2424
                    'success'   => false,
2425
                    'data'   => $messages
2426
                ]);
2427
            }
2428
        }
2429
 
2430
 
2431
        $data = [
2432
            'success' => false,
2433
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2434
        ];
2435
 
2436
 
2437
        return new JsonModel($data);
2438
    }
2439
 
2440
 
2441
 
2442
 
2443
 
2444
 
2445
}