Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

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