Proyectos de Subversion LeadersLinked - Backend

Rev

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