Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1 www 1
<?php
2
/**
3
 *
4
 * Controlador: Mis Perfiles
5
 *
6
 */
7
declare(strict_types=1);
8
 
9
namespace LeadersLinked\Controller;
10
 
11
use Laminas\Db\Adapter\AdapterInterface;
6849 efrain 12
 
1 www 13
use Laminas\Mvc\Controller\AbstractActionController;
14
use Laminas\Log\LoggerInterface;
15
use Laminas\View\Model\ViewModel;
16
use Laminas\View\Model\JsonModel;
17
 
18
use LeadersLinked\Library\Functions;
19
use LeadersLinked\Mapper\CompanyUserMapper;
20
use LeadersLinked\Model\Job;
21
use LeadersLinked\Mapper\LocationMapper;
22
use LeadersLinked\Mapper\JobMapper;
23
use LeadersLinked\Mapper\CompanyMapper;
24
use LeadersLinked\Mapper\JobCategoryMapper;
25
use LeadersLinked\Mapper\JobSkillMapper;
26
use LeadersLinked\Mapper\JobDegreeMapper;
27
use LeadersLinked\Mapper\JobLanguageMapper;
28
use LeadersLinked\Mapper\DegreeMapper;
29
use LeadersLinked\Mapper\LanguageMapper;
30
use LeadersLinked\Mapper\SkillMapper;
31
use LeadersLinked\Mapper\IndustryMapper;
32
use LeadersLinked\Mapper\CompanySizeMapper;
33
use LeadersLinked\Mapper\CompanyLocationMapper;
34
use LeadersLinked\Mapper\JobApplicationMapper;
35
use LeadersLinked\Form\Job\ApplyForm;
36
use LeadersLinked\Model\JobApplication;
37
use LeadersLinked\Mapper\JobSaveMapper;
38
use LeadersLinked\Model\JobSave;
39
use LeadersLinked\Mapper\QueryMapper;
40
use LeadersLinked\Mapper\UserProfileMapper;
41
 
2805 kerby 42
 
1 www 43
class JobController extends AbstractActionController
44
{
45
    /**
46
     *
6866 efrain 47
     * @var \Laminas\Db\Adapter\AdapterInterface
1 www 48
     */
49
    private $adapter;
50
 
51
    /**
52
     *
6866 efrain 53
     * @var \LeadersLinked\Cache\CacheInterface
1 www 54
     */
6866 efrain 55
    private $cache;
56
 
57
 
58
    /**
59
     *
60
     * @var \Laminas\Log\LoggerInterface
61
     */
1 www 62
    private $logger;
63
 
64
    /**
65
     *
66
     * @var array
67
     */
68
    private $config;
69
 
6866 efrain 70
 
1 www 71
    /**
72
     *
6866 efrain 73
     * @var \Laminas\Mvc\I18n\Translator
74
     */
75
    private $translator;
76
 
77
 
78
    /**
79
     *
80
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
81
     * @param \LeadersLinked\Cache\CacheInterface $cache
82
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
1 www 83
     * @param array $config
6866 efrain 84
     * @param \Laminas\Mvc\I18n\Translator $translator
1 www 85
     */
6866 efrain 86
    public function __construct($adapter, $cache, $logger, $config, $translator)
1 www 87
    {
88
        $this->adapter      = $adapter;
6866 efrain 89
        $this->cache        = $cache;
1 www 90
        $this->logger       = $logger;
91
        $this->config       = $config;
6866 efrain 92
        $this->translator   = $translator;
1 www 93
    }
94
 
95
    /**
96
     *
97
     * Generación del listado de perfiles
98
     * {@inheritDoc}
99
     * @see \Laminas\Mvc\Controller\AbstractActionController::indexAction()
100
     */
101
    public function indexAction()
102
    {
103
 
104
        return new JsonModel([
105
            'success' => false,
106
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
107
        ]);
108
    }
109
 
110
    public function viewAction()
111
    {
3639 efrain 112
        $currentUserPlugin = $this->plugin('currentUserPlugin');
113
        $currentUser = $currentUserPlugin->getUser();
1 www 114
 
115
        $flashMessenger = $this->plugin('FlashMessenger');
116
        $request = $this->getRequest();
117
        $id = $this->params()->fromRoute('id');
118
 
119
        if(!$id) {
120
            $flashMessenger->addErrorMessage('ERROR_INVALID_PARAMETER');
121
            return $this->redirect()->toRoute('dashboard');
122
        }
123
 
124
        $jobMapper = JobMapper::getInstance($this->adapter);
3639 efrain 125
        $job = $jobMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1 www 126
        if(!$job) {
127
            $flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
128
            return $this->redirect()->toRoute('dashboard');
129
        }
130
 
131
        if($job->status != Job::STATUS_ACTIVE) {
132
            $flashMessenger->addErrorMessage('ERROR_UNAUTHORIZED');
133
            return $this->redirect()->toRoute('dashboard');
134
        }
135
 
136
        $companyMapper = CompanyMapper::getInstance($this->adapter);
137
        $company = $companyMapper->fetchOne($job->company_id);
138
        if(!$company) {
139
            $flashMessenger->addErrorMessage('ERROR_RECORD_NOT_FOUND');
140
            return $this->redirect()->toRoute('dashboard');
141
        }
142
 
143
 
144
 
145
 
146
 
147
        if($request->isGet()) {
148
            $currentUserPlugin = $this->plugin('currentUserPlugin');
149
            $currentUser = $currentUserPlugin->getUser();
150
 
151
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
6388 efrain 152
            $now = $companyUserMapper->getDatebaseNow();
153
 
1 www 154
            $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($company->id, $currentUser->id);
155
 
156
            $jobApplicationMapper = JobApplicationMapper::getInstance($this->adapter);
157
            $total_applications = $jobApplicationMapper->fetchTotalApplicationsByJobId($job->id);
158
 
159
 
160
            $job->visits++;
161
            $jobMapper->updateVisits($job);
162
 
163
 
164
            //if($companyUser) {
165
            //   $job_apply_operation = '';
166
            //} else {
167
                $jobApplication = $jobApplicationMapper->fetchOneByJobIdAndUserId($job->id, $currentUser->id);
168
                if($jobApplication) {
169
                    $job_apply_operation = 'remove-apply';
170
                } else {
171
                    $job_apply_operation = 'apply';
172
                }
173
 
174
            //}
175
 
176
            $jobSaveMapper = JobSaveMapper::getInstance($this->adapter);
177
            $jobSave = $jobSaveMapper->fetchOneByJobIdAndUserId($job->id, $currentUser->id);
178
            if($jobSave) {
179
                $job_save_operation = 'remove-job-saved';
180
            } else {
181
                $job_save_operation = 'job-save';
182
            }
183
 
184
 
185
            $months = [
186
                1 => 'LABEL_MONTH_JANUARY',
187
                2 => 'LABEL_MONTH_FEBRUARY',
188
                3 => 'LABEL_MONTH_MARCH',
189
                4 => 'LABEL_MONTH_APRIL',
190
                5 => 'LABEL_MONTH_MAY',
191
                6 => 'LABEL_MONTH_JUNE',
192
                7 => 'LABEL_MONTH_JULY',
193
                8 => 'LABEL_MONTH_AUGUST',
194
                9 => 'LABEL_MONTH_SEPTEMBER',
195
                10 => 'LABEL_MONTH_OCTOBER',
196
                11 => 'LABEL_MONTH_NOVEMBER',
197
                12 => 'LABEL_MONTH_DECEMBER',
198
            ];
199
 
200
            $dt = \dateTime::createFromFormat('Y-m-d', $job->last_date_of_application);
201
            $last_date_of_application = $dt->format('d') . ' de ' . $months[$dt->format('n')] . ' de ' . $dt->format('Y');
202
 
203
            $locationMapper = LocationMapper::getInstance($this->adapter);
204
            $location = $locationMapper->fetchOne($job->location_id);
205
 
206
            $jobCategoryMapper = JobCategoryMapper::getInstance($this->adapter);
207
            $jobCategory = $jobCategoryMapper->fetchOne($job->job_category_id);
208
 
209
            switch($job->employment_type)
210
            {
211
                case Job::EMPLOYMENT_TYPE_FULL_TIME :
212
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_FULL_TIME';
213
                    break;
214
                case Job::EMPLOYMENT_TYPE_PART_TIME :
215
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_PART_TIME';
216
                    break;
217
 
218
                case Job::EMPLOYMENT_TYPE_CONTRACT :
219
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_CONTRACT';
220
                    break;
221
 
222
                case Job::EMPLOYMENT_TYPE_TEMPORARY :
223
                    $employment_type = 'LABEL_EMPLOYMENT_TYPE_TEMPORARY';
224
                    break;
225
 
226
                default :
227
                    $employment_type = '';
228
                    break;
229
            }
230
 
231
            $degrees = [];
232
            $degreeMapper = DegreeMapper::getInstance($this->adapter);
3454 efrain 233
            $records = $degreeMapper->fetchAllActive();
1 www 234
            foreach($records as $record)
235
            {
236
                $degrees[$record->uuid] = $record->name;
237
            }
238
 
239
            $jobDegreeMapper = JobDegreeMapper::getInstance($this->adapter);
240
            $records = $jobDegreeMapper->fetchAllByJobId($job->id);
241
 
242
            $job_degrees = [];
243
            foreach($records as $record)
244
            {
245
                $degree = $degreeMapper->fetchOne($record->degree_id);
246
                array_push($job_degrees, $degree->name);
247
            }
248
 
249
            $languages = [];
250
            $languageMapper = LanguageMapper::getInstance($this->adapter);
3454 efrain 251
            $records = $languageMapper->fetchAllActive();
1 www 252
            foreach($records as $record)
253
            {
254
                $languages[$record->id] = $record->name;
255
            }
256
 
257
            $jobLanguageMapper = JobLanguageMapper::getInstance($this->adapter);
258
            $records = $jobLanguageMapper->fetchAllByJobId($job->id);
259
 
260
 
261
            $job_languages = [];
262
            foreach($records as $record)
263
            {
264
                $language = $languageMapper->fetchOne($record->language_id);
265
                array_push($job_languages, $language->name);
266
            }
267
 
268
            $skills = [];
269
            $skillMapper = SkillMapper::getInstance($this->adapter);
270
 
3454 efrain 271
            $records = $skillMapper->fetchAllActive();
1 www 272
            foreach($records as $record)
273
            {
274
                $skills[$record->uuid] = $record->name;
275
            }
276
 
277
 
278
            $jobSkillMapper = JobSkillMapper::getInstance($this->adapter);
279
            $records = $jobSkillMapper->fetchAllByJobId($job->id);
280
 
281
            $job_skills = [];
282
            foreach($records as $record)
283
            {
284
                $skill = $skillMapper->fetchOne($record->skill_id);
285
                array_push($job_skills, $skill->name);
286
            }
287
 
288
 
289
            $industryMapper = IndustryMapper::getInstance($this->adapter);
290
            $industry = $industryMapper->fetchOne($company->industry_id);
291
 
292
            $companySizeMapper = CompanySizeMapper::getInstance($this->adapter);
293
            $companySize = $companySizeMapper->fetchOne($company->company_size_id);
294
 
295
            $companyLocationMapper = CompanyLocationMapper::getInstance($this->adapter);
296
            $companyLocation = $companyLocationMapper->fetchOneMainLocationByCompanyId($company->id);
297
 
298
 
299
            $company_address = '';
300
            if($companyLocation) {
301
                $mainLocation = $locationMapper->fetchOne($companyLocation->location_id);
302
                if($mainLocation) {
303
                    $company_address = $mainLocation->formatted_address;
304
                }
305
            }
306
 
307
            $user_profiles = [];
308
            $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
309
            $records = $userProfileMapper->fetchAllByUserId($currentUser->id);
310
            foreach($records as $record)
311
            {
312
                $user_profiles[$record->uuid] = $record->name;
313
            }
314
 
315
 
316
 
6388 efrain 317
 
3138 efrain 318
            $timeElapsed = Functions::timeAgo($job->updated_on, $now);
319
 
1 www 320
            $formApply = new ApplyForm($this->adapter, $currentUser->id);
321
 
322
 
323
            $this->layout()->setTemplate('layout/layout.phtml');
324
            $viewModel = new ViewModel();
325
            $viewModel->setTemplate('leaders-linked/job/view.phtml');
326
            $viewModel->setVariables([
327
                'company_uuid'  => $company->uuid,
328
                'company_image'         => $company->image,
329
                'job_uuid'              => $job->uuid,
330
                'job_title'             => $job->title,
331
                'job_description'       => $job->description,
332
                'total_applications'    => $total_applications,
333
                'location'              => $location->formatted_address,
334
                'employment_type'       => $employment_type,
335
                'last_date_of_application'  => $last_date_of_application,
336
                'job_category'              => $jobCategory->name,
337
                'timeElapsed'               => $timeElapsed,
338
                'experience'                => $job->experience_visible ? $job->experience_min . '-' . $job->experience_max : '',
339
                'salary'                    => $job->salary_visible ? $job->salary_min . '-' . $job->salary_max . ' (' . $job->salary_currency . ')' : '',
340
                'job_degrees'               => $job_degrees,
341
                'job_languages'             => $job_languages,
342
                'job_skills'                => $job_skills,
343
                'job_visits'                => $job->visits,
344
                'job_apply_operation'       => $job_apply_operation,
345
                'job_save_operation'        => $job_save_operation,
346
                'company_name'              => $company->name,
347
                'company_foundation_year'   => $company->foundation_year,
348
                'company_website'           => $company->website,
349
                'company_industry'          => $industry->name,
350
                'company_size'              => $companySize->minimum_no_of_employee . '-' . $companySize->maximum_no_of_employee,
351
                'company_address'           => $company_address,
352
                'formApply'                 => $formApply,
353
                'user_profiles'             => $user_profiles
354
 
355
 
356
            ]);
357
            return $viewModel ;
358
 
359
        } else {
360
            $data = [
361
                'success' => false,
362
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
363
            ];
364
 
365
            return new JsonModel($data);
366
        }
367
 
368
        return new JsonModel($data);
369
    }
370
 
371
    public function applyJobAction()
372
    {
3639 efrain 373
        $currentUserPlugin = $this->plugin('currentUserPlugin');
374
        $currentUser = $currentUserPlugin->getUser();
375
 
376
 
1 www 377
        $request = $this->getRequest();
378
        $id = $this->params()->fromRoute('id');
379
 
380
        if(!$id) {
381
            $data = [
382
                'success' => false,
383
                'data' => 'ERROR_INVALID_PARAMETER'
384
            ];
385
 
386
            return new JsonModel($data);
387
        }
388
 
389
        $jobMapper = JobMapper::getInstance($this->adapter);
3639 efrain 390
        $job = $jobMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1 www 391
        if(!$job) {
392
            $data = [
393
                'success' => false,
394
                'data' => 'ERROR_RECORD_NOT_FOUND'
395
            ];
396
 
397
            return new JsonModel($data);
398
        }
399
 
400
        if($job->status != Job::STATUS_ACTIVE) {
401
            $data = [
402
                'success' => false,
403
                'data' => 'ERROR_UNAUTHORIZED'
404
            ];
405
 
406
            return new JsonModel($data);
407
        }
408
 
409
        $companyMapper = CompanyMapper::getInstance($this->adapter);
410
        $company = $companyMapper->fetchOne($job->company_id);
411
        if(!$company) {
412
            $data = [
413
                'success' => false,
414
                'data' => 'ERROR_RECORD_NOT_FOUND'
415
            ];
416
 
417
            return new JsonModel($data);
418
        }
419
 
420
 
421
        if($request->isPost()) {
3639 efrain 422
 
1 www 423
            $form = new ApplyForm($this->adapter, $currentUser->id);
424
            $dataPost = $request->getPost()->toArray();
425
 
426
            $form->setData($dataPost);
427
 
428
            if($form->isValid()) {
429
                $dataPost = (array) $form->getData();
430
 
431
                $userProfileMapper = UserProfileMapper::getInstance($this->adapter);
432
                $userProfile = $userProfileMapper->fetchOneByUuid($dataPost['user_profile_id']);
433
 
434
                $jobApplicationMapper = JobApplicationMapper::getInstance($this->adapter);
435
                $jobApplication = $jobApplicationMapper->fetchOneByJobIdAndUserId($job->id, $currentUser->id);
436
 
437
                $result = true;
438
 
439
                if(!$jobApplication) {
440
                    $jobApplication = new JobApplication();
441
                    $jobApplication->job_id = $job->id;
442
                    $jobApplication->user_id = $currentUser->id;
443
                    $jobApplication->user_profile_id = $userProfile->id;
444
 
445
                    $result = $jobApplicationMapper->insert($jobApplication);
446
                    if($result) {
447
                        $this->logger->info('El usuario  ' . $currentUser->first_name .  ' ' . $currentUser->last_name . ' aplico al trabajo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
448
                    }
449
                }
450
 
451
                if($result) {
452
 
453
                    $total = $jobApplicationMapper->fetchTotalApplicationsByJobId($job->id);
454
 
455
                    $data = [
456
                        'success'   => true,
457
                        'data'      => 'LABEL_SUCCESSFUL_APPLICATION',
458
                        'total'     => $total
459
                    ];
460
 
461
 
462
 
463
                } else {
464
                    $data = [
465
                        'success'   => false,
466
                        'data'      => $jobApplicationMapper->getError()
467
                    ];
468
                }
469
 
470
 
471
                return new JsonModel($data);
472
 
473
            } else {
474
                $messages = [];
475
                $form_messages = (array) $form->getMessages();
476
                foreach($form_messages  as $fieldname => $field_messages)
477
                {
478
                    $messages[$fieldname] = array_values($field_messages);
479
                }
480
 
481
                return new JsonModel([
482
                    'success'   => false,
483
                    'data'   => $messages
484
                ]);
485
            }
486
 
487
        } else {
488
            $data = [
489
                'success' => false,
490
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
491
            ];
492
 
493
            return new JsonModel($data);
494
 
495
        }
496
    }
497
 
498
    public function removeApplyJobAction()
499
    {
3639 efrain 500
        $currentUserPlugin = $this->plugin('currentUserPlugin');
501
        $currentUser = $currentUserPlugin->getUser();
502
 
1 www 503
        $request = $this->getRequest();
504
        $id = $this->params()->fromRoute('id');
505
 
506
        if(!$id) {
507
            $data = [
508
                'success' => false,
509
                'data' => 'ERROR_INVALID_PARAMETER'
510
            ];
511
 
512
            return new JsonModel($data);
513
        }
514
 
515
        $jobMapper = JobMapper::getInstance($this->adapter);
3639 efrain 516
        $job = $jobMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1 www 517
        if(!$job) {
518
            $data = [
519
                'success' => false,
520
                'data' => 'ERROR_RECORD_NOT_FOUND'
521
            ];
522
 
523
            return new JsonModel($data);
524
        }
525
 
526
        if($job->status != Job::STATUS_ACTIVE) {
527
            $data = [
528
                'success' => false,
529
                'data' => 'ERROR_UNAUTHORIZED'
530
            ];
531
 
532
            return new JsonModel($data);
533
        }
534
 
535
        $companyMapper = CompanyMapper::getInstance($this->adapter);
536
        $company = $companyMapper->fetchOne($job->company_id);
537
        if(!$company) {
538
            $data = [
539
                'success' => false,
540
                'data' => 'ERROR_RECORD_NOT_FOUND'
541
            ];
542
 
543
            return new JsonModel($data);
544
        }
545
 
546
 
547
        if($request->isPost()) {
548
 
549
            $jobApplicationMapper = JobApplicationMapper::getInstance($this->adapter);
550
            $result = $jobApplicationMapper->deleteByJobIdAndUserId($job->id, $currentUser->id);
551
 
552
            if($result) {
553
                $this->logger->info('El usuario  ' . $currentUser->first_name .  ' ' . $currentUser->last_name . ' removio su aplicación al trabajo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
554
 
555
                $total = $jobApplicationMapper->fetchTotalApplicationsByJobId($job->id);
556
                $data = [
557
                    'success'   => true,
558
                    'data'      => 'LABEL_APPLICATION_WAS_REMOVED',
559
                    'total'     => $total
560
                ];
561
            } else {
562
                $data = [
563
                    'success'   => false,
564
                    'data'      => $jobApplicationMapper->getError()
565
                ];
566
 
567
 
568
            }
569
 
570
            return new JsonModel($data);
571
 
572
        } else {
573
            $data = [
574
                'success' => false,
575
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
576
            ];
577
 
578
            return new JsonModel($data);
579
 
580
        }
581
    }
582
 
583
    public function removeSaveJobAction()
584
    {
3639 efrain 585
        $currentUserPlugin = $this->plugin('currentUserPlugin');
586
        $currentUser = $currentUserPlugin->getUser();
587
 
1 www 588
        $request = $this->getRequest();
589
        $id = $this->params()->fromRoute('id');
590
 
591
        if(!$id) {
592
            $data = [
593
                'success' => false,
594
                'data' => 'ERROR_INVALID_PARAMETER'
595
            ];
596
 
597
            return new JsonModel($data);
598
        }
599
 
600
        $jobMapper = JobMapper::getInstance($this->adapter);
3639 efrain 601
        $job = $jobMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1 www 602
        if(!$job) {
603
            $data = [
604
                'success' => false,
605
                'data' => 'ERROR_RECORD_NOT_FOUND'
606
            ];
607
 
608
            return new JsonModel($data);
609
        }
610
 
611
        if($job->status != Job::STATUS_ACTIVE) {
612
            $data = [
613
                'success' => false,
614
                'data' => 'ERROR_UNAUTHORIZED'
615
            ];
616
 
617
            return new JsonModel($data);
618
        }
619
 
620
        $companyMapper = CompanyMapper::getInstance($this->adapter);
621
        $company = $companyMapper->fetchOne($job->company_id);
622
        if(!$company) {
623
            $data = [
624
                'success' => false,
625
                'data' => 'ERROR_RECORD_NOT_FOUND'
626
            ];
627
 
628
            return new JsonModel($data);
629
        }
630
 
631
 
632
        if($request->isPost()) {
3639 efrain 633
 
1 www 634
            $jobSaveMapper = JobSaveMapper::getInstance($this->adapter);
635
            $result = $jobSaveMapper->deleteByJobIdAndUserId($job->id, $currentUser->id);
636
 
637
            if($result) {
638
                $this->logger->info('El usuario  ' . $currentUser->first_name .  ' ' . $currentUser->last_name . ' removio este trabajo salvado ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
639
 
640
                $data = [
641
                    'success'   => true,
642
                    ''
643
                ];
644
            } else {
645
                $data = [
646
                    'success'   => false,
647
                    'data'      => $jobSaveMapper->getError()
648
                ];
649
 
650
 
651
            }
652
 
653
            return new JsonModel($data);
654
 
655
        } else {
656
            $data = [
657
                'success' => false,
658
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
659
            ];
660
 
661
            return new JsonModel($data);
662
 
663
        }
664
    }
665
 
666
 
667
    public function saveJobAction()
668
    {
3639 efrain 669
        $currentUserPlugin = $this->plugin('currentUserPlugin');
670
        $currentUser = $currentUserPlugin->getUser();
671
 
1 www 672
        $request = $this->getRequest();
673
        $id = $this->params()->fromRoute('id');
674
 
675
        if(!$id) {
676
            $data = [
677
                'success' => false,
678
                'data' => 'ERROR_INVALID_PARAMETER'
679
            ];
680
 
681
            return new JsonModel($data);
682
        }
683
 
684
        $jobMapper = JobMapper::getInstance($this->adapter);
3639 efrain 685
        $job = $jobMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
1 www 686
        if(!$job) {
687
            $data = [
688
                'success' => false,
689
                'data' => 'ERROR_RECORD_NOT_FOUND'
690
            ];
691
 
692
            return new JsonModel($data);
693
        }
694
 
695
        if($job->status != Job::STATUS_ACTIVE) {
696
            $data = [
697
                'success' => false,
698
                'data' => 'ERROR_UNAUTHORIZED'
699
            ];
700
 
701
            return new JsonModel($data);
702
        }
703
 
704
        $companyMapper = CompanyMapper::getInstance($this->adapter);
705
        $company = $companyMapper->fetchOne($job->company_id);
706
        if(!$company) {
707
            $data = [
708
                'success' => false,
709
                'data' => 'ERROR_RECORD_NOT_FOUND'
710
            ];
711
 
712
            return new JsonModel($data);
713
        }
714
 
715
 
716
        if($request->isPost()) {
3639 efrain 717
 
1 www 718
            $jobSaveMapper = JobSaveMapper::getInstance($this->adapter);
719
            $jobSave = $jobSaveMapper->fetchOneByJobIdAndUserId($job->id, $currentUser->id);
720
 
721
            if($jobSave) {
722
                $result = true;
723
            } else {
724
                $jobSave = new JobSave();
725
                $jobSave->job_id = $job->id;
726
                $jobSave->user_id = $currentUser->id;
727
 
728
                $result = $jobSaveMapper->insert($jobSave);
729
            }
730
 
731
            if($result) {
732
                $this->logger->info('El usuario  ' . $currentUser->first_name .  ' ' . $currentUser->last_name . ' salvo este trabajo ' . $job->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
733
 
734
                $data = [
735
                    'success'   => true,
736
                ];
737
            } else {
738
                $data = [
739
                    'success'   => false,
740
                    'data'      => $jobSaveMapper->getError()
741
                ];
742
 
743
 
744
            }
745
 
746
            return new JsonModel($data);
747
 
748
        } else {
749
            $data = [
750
                'success' => false,
751
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
752
            ];
753
 
754
            return new JsonModel($data);
755
 
756
        }
757
    }
758
 
759
    public function appliedJobsAction()
760
    {
761
        $currentUserPlugin = $this->plugin('currentUserPlugin');
762
        $currentUser = $currentUserPlugin->getUser();
3639 efrain 763
 
1 www 764
        $request = $this->getRequest();
765
        if($request->isGet()) {
766
 
767
 
768
            $headers  = $request->getHeaders();
769
            $isJson = false;
770
            if($headers->has('Accept')) {
771
                $accept = $headers->get('Accept');
772
 
773
                $prioritized = $accept->getPrioritized();
774
 
775
                foreach($prioritized as $key => $value) {
776
                    $raw = trim($value->getRaw());
777
 
778
                    if(!$isJson) {
779
                        $isJson = strpos($raw, 'json');
780
                    }
781
 
782
                }
783
            }
784
 
785
            if($isJson) {
786
                $employment_types = [
787
                    job::EMPLOYMENT_TYPE_FULL_TIME => 'LABEL_EMPLOYMENT_TYPE_FULL_TIME',
788
                    Job::EMPLOYMENT_TYPE_PART_TIME  => 'LABEL_EMPLOYMENT_TYPE_PART_TIME',
789
                    Job::EMPLOYMENT_TYPE_TEMPORARY => 'LABEL_EMPLOYMENT_TYPE_TEMPORARY',
1327 efrain 790
                    Job::EMPLOYMENT_TYPE_CONTRACT =>  'LABEL_EMPLOYMENT_TYPE_CONTRACT',
1 www 791
                ];
792
 
6749 efrain 793
                $search = Functions::sanitizeFilterString($this->params()->fromQuery('search', ''));
1 www 794
 
795
                $queryMapper = QueryMapper::getInstance($this->adapter);
796
 
797
                $select = $queryMapper->getSql()->select();
798
                $select->columns(['id', 'uuid', 'title', 'employment_type', 'last_date_of_application']);
799
                $select->from(['j' => JobMapper::_TABLE]);
800
                $select->join(['ja' => JobApplicationMapper::_TABLE], 'j.id = ja.job_id');
3639 efrain 801
                $select->where->equalTo('j.network_id', $currentUser->network_id);
1 www 802
                $select->where->equalTo('j.status', Job::STATUS_ACTIVE);
803
                $select->where->equalTo('ja.user_id', $currentUser->id);
804
 
805
                if($search) {
806
                    $select->where->like('title', '%' . $search . '%');
807
                }
808
 
809
                $select->order('last_date_of_application DESC');
810
 
811
                $records = $queryMapper->fetchAll($select);
812
 
1327 efrain 813
 
814
 
1 www 815
 
816
                $items = [];
817
                foreach($records as $record)
818
                {
819
 
820
                    $item = [
821
                        'id' => $record['uuid'],
822
                        'title' => $record['title'],
823
                        'employment_type' => $employment_types[$record['employment_type']],
824
                        'last_date_of_application' => $record['last_date_of_application'],
825
                        'link_remove' => $this->url()->fromRoute('job/remove-apply-job', ['id' => $record['uuid']  ]),
826
                        'link_view' => $this->url()->fromRoute('job/view', ['id' => $record['uuid'] ]),
827
                    ];
828
 
829
                    array_push($items, $item);
830
                }
831
 
832
 
833
 
834
                $response = [
835
                    'success' => true,
836
                    'data' => $items
837
                ];
838
 
839
                return new JsonModel($response);
840
 
841
 
842
            } else {
843
                $this->layout()->setTemplate('layout/layout.phtml');
844
                $viewModel = new ViewModel();
845
                $viewModel->setTemplate('leaders-linked/job/applied-jobs.phtml');
846
                return $viewModel ;
847
            }
848
 
849
        } else {
850
            return new JsonModel([
851
                'success' => false,
852
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
853
            ]);
854
        }
855
    }
856
 
857
    public function savedJobsAction()
858
    {
859
        $currentUserPlugin = $this->plugin('currentUserPlugin');
860
        $currentUser = $currentUserPlugin->getUser();
3639 efrain 861
 
1 www 862
        $request = $this->getRequest();
863
        if($request->isGet()) {
864
 
865
 
866
            $headers  = $request->getHeaders();
867
 
868
            $isJson = false;
869
            if($headers->has('Accept')) {
870
                $accept = $headers->get('Accept');
871
 
872
                $prioritized = $accept->getPrioritized();
873
 
874
                foreach($prioritized as $key => $value) {
875
                    $raw = trim($value->getRaw());
876
 
877
                    if(!$isJson) {
878
                        $isJson = strpos($raw, 'json');
879
                    }
880
 
881
                }
882
            }
883
 
884
            if($isJson) {
885
                $employment_types = [
886
                    job::EMPLOYMENT_TYPE_FULL_TIME => 'LABEL_EMPLOYMENT_TYPE_FULL_TIME',
887
                    Job::EMPLOYMENT_TYPE_PART_TIME  => 'LABEL_EMPLOYMENT_TYPE_PART_TIME',
888
                    Job::EMPLOYMENT_TYPE_TEMPORARY => 'LABEL_EMPLOYMENT_TYPE_TEMPORARY',
889
                ];
890
 
6749 efrain 891
                $search = Functions::sanitizeFilterString($this->params()->fromQuery('search', ''));
1 www 892
 
893
                $queryMapper = QueryMapper::getInstance($this->adapter);
894
 
895
                $select = $queryMapper->getSql()->select();
2803 kerby 896
                $select->columns(['id', 'uuid', 'title', 'employment_type', 'last_date_of_application']);
1 www 897
                $select->from(['j' => JobMapper::_TABLE]);
898
                $select->join(['js' => JobSaveMapper::_TABLE], 'j.id = js.job_id');
2807 kerby 899
                $select->join(['c' => CompanyMapper::_TABLE], 'j.company_id = c.id',['image', 'comp_uuid'=>'uuid']);
3639 efrain 900
                $select->where->equalTo('j.network_id', $currentUser->network_id);
1 www 901
                $select->where->equalTo('j.status', Job::STATUS_ACTIVE);
902
                $select->where->equalTo('js.user_id', $currentUser->id);
903
 
904
                if($search) {
905
                    $select->where->like('title', '%' . $search . '%');
906
                }
907
 
908
                $select->order('last_date_of_application DESC');
2796 kerby 909
 
2807 kerby 910
                // $selectString = $queryMapper->getSql()->buildSqlString($select);
2796 kerby 911
 
2807 kerby 912
                // print_r(
913
                //     $selectString
914
                // );
2796 kerby 915
 
1 www 916
 
917
                $records = $queryMapper->fetchAll($select);
918
 
2809 kerby 919
                // print_r($records);
1 www 920
                $items = [];
921
                foreach($records as $record)
922
                {
923
 
924
                    $item = [
925
                        'id' => $record['uuid'],
926
                        'title' => $record['title'],
927
                        'employment_type' => $employment_types[$record['employment_type']],
928
                        'last_date_of_application' => $record['last_date_of_application'],
2808 kerby 929
                        'image' => $this->url()->fromRoute('storage', ['type' => 'company', 'code' => $record['comp_uuid'], 'filename' => $record['image']]),
1 www 930
                        'link_remove' => $this->url()->fromRoute('job/remove-save-job', ['id' => $record['uuid']  ]),
931
                        'link_view' => $this->url()->fromRoute('job/view', ['id' => $record['uuid'] ]),
932
                    ];
933
 
934
                    array_push($items, $item);
935
                }
936
 
937
 
938
 
939
                $response = [
940
                    'success' => true,
941
                    'data' => $items
942
                ];
943
 
944
                return new JsonModel($response);
945
 
946
 
947
            } else {
948
                $this->layout()->setTemplate('layout/layout.phtml');
949
                $viewModel = new ViewModel();
950
                $viewModel->setTemplate('leaders-linked/job/saved-jobs.phtml');
951
                return $viewModel ;
952
            }
953
 
954
        } else {
955
            return new JsonModel([
956
                'success' => false,
957
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
958
            ]);
959
        }
960
    }
961
 
962
}