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
15444 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
16768 efrain 8
 
15444 efrain 9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Mvc\I18n\Translator;
11
use Laminas\Log\LoggerInterface;
12
use Laminas\View\Model\ViewModel;
13
use Laminas\View\Model\JsonModel;
14
use LeadersLinked\Mapper\QueryMapper;
15
use LeadersLinked\Mapper\UserMapper;
16
use Laminas\Hydrator\ArraySerializableHydrator;
17
use Laminas\Db\ResultSet\HydratingResultSet;
18
use Laminas\Paginator\Adapter\DbSelect;
19
use Laminas\Paginator\Paginator;
20
use LeadersLinked\Mapper\PerformanceEvaluationTestMapper;
21
use LeadersLinked\Mapper\PerformanceEvaluationFormMapper;
22
use LeadersLinked\Model\PerformanceEvaluationTest;
23
use LeadersLinked\Form\PerformanceEvaluation\PerformanceEvaluationTestForm;
24
use Laminas\Hydrator\ObjectPropertyHydrator;
25
use LeadersLinked\Library\Functions;
26
use LeadersLinked\Library\PerformanceEvaluationInterviewPDF;
27
 
28
class PerformanceEvaluationTestController extends AbstractActionController {
29
 
30
    /**
31
     *
32
     * @var AdapterInterface
33
     */
34
    private $adapter;
35
 
36
 
37
    /**
38
     *
39
     * @var  LoggerInterface
40
     */
41
    private $logger;
42
 
43
    /**
44
     *
45
     * @var array
46
     */
47
    private $config;
48
 
49
    /**
50
     *
51
     * @var Translator
52
     */
53
    private $translator;
54
 
55
    /**
56
     *
57
     * @param AdapterInterface $adapter
58
     * @param LoggerInterface $logger
59
     * @param array $config
60
     * @param Translator $translator
61
     */
16768 efrain 62
    public function __construct($adapter, $logger, $config, $translator)
15444 efrain 63
    {
64
        $this->adapter = $adapter;
65
        $this->logger = $logger;
66
        $this->config = $config;
67
        $this->translator = $translator;
68
    }
69
 
70
 
71
    public function indexAction() {
72
        $currentUserPlugin = $this->plugin('currentUserPlugin');
73
        $currentUser = $currentUserPlugin->getUser();
74
        $currentCompany = $currentUserPlugin->getCompany();
75
 
76
 
77
 
78
 
79
 
80
        $request = $this->getRequest();
81
 
82
        if ($request->isGet()) {
83
 
84
            $headers = $request->getHeaders();
85
 
86
            $isJson = false;
87
            if ($headers->has('Accept')) {
88
                $accept = $headers->get('Accept');
89
 
90
                $prioritized = $accept->getPrioritized();
91
 
92
                foreach ($prioritized as $key => $value) {
93
                    $raw = trim($value->getRaw());
94
 
95
                    if (!$isJson) {
96
                        $isJson = strpos($raw, 'json');
97
                    }
98
                }
99
            }
100
 
101
 
102
            if ($isJson) {
103
 
104
 
105
                $data = [
106
                    'items' => [],
107
                    'total' => 0,
108
                ];
109
 
110
 
111
                $search = $this->params()->fromQuery('search');
16766 efrain 112
                $search = empty($search) ? '' : Functions::sanitizeFilterString($search);
15444 efrain 113
 
114
                $start = intval($this->params()->fromQuery('start', 0), 10);
115
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
116
                $page =  intval($start / $records_x_page);
117
                $page++;
118
 
119
                $order = $this->params()->fromQuery('order', []);
120
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
16766 efrain 121
                $order_direction = empty($order[0]['dir']) ? 'ASC' : Functions::sanitizeFilterString(filter_var($order[0]['dir']));
15444 efrain 122
 
123
                $fields = ['max_date'];
124
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
125
 
126
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
127
                    $order_direction = 'ASC';
128
                }
129
 
130
 
131
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
132
                //$allowDelete = $acl->isAllowed($currentUser->usertype_id, 'performance-evaluation/evaluations/delete');
133
 
134
 
135
 
136
                $queryMapper = QueryMapper::getInstance($this->adapter);
137
                $sql = $queryMapper->getSql();
138
                $select = $sql->select();
139
                $select->columns([
140
                    'id',
141
                    'uuid',
142
                    'last_date',
143
                    'status',
144
                    'added_on',
145
                    'updated_on'
146
                ]);
147
 
148
                $select->from(['tb1' => PerformanceEvaluationTestMapper::_TABLE]);
149
                $select->join(['tb2' => PerformanceEvaluationFormMapper::_TABLE], 'tb1.form_id = tb2.id ', ['form' => 'name']);
150
                $select->join(['tb3' => UserMapper::_TABLE], 'tb1.supervisor_id = tb3.id ', ['supervisor_first_name' => 'first_name', 'supervisor_last_name' => 'last_name', 'supervisor_email' => 'email']);
151
                $select->join(['tb4' => UserMapper::_TABLE], 'tb1.employee_id = tb4.id ', ['employee_first_name' => 'first_name', 'employee_last_name' => 'last_name', 'employee_email' => 'email']);
152
                $select->where->equalTo('tb1.company_id', $currentCompany->id);
153
                $select->where->equalTo('tb1.type', PerformanceEvaluationTest::TYPE_BOTH);
154
 
155
 
156
 
157
                if ($search) {
158
                    $select->where->nest()
159
                        ->like('tb1.last_date', '%' . $search . '%')
160
                        ->or->like('tb2.name', '%' . $search . '%')
161
                        ->or->like('tb3.first_name', '%' . $search . '%')
162
                        ->or->like('tb3.last_name', '%' . $search . '%')
163
                        ->or->like('tb3.email', '%' . $search . '%')
164
                        ->or->like('tb4.first_name', '%' . $search . '%')
165
                        ->or->like('tb4.last_name', '%' . $search . '%')
166
                        ->or->like('tb4.email', '%' . $search . '%')
167
                    ->unnest();
168
                }
169
 
170
 
171
                $select->order('tb1.last_date DESC, tb2.name ASC');
172
 
173
 
174
                $hydrator = new ArraySerializableHydrator();
175
                $resultset = new HydratingResultSet($hydrator);
176
 
177
                $adapter = new DbSelect($select, $sql, $resultset);
178
                $paginator = new Paginator($adapter);
179
                $paginator->setItemCountPerPage($records_x_page);
180
                $paginator->setCurrentPageNumber($page);
181
 
182
 
183
                $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
184
 
185
 
186
                $items = [];
187
                $records = $paginator->getCurrentItems();
188
                foreach ($records as $record)
189
                {
190
                    //$performanceEvaluationTestEmployee =  $performanceEvaluationTestMapper->fetchOneByParentIdAndType($record['id'], PerformanceEvaluationTest::TYPE_EMPLOYEE);
191
                    //$performanceEvaluationTestSupervisor =  $performanceEvaluationTestMapper->fetchOneByParentIdAndType($record['id'], PerformanceEvaluationTest::TYPE_SUPERVISOR);
192
 
193
 
194
                    $dt = \DateTime::createFromFormat('Y-m-d', $record['last_date']);
195
                    $last_date = $dt->format('d/m/Y');
196
 
197
                    switch($record['status'])
198
                    {
199
                        case PerformanceEvaluationTest::STATUS_PENDING :
200
                            $status = 'LABEL_PENDING';
201
                            break;
202
 
203
                        case PerformanceEvaluationTest::STATUS_COMPLETED :
204
                            $status = 'LABEL_COMPLETED';
205
                            break;
206
 
207
                        default :
208
                            $status = 'LABEL_UNKNOW';
209
                            break;
210
                    }
211
 
212
 
213
                    $actions = [
214
                        'link_delete' => $this->url()->fromRoute('performance-evaluation/evaluations/delete', ['id' => $record['uuid']]),
215
                    ];
216
 
217
                    if($record['status'] == PerformanceEvaluationTest::STATUS_COMPLETED) {
218
 
219
                        $actions['link_pdf_both'] = $this->url()->fromRoute('performance-evaluation/evaluations/report', ['id' => $record['uuid'] ]);
220
                    } else {
221
                        $actions['link_pdf_both'] = '';
222
                    }
223
 
224
                    $performanceEvaluationTestEmployee = $performanceEvaluationTestMapper->fetchOneByParentIdAndType( $record['id'],  PerformanceEvaluationTest::TYPE_EMPLOYEE );
225
 
226
                    if($performanceEvaluationTestEmployee->status == PerformanceEvaluationTest::STATUS_COMPLETED) {
227
 
228
                        $actions['link_pdf_employee'] = $this->url()->fromRoute('performance-evaluation/evaluations/report', ['id' => $performanceEvaluationTestEmployee->uuid ]);
229
                    } else {
230
                        $actions['link_pdf_employee'] = '';
231
                    }
232
 
233
                    $performanceEvaluationTestSupervisor = $performanceEvaluationTestMapper->fetchOneByParentIdAndType( $record['id'],  PerformanceEvaluationTest::TYPE_SUPERVISOR );
234
 
235
                    if($performanceEvaluationTestSupervisor->status == PerformanceEvaluationTest::STATUS_COMPLETED) {
236
 
237
                        $actions['link_pdf_supervisor'] = $this->url()->fromRoute('performance-evaluation/evaluations/report', ['id' => $performanceEvaluationTestSupervisor->uuid ]);
238
                    } else {
239
                        $actions['link_pdf_supervisor'] = '';
240
                    }
241
 
242
 
243
                    $item = [
244
                        'last_date' => $last_date,
245
                        'form' => $record['form'],
246
                        'supervisor_first_name' => $record['supervisor_first_name'],
247
                        'supervisor_last_name' => $record['supervisor_last_name'],
248
                        'supervisor_email' => $record['supervisor_email'],
249
                        'employee_first_name' => $record['employee_first_name'],
250
                        'employee_last_name' => $record['employee_last_name'],
251
                        'employee_email' => $record['employee_email'],
252
                        'status' => $status,
253
                        'actions' => $actions
254
                    ];
255
 
256
 
257
                    array_push($items, $item);
258
                }
259
 
260
                $data['items'] = $items;
261
                $data['total'] = $paginator->getTotalItemCount();
262
 
263
 
264
                return new JsonModel([
265
                    'success' => true,
266
                    'data' => $data
267
                ]);
268
            } else {
269
 
270
                $form = new PerformanceEvaluationTestForm($this->adapter, $currentCompany->id);
271
 
272
                $this->layout()->setTemplate('layout/layout-backend');
273
                $viewModel = new ViewModel();
274
                $viewModel->setTemplate('leaders-linked/performance-evaluation-tests/index.phtml');
275
                $viewModel->setVariables([
276
                    'form' => $form,
277
                ]);
278
                return $viewModel;
279
            }
280
        } else {
281
            return new JsonModel([
282
                'success' => false,
283
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
284
            ]);
285
 
286
        }
287
 
288
    }
289
 
290
    public function addAction()
291
    {
292
        $request = $this->getRequest();
293
        $currentUserPlugin = $this->plugin('currentUserPlugin');
294
        $currentCompany = $currentUserPlugin->getCompany();
295
        $currentUser = $currentUserPlugin->getUser();
296
 
297
        $request = $this->getRequest();
298
 
299
 
300
        if ($request->isPost()) {
301
            $dataPost = $request->getPost()->toArray();
302
 
303
            $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
304
            if($dt) {
305
                $dataPost['last_date'] = $dt->format('Y-m-d');
306
            }
307
 
308
 
309
            $form = new PerformanceEvaluationTestForm($this->adapter, $currentCompany->id);
310
            $form->setData($dataPost);
311
 
312
            if ($form->isValid()) {
313
 
314
 
315
                $dataPost = (array) $form->getData();
316
 
317
                $companyPerformanceFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
318
                $companyPerformanceForm = $companyPerformanceFormMapper->fetchOneByUuid($dataPost['form_id']);
319
 
320
                $userMapper = UserMapper::getInstance($this->adapter);
321
                $supervisor = $userMapper->fetchOneByUuid($dataPost['supervisor_id']);
322
                $employee = $userMapper->fetchOneByUuid($dataPost['employee_id']);
323
 
324
 
325
                $performanceEvaluationTest = new PerformanceEvaluationTest();
326
                $performanceEvaluationTest->company_id      = $currentCompany->id;
327
                $performanceEvaluationTest->form_id         = $companyPerformanceForm->id;
328
                $performanceEvaluationTest->supervisor_id   = $supervisor->id;
329
                $performanceEvaluationTest->employee_id     = $employee->id;
330
                $performanceEvaluationTest->last_date       = $dataPost['last_date'];
331
                $performanceEvaluationTest->type            = PerformanceEvaluationTest::TYPE_BOTH;
332
                $performanceEvaluationTest->status          = PerformanceEvaluationTest::STATUS_PENDING;
333
                $performanceEvaluationTest->content         = $companyPerformanceForm->content;
334
 
335
 
336
 
337
                $performanceTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
338
                $result = $performanceTestMapper->insert($performanceEvaluationTest);
339
 
340
 
341
                if ($result) {
342
 
343
                    $this->logger->info('Se agrego la Evaluación para el Formulario de Evaluación de Desempeño : ' . $companyPerformanceForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
344
 
345
 
346
                    $performanceEvaluationTestEmployee = new PerformanceEvaluationTest();
347
                    $performanceEvaluationTestEmployee->company_id        = $currentCompany->id;
348
                    $performanceEvaluationTestEmployee->form_id           = $companyPerformanceForm->id;
349
                    $performanceEvaluationTestEmployee->employee_id       = $employee->id;
350
                    $performanceEvaluationTestEmployee->supervisor_id     = $supervisor->id;
351
                    $performanceEvaluationTestEmployee->parent_id         = $performanceEvaluationTest->id;
352
                    $performanceEvaluationTestEmployee->last_date         = $performanceEvaluationTest->last_date;
353
                    $performanceEvaluationTestEmployee->type              = PerformanceEvaluationTest::TYPE_EMPLOYEE;
354
                    $performanceEvaluationTestEmployee->status            = PerformanceEvaluationTest::STATUS_PENDING;
355
                    $performanceEvaluationTestEmployee->content             = $companyPerformanceForm->content;
356
                    $performanceTestMapper->insert($performanceEvaluationTestEmployee);
357
 
358
                    $performanceEvaluationTestSurpevisor = new PerformanceEvaluationTest();
359
                    $performanceEvaluationTestSurpevisor->company_id        = $currentCompany->id;
360
                    $performanceEvaluationTestSurpevisor->form_id           = $companyPerformanceForm->id;
361
                    $performanceEvaluationTestSurpevisor->employee_id       = $employee->id;
362
                    $performanceEvaluationTestSurpevisor->supervisor_id     = $supervisor->id;
363
                    $performanceEvaluationTestSurpevisor->parent_id         = $performanceEvaluationTest->id;
364
                    $performanceEvaluationTestSurpevisor->last_date         = $performanceEvaluationTest->last_date;
365
                    $performanceEvaluationTestSurpevisor->type              = PerformanceEvaluationTest::TYPE_SUPERVISOR;
366
                    $performanceEvaluationTestSurpevisor->status            = PerformanceEvaluationTest::STATUS_PENDING;
367
                    $performanceEvaluationTestSurpevisor->content         = $companyPerformanceForm->content;
368
                    $performanceTestMapper->insert($performanceEvaluationTestSurpevisor);
369
 
370
 
371
                    $data = [
372
                        'success' => true,
373
                        'data' => 'LABEL_RECORD_ADDED'
374
                    ];
375
 
376
                } else {
377
                    $data = [
378
                        'success' => false,
379
                        'data' => $performanceTestMapper->getError()
380
                    ];
381
                }
382
 
383
                return new JsonModel($data);
384
            } else {
385
                $messages = [];
386
                $form_messages = (array) $form->getMessages();
387
                foreach ($form_messages as $fieldname => $field_messages) {
388
 
389
                    $messages[$fieldname] = array_values($field_messages);
390
                }
391
 
392
                return new JsonModel([
393
                    'success' => false,
394
                    'data' => $messages
395
                ]);
396
            }
397
        } else {
398
            $data = [
399
                'success' => false,
400
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
401
            ];
402
 
403
            return new JsonModel($data);
404
        }
405
 
406
        return new JsonModel($data);
407
    }
408
 
409
 
410
    public function deleteAction()
411
    {
412
        $currentUserPlugin = $this->plugin('currentUserPlugin');
413
        $currentUser = $currentUserPlugin->getUser();
414
        $currentCompany = $currentUserPlugin->getCompany();
415
 
416
        $request = $this->getRequest();
417
        $uuid = $this->params()->fromRoute('id');
418
 
419
        if (!$uuid) {
420
            $data = [
421
                'success' => false,
422
                'data' => 'ERROR_INVALID_PARAMETER'
423
            ];
424
 
425
            return new JsonModel($data);
426
        }
427
 
428
 
429
        $performanceTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
430
        $performanceTest = $performanceTestMapper->fetchOneByUuid($uuid);
431
        if (!$performanceTest) {
432
            $data = [
433
                'success' => false,
434
                'data' => 'ERROR_RECORD_NOT_FOUND'
435
            ];
436
 
437
            return new JsonModel($data);
438
        }
439
 
440
        if ($currentCompany && $performanceTest->company_id != $currentCompany->id) {
441
            $data = [
442
                'success' => false,
443
                'data' => 'ERROR_UNAUTHORIZED'
444
            ];
445
 
446
            return new JsonModel($data);
447
        }
448
 
449
 
450
        if ($request->isPost()) {
451
            $result = $performanceTestMapper->delete($performanceTest);
452
            if ($result) {
453
                $performanceFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
454
                $performanceForm = $performanceFormMapper->fetchOne($performanceTest->form_id);
455
 
456
 
457
                $this->logger->info('Se borro una evaluación del formulario ' . $performanceForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
458
 
459
                $data = [
460
                    'success' => true,
461
                    'data' => 'LABEL_RECORD_DELETED'
462
                ];
463
            } else {
464
 
465
                $data = [
466
                    'success' => false,
467
                    'data' => $performanceTestMapper->getError()
468
                ];
469
 
470
                return new JsonModel($data);
471
            }
472
        } else {
473
            $data = [
474
                'success' => false,
475
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
476
            ];
477
 
478
            return new JsonModel($data);
479
        }
480
 
481
        return new JsonModel($data);
482
    }
483
 
484
    public function reportAction()
485
    {
486
        $request = $this->getRequest();
487
        $currentUserPlugin = $this->plugin('currentUserPlugin');
488
        $currentCompany = $currentUserPlugin->getCompany();
489
        $currentUser = $currentUserPlugin->getUser();
490
 
491
        $request = $this->getRequest();
492
        $uuid = $this->params()->fromRoute('id');
493
 
494
        if (!$uuid) {
495
            $data = [
496
                'success' => false,
497
                'data' => 'ERROR_INVALID_PARAMETER'
498
            ];
499
 
500
            return new JsonModel($data);
501
        }
502
 
503
        $performanceEvaluationTestMapper = PerformanceEvaluationTestMapper::getInstance($this->adapter);
504
        $performanceEvaluationTest = $performanceEvaluationTestMapper->fetchOneByUuid($uuid);
505
        if (!$performanceEvaluationTest) {
506
            $data = [
507
                'success' => false,
508
                'data' => 'ERROR_RECORD_NOT_FOUND'
509
            ];
510
 
511
            return new JsonModel($data);
512
        }
513
 
514
 
515
        if ($performanceEvaluationTest->company_id != $currentCompany->id) {
516
            return new JsonModel([
517
                'success' => false,
518
                'data' => 'ERROR_UNAUTHORIZED'
519
            ]);
520
        }
521
 
522
        if ($performanceEvaluationTest->employee_id != $currentUser->id
523
            && $performanceEvaluationTest->supervisor_id != $currentUser->id ) {
524
                return new JsonModel([
525
                    'success' => false,
526
                    'data' => 'ERROR_UNAUTHORIZED'
527
                ]);
528
            }
529
 
530
            if($performanceEvaluationTest->status ==PerformanceEvaluationTest::STATUS_PENDING) {
531
                return new JsonModel([
532
                    'success' => false,
533
                    'data' =>   'ERROR_RECORD_IS_PENDING'
534
                ]);
535
 
536
            }
537
 
538
 
539
 
540
            $request = $this->getRequest();
541
            if ($request->isGet()) {
542
 
543
                switch( $performanceEvaluationTest->type)
544
                {
545
                    case PerformanceEvaluationTest::TYPE_BOTH :
546
                        $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH');
547
                        break;
548
 
549
                    case PerformanceEvaluationTest::TYPE_SUPERVISOR :
550
                        $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR');
551
                        break;
552
 
553
                    case PerformanceEvaluationTest::TYPE_EMPLOYEE :
554
                        $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE');
555
                        break;
556
 
557
                    default :
558
                        $type = $this->translator->translate('LABEL_UNKNOWN');
559
                        break;
560
                }
561
 
562
 
563
                $performanceEvaluationFormMapper = PerformanceEvaluationFormMapper::getInstance($this->adapter);
564
                $performanceEvaluationForm = $performanceEvaluationFormMapper->fetchOne($performanceEvaluationTest->form_id);
565
 
566
                $userMapper = UserMapper::getInstance($this->adapter);
567
                $employee = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
568
 
569
                $filename = $performanceEvaluationForm->name . '-' . trim($employee->first_name) . '-' . trim($employee->last_name)  . '-' . $type . '-' . date('Y-m-d H:i a') . '.pdf';
570
 
571
                $filename = Functions::normalizeStringFilename( $filename );
572
 
573
 
574
 
575
 
576
                $content = base64_encode($this->renderPDF($performanceEvaluationTest));
577
                $data = [
578
                    'success' => true,
579
                    'data' => [
580
                        'basename' => $filename,
581
                        'content' => $content
582
                    ]
583
                ];
584
 
585
                return new JsonModel($data);
586
 
587
                /*
588
 
589
                $content = $this->renderPdf($currentCompany, $jobDescription);
590
                $response = new Response();
591
                $response->setStatusCode(200);
592
                $response->setContent($content);
593
 
594
 
595
 
596
                $headers = $response->getHeaders();
597
                $headers->clearHeaders();
598
 
599
                $headers->addHeaderLine('Content-Description: File Transfer');
600
                $headers->addHeaderLine('Content-Type: application/pdf');
601
                //$headers->addHeaderLine('Content-Disposition: attachment; filename=' . $filename);
602
                $headers->addHeaderLine('Content-Transfer-Encoding: binary');
603
                $headers->addHeaderLine('Expires: 0');
604
                $headers->addHeaderLine('Cache-Control: must-revalidate');
605
                $headers->addHeaderLine('Pragma: public');
606
                return $response;
607
                */
608
 
609
 
610
 
611
 
612
                return ;
613
            } else {
614
 
615
 
616
                return new JsonModel([
617
                    'success' => false,
618
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
619
                ]);
620
            }
621
    }
622
 
623
    /**
624
     * Render PDF
625
     * @param PerformanceEvaluationTest $performanceEvaluationTest
626
 
627
     * @return mixed
628
     */
629
    private function renderPDF($performanceEvaluationTest)
630
    {
631
        $request = $this->getRequest();
632
        $currentUserPlugin = $this->plugin('currentUserPlugin');
633
        $currentCompany = $currentUserPlugin->getCompany();
634
        $currentUser = $currentUserPlugin->getUser();
635
 
636
 
637
        //Generate New PDF
638
        $pdf = new PerformanceEvaluationInterviewPDF();
639
 
640
        $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $currentCompany->uuid;
641
        $header = $currentCompany->header ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->header : '';
642
        if (empty($header) || !file_exists($header)) {
643
            $header = $this->config['leaderslinked.images_default.company_pdf_header'];
644
        }
645
 
646
        $footer = $currentCompany->footer ? $target_path . DIRECTORY_SEPARATOR . $currentCompany->footer : '';
647
        if (empty($footer) || !file_exists($footer)) {
648
            $footer = $this->config['leaderslinked.images_default.company_pdf_footer'];
649
        }
650
 
651
        $content = json_decode($performanceEvaluationTest->content);
652
 
653
        $pdf->header = $header;
654
        $pdf->footer = $footer;
655
        $pdf->translator = $this->translator;
656
 
657
        $pdf->SetMargins(10, 0, 10);
658
 
659
        $pdf->AliasNbPages();
660
        $pdf->AddPage();
661
 
662
        switch( $performanceEvaluationTest->type)
663
        {
664
            case PerformanceEvaluationTest::TYPE_BOTH :
665
                $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_BOTH');
666
                break;
667
 
668
            case PerformanceEvaluationTest::TYPE_SUPERVISOR :
669
                $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_SUPERVISOR');
670
                break;
671
 
672
            case PerformanceEvaluationTest::TYPE_EMPLOYEE :
673
                $type = $this->translator->translate('LABEL_PERFORMANCE_EVALUATION_TYPE_EMPLOYEE');
674
                break;
675
 
676
            default :
677
                $type = $this->translator->translate('LABEL_UNKNOWN');
678
                break;
679
        }
680
 
681
        $dt = \DateTime::createFromFormat('Y-m-d H:i:s', $performanceEvaluationTest->updated_on);
682
 
683
        $evaluated = '';
684
        $evaluator = '';
685
 
686
        $userMapper = UserMapper::getInstance($this->adapter);
687
        if($performanceEvaluationTest->employee_id) {
688
            $user = $userMapper->fetchOne($performanceEvaluationTest->employee_id);
689
            if($user) {
690
                $evaluated = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
691
            }
692
        }
693
        if($performanceEvaluationTest->supervisor_id) {
694
            $user = $userMapper->fetchOne($performanceEvaluationTest->supervisor_id);
695
            if($user) {
696
                $evaluator = ucwords(strtolower(trim($user->first_name . ' ' . $user->last_name)));
697
            }
698
        }
699
 
700
        $rows = [
701
            [
702
                'title' => $this->translator->translate('LABEL_TYPE') . ' : ',
703
                'content' => $type,
704
            ],
705
            [
706
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_POSITION') . ' : ',
707
                'content' => $content->name,
708
            ],
709
            [
710
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATED')  . ' : ',
16768 efrain 711
                'content' => Functions::utf8_decode($evaluated),
15444 efrain 712
            ],
713
 
714
            [
715
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATE_SIGNATURE') . ' : ',
716
                'content' => ''
717
            ],
718
            [
719
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATOR') . ' : ',
16768 efrain 720
                'content' => Functions::utf8_decode($evaluator),
15444 efrain 721
            ],
722
            [
723
                'title' => $this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_EVALUATOR_SIGNATURE') . ' : ',
724
                'content' => ''
725
            ],
726
            [
727
                'title' => $this->translator->translate( 'LABEL_PDF_PERFORMANCE_EVALUATION_MANAGER_SIGNATURE') . ' : ',
728
                'content' => ''
729
            ],
730
            [
731
                'title' => $this->translator->translate('LABEL_DATE'),
732
                'content' => $dt->format('d/m/Y H:i a')
733
            ]
734
        ];
735
 
736
 
737
 
738
        $pdf->borderTable($this->translator->translate('LABEL_PDF_PERFORMANCE_EVALUATION_TITLE'), $rows);
739
 
740
        $pdf->evaluationTable($content->comment, $content->points);
741
 
742
 
743
 
744
        // Competencies
745
        if ($content->competencies_selected) {
746
            $pdf->AddPage();
747
 
748
            $i = 0;
749
 
750
            $max = count($content->competencies_selected);
751
            for($i = 0; $i < $max; $i++)
752
            {
753
                $competency_selected = $content->competencies_selected[$i];
754
 
755
                $j = $i + 1;
756
                $last = $j == $max;
757
                $pdf->competencyTable($i, $competency_selected, $content->competencies, $content->competency_types, $content->behaviors, $content->evaluation, $last);
758
            }
759
 
760
        }
761
 
762
        return $pdf->Output('S');
763
    }
764
 
765
}