Proyectos de Subversion LeadersLinked - Backend

Rev

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