Proyectos de Subversion LeadersLinked - Backend

Rev

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