Proyectos de Subversion LeadersLinked - Backend

Rev

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