Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev Autor Línea Nro. Línea
1709 eleazar 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
9
use Laminas\Mvc\Controller\AbstractActionController;
15461 efrain 10
use Laminas\Mvc\I18n\Translator;
1709 eleazar 11
use Laminas\Log\LoggerInterface;
12
use Laminas\View\Model\JsonModel;
15461 efrain 13
use LeadersLinked\Mapper\RecruitmentSelectionApplicationMapper;
14
use LeadersLinked\Mapper\RecruitmentSelectionCandidateMapper;
15
use LeadersLinked\Mapper\RecruitmentSelectionInterviewMapper;
16
use LeadersLinked\Mapper\RecruitmentSelectionVacancyMapper;
17
use LeadersLinked\Mapper\UserMapper;
18
use LeadersLinked\Model\RecruitmentSelectionApplication;
19
use LeadersLinked\Model\RecruitmentSelectionInterview;
20
use LeadersLinked\Model\RecruitmentSelectionVacancy;
21
use LeadersLinked\Form\RecruitmentSelection\RecruitmentSelectionApplicationInterviewForm;
22
use LeadersLinked\Library\Functions;
23
use LeadersLinked\Library\RecruitmentSelectionInterviewPDF;
1709 eleazar 24
 
25
class RecruitmentSelectionInterviewController extends AbstractActionController {
26
 
27
    /**
28
     *
29
     * @var AdapterInterface
30
     */
31
    private $adapter;
15461 efrain 32
 
1709 eleazar 33
    /**
34
     *
35
     * @var AbstractAdapter
36
     */
37
    private $cache;
15461 efrain 38
 
1709 eleazar 39
    /**
40
     *
41
     * @var  LoggerInterface
42
     */
43
    private $logger;
15461 efrain 44
 
1709 eleazar 45
    /**
46
     *
47
     * @var array
48
     */
49
    private $config;
15461 efrain 50
 
1709 eleazar 51
    /**
52
     *
15461 efrain 53
     * @var Translator
54
     */
55
    private $translator;
56
 
57
    /**
58
     *
1709 eleazar 59
     * @param AdapterInterface $adapter
60
     * @param AbstractAdapter $cache
61
     * @param LoggerInterface $logger
62
     * @param array $config
15461 efrain 63
     * @param Translator $translator
1709 eleazar 64
     */
15461 efrain 65
    public function __construct($adapter, $cache, $logger, $config, $translator)
66
    {
1709 eleazar 67
        $this->adapter = $adapter;
68
        $this->cache = $cache;
69
        $this->logger = $logger;
70
        $this->config = $config;
15461 efrain 71
        $this->translator = $translator;
1709 eleazar 72
    }
73
 
15461 efrain 74
    public function indexAction()
75
    {
76
 
77
        $data = [
1709 eleazar 78
            'success' => false,
79
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
15461 efrain 80
        ];
81
 
82
        return new JsonModel($data);
83
 
1709 eleazar 84
    }
15461 efrain 85
 
86
    public function addAction()
87
    {
88
        $request = $this->getRequest();
89
        $currentUserPlugin = $this->plugin('currentUserPlugin');
90
        $currentCompany = $currentUserPlugin->getCompany();
91
        $currentUser = $currentUserPlugin->getUser();
92
 
93
        $request = $this->getRequest();
94
        $application_id = $this->params()->fromRoute('application_id');
95
 
96
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
97
 
98
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
99
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
100
 
101
        if(!$vacancy) {
102
            $data = [
103
                'success' => false,
104
                'data' => 'ERROR_VACANCY_NOT_FOUND'
105
            ];
106
 
107
            return new JsonModel($data);
108
        }
109
 
110
 
111
        if($vacancy->company_id != $currentCompany->id) {
112
            $data = [
113
                'success' => false,
114
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
115
            ];
116
 
117
            return new JsonModel($data);
118
        }
119
 
120
 
121
 
122
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
123
        $application = $applicationMapper->fetchOneByUuid($application_id);
124
 
125
 
126
        if (!$application) {
127
            $data = [
128
                'success' => false,
129
                'data' => 'ERROR_RECORD_NOT_FOUND'
130
            ];
131
 
132
            return new JsonModel($data);
133
        }
134
 
135
 
136
        if ($application->vacancy_id != $vacancy->id) {
137
            return new JsonModel([
138
                'success' => false,
139
                'data' => 'ERROR_UNAUTHORIZED'
140
            ]);
141
        }
142
 
143
        if($request->isPost()) {
144
            $form = new  RecruitmentSelectionApplicationInterviewForm($this->adapter, $currentCompany->id);
145
 
146
            $dataPost = $request->getPost()->toArray();
147
 
148
            if(!empty($dataPost['last_date'])) {
149
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
150
                if($dt) {
151
                    $dataPost['last_date'] = $dt->format('Y-m-d');
152
                } else {
153
                    $dataPost['last_date'] = '';
154
                }
155
 
156
            }
157
 
158
 
159
            $form->setData($dataPost);
160
 
161
            if($form->isValid()) {
162
 
163
                $dataPost = (array) $form->getData();
164
                $userMapper = UserMapper::getInstance($this->adapter);
165
                $user = $userMapper->fetchOneByUuid($dataPost['user_id']);
166
 
167
 
168
 
169
                $interview = new RecruitmentSelectionInterview();
170
                $interview->company_id = $currentCompany->id;
171
                $interview->application_id = $application->id;
172
                $interview->candidate_id = $application->candidate_id;
173
                $interview->vacancy_id = $application->vacancy_id;
174
                $interview->interviewer_id = $user->id;
175
                $interview->type = $dataPost['type'];
176
                $interview->last_date = $dataPost['last_date'];
177
                $interview->comment = '';
178
                $interview->points = 0;
179
 
180
 
1709 eleazar 181
 
15461 efrain 182
 
183
                $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
184
 
185
                if($interviewMapper->insert($interview)) {
186
 
187
 
188
 
189
                   $this->logger->info('Se agrego la entrevista : '  . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
190
                   $data = [
191
                        'success'   => true,
192
                        'data'   => [
193
                            'message' => 'LABEL_RECORD_ADDED',
194
                            'interviews' => $this->renderInterview($vacancy, $application)
195
                            ],
196
                    ];
197
 
198
                } else {
199
                    $data = [
200
                        'success'   => false,
201
                        'data'      => $interviewMapper->getError()
202
                    ];
203
 
204
                }
205
 
206
                return new JsonModel($data);
207
 
208
            } else {
209
                $messages = [];
210
                $form_messages = (array) $form->getMessages();
211
                foreach ($form_messages as $fieldname => $field_messages) {
212
                    $messages[$fieldname] = array_values($field_messages);
213
                }
214
 
215
                return new JsonModel([
216
                    'success' => false,
217
                    'data' => $messages
218
                ]);
219
 
220
            }
221
 
222
        } else {
223
            $data = [
224
                'success' => false,
225
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
226
            ];
227
 
228
            return new JsonModel($data);
229
        }
230
 
231
    }
232
 
233
 
234
    public function editAction()
235
    {
236
        $request = $this->getRequest();
237
        $currentUserPlugin = $this->plugin('currentUserPlugin');
238
        $currentCompany = $currentUserPlugin->getCompany();
239
        $currentUser = $currentUserPlugin->getUser();
240
 
241
        $request = $this->getRequest();
242
        $application_id = $this->params()->fromRoute('application_id');
243
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
244
        $id = $this->params()->fromRoute('id');
245
 
246
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
247
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
248
 
249
        if(!$vacancy) {
250
            $data = [
251
                'success' => false,
252
                'data' => 'ERROR_VACANCY_NOT_FOUND'
253
            ];
254
 
255
            return new JsonModel($data);
256
        }
257
 
258
 
259
        if($vacancy->company_id != $currentCompany->id) {
260
            $data = [
261
                'success' => false,
262
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
263
            ];
264
 
265
            return new JsonModel($data);
266
        }
267
 
268
 
269
 
270
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
271
        $application = $applicationMapper->fetchOneByUuid($application_id);
272
 
273
 
274
        if (!$application) {
275
            $data = [
276
                'success' => false,
277
                'data' => 'ERROR_RECORD_NOT_FOUND'
278
            ];
279
 
280
            return new JsonModel($data);
281
        }
282
 
283
 
284
        if ($application->vacancy_id != $vacancy->id) {
285
            return new JsonModel([
286
                'success' => false,
287
                'data' => 'ERROR_UNAUTHORIZED'
288
            ]);
289
        }
290
 
291
 
292
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
293
        $interview = $interviewMapper->fetchOneByUuid($id);
294
        if(!$interview) {
295
            return new JsonModel([
296
                'success' => false,
297
                'data' => 'ERROR_INTERVIEW_NOT_FOUND'
298
            ]);
299
        }
300
 
301
        if($interview->application_id != $application->id) {
302
            return new JsonModel([
303
                'success' => false,
304
                'data' => 'ERROR_UNAUTHORIZED'
305
            ]);
306
        }
307
 
308
 
309
        if($interview->status != RecruitmentSelectionInterview::STATUS_PENDING) {
310
            return new JsonModel([
311
                'success' => false,
312
                'data' => 'ERROR_INTERVIEW_HAS_ALREADY_BEEN_DONE'
313
            ]);
314
 
315
        }
316
 
317
        if($request->isGet()) {
318
            $userMapper = UserMapper::getInstance($this->adapter);
319
            $user = $userMapper->fetchOne($interview->interviewer_id);
320
 
321
            $dt = \DateTime::createFromFormat('Y-m-d', $interview->last_date);
322
 
323
            return new JsonModel([
324
                'success' => true,
325
                'data' => [
326
                    'user_id' => $user->uuid,
327
                    'type' => $interview->type,
328
                    'last_date' => $dt->format('d/m/Y')
329
                ]
330
            ]);
331
 
332
 
333
        } else  if($request->isPost()) {
334
            $form = new  RecruitmentSelectionApplicationInterviewForm($this->adapter, $currentCompany->id);
335
            $dataPost = $request->getPost()->toArray();
336
            if(!empty($dataPost['last_date'])) {
337
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
338
                if($dt) {
339
                    $dataPost['last_date'] = $dt->format('Y-m-d');
340
                } else {
341
                    $dataPost['last_date'] = '';
342
                }
343
 
344
            }
345
 
346
            $form->setData($dataPost);
347
 
348
            if($form->isValid()) {
349
 
350
                $dataPost = (array) $form->getData();
351
                $userMapper = UserMapper::getInstance($this->adapter);
352
                $user = $userMapper->fetchOneByUuid($dataPost['user_id']);
353
 
354
 
355
                $interview->interviewer_id = $user->id;
356
                $interview->type = $dataPost['type'];
357
                $interview->last_date = $dataPost['last_date'];
358
 
359
                $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
360
 
361
                if($interviewMapper->update($interview)) {
362
 
363
 
364
 
365
                    $this->logger->info('Se actualizo la entrevista : '  . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
366
                    $data = [
367
                        'success'   => true,
368
                        'data'   => [
369
                            'message' => 'LABEL_RECORD_UPDATED',
370
                            'interviews' => $this->renderInterview($vacancy, $application)
371
                        ],
372
                    ];
373
 
374
                } else {
375
                    $data = [
376
                        'success'   => false,
377
                        'data'      => $interviewMapper->getError()
378
                    ];
379
 
380
                }
381
 
382
                return new JsonModel($data);
383
 
384
            } else {
385
                $messages = [];
386
                $form_messages = (array) $form->getMessages();
387
                foreach ($form_messages as $fieldname => $field_messages) {
388
                    $messages[$fieldname] = array_values($field_messages);
389
                }
390
 
391
                return new JsonModel([
392
                    'success' => false,
393
                    'data' => $messages
394
                ]);
395
 
396
            }
397
 
398
 
399
 
400
        } else {
401
            $data = [
402
                'success' => false,
403
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
404
            ];
405
 
406
            return new JsonModel($data);
407
        }
408
 
409
    }
410
 
411
 
412
    public function deleteAction()
413
    {
414
        $request = $this->getRequest();
415
        $currentUserPlugin = $this->plugin('currentUserPlugin');
416
        $currentCompany = $currentUserPlugin->getCompany();
417
        $currentUser = $currentUserPlugin->getUser();
418
 
419
        $request = $this->getRequest();
420
        $application_id = $this->params()->fromRoute('application_id');
421
 
422
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
423
        $id = $this->params()->fromRoute('id');
424
 
425
 
426
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
427
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
428
 
429
        if(!$vacancy) {
430
            $data = [
431
                'success' => false,
432
                'data' => 'ERROR_VACANCY_NOT_FOUND'
433
            ];
434
 
435
            return new JsonModel($data);
436
        }
437
 
438
 
439
        if($vacancy->company_id != $currentCompany->id) {
440
            $data = [
441
                'success' => false,
442
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
443
            ];
444
 
445
            return new JsonModel($data);
446
        }
447
 
448
 
449
 
450
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
451
        $application = $applicationMapper->fetchOneByUuid($application_id);
452
 
453
 
454
        if (!$application) {
455
            $data = [
456
                'success' => false,
457
                'data' => 'ERROR_RECORD_NOT_FOUND'
458
            ];
459
 
460
            return new JsonModel($data);
461
        }
462
 
463
 
464
        if ($application->vacancy_id != $vacancy->id) {
465
            return new JsonModel([
466
                'success' => false,
467
                'data' => 'ERROR_UNAUTHORIZED'
468
            ]);
469
        }
470
 
471
 
472
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
473
        $interview = $interviewMapper->fetchOneByUuid($id);
474
        if(!$interview) {
475
            return new JsonModel([
476
                'success' => false,
477
                'data' => 'ERROR_INTERVIEW_NOT_FOUND'
478
            ]);
479
        }
480
 
481
        if($interview->application_id != $application->id) {
482
            return new JsonModel([
483
                'success' => false,
484
                'data' => 'ERROR_UNAUTHORIZED'
485
            ]);
486
        }
487
 
488
 
489
        if($interview->status != RecruitmentSelectionInterview::STATUS_PENDING) {
490
            return new JsonModel([
491
                'success' => false,
492
                'data' => 'ERROR_INTERVIEW_HAS_ALREADY_BEEN_DONE'
493
            ]);
494
 
495
        }
496
 
497
        if($request->isPost()) {
498
 
499
            $userMapper = UserMapper::getInstance($this->adapter);
500
            $user = $userMapper->fetchOne($interview->interviewer_id);
501
 
502
 
503
            if($interviewMapper->delete($interview->id)) {
504
 
505
                $this->logger->info('Se borro la entrevista : '  . $user->first_name . ' ' . $user->last_name . ' (' . $user->email . ')', ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
506
                $data = [
507
                    'success'   => true,
508
                    'data'   => [
15462 efrain 509
                        'message' => 'LABEL_RECORD_DELETED',
15461 efrain 510
                        'interviews' => $this->renderInterview($vacancy, $application)
511
                    ],
512
                ];
513
 
514
            } else {
515
                $data = [
516
                    'success'   => false,
517
                    'data'      => $interviewMapper->getError()
518
                ];
519
 
520
            }
521
 
15462 efrain 522
 
523
            return new JsonModel($data);
15461 efrain 524
 
525
 
526
        } else {
527
            $data = [
528
                'success' => false,
529
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
530
            ];
531
 
532
            return new JsonModel($data);
533
        }
534
 
535
    }
536
 
537
    /**
538
     *
539
     * @param RecruitmentSelectionVacancy $vacany
540
     * @param RecruitmentSelectionApplication $application
541
     * @return array
542
     */
543
    public function renderInterview($vacancy, $application)
544
    {
545
        $userMapper = UserMapper::getInstance($this->adapter);
546
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
547
 
548
 
549
 
550
 
551
        $interviews = [];
552
        $records = $interviewMapper->fetchAllByVacancyId($vacancy->id);
553
        foreach($records as $record)
554
        {
555
            $status = '';
556
            switch($record->status)
557
            {
558
                case RecruitmentSelectionInterview::STATUS_ACCEPTED :
559
                    $status = 'LABEL_ACCEPTED';
560
                    $link_report = $this->url()->fromRoute('recruitment-and-selection/applications/interviews/report', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]);
561
                    break;
562
 
563
                case RecruitmentSelectionInterview::STATUS_PENDING :
15462 efrain 564
                    $status = 'LABEL_PENDING';
565
                    $link_report = '';
15461 efrain 566
                    break;
567
 
568
                case RecruitmentSelectionInterview::STATUS_REJECTED :
15462 efrain 569
                    $status  = 'LABEL_REJECTED';
570
                    $link_report = $this->url()->fromRoute('recruitment-and-selection/applications/interviews/report', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]);
571
                                      break;
15461 efrain 572
 
573
                default :
15462 efrain 574
                    $status = 'LABEL_UNKNOWN';
15461 efrain 575
                    $link_report = '';
15462 efrain 576
 
15461 efrain 577
                    break;
578
 
579
            }
580
 
581
            $type = '';
582
            switch($record->type)
583
            {
584
                case RecruitmentSelectionInterview::TYPE_BOSS :
585
                    $type = 'LABEL_BOSS_INTERVIEW';
586
                    break;
587
 
588
                case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
589
                    $type = 'LABEL_HUMAN_RESOURCE';
590
                    break;
591
 
592
                default :
593
                    $type = 'LABEL_UNKNOWN';
594
                    break;
595
 
596
            }
597
 
598
            $dt = \DateTime::createFromFormat('Y-m-d',  $record->last_date);
599
            $last_date = $dt->format('d/m/Y');
600
 
601
            if($record->actual_date) {
602
 
603
                $dt = \DateTime::createFromFormat('Y-m-d',  $record->actual_date);
604
                $actual_date = $dt->format('d/m/Y');
605
            } else {
606
                $actual_date = '';
607
            }
608
 
609
            $user = $userMapper->fetchOne($record->interviewer_id);
610
            $interviewer = $user->first_name . ' ' . $user->last_name  . '(' . $user->email . ')';
611
 
612
 
613
 
614
 
615
            array_push($interviews, [
616
                'type' => $type,
617
                'status' => $status,
618
                'last_date' => $last_date,
619
                'actual_date' => $actual_date,
620
                'interviewer' => $interviewer,
621
                'points' => $record->points,
622
                'link_edit' => $this->url()->fromRoute('recruitment-and-selection/applications/interviews/edit', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]),
623
                'link_report' => $link_report,
624
                'link_delete' => $this->url()->fromRoute('recruitment-and-selection/applications/interviews/delete', ['vacancy_id' => $vacancy->uuid, 'application_id' => $application->uuid, 'id' => $record->uuid]),
625
 
626
            ]);
627
        }
628
 
629
        return $interviews;
630
 
631
    }
632
 
633
    public function reportAction()
634
    {
635
        $request = $this->getRequest();
636
        $currentUserPlugin = $this->plugin('currentUserPlugin');
637
        $currentCompany = $currentUserPlugin->getCompany();
638
        $currentUser = $currentUserPlugin->getUser();
639
 
640
        $request = $this->getRequest();
641
        $application_id = $this->params()->fromRoute('application_id');
642
 
643
        $vacancy_uuid = $this->params()->fromRoute('vacancy_id');
644
        $id = $this->params()->fromRoute('id');
645
 
646
 
647
        $vacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
648
        $vacancy = $vacancyMapper->fetchOneByUuid($vacancy_uuid);
649
 
650
        if(!$vacancy) {
651
            $data = [
652
                'success' => false,
653
                'data' => 'ERROR_VACANCY_NOT_FOUND'
654
            ];
655
 
656
            return new JsonModel($data);
657
        }
658
 
659
 
660
        if($vacancy->company_id != $currentCompany->id) {
661
            $data = [
662
                'success' => false,
663
                'data' => 'ERROR_VACANCY_IS_OTHER_COMPANY',
664
            ];
665
 
666
            return new JsonModel($data);
667
        }
668
 
669
 
670
 
671
        $applicationMapper = RecruitmentSelectionApplicationMapper::getInstance($this->adapter);
672
        $application = $applicationMapper->fetchOneByUuid($application_id);
673
 
674
 
675
        if (!$application) {
676
            $data = [
677
                'success' => false,
678
                'data' => 'ERROR_RECORD_NOT_FOUND'
679
            ];
680
 
681
            return new JsonModel($data);
682
        }
683
 
684
 
685
        if ($application->vacancy_id != $vacancy->id) {
686
            return new JsonModel([
687
                'success' => false,
688
                'data' => 'ERROR_UNAUTHORIZED'
689
            ]);
690
        }
691
 
692
 
693
        $interviewMapper = RecruitmentSelectionInterviewMapper::getInstance($this->adapter);
694
        $interview = $interviewMapper->fetchOneByUuid($id);
695
        if(!$interview) {
696
            return new JsonModel([
697
                'success' => false,
698
                'data' => 'ERROR_INTERVIEW_NOT_FOUND'
699
            ]);
700
        }
701
 
702
        if($interview->application_id != $application->id) {
703
            return new JsonModel([
704
                'success' => false,
705
                'data' => 'ERROR_UNAUTHORIZED'
706
            ]);
707
        }
708
 
709
        if($interview->status == RecruitmentSelectionInterview::STATUS_PENDING) {
710
            return new JsonModel([
711
                'success' => false,
712
                'data' =>   'ERROR_RECORD_IS_PENDING'
713
            ]);
714
 
715
        }
716
 
717
 
718
 
719
        $request = $this->getRequest();
720
        if ($request->isGet()) {
721
 
722
            switch( $interview->type)
723
            {
724
                case RecruitmentSelectionInterview::TYPE_BOSS :
725
                    $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_BOTH');
726
                    break;
727
 
728
                case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
729
                    $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_HUMAN_RESOURCE');
730
                    break;
731
 
732
 
733
 
734
                default :
735
                    $type = $this->translator->translate('LABEL_UNKNOWN');
736
                    break;
737
            }
738
 
739
 
740
            $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
741
            $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($interview->vacancy_id);
742
 
743
 
744
            $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
745
            $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($interview->candidate_id);
746
 
747
            $filename = $recruitmentSelectionVacancy->name . '-' . trim($recruitmentSelectionCandidate->first_name) . '-' . trim($recruitmentSelectionCandidate->last_name)  . '-' . $type . '-' . date('Y-m-d H:i a') . '.pdf';
748
 
749
            $filename = Functions::normalizeStringFilename( $filename );
750
 
751
 
752
 
753
 
754
            $content = base64_encode($this->renderPDF($interview));
755
            $data = [
756
                'success' => true,
757
                'data' => [
758
                    'basename' => $filename,
759
                    'content' => $content
760
                ]
761
            ];
762
 
763
            return new JsonModel($data);
764
 
765
            /*
766
 
767
            $content = $this->renderPdf($currentCompany, $jobDescription);
768
            $response = new Response();
769
            $response->setStatusCode(200);
770
            $response->setContent($content);
771
 
772
 
773
 
774
            $headers = $response->getHeaders();
775
            $headers->clearHeaders();
776
 
777
            $headers->addHeaderLine('Content-Description: File Transfer');
778
            $headers->addHeaderLine('Content-Type: application/pdf');
779
            //$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
780
            $headers->addHeaderLine('Content-Transfer-Encoding: binary');
781
            $headers->addHeaderLine('Expires: 0');
782
            $headers->addHeaderLine('Cache-Control: must-revalidate');
783
            $headers->addHeaderLine('Pragma: public');
784
            return $response;
785
            */
786
 
787
 
788
 
789
 
790
            return ;
791
        } else {
792
 
793
 
794
            return new JsonModel([
795
                'success' => false,
796
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
797
            ]);
798
        }
799
    }
800
 
801
    /**
802
     * Render PDF
803
     * @param RecruitmentSelectionInterview $recruitmentSelectionInterview
804
 
805
     * @return mixed
806
     */
807
    private function renderPDF($recruitmentSelectionInterview)
808
    {
809
        $request = $this->getRequest();
810
        $currentUserPlugin = $this->plugin('currentUserPlugin');
811
        $currentCompany = $currentUserPlugin->getCompany();
812
        $currentUser = $currentUserPlugin->getUser();
813
 
814
 
815
        //Generate New PDF
816
        $pdf = new RecruitmentSelectionInterviewPDF();
817
 
818
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $currentCompany->uuid;
819
        $header = $currentCompany->header ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->header : '';
820
        if (empty($header) || !file_exists($header)) {
821
            $header = $this->config['leaderslinked.images_default.company_pdf_header'];
822
        }
823
 
824
        $footer = $currentCompany->footer ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->footer : '';
825
        if (empty($footer) || !file_exists($footer)) {
826
            $footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
827
        }
828
 
829
        $content = json_decode($recruitmentSelectionInterview->content);
830
 
831
        $pdf->header = $header;
832
        $pdf->footer = $footer;
833
        $pdf->translator = $this->translator;
834
 
835
        $pdf->SetMargins(10, 0, 10);
836
 
837
        $pdf->AliasNbPages();
838
        $pdf->AddPage();
839
 
840
        switch( $recruitmentSelectionInterview->type)
841
        {
842
            case RecruitmentSelectionInterview::TYPE_BOSS :
843
                $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_BOTH');
844
                break;
845
 
846
            case RecruitmentSelectionInterview::TYPE_HUMAN_RESOURCE :
847
                $type = $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_TYPE_HUMAN_RESOURCE');
848
                break;
849
 
850
 
851
 
852
            default :
853
                $type = $this->translator->translate('LABEL_UNKNOWN');
854
                break;
855
        }
856
 
857
        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $recruitmentSelectionInterview->updated_on);
858
 
859
 
860
 
861
        $recruitmentSelectionVacancyMapper = RecruitmentSelectionVacancyMapper::getInstance($this->adapter);
862
        $recruitmentSelectionVacancy = $recruitmentSelectionVacancyMapper->fetchOne($recruitmentSelectionInterview->vacancy_id);
863
 
864
 
865
        $recruitmentSelectionCandidateMapper = RecruitmentSelectionCandidateMapper::getInstance($this->adapter);
866
        $recruitmentSelectionCandidate = $recruitmentSelectionCandidateMapper->fetchOne($recruitmentSelectionInterview->candidate_id);
867
 
868
        $userMapper = UserMapper::getInstance($this->adapter);
869
        $user = $userMapper->fetchOne($recruitmentSelectionInterview->interviewer_id);
870
        if($user) {
871
            $interviewer  = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
872
 
873
        }
874
        if($recruitmentSelectionCandidate) {
875
            $candidate = ucwords(strtolower(trim($recruitmentSelectionCandidate->first_name . ' ' . $recruitmentSelectionCandidate->last_name)));
876
 
877
        }
878
 
879
        $rows = [
880
            [
881
                'title' => $this->translator->translate('LABEL_TYPE') . ' : ',
882
                'content' => $type,
883
            ],
884
            [
885
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_POSITION') . ' : ',
886
                'content' => $recruitmentSelectionVacancy->name,
887
            ],
888
            [
889
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_CANDIDATE')  . ' : ',
890
                'content' => utf8_decode($candidate),
891
            ],
892
 
893
            [
894
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_CANDIDATE_SIGNATURE') . ' : ',
895
                'content' => ''
896
            ],
897
            [
898
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_INTERVIEWER') . ' : ',
899
                'content' => utf8_decode($interviewer),
900
            ],
901
            [
902
                'title' => $this->translator->translate('LABEL_PDF_RECRUITMENT_AND_SELECTION_INTERVIEWER_SIGNATURE') . ' : ',
903
                'content' => ''
904
            ],
905
            [
906
                'title' => $this->translator->translate('LABEL_DATE'),
907
                'content' => $dt->format('d/m/Y H:i a')
908
            ]
909
        ];
910
 
911
 
912
 
913
 
914
 
915
        $pdf->borderTable($this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_TITLE'), $rows);
916
 
917
        switch( $recruitmentSelectionInterview->status)
918
        {
919
            case RecruitmentSelectionInterview::STATUS_ACCEPTED :
920
                $status = $this->translator->translate('LABEL_ACCEPTED');
921
                break;
922
 
923
            case RecruitmentSelectionInterview::STATUS_REJECTED :
924
                $status = $this->translator->translate('LABEL_REJECTED');
925
                break;
926
 
927
 
928
 
929
            default :
930
                $status = $this->translator->translate('LABEL_UNKNOWN');
931
                break;
932
        }
933
 
934
 
935
        $pdf->evaluationTable($status, $content->comment, $content->points);
936
 
937
 
938
 
939
        // Competencies
940
        if ($content->competencies_selected) {
941
            $pdf->AddPage();
942
 
943
            $i = 0;
944
 
945
            $max = count($content->competencies_selected);
946
            for($i = 0; $i < $max; $i++)
947
            {
948
                $competency_selected = $content->competencies_selected[$i];
949
 
950
                $j = $i + 1;
951
                $last = $j == $max;
952
                $pdf->competencyTable($i, $competency_selected, $content->competencies, $content->competency_types, $content->behaviors, $content->evaluation, $last);
953
            }
954
 
955
        }
956
 
957
        return $pdf->Output('S');
958
    }
959
 
960
 
1709 eleazar 961
}