Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 8142 | Rev 11139 | 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,
8142 stevensc 728
                    'description'               => $job->description,
1 www 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
 
8367 efrain 1051
        $employment_types = [];
1052
        $employment_types[Job::EMPLOYMENT_TYPE_FULL_TIME] = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
1053
        $employment_types[Job::EMPLOYMENT_TYPE_PART_TIME] = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
1054
        $employment_types[Job::EMPLOYMENT_TYPE_CONTRACT] = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
1055
        $employment_types[Job::EMPLOYMENT_TYPE_TEMPORARY] = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
1056
 
1 www 1057
 
1058
        $request = $this->getRequest();
1059
        if($request->isGet()) {
1060
            $data = [
1061
                'success' => true,
8367 efrain 1062
                'data' => [
1063
                    'employment_type' => $job->employment_type,
1064
                    'employment_types' => $employment_types
1065
                ]
1 www 1066
            ];
1067
 
1068
            return new JsonModel($data);
1069
 
1070
 
1071
        } else if($request->isPost()) {
1072
 
1073
            $form = new CompanyJobEmploymentTypeForm();
1074
            $dataPost = $request->getPost()->toArray();
1075
 
1076
            $form->setData($dataPost);
1077
 
1078
            if($form->isValid()) {
1079
 
1080
                $dataPost = (array) $form->getData();
1081
 
1082
                $hydrator = new ObjectPropertyHydrator();
1083
                $hydrator->hydrate($dataPost, $job);
1084
 
1085
                if($jobMapper->updateEmploymentType($job)) {
1086
                    $this->logger->info('Se actualizo tipo de empleo: '. $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1087
 
1088
                    switch($job->employment_type)
1089
                    {
1090
                        case Job::EMPLOYMENT_TYPE_FULL_TIME :
1091
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
1092
                            break;
1093
                        case Job::EMPLOYMENT_TYPE_PART_TIME :
1094
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
1095
                            break;
1096
 
1097
                        case Job::EMPLOYMENT_TYPE_CONTRACT :
1098
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
1099
                            break;
1100
 
1101
                        case Job::EMPLOYMENT_TYPE_TEMPORARY :
1102
                            $employment_type = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
1103
                            break;
1104
 
1105
                        default :
1106
                            $employment_type = '';
1107
                            break;
1108
                    }
1109
 
1110
 
1111
 
1112
                    return new JsonModel([
1113
                        'success'   => true,
1114
                        'data' => $employment_type
1115
                    ]);
1116
                }  else {
1117
                    return new JsonModel([
1118
                        'success'   => false,
1119
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
1120
                    ]);
1121
                }
1122
 
1123
 
1124
            } else {
1125
                $messages = [];
1126
                $form_messages = (array) $form->getMessages();
1127
                foreach($form_messages  as $fieldname => $field_messages)
1128
                {
1129
                    $messages[$fieldname] = array_values($field_messages);
1130
                }
1131
 
1132
                return new JsonModel([
1133
                    'success'   => false,
1134
                    'data'   => $messages
1135
                ]);
1136
            }
1137
        }
1138
 
1139
 
1140
        $data = [
1141
            'success' => false,
1142
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1143
        ];
1144
 
1145
 
1146
        return new JsonModel($data);
1147
    }
1148
 
1149
    public function jobCategoryAction()
1150
    {
1151
 
1152
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1153
        $currentUser = $currentUserPlugin->getUser();
1154
        $currentCompany = $currentUserPlugin->getCompany();
1155
 
1156
 
1157
        $request = $this->getRequest();
1158
        $id = $this->params()->fromRoute('id');
1159
 
1160
 
1161
        if(!$id) {
1162
            $response = [
1163
                'success' => false,
1164
                'data' => 'ERROR_INVALID_PARAMETER'
1165
            ];
1166
 
1167
            return new JsonModel($response);
1168
 
1169
        }
1170
 
1171
        $jobMapper = JobMapper::getInstance($this->adapter);
1172
        $job = $jobMapper->fetchOneByUuid($id);
1173
 
1174
        if(!$job) {
1175
            $response = [
1176
                'success' => false,
1177
                'data' => 'ERROR_JOB_NOT_FOUND'
1178
            ];
1179
 
1180
            return new JsonModel($response);
1181
        }
1182
 
1183
        if($job->company_id != $currentCompany->id) {
1184
            $response = [
1185
                'success' => false,
1186
                'data' => 'ERROR_UNAUTHORIZED'
1187
            ];
1188
 
1189
            return new JsonModel($response);
1190
        }
1191
 
1192
 
1193
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1194
        $company = $companyMapper->fetchOne($currentCompany->id);
1195
        if(!$company) {
1196
            $response = [
1197
                'success' => false,
1198
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1199
            ];
1200
 
1201
            return new JsonModel($response);
1202
        }
1203
 
8367 efrain 1204
        $jobCategories = [];
1 www 1205
        $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
8367 efrain 1206
        $records = $jobCategoryMapper->fetchAllActives();
1207
 
1208
        foreach($records as $record)
1209
        {
1210
            $jobCategories[$record->uuid] = $record->name;
1211
        }
1212
 
1213
 
1 www 1214
        $jobCategory = $jobCategoryMapper->fetchOne( $job->job_category_id );
1215
 
1216
 
1217
        $request = $this->getRequest();
1218
        if($request->isGet()) {
1219
            $data = [
1220
                'success' => true,
8367 efrain 1221
                'data' => [
1222
                    'job_category' => $jobCategory->uuid,
1223
                    'job_categories' => $jobCategories
1224
                 ],
1 www 1225
            ];
1226
 
1227
            return new JsonModel($data);
1228
 
1229
 
1230
        } else if($request->isPost()) {
1231
 
1232
            $form = new CompanyJobCategoryForm($this->adapter);
1233
            $dataPost = $request->getPost()->toArray();
1234
 
1235
            $form->setData($dataPost);
1236
 
1237
            if($form->isValid()) {
1238
                $this->logger->info('Se actualizaron la categoría de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1239
 
1240
                $dataPost = (array) $form->getData();
1241
 
1242
                $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
1243
                $jobCategory = $jobCategoryMapper->fetchOneByUuid( $dataPost['job_category_id'] );
1244
 
1245
                $job->job_category_id = $jobCategory->id;
1246
 
1247
                if($jobMapper->updateJobCategory($job)) {
1248
 
1249
 
1250
                    return new JsonModel([
1251
                        'success'   => true,
1252
                        'data' => $jobCategory->name
1253
                    ]);
1254
                }  else {
1255
                    return new JsonModel([
1256
                        'success'   => false,
1257
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
1258
                    ]);
1259
                }
1260
 
1261
 
1262
            } else {
1263
                $messages = [];
1264
                $form_messages = (array) $form->getMessages();
1265
                foreach($form_messages  as $fieldname => $field_messages)
1266
                {
1267
                    $messages[$fieldname] = array_values($field_messages);
1268
                }
1269
 
1270
                return new JsonModel([
1271
                    'success'   => false,
1272
                    'data'   => $messages
1273
                ]);
1274
            }
1275
        }
1276
 
1277
 
1278
        $data = [
1279
            'success' => false,
1280
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1281
        ];
1282
 
1283
 
1284
        return new JsonModel($data);
1285
    }
1286
 
1287
 
1288
    public function salaryAction()
1289
    {
1290
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1291
        $currentUser = $currentUserPlugin->getUser();
1292
        $currentCompany = $currentUserPlugin->getCompany();
1293
 
1294
 
1295
        $request = $this->getRequest();
1296
        $id = $this->params()->fromRoute('id');
1297
 
1298
 
1299
        if(!$id) {
1300
            $response = [
1301
                'success' => false,
1302
                'data' => 'ERROR_INVALID_PARAMETER'
1303
            ];
1304
 
1305
            return new JsonModel($response);
1306
 
1307
        }
1308
 
1309
        $jobMapper = JobMapper::getInstance($this->adapter);
1310
        $job = $jobMapper->fetchOneByUuid($id);
1311
 
1312
        if(!$job) {
1313
            $response = [
1314
                'success' => false,
1315
                'data' => 'ERROR_JOB_NOT_FOUND'
1316
            ];
1317
 
1318
            return new JsonModel($response);
1319
        }
1320
 
1321
        if($job->company_id != $currentCompany->id) {
1322
            $response = [
1323
                'success' => false,
1324
                'data' => 'ERROR_UNAUTHORIZED'
1325
            ];
1326
 
1327
            return new JsonModel($response);
1328
        }
1329
 
1330
 
1331
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1332
        $company = $companyMapper->fetchOne($currentCompany->id);
1333
        if(!$company) {
1334
            $response = [
1335
                'success' => false,
1336
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1337
            ];
1338
 
1339
            return new JsonModel($response);
1340
        }
1341
 
1342
 
1343
 
1344
        $request = $this->getRequest();
1345
        if($request->isGet()) {
1346
            $data = [
1347
                'success' => true,
1348
                'data' => [
1349
                    'salary_visible' => $job->salary_visible,
1350
                    'salary_currency' => $job->salary_currency,
1351
                    'salary_min' => $job->salary_min,
1352
                    'salary_max' =>  $job->salary_max
1353
                ]
1354
            ];
1355
 
1356
            return new JsonModel($data);
1357
 
1358
 
1359
        } else if($request->isPost()) {
1360
 
1361
 
1362
            $form = new CompanyJobSalaryForm($this->adapter);
1363
            $dataPost = $request->getPost()->toArray();
1364
 
1365
            $dataPost['salary_visible'] = empty( $dataPost['salary_visible']) ? Job::SALARY_VISIBLE_NO :  $dataPost['salary_visible'];
1366
            $dataPost['salary_currency'] = empty( $dataPost['salary_currency']) ? 'USD' :  $dataPost['salary_currency'];
1367
 
1368
 
1369
            $form->setData($dataPost);
1370
 
1371
            if($form->isValid()) {
1372
                $dataPost = (array) $form->getData();
1373
 
1374
                $hydrator = new ObjectPropertyHydrator();
1375
                $hydrator->hydrate($dataPost, $job);
1376
 
1377
                $jobMapper->updateSalary($job);
1378
 
1379
                $this->logger->info('Se actualizo el salario del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1380
 
1381
                return new JsonModel([
1382
                    'success'   => true,
1383
                    'data' =>  $job->salary_visible == Job::SALARY_VISIBLE_YES ?  $job->salary_min . '-' . $job->salary_max . ' ' . $job->salary_currency: ''
1384
                ]);
1385
 
1386
            } else {
1387
                $messages = [];
1388
                $form_messages = (array) $form->getMessages();
1389
                foreach($form_messages  as $fieldname => $field_messages)
1390
                {
1391
                    $messages[$fieldname] = array_values($field_messages);
1392
                }
1393
 
1394
                return new JsonModel([
1395
                    'success'   => false,
1396
                    'data'   => $messages
1397
                ]);
1398
            }
1399
        }
1400
 
1401
 
1402
        $data = [
1403
            'success' => false,
1404
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1405
        ];
1406
 
1407
 
1408
        return new JsonModel($data);
1409
    }
1410
 
1411
    public function experienceAction()
1412
    {
1413
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1414
        $currentUser = $currentUserPlugin->getUser();
1415
        $currentCompany = $currentUserPlugin->getCompany();
1416
 
1417
 
1418
        $request = $this->getRequest();
1419
        $id = $this->params()->fromRoute('id');
1420
 
1421
 
1422
        if(!$id) {
1423
            $response = [
1424
                'success' => false,
1425
                'data' => 'ERROR_INVALID_PARAMETER'
1426
            ];
1427
 
1428
            return new JsonModel($response);
1429
 
1430
        }
1431
 
1432
        $jobMapper = JobMapper::getInstance($this->adapter);
1433
        $job = $jobMapper->fetchOneByUuid($id);
1434
 
1435
        if(!$job) {
1436
            $response = [
1437
                'success' => false,
1438
                'data' => 'ERROR_JOB_NOT_FOUND'
1439
            ];
1440
 
1441
            return new JsonModel($response);
1442
        }
1443
 
1444
        if($job->company_id != $currentCompany->id) {
1445
            $response = [
1446
                'success' => false,
1447
                'data' => 'ERROR_UNAUTHORIZED'
1448
            ];
1449
 
1450
            return new JsonModel($response);
1451
        }
1452
 
1453
 
1454
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1455
        $company = $companyMapper->fetchOne($currentCompany->id);
1456
        if(!$company) {
1457
            $response = [
1458
                'success' => false,
1459
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1460
            ];
1461
 
1462
            return new JsonModel($response);
1463
        }
1464
 
1465
        $request = $this->getRequest();
1466
        if($request->isGet()) {
1467
            $data = [
1468
                'success' => true,
1469
                'data' =>  [
1470
                    'experience_visible' => $job->experience_visible,
1471
                    'experience_min' => $job->experience_min,
1472
                    'experience_max' => $job->experience_max
1473
                ]
1474
            ];
1475
 
1476
            return new JsonModel($data);
1477
 
1478
 
1479
        } else if($request->isPost()) {
1480
 
1481
 
1482
            $form = new CompanyJobExperienceForm();
1483
            $dataPost = $request->getPost()->toArray();
1484
 
1485
            $form->setData($dataPost);
1486
 
1487
            if($form->isValid()) {
1488
                $dataPost = (array) $form->getData();
1489
 
1490
                $hydrator = new ObjectPropertyHydrator();
1491
                $hydrator->hydrate($dataPost, $job);
1492
 
1493
                $jobMapper->updateExperience($job);
1494
 
1495
                $this->logger->info('Se actualizo el experiencia del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1496
 
1497
                return new JsonModel([
1498
                    'success'   => true,
1499
                    'data' => $job->experience_visible ? $job->experience_min . '-' . $job->experience_max . ' LABEL_YEARS' : ''
1500
                ]);
1501
 
1502
            } else {
1503
                $messages = [];
1504
                $form_messages = (array) $form->getMessages();
1505
                foreach($form_messages  as $fieldname => $field_messages)
1506
                {
1507
                    $messages[$fieldname] = array_values($field_messages);
1508
                }
1509
 
1510
                return new JsonModel([
1511
                    'success'   => false,
1512
                    'data'   => $messages
1513
                ]);
1514
            }
1515
        }
1516
 
1517
 
1518
        $data = [
1519
            'success' => false,
1520
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1521
        ];
1522
 
1523
 
1524
        return new JsonModel($data);
1525
    }
1526
 
1527
    public function skillAction()
1528
    {
1529
 
1530
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1531
        $currentUser = $currentUserPlugin->getUser();
1532
        $currentCompany = $currentUserPlugin->getCompany();
1533
 
1534
 
1535
        $request = $this->getRequest();
1536
        $id = $this->params()->fromRoute('id');
1537
 
1538
 
1539
        if(!$id) {
1540
            $response = [
1541
                'success' => false,
1542
                'data' => 'ERROR_INVALID_PARAMETER'
1543
            ];
1544
 
1545
            return new JsonModel($response);
1546
 
1547
        }
1548
 
1549
        $jobMapper = JobMapper::getInstance($this->adapter);
1550
        $job = $jobMapper->fetchOneByUuid($id);
1551
 
1552
        if(!$job) {
1553
            $response = [
1554
                'success' => false,
1555
                'data' => 'ERROR_JOB_NOT_FOUND'
1556
            ];
1557
 
1558
            return new JsonModel($response);
1559
        }
1560
 
1561
        if($job->company_id != $currentCompany->id) {
1562
            $response = [
1563
                'success' => false,
1564
                'data' => 'ERROR_UNAUTHORIZED'
1565
            ];
1566
 
1567
            return new JsonModel($response);
1568
        }
1569
 
1570
 
1571
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1572
        $company = $companyMapper->fetchOne($currentCompany->id);
1573
        if(!$company) {
1574
            $response = [
1575
                'success' => false,
1576
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1577
            ];
1578
 
1579
            return new JsonModel($response);
1580
        }
1581
 
1582
 
1583
 
1584
        $request = $this->getRequest();
1585
        if($request->isGet()) {
1586
 
8367 efrain 1587
            $skills = [];
1 www 1588
            $skillMapper = SkillMapper::getInstance($this->adapter);
8367 efrain 1589
            $records = $skillMapper->fetchAllActives();
1 www 1590
 
8367 efrain 1591
            foreach($records as $record)
1592
            {
1593
                $skills[$record->uuid] = $record->name;
1594
            }
1595
 
1 www 1596
            $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
8367 efrain 1597
            $skillsByjob  = $jobSkillMapper->fetchAllByJobId($job->id);
1 www 1598
 
1599
            $items = [];
8367 efrain 1600
            foreach($skillsByjob as $skill)
1 www 1601
            {
1602
                $skill = $skillMapper->fetchOne( $skill->skill_id );
1603
 
1604
 
1605
                array_push($items, $skill->uuid );
1606
            }
1607
 
1608
            $data = [
1609
                'success' => true,
8367 efrain 1610
                'data' => [
1611
                    'skills_selected' => $items,
1612
                    'skills_available' => $skills
1613
                 ]
1 www 1614
            ];
1615
 
1616
            return new JsonModel($data);
1617
 
1618
 
1619
        } else if($request->isPost()) {
1620
 
1621
            $form = new CompanyJobSkillForm($this->adapter);
1622
            $dataPost = $request->getPost()->toArray();
1623
 
1624
            $form->setData($dataPost);
1625
 
1626
            if($form->isValid()) {
1627
                $this->logger->info('Se actualizaron las habilidades requeridas del empleo : ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1628
 
1629
                $skillMapper = SkillMapper::getInstance($this->adapter);
1630
 
1631
                $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
1632
                $jobSkillMapper->deleteByJobId($job->id);
1633
 
1634
                $dataPost = (array) $form->getData();
1635
                $skills = $dataPost['skills'];
1636
                foreach($skills as $skill_id)
1637
                {
1638
                    $skill = $skillMapper->fetchOneByUuid( $skill_id );
1639
 
1640
                    $jobSkill = new JobSkill();
1641
                    $jobSkill->job_id = $job->id;
1642
                    $jobSkill->skill_id = $skill->id;
1643
 
1644
                    $jobSkillMapper->insert($jobSkill);
1645
                }
1646
 
1647
                $items = [];
1648
                $records = $jobSkillMapper->fetchAllByJobId( $job->id );
1649
                foreach($records as $record)
1650
                {
1651
                    $skill = $skillMapper->fetchOne($record->skill_id);
1652
 
1653
                    array_push($items,  ['value' => $skill->uuid, 'label' => $skill->name ]);
1654
                }
1655
 
1656
                return new JsonModel([
1657
                    'success'   => true,
1658
                    'data'   => $items
1659
                ]);
1660
 
1661
            } else {
1662
                $messages = [];
1663
                $form_messages = (array) $form->getMessages();
1664
                foreach($form_messages  as $fieldname => $field_messages)
1665
                {
1666
                    $messages[$fieldname] = array_values($field_messages);
1667
                }
1668
 
1669
                return new JsonModel([
1670
                    'success'   => false,
1671
                    'data'   => $messages
1672
                ]);
1673
            }
1674
 
1675
            $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
1676
 
1677
        }
1678
 
1679
 
1680
        $data = [
1681
            'success' => false,
1682
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1683
        ];
1684
 
1685
 
1686
        return new JsonModel($data);
1687
    }
1688
 
1689
 
1690
    public function languageAction()
1691
    {
1692
 
1693
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1694
        $currentUser = $currentUserPlugin->getUser();
1695
        $currentCompany = $currentUserPlugin->getCompany();
1696
 
1697
 
1698
        $request = $this->getRequest();
1699
        $id = $this->params()->fromRoute('id');
1700
 
1701
 
1702
        if(!$id) {
1703
            $response = [
1704
                'success' => false,
1705
                'data' => 'ERROR_INVALID_PARAMETER'
1706
            ];
1707
 
1708
            return new JsonModel($response);
1709
 
1710
        }
1711
 
1712
        $jobMapper = JobMapper::getInstance($this->adapter);
1713
        $job = $jobMapper->fetchOneByUuid($id);
1714
 
1715
        if(!$job) {
1716
            $response = [
1717
                'success' => false,
1718
                'data' => 'ERROR_JOB_NOT_FOUND'
1719
            ];
1720
 
1721
            return new JsonModel($response);
1722
        }
1723
 
1724
        if($job->company_id != $currentCompany->id) {
1725
            $response = [
1726
                'success' => false,
1727
                'data' => 'ERROR_UNAUTHORIZED'
1728
            ];
1729
 
1730
            return new JsonModel($response);
1731
        }
1732
 
1733
 
1734
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1735
        $company = $companyMapper->fetchOne($currentCompany->id);
1736
        if(!$company) {
1737
            $response = [
1738
                'success' => false,
1739
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1740
            ];
1741
 
1742
            return new JsonModel($response);
1743
        }
1744
 
1745
 
1746
 
1747
        $request = $this->getRequest();
1748
        if($request->isGet()) {
1749
            $this->logger->info('Se actualizaron los idiomas requeridos del empleo : ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1750
 
8367 efrain 1751
            $languages = [];
1752
            $languageMapper = LanguageMapper::getInstance($this->adapter);
1753
            $records = $languageMapper->fetchAllActives();
1754
 
1755
            foreach($records as $record)
1756
            {
1757
                $languages[$record->id] = $record->name;
1758
            }
1759
 
1 www 1760
            $jobLanguageMapper = JobLanguageMapper::getInstance($this->adapter);
8367 efrain 1761
            $languagesSelected  = $jobLanguageMapper->fetchAllByJobId($job->id);
1 www 1762
 
1763
            $items = [];
8367 efrain 1764
            foreach($languagesSelected as $language)
1 www 1765
            {
1766
                array_push($items, $language->language_id);
1767
            }
1768
 
1769
            $data = [
1770
                'success' => true,
8367 efrain 1771
                'data' => [
1772
                    'languages_selected' => $items,
1773
                    'languages_available' => $languages
1774
                ]
1 www 1775
            ];
1776
 
1777
            return new JsonModel($data);
1778
 
1779
 
1780
        } else if($request->isPost()) {
1781
 
1782
            $form = new CompanyJobLanguageForm($this->adapter);
1783
            $dataPost = $request->getPost()->toArray();
1784
 
1785
            $form->setData($dataPost);
1786
 
1787
            if($form->isValid()) {
1788
                $languageMapper = LanguageMapper::getInstance($this->adapter);
1789
 
1790
                $jobLanguageMapper = JobLanguageMapper::getInstance($this->adapter);
1791
                $jobLanguageMapper->deleteByJobId($job->id);
1792
 
1793
                $dataPost = (array) $form->getData();
1794
                $languages = $dataPost['languages'];
1795
                foreach($languages as $language_id)
1796
                {
1797
                    $language = $languageMapper->fetchOne($language_id);
1798
 
1799
                    $jobLanguage = new JobLanguage();
1800
                    $jobLanguage->job_id = $job->id;
1801
                    $jobLanguage->language_id = $language->id;
1802
 
1803
                    $jobLanguageMapper->insert($jobLanguage);
1804
                }
1805
 
1806
                $items = [];
1807
                $records = $jobLanguageMapper->fetchAllByJobId($job->id);
1808
                foreach($records as $record)
1809
                {
1810
                    $language = $languageMapper->fetchOne($record->language_id);
1811
 
1812
                    array_push($items,  ['value' => $language->id, 'label' => $language->name]);
1813
                }
1814
 
1815
                return new JsonModel([
1816
                    'success'   => true,
1817
                    'data'   => $items
1818
                ]);
1819
 
1820
            } else {
1821
                $messages = [];
1822
                $form_messages = (array) $form->getMessages();
1823
                foreach($form_messages  as $fieldname => $field_messages)
1824
                {
1825
                    $messages[$fieldname] = array_values($field_messages);
1826
                }
1827
 
1828
                return new JsonModel([
1829
                    'success'   => false,
1830
                    'data'   => $messages
1831
                ]);
1832
            }
1833
        }
1834
 
1835
 
1836
        $data = [
1837
            'success' => false,
1838
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1839
        ];
1840
 
1841
 
1842
        return new JsonModel($data);
1843
    }
1844
 
1845
    public function degreeAction()
1846
    {
1847
 
1848
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1849
        $currentUser = $currentUserPlugin->getUser();
1850
        $currentCompany = $currentUserPlugin->getCompany();
1851
 
1852
 
1853
        $request = $this->getRequest();
1854
        $id = $this->params()->fromRoute('id');
1855
 
1856
 
1857
        if(!$id) {
1858
            $response = [
1859
                'success' => false,
1860
                'data' => 'ERROR_INVALID_PARAMETER'
1861
            ];
1862
 
1863
            return new JsonModel($response);
1864
 
1865
        }
1866
 
1867
        $jobMapper = JobMapper::getInstance($this->adapter);
1868
        $job = $jobMapper->fetchOneByUuid($id);
1869
 
1870
        if(!$job) {
1871
            $response = [
1872
                'success' => false,
1873
                'data' => 'ERROR_JOB_NOT_FOUND'
1874
            ];
1875
 
1876
            return new JsonModel($response);
1877
        }
1878
 
1879
        if($job->company_id != $currentCompany->id) {
1880
            $response = [
1881
                'success' => false,
1882
                'data' => 'ERROR_UNAUTHORIZED'
1883
            ];
1884
 
1885
            return new JsonModel($response);
1886
        }
1887
 
1888
 
1889
        $companyMapper = CompanyMapper::getInstance($this->adapter);
1890
        $company = $companyMapper->fetchOne($currentCompany->id);
1891
        if(!$company) {
1892
            $response = [
1893
                'success' => false,
1894
                'data' => 'ERROR_COMPANY_NOT_FOUND'
1895
            ];
1896
 
1897
            return new JsonModel($response);
1898
        }
1899
 
1900
 
1901
 
1902
        $request = $this->getRequest();
1903
        if($request->isGet()) {
1904
            $this->logger->info('Se actualizaron los idiomas requeridos del empleo : ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1905
 
8367 efrain 1906
 
1907
            $degrees_available = [];
1 www 1908
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
8367 efrain 1909
 
1910
            $records = $degreeMapper->fetchAllActives();
1911
            foreach($records as $record)
1912
            {
1913
                $degrees_available[$record->uuid] = $record->name;
1914
 
1915
            }
1916
 
1 www 1917
            $jobDegreeMapper = JobDegreeMapper::getInstance($this->adapter);
1918
            $records  = $jobDegreeMapper->fetchAllByJobId($job->id);
1919
 
1920
            $items = [];
1921
            foreach($records as $record)
1922
            {
1923
                $degree = $degreeMapper->fetchOne($record->degree_id);
1924
 
1925
                array_push($items, $degree->uuid);
1926
 
1927
            }
1928
 
1929
            $data = [
1930
                'success' => true,
8367 efrain 1931
                'data' => [
1932
                    'degrees_selected' => $items,
1933
                    'degrees_available' => $degrees_available
1934
                ]
1 www 1935
            ];
1936
 
1937
            return new JsonModel($data);
1938
 
1939
 
1940
        } else if($request->isPost()) {
1941
 
1942
            $form = new CompanyJobDegreeForm($this->adapter);
1943
            $dataPost = $request->getPost()->toArray();
1944
 
1945
            $form->setData($dataPost);
1946
 
1947
            if($form->isValid()) {
1948
                $degreeMapper = DegreeMapper::getInstance($this->adapter);
1949
 
1950
                $jobDegreeMapper = JobDegreeMapper::getInstance($this->adapter);
1951
                $jobDegreeMapper->deleteByJobId($job->id);
1952
 
1953
                $dataPost = (array) $form->getData();
1954
                $degrees = $dataPost['degrees'];
1955
                foreach($degrees as $degree_id)
1956
                {
1957
                    $degree = $degreeMapper->fetchOneByUuid($degree_id);
1958
 
1959
                    $jobDegree = new JobDegree();
1960
                    $jobDegree->job_id = $job->id;
1961
                    $jobDegree->degree_id = $degree->id;
1962
                    $jobDegreeMapper->insert($jobDegree);
1963
                }
1964
 
1965
                $items = [];
1966
                $records = $jobDegreeMapper->fetchAllByJobId($job->id);
1967
                foreach($records as $record)
1968
                {
1969
                    $degree = $degreeMapper->fetchOne($record->degree_id);
1970
                    array_push($items,  ['value' => $degree->uuid, 'label' => $degree->name]);
1971
                }
1972
 
1973
                return new JsonModel([
1974
                    'success'   => true,
1975
                    'data'   => $items
1976
                ]);
1977
 
1978
            } else {
1979
                $messages = [];
1980
                $form_messages = (array) $form->getMessages();
1981
                foreach($form_messages  as $fieldname => $field_messages)
1982
                {
1983
                    $messages[$fieldname] = array_values($field_messages);
1984
                }
1985
 
1986
                return new JsonModel([
1987
                    'success'   => false,
1988
                    'data'   => $messages
1989
                ]);
1990
            }
1991
 
1992
        }
1993
 
1994
 
1995
        $data = [
1996
            'success' => false,
1997
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1998
        ];
1999
 
2000
 
2001
        return new JsonModel($data);
2002
    }
2003
 
2004
    public function lastDateOfApplicationAction()
2005
    {
2006
 
2007
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2008
        $currentUser = $currentUserPlugin->getUser();
2009
        $currentCompany = $currentUserPlugin->getCompany();
2010
 
2011
 
2012
        $request = $this->getRequest();
2013
        $id = $this->params()->fromRoute('id');
2014
 
2015
 
2016
        if(!$id) {
2017
            $response = [
2018
                'success' => false,
2019
                'data' => 'ERROR_INVALID_PARAMETER'
2020
            ];
2021
 
2022
            return new JsonModel($response);
2023
 
2024
        }
2025
 
2026
        $jobMapper = JobMapper::getInstance($this->adapter);
2027
        $job = $jobMapper->fetchOneByUuid($id);
2028
 
2029
        if(!$job) {
2030
            $response = [
2031
                'success' => false,
2032
                'data' => 'ERROR_JOB_NOT_FOUND'
2033
            ];
2034
 
2035
            return new JsonModel($response);
2036
        }
2037
 
2038
        if($job->company_id != $currentCompany->id) {
2039
            $response = [
2040
                'success' => false,
2041
                'data' => 'ERROR_UNAUTHORIZED'
2042
            ];
2043
 
2044
            return new JsonModel($response);
2045
        }
2046
 
2047
 
2048
        $companyMapper = CompanyMapper::getInstance($this->adapter);
2049
        $company = $companyMapper->fetchOne($currentCompany->id);
2050
        if(!$company) {
2051
            $response = [
2052
                'success' => false,
2053
                'data' => 'ERROR_COMPANY_NOT_FOUND'
2054
            ];
2055
 
2056
            return new JsonModel($response);
2057
        }
2058
 
2059
 
2060
 
2061
        $request = $this->getRequest();
2062
        if($request->isGet()) {
2063
            $dt = \DateTime::createFromFormat('Y-m-d', $job->last_date_of_application);
2064
 
2065
            $data = [
2066
                'success' => true,
2067
                'data' => $dt->format('d/m/Y'),
2068
            ];
2069
 
2070
            return new JsonModel($data);
2071
 
2072
 
2073
        } else if($request->isPost()) {
2074
 
2075
            $form = new CompanyJobLastDateOfApplicationForm();
2076
            $dataPost = $request->getPost()->toArray();
2077
 
2078
            $form->setData($dataPost);
2079
 
2080
            if($form->isValid()) {
2081
                $this->logger->info('Se actualizo la última fecha de aplicación de la empresa: '. $company->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2082
 
2083
                $dt = \DateTime::createFromFormat('d/m/Y', $form->get('last_date_of_application')->getValue());
2084
                $job->last_date_of_application = $dt->format('Y-m-d');
2085
 
2086
                if($jobMapper->updateLastDateOfApplication($job)) {
2087
                    $months = [
2088
                        1 => 'LABEL_MONTH_JANUARY',
2089
                        2 => 'LABEL_MONTH_FEBRUARY',
2090
                        3 => 'LABEL_MONTH_MARCH',
2091
                        4 => 'LABEL_MONTH_APRIL',
2092
                        5 => 'LABEL_MONTH_MAY',
2093
                        6 => 'LABEL_MONTH_JUNE',
2094
                        7 => 'LABEL_MONTH_JULY',
2095
                        8 => 'LABEL_MONTH_AUGUST',
2096
                        9 => 'LABEL_MONTH_SEPTEMBER',
2097
                        10 => 'LABEL_MONTH_OCTOBER',
2098
                        11 => 'LABEL_MONTH_NOVEMBER',
2099
                        12 => 'LABEL_MONTH_DECEMBER',
2100
                    ];
2101
 
2102
                   $last_date_of_application = $dt->format('d') . ' de ' . $months[$dt->format('n')] . ' de ' . $dt->format('Y');
2103
 
2104
 
2105
                    return new JsonModel([
2106
                        'success'   => true,
2107
                        'data' => $last_date_of_application
2108
                    ]);
2109
                }  else {
2110
                    return new JsonModel([
2111
                        'success'   => false,
2112
                        'data' => 'ERROR_THERE_WAS_AN_ERROR'
2113
                    ]);
2114
                }
2115
 
2116
 
2117
            } else {
2118
                $messages = [];
2119
                $form_messages = (array) $form->getMessages();
2120
                foreach($form_messages  as $fieldname => $field_messages)
2121
                {
2122
                    $messages[$fieldname] = array_values($field_messages);
2123
                }
2124
 
2125
                return new JsonModel([
2126
                    'success'   => false,
2127
                    'data'   => $messages
2128
                ]);
2129
            }
2130
        }
2131
 
2132
 
2133
        $data = [
2134
            'success' => false,
2135
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2136
        ];
2137
 
2138
 
2139
        return new JsonModel($data);
2140
    }
2141
 
2142
    public function usersWhoAppliedAction()
2143
    {
2144
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2145
        $currentUser = $currentUserPlugin->getUser();
2146
        $currentCompany = $currentUserPlugin->getCompany();
2147
 
2148
 
2149
        $request = $this->getRequest();
2150
        $id = $this->params()->fromRoute('id');
2151
 
2152
        if(!$id) {
2153
            $data = [
2154
                'success'   => false,
2155
                'data'   => 'ERROR_INVALID_PARAMETER'
2156
            ];
2157
 
2158
            return new JsonModel($data);
2159
        }
2160
 
2161
        $jobMapper = JobMapper::getInstance($this->adapter);
2162
        $job = $jobMapper->fetchOneByUuid($id);
2163
        if(!$job) {
2164
            $data = [
2165
                'success'   => false,
2166
                'data'   => 'ERROR_JOB_NOT_FOUND'
2167
            ];
2168
 
2169
            return new JsonModel($data);
2170
        }
2171
 
2172
        if($job->company_id != $currentCompany->id) {
2173
            $data = [
2174
                'success'   => false,
2175
                'data'   => 'ERROR_UNAUTHORIZED'
2176
            ];
2177
 
2178
            return new JsonModel($data);
2179
        }
2180
 
2181
 
2182
        $request = $this->getRequest();
2183
        if($request->isGet()) {
2184
 
2185
            $sandbox = $this->config['leaderslinked.runmode.sandbox'];
2186
            if($sandbox) {
2187
                $user_profile_url = $this->config['leaderslinked.frontend.sandbox_user_profile'];
2188
            } else {
2189
                $user_profile_url = $this->config['leaderslinked.frontend.production_user_profile'];
2190
            }
2191
 
2192
 
2193
            $queryMapper = QueryMapper::getInstance($this->adapter);
2194
            $select = $queryMapper->getSql()->select();
2195
            $select->columns(['id',  'user_uuid' => 'uuid', 'first_name','last_name', 'email']);
2196
            $select->from(['u' => UserMapper::_TABLE]);
2197
            $select->join(['ja' => JobApplicationMapper::_TABLE], 'ja.user_id = u.id', ['user_profile_id']);
2198
            $select->join(['up' => UserProfileMapper::_TABLE], 'ja.user_profile_id = up.id', ['user_profile_uuid' => 'uuid']);
2199
            $select->where->equalTo('u.status', User::STATUS_ACTIVE);
2200
            $select->order(['first_name', 'last_name']);
2201
 
2202
            $items = [];
2203
            $records = $queryMapper->fetchAll($select);
2204
 
2205
            foreach($records as $record)
2206
            {
2207
                $item = [
2208
                    'first_name' => $record['first_name'],
2209
                    'last_name' => $record['last_name'],
2210
                    'email' => $record['email'],
2211
                    'link_view' => str_replace('[uuid]', $record['user_profile_uuid'], $user_profile_url),
2212
 
2213
                ];
2214
 
2215
                array_push($items, $item);
2216
            }
2217
 
2218
 
2219
            $response = [
2220
                'success' => true,
2221
                'data' => $items
2222
            ];
2223
 
2224
            return new JsonModel($response);
2225
 
2226
 
2227
        } else {
2228
            return new JsonModel([
2229
                'success' => false,
2230
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2231
            ]);
2232
        }
2233
    }
2234
 
2235
 
2236
    public function statusAction()
2237
    {
2238
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2239
        $currentUser = $currentUserPlugin->getUser();
2240
        $currentCompany = $currentUserPlugin->getCompany();
2241
 
2242
 
2243
        $request = $this->getRequest();
2244
        $id = $this->params()->fromRoute('id');
2245
 
2246
 
2247
        if(!$id) {
2248
            $response = [
2249
                'success' => false,
2250
                'data' => 'ERROR_INVALID_PARAMETER'
2251
            ];
2252
 
2253
            return new JsonModel($response);
2254
 
2255
        }
2256
 
2257
        $jobMapper = JobMapper::getInstance($this->adapter);
2258
        $job = $jobMapper->fetchOneByUuid($id);
2259
 
2260
        if(!$job) {
2261
            $response = [
2262
                'success' => false,
2263
                'data' => 'ERROR_JOB_NOT_FOUND'
2264
            ];
2265
 
2266
            return new JsonModel($response);
2267
        }
2268
 
2269
        if($job->company_id != $currentCompany->id) {
2270
            $response = [
2271
                'success' => false,
2272
                'data' => 'ERROR_UNAUTHORIZED'
2273
            ];
2274
 
2275
            return new JsonModel($response);
2276
        }
2277
 
2278
 
2279
        $companyMapper = CompanyMapper::getInstance($this->adapter);
2280
        $company = $companyMapper->fetchOne($currentCompany->id);
2281
        if(!$company) {
2282
            $response = [
2283
                'success' => false,
2284
                'data' => 'ERROR_COMPANY_NOT_FOUND'
2285
            ];
2286
 
2287
            return new JsonModel($response);
2288
        }
2289
 
2290
 
2291
 
2292
 
2293
        $request = $this->getRequest();
2294
        if($request->isGet()) {
2295
            $data = [
2296
                'success' => true,
2297
                'data' => [
2298
                    'status' => $job->status,
2299
                ]
2300
            ];
2301
 
2302
            return new JsonModel($data);
2303
 
2304
 
2305
        } else if($request->isPost()) {
2306
 
2307
 
2308
            $form = new CompanyJobStatusForm();
2309
            $dataPost = $request->getPost()->toArray();
2310
 
2311
            $form->setData($dataPost);
2312
 
2313
            if($form->isValid()) {
2314
                $dataPost = (array) $form->getData();
2315
 
2316
                $hydrator = new ObjectPropertyHydrator();
2317
                $hydrator->hydrate($dataPost, $job);
2318
 
2319
                $jobMapper->updateStatus($job);
2320
 
2321
                $this->logger->info('Se actualizo el estatus del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2322
 
2323
                switch($job->status) {
2324
                    case  Job::STATUS_ACTIVE :
2325
                        $status = 'LABEL_ACTIVE';
2326
                        break;
2327
 
2328
                    case  Job::STATUS_INACTIVE :
2329
                        $status = 'LABEL_INACTIVE';
2330
                        break;
2331
 
2332
 
2333
                    case  Job::STATUS_DELETED :
2334
                        $status = 'LABEL_DELETED';
2335
                        break;
2336
 
2337
                    default :
2338
                        $status = '';
2339
                        break;
2340
                }
2341
 
2342
 
2343
                return new JsonModel([
2344
                    'success'   => true,
2345
                    'data' => [
2346
                        'status' => $status,
2347
                    ]
2348
                ]);
2349
 
2350
            } else {
2351
                $messages = [];
2352
                $form_messages = (array) $form->getMessages();
2353
                foreach($form_messages  as $fieldname => $field_messages)
2354
                {
2355
                    $messages[$fieldname] = array_values($field_messages);
2356
                }
2357
 
2358
                return new JsonModel([
2359
                    'success'   => false,
2360
                    'data'   => $messages
2361
                ]);
2362
            }
2363
        }
2364
 
2365
 
2366
        $data = [
2367
            'success' => false,
2368
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2369
        ];
2370
 
2371
 
2372
        return new JsonModel($data);
2373
    }
2374
 
2375
 
2376
    public function titleAction()
2377
    {
2378
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2379
        $currentUser = $currentUserPlugin->getUser();
2380
        $currentCompany = $currentUserPlugin->getCompany();
2381
 
2382
 
2383
        $request = $this->getRequest();
2384
        $id = $this->params()->fromRoute('id');
2385
 
2386
 
2387
        if(!$id) {
2388
            $response = [
2389
                'success' => false,
2390
                'data' => 'ERROR_INVALID_PARAMETER'
2391
            ];
2392
 
2393
            return new JsonModel($response);
2394
 
2395
        }
2396
 
2397
        $jobMapper = JobMapper::getInstance($this->adapter);
2398
        $job = $jobMapper->fetchOneByUuid($id);
2399
 
2400
        if(!$job) {
2401
            $response = [
2402
                'success' => false,
2403
                'data' => 'ERROR_JOB_NOT_FOUND'
2404
            ];
2405
 
2406
            return new JsonModel($response);
2407
        }
2408
 
2409
        if($job->company_id != $currentCompany->id) {
2410
            $response = [
2411
                'success' => false,
2412
                'data' => 'ERROR_UNAUTHORIZED'
2413
            ];
2414
 
2415
            return new JsonModel($response);
2416
        }
2417
 
2418
 
2419
        $companyMapper = CompanyMapper::getInstance($this->adapter);
2420
        $company = $companyMapper->fetchOne($currentCompany->id);
2421
        if(!$company) {
2422
            $response = [
2423
                'success' => false,
2424
                'data' => 'ERROR_COMPANY_NOT_FOUND'
2425
            ];
2426
 
2427
            return new JsonModel($response);
2428
        }
2429
 
2430
 
2431
 
2432
 
2433
        $request = $this->getRequest();
2434
        if($request->isGet()) {
2435
            $data = [
2436
                'success' => true,
2437
                'data' => [
2438
                    'title' => $job->title,
2439
                ]
2440
            ];
2441
 
2442
            return new JsonModel($data);
2443
 
2444
 
2445
        } else if($request->isPost()) {
2446
 
2447
 
2448
            $form = new CompanyJobTitleForm();
2449
            $dataPost = $request->getPost()->toArray();
2450
 
2451
            $form->setData($dataPost);
2452
 
2453
            if($form->isValid()) {
2454
                $dataPost = (array) $form->getData();
2455
 
2456
                $hydrator = new ObjectPropertyHydrator();
2457
                $hydrator->hydrate($dataPost, $job);
2458
 
2459
                $jobMapper->updateTitle($job);
2460
 
2461
                $this->logger->info('Se actualizo el título del empleo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2462
 
2463
                return new JsonModel([
2464
                    'success'   => true,
2465
                    'data' => [
2466
                        'title' => $job->title,
2467
                    ]
2468
                ]);
2469
 
2470
            } else {
2471
                $messages = [];
2472
                $form_messages = (array) $form->getMessages();
2473
                foreach($form_messages  as $fieldname => $field_messages)
2474
                {
2475
                    $messages[$fieldname] = array_values($field_messages);
2476
                }
2477
 
2478
                return new JsonModel([
2479
                    'success'   => false,
2480
                    'data'   => $messages
2481
                ]);
2482
            }
2483
        }
2484
 
2485
 
2486
        $data = [
2487
            'success' => false,
2488
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
2489
        ];
2490
 
2491
 
2492
        return new JsonModel($data);
2493
    }
2494
 
2495
 
2496
 
2497
 
2498
 
2499
 
2500
}