Proyectos de Subversion LeadersLinked - Services

Rev

Rev 283 | | Comparar con el anterior | Ultima modificación | Ver Log |

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