Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1384 efrain 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace LeadersLinked\Controller;
6
 
7
use Laminas\Db\Adapter\AdapterInterface;
8
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
9
use Laminas\Mvc\Controller\AbstractActionController;
10
use Laminas\Log\LoggerInterface;
11
use Laminas\View\Model\ViewModel;
12
use Laminas\View\Model\JsonModel;
7778 eleazar 13
use LeadersLinked\Library\Functions;
1384 efrain 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;
8169 eleazar 19
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
1384 efrain 20
use Laminas\Paginator\Paginator;
21
use LeadersLinked\Mapper\CompanyPerformanceEvaluationFormMapper;
8203 eleazar 22
use LeadersLinked\Mapper\CompanyMapper;
1384 efrain 23
use LeadersLinked\Mapper\CompanyUserMapper;
8100 eleazar 24
use LeadersLinked\Mapper\JobDescriptionMapper;
8101 eleazar 25
use LeadersLinked\Mapper\CompetencyTypeMapper;
26
use LeadersLinked\Model\JobDescription;
27
use LeadersLinked\Mapper\CompetencyMapper;
28
use LeadersLinked\Mapper\BehaviorCompetencyMapper;
29
use LeadersLinked\Model\BehaviorCompetency;
30
use LeadersLinked\Library\JobPdf;
31
use LeadersLinked\Mapper\JobDescriptionCompetencyMapper;
32
use LeadersLinked\Mapper\JobDescriptionSubordinateMapper;
33
use LeadersLinked\Model\JobDescriptionCompetency;
34
use LeadersLinked\Model\JobDescriptionBehaviorCompetency;
35
use LeadersLinked\Mapper\JobDescriptionBehaviorCompetencyMapper;
36
use LeadersLinked\Model\JobDescriptionSubordinate;
37
use LeadersLinked\Mapper\BehaviorMapper;
8190 eleazar 38
use LeadersLinked\Library\InterviewPDF;
8101 eleazar 39
use LeadersLinked\Model\Behavior;
1384 efrain 40
use LeadersLinked\Form\PerformanceEvaluationEvaluationForm;
8087 eleazar 41
use LeadersLinked\Form\PerformanceEvaluationEvaluationSelfForm;
8179 eleazar 42
use LeadersLinked\Form\PerformanceEvaluationEvaluationBothForm;
43
use LeadersLinked\Form\PerformanceEvaluationEvaluationSupervisorForm;
1384 efrain 44
use LeadersLinked\Mapper\CompanyPerformanceEvaluationTestMapper;
8170 eleazar 45
use LeadersLinked\Mapper\CompanyPerformanceEvaluationTestSelfMapper;
8179 eleazar 46
use LeadersLinked\Mapper\CompanyPerformanceEvaluationTestBothMapper;
47
use LeadersLinked\Mapper\CompanyPerformanceEvaluationTestSupervisorMapper;
1384 efrain 48
use LeadersLinked\Model\CompanyPerformanceEvaluationTest;
49
use LeadersLinked\Model\CompanyPerformanceEvaluationForm;
8087 eleazar 50
use LeadersLinked\Model\CompanyPerformanceEvaluationTestSelf;
8179 eleazar 51
use LeadersLinked\Model\CompanyPerformanceEvaluationTestBoth;
52
use LeadersLinked\Model\CompanyPerformanceEvaluationTestSupervisor;
1384 efrain 53
 
54
class PerformanceEvaluationEvaluationController extends AbstractActionController {
55
 
56
    /**
57
     *
58
     * @var AdapterInterface
59
     */
60
    private $adapter;
61
 
62
    /**
63
     *
64
     * @var AbstractAdapter
65
     */
66
    private $cache;
67
 
68
    /**
69
     *
70
     * @var  LoggerInterface
71
     */
72
    private $logger;
73
 
74
    /**
75
     *
76
     * @var array
77
     */
78
    private $config;
79
 
80
    /**
81
     *
82
     * @param AdapterInterface $adapter
83
     * @param AbstractAdapter $cache
84
     * @param LoggerInterface $logger
85
     * @param array $config
86
     */
87
    public function __construct($adapter, $cache, $logger, $config) {
88
        $this->adapter = $adapter;
89
        $this->cache = $cache;
90
        $this->logger = $logger;
91
        $this->config = $config;
92
    }
93
 
94
    public function indexAction() {
95
        $currentUserPlugin = $this->plugin('currentUserPlugin');
96
        $currentUser = $currentUserPlugin->getUser();
97
        $currentCompany = $currentUserPlugin->getCompany();
98
 
7897 eleazar 99
        try{
1384 efrain 100
        $request = $this->getRequest();
101
 
102
        if ($request->isGet()) {
103
 
104
            $headers = $request->getHeaders();
105
 
106
            $isJson = false;
107
            if ($headers->has('Accept')) {
108
                $accept = $headers->get('Accept');
109
 
110
                $prioritized = $accept->getPrioritized();
111
 
112
                foreach ($prioritized as $key => $value) {
113
                    $raw = trim($value->getRaw());
114
 
115
                    if (!$isJson) {
116
                        $isJson = strpos($raw, 'json');
117
                    }
118
                }
119
            }
120
 
121
            //$isJson = true;
122
            if ($isJson) {
123
 
124
 
125
                $data = [
126
                    'items' => [],
127
                    'total' => 0,
128
                ];
129
 
130
 
131
                $search = $this->params()->fromQuery('search', []);
132
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
133
 
134
                $page = intval($this->params()->fromQuery('start', 1), 10);
135
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
136
                $order = $this->params()->fromQuery('order', []);
137
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
138
                $order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
139
 
140
                $fields = ['max_date'];
141
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'first_name';
142
 
143
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
144
                    $order_direction = 'ASC';
145
                }
146
 
147
 
148
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
149
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'performance-evaluation/evaluations/delete');
7913 eleazar 150
 
1384 efrain 151
 
7906 eleazar 152
 
1384 efrain 153
                $queryMapper = QueryMapper::getInstance($this->adapter);
154
                $sql = $queryMapper->getSql();
155
                $select = $sql->select();
8082 eleazar 156
                $select->columns(['uuid', 'last_date', 'form_id']);
1384 efrain 157
                $select->from(['tb1' => CompanyPerformanceEvaluationTestMapper::_TABLE]);
158
                $select->join(['tb2' => CompanyPerformanceEvaluationFormMapper::_TABLE], 'tb1.form_id = tb2.id ', ['form' =>'name']);
159
                $select->join(['tb3' => UserMapper::_TABLE], 'tb1.supervisor_id = tb3.id ', ['first_name', 'last_name', 'email']);
160
                $select->where->equalTo('tb1.company_id', $currentCompany->id);
161
 
162
                if ($search) {
163
                    $select->where->nest()
164
                            ->like('tb1.last_date', '%' . $search . '%')
165
                            ->like('tb2.name', '%' . $search . '%')
166
                            ->like('tb3.first_name', '%' . $search . '%')
167
                            ->or->like('tb3.last_name', '%' . $search . '%')
168
                            ->or->like('tb3.email', '%' . $search . '%')
169
                            ->unnest();
170
                }
171
 
172
 
173
                $select->order($order_field . ' ' . $order_direction);
174
 
175
                $hydrator = new ArraySerializableHydrator();
176
                $resultset = new HydratingResultSet($hydrator);
177
 
178
                $adapter = new DbSelect($select, $sql, $resultset);
179
                $paginator = new Paginator($adapter);
180
                $paginator->setItemCountPerPage($records_x_page);
181
                $paginator->setCurrentPageNumber($page);
182
 
183
                $items = [];
184
                $records = $paginator->getCurrentItems();
8175 eleazar 185
                $testSelfMapper = CompanyPerformanceEvaluationTestSelfMapper::getInstance($this->adapter);
8188 eleazar 186
                $testBothMapper = CompanyPerformanceEvaluationTestBothMapper::getInstance($this->adapter);
187
                $testSupervisorMapper = CompanyPerformanceEvaluationTestSupervisorMapper::getInstance($this->adapter);
1384 efrain 188
                foreach ($records as $record)
189
                {
8082 eleazar 190
                    $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
191
                    $test =  $testMapper->fetchOneByUuid($record['uuid']);
8083 eleazar 192
 
1384 efrain 193
                    $dt = \DateTime::createFromFormat('Y-m-d', $record['last_date']);
194
                    $last_date = $dt->format('d/m/Y');
195
 
8175 eleazar 196
                    $testSelf = $testSelfMapper->fetchOneByTestId($test->id);
8188 eleazar 197
                    $testBoth = $testBothMapper->fetchOneByTestId($test->id);
198
                    $testSupervisor = $testSupervisorMapper->fetchOneByTestId($test->id);
7778 eleazar 199
                    $link_delete = $this->url()->fromRoute('performance-evaluation/evaluations/delete', ['id' => $record['uuid'] ]);
8182 eleazar 200
 
7897 eleazar 201
                    $item = [
1384 efrain 202
                        'last_date' => $last_date,
203
                        'form' => $record['form'],
8083 eleazar 204
                        'first_name' => $test->first_name,
205
                        'last_name' => $test->last_name,
1384 efrain 206
                        'supervisor' => trim(trim($record['first_name']) . ' ' . trim($record['last_name'])) . ' (' . trim($record['email']) . ')',
207
                        'actions' => [
208
                            'link_delete' => $allowDelete ? $link_delete : '',
209
                        ]
210
                    ];
8184 eleazar 211
                    if($testSelf) {
8220 eleazar 212
                        $item['actions']['link_report_self'] = $this->url()->fromRoute('performance-evaluation/evaluations/report-self', ['id' => $record['uuid'] ]);
8182 eleazar 213
                    } else{
8184 eleazar 214
                        $item['actions']['link_self'] = $this->url()->fromRoute('performance-evaluation/evaluations/self', ['id' => $record['uuid'] ]);
8182 eleazar 215
                    }
8188 eleazar 216
                    if($testBoth) {
8220 eleazar 217
                        $item['actions']['link_report_both'] = $this->url()->fromRoute('performance-evaluation/evaluations/report-both', ['id' => $record['uuid'] ]);
8188 eleazar 218
                    } else{
219
                        $item['actions']['link_both'] = $this->url()->fromRoute('performance-evaluation/evaluations/both', ['id' => $record['uuid'] ]);
220
                    }
221
                    if($testSupervisor) {
8220 eleazar 222
                        $item['actions']['link_report_superviser'] = $this->url()->fromRoute('performance-evaluation/evaluations/report-superviser', ['id' => $record['uuid'] ]);
8188 eleazar 223
                    } else{
224
                        $item['actions']['link_superviser'] = $this->url()->fromRoute('performance-evaluation/evaluations/superviser', ['id' => $record['uuid'] ]);
225
                    }
1384 efrain 226
 
227
                    array_push($items, $item);
228
                }
229
 
230
                $data['items'] = $items;
231
                $data['total'] = $paginator->getTotalItemCount();
232
 
233
 
234
                return new JsonModel([
7890 eleazar 235
                    'success' => true,
1384 efrain 236
                    'data' => $data
237
                ]);
238
            } else {
239
 
240
 
241
                $form = new PerformanceEvaluationEvaluationForm($this->adapter, $currentCompany->id);
8088 eleazar 242
                $formSelf = new PerformanceEvaluationEvaluationSelfForm($this->adapter, $currentCompany->id);
1384 efrain 243
 
244
 
245
                $this->layout()->setTemplate('layout/layout-backend');
246
                $viewModel = new ViewModel();
247
                $viewModel->setTemplate('leaders-linked/performance-evaluation-evaluations/index.phtml');
248
                $viewModel->setVariables([
249
                    'form' => $form,
8088 eleazar 250
                    'formSelf' => $formSelf,
1384 efrain 251
                ]);
252
 
253
                return $viewModel;
254
            }
255
        } else {
256
            return new JsonModel([
257
                'success' => false,
258
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
259
            ]);
7897 eleazar 260
 
1384 efrain 261
        }
7897 eleazar 262
        } catch (\Throwable $e) {
263
            $e->getMessage();
264
            return new JsonModel([
265
                'success' => false,
266
                'data' => $e
267
            ]);
268
        }
1384 efrain 269
    }
270
 
8068 eleazar 271
 
272
    public function emailAction() {
273
        $request = $this->getRequest();
274
        $currentUserPlugin = $this->plugin('currentUserPlugin');
275
        $currentCompany = $currentUserPlugin->getCompany();
276
        $currentUser = $currentUserPlugin->getUser();
277
 
278
        $email = $request->getQuery('email');
279
 
280
        if(!$email){
281
            $data = [
282
                'success' => false,
283
                'data' => 'ERROR_INVALID_PARAMETER'
284
            ];
285
 
286
            return new JsonModel($data);
287
        }
288
 
289
        $userMapper = UserMapper::getInstance($this->adapter);
290
        $user = $userMapper->fetchOneByEmail($email);
291
 
292
        if (!$user) {
293
            return new JsonModel([
294
                'success' => false,
295
                'data' => 'ERROR_USER_NOT_FOUND',
296
            ]);
297
        } else if($request->isGet()){
298
            $data = [
299
                'success' => true,
300
                'data' => [
301
                    'user_id' => $user->id,
302
                    'first_name' => $user->first_name,
303
                    'last_name' => $user->last_name,
304
 
305
                ]
306
            ];
307
            return new JsonModel($data);
308
 
309
        }else {
310
            $data = [
311
                'success' => false,
312
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
313
            ];
314
 
315
            return new JsonModel($data);
316
        }
317
    }
318
 
1384 efrain 319
    public function addAction() {
320
        $request = $this->getRequest();
321
 
322
        $currentUserPlugin = $this->plugin('currentUserPlugin');
323
        $currentUser = $currentUserPlugin->getUser();
324
        $currentCompany = $currentUserPlugin->getCompany();
325
 
326
        $request = $this->getRequest();
327
 
328
 
329
        if ($request->isPost()) {
330
            $dataPost = $request->getPost()->toArray();
331
            $form = new  PerformanceEvaluationEvaluationForm($this->adapter, $currentCompany->id);
332
            $form->setData($dataPost);
8077 eleazar 333
 
1384 efrain 334
            if($form->isValid()) {
335
                $dataPost = (array) $form->getData();
336
 
337
                $form_id = $dataPost['form_id'];
8072 eleazar 338
                $supervisor_id = $dataPost['supervisor_id'];
339
                $first_name= $dataPost['first_name'];
340
                $last_name= $dataPost['last_name'];
341
                $email= $dataPost['email'];
342
                $user_id= $dataPost['user_id'];
1384 efrain 343
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
344
                $last_date = $dt->format('Y-m-d');
345
 
346
                $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
347
                $form = $formMapper->fetchOneByUuid($form_id);
348
                if (!$form) {
349
                    return new JsonModel([
350
                        'success' => true,
351
                        'data' => 'ERROR_FORM_NOT_FOUND'
352
                    ]);
353
                }
354
 
355
                if ($form->company_id != $currentCompany->id) {
356
                    return new JsonModel([
357
                        'success' => true,
358
                        'data' => 'ERROR_UNAUTHORIZED'
359
                    ]);
360
                }
361
 
362
 
363
                $userMapper = UserMapper::getInstance($this->adapter);
8073 eleazar 364
                $supervisor = $userMapper->fetchOneByUuid($supervisor_id);
1384 efrain 365
 
8072 eleazar 366
                if (!$supervisor) {
1384 efrain 367
                    return new JsonModel([
368
                        'success' => false,
369
                        'data' => 'ERROR_USER_NOT_FOUND'
370
                    ]);
371
                }
372
 
373
 
374
 
375
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
8074 eleazar 376
                $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($form->company_id, $supervisor->id);
1384 efrain 377
                if (!$companyUser) {
378
                    return new JsonModel([
379
                        'success' => false,
380
                        'data' => 'ERROR_UNAUTHORIZED'
381
                    ]);
382
                }
383
 
384
 
385
                $test = new CompanyPerformanceEvaluationTest();
386
                $test->company_id = $form->company_id;
387
                $test->form_id = $form->id;
8072 eleazar 388
                $test->supervisor_id = $supervisor->id;
1384 efrain 389
                $test->last_date = $last_date;
8072 eleazar 390
                $test->first_name = $first_name;
391
                $test->last_name = $last_name;
392
                $test->email = $email;
8078 eleazar 393
                //$tst->user_id = $user_id;
1384 efrain 394
 
395
 
396
                $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
397
                $result = $testMapper->insert($test);
398
 
399
                if($result) {
400
                    $this->logger->info('Se agrego el Test de Performance ' . $form->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
401
 
402
                    $data = [
403
                        'success'   => true,
404
                        'data'   => 'LABEL_RECORD_ADDED'
405
                    ];
406
                } else {
407
                    $data = [
408
                        'success'   => false,
409
                        'data'      => $testMapper->getError()
410
                    ];
411
 
412
                }
413
 
414
                return new JsonModel($data);
415
 
416
            } else {
417
                $messages = [];
418
                $form_messages = (array) $form->getMessages();
419
                foreach($form_messages  as $fieldname => $field_messages)
420
                {
421
 
422
                    $messages[$fieldname] = array_values($field_messages);
423
                }
424
 
425
                return new JsonModel([
426
                    'success'   => false,
427
                    'data'   => $messages
428
                ]);
429
            }
430
 
431
 
432
 
433
        }
434
 
435
        return new JsonModel([
436
            'success' => false,
437
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
438
        ]);
439
    }
8087 eleazar 440
 
441
    public function selfAction() {
442
        $currentUserPlugin = $this->plugin('currentUserPlugin');
443
        $currentUser = $currentUserPlugin->getUser();
444
        $currentCompany = $currentUserPlugin->getCompany();
445
 
446
        $request = $this->getRequest();
447
 
448
        $uuid = $this->params()->fromRoute('id');
449
 
450
        if ($request->isGet()) {
451
            $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
452
            $test = $testMapper->fetchOneByUuid($uuid);
8094 eleazar 453
 
454
            $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
8097 eleazar 455
            $form = $formMapper->fetchOne($test->form_id);
8099 eleazar 456
 
8087 eleazar 457
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
458
            $jobDescription = $jobDescriptionMapper->fetchOne($form->job_description_id);
8101 eleazar 459
 
460
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
461
            $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescription->id);
8102 eleazar 462
            // return new JsonModel([
463
            //     'success' => false,
464
            //     'data' => $jobDescriptionCompetencies
465
            // ]);
8087 eleazar 466
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
467
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
468
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
469
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
1384 efrain 470
 
8087 eleazar 471
            $data = [
472
                'job_description' => [
473
                    'uuid' => $jobDescription->uuid,
474
                    'name' => $jobDescription->name,
475
                    'functions' => $jobDescription->functions,
476
                    'objectives' => $jobDescription->objectives,
477
                    'competencies' => []
478
                ],
479
                'self' => [
480
                    'points' => 0,
481
                    'comment' => '',
482
                ],
483
                'test' => $test,
484
            ];
485
 
486
            foreach ($jobDescriptionCompetencies as $jobDescriptionCompetency) {
487
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
488
                $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
489
                $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
490
 
491
                $behaviors = [];
492
 
493
                foreach ($behaviorCompetencies as $behaviorCompetency) {
494
                    $behavior = $behaviorMapper->fetchOne($behaviorCompetency->behavior_id);
495
 
496
                    $behaviors []= [
497
                        'uuid' => $behavior->uuid,
498
                        'description' => $behavior->description,
499
                        'points' => 0,
500
                        'comment' => '',
501
                        'competency_uuid' => $competency->uuid,
502
                    ];
503
                }
504
 
505
                array_push($data['job_description']['competencies'], [
506
                    'competency_uuid' => $competency->uuid,
507
                    'competency_name' => $competency->name,
508
                    'competency_type_uuid' => $competencyType->uuid,
509
                    'competency_type_name' => $competencyType->name,
510
                    'behaviors' => $behaviors,
511
                ]);
512
            }
513
 
514
            return new JsonModel([
515
                'success' => true,
516
                'data' => $data
517
            ]);
518
 
519
        } else if($request->isPost()){
8168 eleazar 520
            try{
8087 eleazar 521
            $dataPost = $request->getPost()->toArray();
522
 
523
            $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
8162 eleazar 524
            $test = $testMapper->fetchOneByUuid($uuid);
8166 eleazar 525
 
8088 eleazar 526
            $formSelf = new PerformanceEvaluationEvaluationSelfForm($this->adapter, $currentCompany->id);
8167 eleazar 527
            $dataPost['first_name'] = $test->first_name;
528
            $dataPost['last_name'] = $test->last_name;
529
            $dataPost['email'] = $test->email;
8091 eleazar 530
            $formSelf->setData($dataPost);
8087 eleazar 531
 
8091 eleazar 532
            if ($formSelf->isValid()) {
533
                $dataPost = (array) $formSelf->getData();
8087 eleazar 534
 
535
                $hydrator = new ObjectPropertyHydrator();
536
                $performanceEvaluationTestSelf = new CompanyPerformanceEvaluationTestSelf();
537
                $hydrator->hydrate($dataPost, $performanceEvaluationTestSelf);
538
 
539
                $performanceEvaluationTestSelf->company_id = $currentCompany->id;
540
                $performanceEvaluationTestSelf->test_id = $test->id;
8171 eleazar 541
                $performanceEvaluationTestSelf->form_id = $test->form_id;
8173 eleazar 542
                $performanceEvaluationTestSelf->supervisor_id = $test->supervisor_id;
8087 eleazar 543
 
544
                $performanceEvaluationTestSelfMapper = CompanyPerformanceEvaluationTestSelfMapper::getInstance($this->adapter);
545
 
546
                $result = $performanceEvaluationTestSelfMapper->insert($performanceEvaluationTestSelf);
547
 
548
 
549
                if ($result) {
8174 eleazar 550
                    $this->logger->info('Se agrego la entrevista ' . $performanceEvaluationTestSelf->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
8087 eleazar 551
 
552
                    // Get record by id
553
                    $performanceEvaluationTestSelfMapper = CompanyPerformanceEvaluationTestSelfMapper::getInstance($this->adapter);
554
                    $record = $performanceEvaluationTestSelfMapper->fetchOne($performanceEvaluationTestSelf->id);
555
 
556
 
557
                    if ($record) {
558
 
559
                        $data = [
560
                            'success' => true,
561
                            'id' => $record->id,
562
                            'data' => 'LABEL_RECORD_ADDED'
563
                        ];
564
                    } else {
565
 
566
                        $data = [
567
                            'success' => false,
568
                            'data' => 'ERROR_RECORD_NOT_FOUND'
569
                        ];
570
                    }
571
                } else {
572
                    $data = [
573
                        'success' => false,
574
                        'data' => $performanceEvaluationTestSelfMapper->getError()
575
                    ];
576
                }
577
 
578
                return new JsonModel($data);
579
            } else {
580
                $messages = [];
8163 eleazar 581
                $form_messages = (array) $formSelf->getMessages();
8087 eleazar 582
                foreach ($form_messages as $fieldname => $field_messages) {
583
 
584
                    $messages[$fieldname] = array_values($field_messages);
585
                }
586
 
587
                return new JsonModel([
588
                    'success' => false,
589
                    'data' => $messages
590
                ]);
8168 eleazar 591
            }}catch (\Throwable $e) {
592
                $e->getMessage();
593
                return new JsonModel([
594
                    'success' => false,
595
                    'data' => $e
596
                ]);
8087 eleazar 597
            }
598
        } else {
599
            $data = [
600
                'success' => false,
601
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
602
            ];
603
 
604
            return new JsonModel($data);
605
        }
606
 
607
        return new JsonModel($data);
608
    }
8179 eleazar 609
 
610
    public function bothAction() {
611
        $currentUserPlugin = $this->plugin('currentUserPlugin');
612
        $currentUser = $currentUserPlugin->getUser();
613
        $currentCompany = $currentUserPlugin->getCompany();
614
 
615
        $request = $this->getRequest();
616
 
617
        $uuid = $this->params()->fromRoute('id');
618
 
619
        if ($request->isGet()) {
620
            $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
621
            $test = $testMapper->fetchOneByUuid($uuid);
622
 
623
            $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
624
            $form = $formMapper->fetchOne($test->form_id);
625
 
626
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
627
            $jobDescription = $jobDescriptionMapper->fetchOne($form->job_description_id);
628
 
629
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
630
            $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescription->id);
631
            // return new JsonModel([
632
            //     'success' => false,
633
            //     'data' => $jobDescriptionCompetencies
634
            // ]);
635
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
636
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
637
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
638
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
8087 eleazar 639
 
8179 eleazar 640
            $data = [
641
                'job_description' => [
642
                    'uuid' => $jobDescription->uuid,
643
                    'name' => $jobDescription->name,
644
                    'functions' => $jobDescription->functions,
645
                    'objectives' => $jobDescription->objectives,
646
                    'competencies' => []
647
                ],
648
                'both' => [
649
                    'points' => 0,
650
                    'comment' => '',
651
                ],
652
                'test' => $test,
653
            ];
654
 
655
            foreach ($jobDescriptionCompetencies as $jobDescriptionCompetency) {
656
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
657
                $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
658
                $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
659
 
660
                $behaviors = [];
661
 
662
                foreach ($behaviorCompetencies as $behaviorCompetency) {
663
                    $behavior = $behaviorMapper->fetchOne($behaviorCompetency->behavior_id);
664
 
665
                    $behaviors []= [
666
                        'uuid' => $behavior->uuid,
667
                        'description' => $behavior->description,
668
                        'points' => 0,
669
                        'comment' => '',
670
                        'competency_uuid' => $competency->uuid,
671
                    ];
672
                }
673
 
674
                array_push($data['job_description']['competencies'], [
675
                    'competency_uuid' => $competency->uuid,
676
                    'competency_name' => $competency->name,
677
                    'competency_type_uuid' => $competencyType->uuid,
678
                    'competency_type_name' => $competencyType->name,
679
                    'behaviors' => $behaviors,
680
                ]);
681
            }
682
 
683
            return new JsonModel([
684
                'success' => true,
685
                'data' => $data
686
            ]);
687
 
688
        } else if($request->isPost()){
689
            try{
690
            $dataPost = $request->getPost()->toArray();
691
 
692
            $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
693
            $test = $testMapper->fetchOneByUuid($uuid);
694
 
695
            $formSelf = new PerformanceEvaluationEvaluationSelfForm($this->adapter, $currentCompany->id);
696
            $dataPost['first_name'] = $test->first_name;
697
            $dataPost['last_name'] = $test->last_name;
698
            $dataPost['email'] = $test->email;
699
            $formSelf->setData($dataPost);
700
 
701
            if ($formSelf->isValid()) {
702
                $dataPost = (array) $formSelf->getData();
703
 
704
                $hydrator = new ObjectPropertyHydrator();
705
                $performanceEvaluationTestBoth = new CompanyPerformanceEvaluationTestBoth();
706
                $hydrator->hydrate($dataPost, $performanceEvaluationTestBoth);
707
 
708
                $performanceEvaluationTestBoth->company_id = $currentCompany->id;
709
                $performanceEvaluationTestBoth->test_id = $test->id;
710
                $performanceEvaluationTestBoth->form_id = $test->form_id;
711
                $performanceEvaluationTestBoth->supervisor_id = $test->supervisor_id;
712
 
713
                $performanceEvaluationTestBothMapper = CompanyPerformanceEvaluationTestBothMapper::getInstance($this->adapter);
714
 
715
                $result = $performanceEvaluationTestBothMapper->insert($performanceEvaluationTestBoth);
716
 
717
 
718
                if ($result) {
719
                    $this->logger->info('Se agrego la entrevista ' . $performanceEvaluationTestBoth->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
720
 
721
                    // Get record by id
722
                    $performanceEvaluationTestBothMapper = CompanyPerformanceEvaluationTestBothMapper::getInstance($this->adapter);
723
                    $record = $performanceEvaluationTestBothMapper->fetchOne($performanceEvaluationTestBoth->id);
724
 
725
 
726
                    if ($record) {
727
 
728
                        $data = [
729
                            'success' => true,
730
                            'id' => $record->id,
731
                            'data' => 'LABEL_RECORD_ADDED'
732
                        ];
733
                    } else {
734
 
735
                        $data = [
736
                            'success' => false,
737
                            'data' => 'ERROR_RECORD_NOT_FOUND'
738
                        ];
739
                    }
740
                } else {
741
                    $data = [
742
                        'success' => false,
743
                        'data' => $performanceEvaluationTestBothMapper->getError()
744
                    ];
745
                }
746
 
747
                return new JsonModel($data);
748
            } else {
749
                $messages = [];
750
                $form_messages = (array) $formSelf->getMessages();
751
                foreach ($form_messages as $fieldname => $field_messages) {
752
 
753
                    $messages[$fieldname] = array_values($field_messages);
754
                }
755
 
756
                return new JsonModel([
757
                    'success' => false,
758
                    'data' => $messages
759
                ]);
760
            }}catch (\Throwable $e) {
761
                $e->getMessage();
762
                return new JsonModel([
763
                    'success' => false,
764
                    'data' => $e
765
                ]);
766
            }
767
        } else {
768
            $data = [
769
                'success' => false,
770
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
771
            ];
772
 
773
            return new JsonModel($data);
774
        }
775
 
776
        return new JsonModel($data);
777
    }
778
 
8181 eleazar 779
    public function superviserAction() {
8179 eleazar 780
        $currentUserPlugin = $this->plugin('currentUserPlugin');
781
        $currentUser = $currentUserPlugin->getUser();
782
        $currentCompany = $currentUserPlugin->getCompany();
783
 
784
        $request = $this->getRequest();
785
 
786
        $uuid = $this->params()->fromRoute('id');
787
 
788
        if ($request->isGet()) {
789
            $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
790
            $test = $testMapper->fetchOneByUuid($uuid);
791
 
792
            $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
793
            $form = $formMapper->fetchOne($test->form_id);
794
 
795
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
796
            $jobDescription = $jobDescriptionMapper->fetchOne($form->job_description_id);
797
 
798
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
799
            $jobDescriptionCompetencies = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($jobDescription->id);
800
            // return new JsonModel([
801
            //     'success' => false,
802
            //     'data' => $jobDescriptionCompetencies
803
            // ]);
804
            $competencyTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
805
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
806
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
807
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
808
 
809
            $data = [
810
                'job_description' => [
811
                    'uuid' => $jobDescription->uuid,
812
                    'name' => $jobDescription->name,
813
                    'functions' => $jobDescription->functions,
814
                    'objectives' => $jobDescription->objectives,
815
                    'competencies' => []
816
                ],
817
                'supervisor' => [
818
                    'points' => 0,
819
                    'comment' => '',
820
                ],
821
                'test' => $test,
822
            ];
823
 
824
            foreach ($jobDescriptionCompetencies as $jobDescriptionCompetency) {
825
                $competency = $competencyMapper->fetchOne($jobDescriptionCompetency->competency_id);
826
                $competencyType = $competencyTypeMapper->fetchOne($competency->competency_type_id);
827
                $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
828
 
829
                $behaviors = [];
830
 
831
                foreach ($behaviorCompetencies as $behaviorCompetency) {
832
                    $behavior = $behaviorMapper->fetchOne($behaviorCompetency->behavior_id);
833
 
834
                    $behaviors []= [
835
                        'uuid' => $behavior->uuid,
836
                        'description' => $behavior->description,
837
                        'points' => 0,
838
                        'comment' => '',
839
                        'competency_uuid' => $competency->uuid,
840
                    ];
841
                }
842
 
843
                array_push($data['job_description']['competencies'], [
844
                    'competency_uuid' => $competency->uuid,
845
                    'competency_name' => $competency->name,
846
                    'competency_type_uuid' => $competencyType->uuid,
847
                    'competency_type_name' => $competencyType->name,
848
                    'behaviors' => $behaviors,
849
                ]);
850
            }
851
 
852
            return new JsonModel([
853
                'success' => true,
854
                'data' => $data
855
            ]);
856
 
857
        } else if($request->isPost()){
858
            try{
859
            $dataPost = $request->getPost()->toArray();
860
 
861
            $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
862
            $test = $testMapper->fetchOneByUuid($uuid);
863
 
864
            $formSelf = new PerformanceEvaluationEvaluationSelfForm($this->adapter, $currentCompany->id);
865
            $dataPost['first_name'] = $test->first_name;
866
            $dataPost['last_name'] = $test->last_name;
867
            $dataPost['email'] = $test->email;
868
            $formSelf->setData($dataPost);
869
 
870
            if ($formSelf->isValid()) {
871
                $dataPost = (array) $formSelf->getData();
872
 
873
                $hydrator = new ObjectPropertyHydrator();
874
                $performanceEvaluationTestSupervisor = new CompanyPerformanceEvaluationTestSupervisor();
875
                $hydrator->hydrate($dataPost, $performanceEvaluationTestSupervisor);
876
 
877
                $performanceEvaluationTestSupervisor->company_id = $currentCompany->id;
878
                $performanceEvaluationTestSupervisor->test_id = $test->id;
879
                $performanceEvaluationTestSupervisor->form_id = $test->form_id;
880
                $performanceEvaluationTestSupervisor->supervisor_id = $test->supervisor_id;
881
 
882
                $performanceEvaluationTestSupervisorMapper = CompanyPerformanceEvaluationTestSupervisorMapper::getInstance($this->adapter);
883
 
884
                $result = $performanceEvaluationTestSupervisorMapper->insert($performanceEvaluationTestSupervisor);
885
 
886
 
887
                if ($result) {
888
                    $this->logger->info('Se agrego la entrevista ' . $performanceEvaluationTestSupervisor->id, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
889
 
890
                    // Get record by id
891
                    $performanceEvaluationTestSupervisorMapper = CompanyPerformanceEvaluationTestSupervisorMapper::getInstance($this->adapter);
892
                    $record = $performanceEvaluationTestSupervisorMapper->fetchOne($performanceEvaluationTestSupervisor->id);
893
 
894
 
895
                    if ($record) {
896
 
897
                        $data = [
898
                            'success' => true,
899
                            'id' => $record->id,
900
                            'data' => 'LABEL_RECORD_ADDED'
901
                        ];
902
                    } else {
903
 
904
                        $data = [
905
                            'success' => false,
906
                            'data' => 'ERROR_RECORD_NOT_FOUND'
907
                        ];
908
                    }
909
                } else {
910
                    $data = [
911
                        'success' => false,
912
                        'data' => $performanceEvaluationTestSupervisorMapper->getError()
913
                    ];
914
                }
915
 
916
                return new JsonModel($data);
917
            } else {
918
                $messages = [];
919
                $form_messages = (array) $formSelf->getMessages();
920
                foreach ($form_messages as $fieldname => $field_messages) {
921
 
922
                    $messages[$fieldname] = array_values($field_messages);
923
                }
924
 
925
                return new JsonModel([
926
                    'success' => false,
927
                    'data' => $messages
928
                ]);
929
            }}catch (\Throwable $e) {
930
                $e->getMessage();
931
                return new JsonModel([
932
                    'success' => false,
933
                    'data' => $e
934
                ]);
935
            }
936
        } else {
937
            $data = [
938
                'success' => false,
939
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
940
            ];
941
 
942
            return new JsonModel($data);
943
        }
944
 
945
        return new JsonModel($data);
946
    }
947
 
1384 efrain 948
    public function editAction() {
949
        $request = $this->getRequest();
950
 
951
        $currentUserPlugin = $this->plugin('currentUserPlugin');
952
        $currentUser = $currentUserPlugin->getUser();
953
        $currentCompany = $currentUserPlugin->getCompany();
954
 
955
        $request = $this->getRequest();
956
        $id = $this->params()->fromRoute('id');
957
 
958
        $formTestMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
959
        $formTest =  $formTestMapper->fetchOneByUuid($id);
8080 eleazar 960
 
1384 efrain 961
        if (!$formTest) {
962
            return new JsonModel([
963
                'success' => true,
964
                'data' => 'ERROR_RECORD_NOT_FOUND'
965
            ]);
966
        }
967
 
968
        if ($formTest->company_id != $currentCompany->id) {
969
            return new JsonModel([
970
                'success' => true,
971
                'data' => 'ERROR_UNAUTHORIZED'
972
            ]);
973
        }
974
 
975
 
976
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
977
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($formTest->company_id, $currentUser->id);
978
        if (!$companyUser) {
979
            return new JsonModel([
980
                'success' => false,
981
                'data' => 'ERROR_UNAUTHORIZED'
982
            ]);
983
        }
984
 
985
        if ($request->isGet()) {
986
 
987
            $dt = \DateTime::createFromFormat('Y-m-d', $formTest->last_date);
988
 
989
            $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
990
            $form = $formMapper->fetchOne($formTest->form_id);
991
 
992
            $userMapper = UserMapper::getInstance($this->adapter);
7785 eleazar 993
            $user = $userMapper->fetchOne($formTest->supervisor_id);
1384 efrain 994
 
995
            $data = [
996
                'success'   => true,
997
                'data'   => [
998
                    'last_date' => $dt->format('d/m/Y'),
999
                    'form' => $form->uuid,
1000
                    'supervisor' => $user->uuid,
1001
                ]
1002
            ];
1003
 
1004
            return new JsonModel($data);
1005
 
1006
 
1007
 
1008
        } else if ($request->isPost()) {
1009
 
1010
 
1011
            $dataPost = $request->getPost()->toArray();
1012
            $form = new  PerformanceEvaluationEvaluationForm($this->adapter, $currentCompany->id);
1013
            $form->setData($dataPost);
1014
 
1015
            if($form->isValid()) {
1016
                $dataPost = (array) $form->getData();
1017
 
1018
                $form_id = $dataPost['form_id'];
1019
                $user_id = $dataPost['supervisor_id'];
1020
                $dt = \DateTime::createFromFormat('d/m/Y', $dataPost['last_date']);
1021
                $last_date = $dt->format('Y-m-d');
1022
 
1023
                $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
1024
                $form = $formMapper->fetchOneByUuid($form_id);
1025
                if (!$form) {
1026
                    return new JsonModel([
1027
                        'success' => true,
1028
                        'data' => 'ERROR_FORM_NOT_FOUND'
1029
                    ]);
1030
                }
1031
 
1032
                if ($form->company_id != $currentCompany->id) {
1033
                    return new JsonModel([
1034
                        'success' => true,
1035
                        'data' => 'ERROR_UNAUTHORIZED'
1036
                    ]);
1037
                }
1038
 
1039
 
1040
                $userMapper = UserMapper::getInstance($this->adapter);
1041
                $user = $userMapper->fetchOneByUuid($user_id);
1042
 
1043
                if (!$user) {
1044
                    return new JsonModel([
1045
                        'success' => false,
1046
                        'data' => 'ERROR_USER_NOT_FOUND'
1047
                    ]);
1048
                }
1049
 
1050
 
1051
 
1052
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1053
                $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($form->company_id, $user->id);
1054
                if (!$companyUser) {
1055
                    return new JsonModel([
1056
                        'success' => false,
1057
                        'data' => 'ERROR_UNAUTHORIZED'
1058
                    ]);
1059
                }
1060
 
1061
                $formTest->supervisor_id = $user->id;
1062
                $formTest->last_date = $last_date;
1063
 
1064
                $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1065
                $result = $testMapper->update($formTest);
1066
 
1067
                if($result) {
1068
                    $this->logger->info('Se actualizo el Test de Performance ' . $form->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
1069
 
1070
                    $data = [
1071
                        'success'   => true,
1072
                        'data'   => 'LABEL_RECORD_UPDATED'
1073
                    ];
1074
                } else {
1075
                    $data = [
1076
                        'success'   => false,
1077
                        'data'      => $testMapper->getError()
1078
                    ];
1079
 
1080
                }
1081
 
1082
                return new JsonModel($data);
1083
 
1084
            } else {
1085
                $messages = [];
1086
                $form_messages = (array) $form->getMessages();
1087
                foreach($form_messages  as $fieldname => $field_messages)
1088
                {
1089
 
1090
                    $messages[$fieldname] = array_values($field_messages);
1091
                }
1092
 
1093
                return new JsonModel([
1094
                    'success'   => false,
1095
                    'data'   => $messages
1096
                ]);
1097
            }
1098
        }
1099
 
1100
        return new JsonModel([
1101
            'success' => false,
1102
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1103
        ]);
1104
    }
1105
 
1106
    public function deleteAction() {
1107
        $request = $this->getRequest();
1108
 
1109
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1110
        $currentUser = $currentUserPlugin->getUser();
1111
        $currentCompany = $currentUserPlugin->getCompany();
1112
 
1113
        $request = $this->getRequest();
1114
        $id = $this->params()->fromRoute('id');
1115
 
1116
        $formTestMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1117
        $formTest =  $formTestMapper->fetchOneByUuid($id);
1118
        if (!$formTest) {
1119
            return new JsonModel([
1120
                'success' => true,
1121
                'data' => 'ERROR_RECORD_NOT_FOUND'
1122
            ]);
1123
        }
1124
 
1125
        if ($formTest->company_id != $currentCompany->id) {
1126
            return new JsonModel([
1127
                'success' => true,
1128
                'data' => 'ERROR_UNAUTHORIZED'
1129
            ]);
1130
        }
1131
 
1132
 
1133
        $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
1134
        $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($formTest->company_id, $currentUser->id);
1135
        if (!$companyUser) {
1136
            return new JsonModel([
1137
                'success' => false,
1138
                'data' => 'ERROR_UNAUTHORIZED'
1139
            ]);
1140
        }
1141
 
1142
        if ($request->isPost()) {
1143
 
1144
 
1145
            $result = $formTestMapper->delete($formTest);
1146
 
1147
            if ($result) {
1148
 
1149
                return new JsonModel([
1150
                    'success' => true,
1151
                    'data' => 'LABEL_PERFORMANCE_TEST_DELETED',
1152
                ]);
1153
            } else {
1154
 
1155
                return new JsonModel([
1156
                    'success' => false,
1157
                    'data' => $formTestMapper->getError()
1158
                ]);
1159
            }
1160
        }
1161
 
1162
        return new JsonModel([
1163
            'success' => false,
1164
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1165
        ]);
1166
    }
1167
 
8179 eleazar 1168
    public function reportSelfAction() {
8167 eleazar 1169
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1170
        $currentUser = $currentUserPlugin->getUser();
1171
        $currentCompany = $currentUserPlugin->getCompany();
1172
 
1173
        $uuid = $this->params()->fromRoute('id');
1174
 
1175
        $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1176
        $test = $testMapper->fetchOneByUuid($uuid);
8194 eleazar 1177
 
1178
        $testSelfMapper = CompanyPerformanceEvaluationTestSelfMapper::getInstance($this->adapter);
1179
        $testSelf = $testSelfMapper->fetchOneByTestId($test->id);
8207 eleazar 1180
 
8196 eleazar 1181
        $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
1182
        $form = $formMapper->fetchOne($test->form_id);
8199 eleazar 1183
 
8167 eleazar 1184
        if (!$form) {
1185
            return new JsonModel([
1186
                'success' => false,
1187
                'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
1188
            ]);
1189
        }
1190
 
1191
        $request = $this->getRequest();
1192
        if ($request->isGet()) {
1193
            //Competencies
1194
 
1195
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
1196
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
1197
            $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
1198
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
1199
            $jobDescriptionBehaviorCompetencyMapper = JobDescriptionBehaviorCompetencyMapper::getInstance($this->adapter);
1200
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
1201
 
1202
            $competencies = [];
1203
 
1204
            $jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($form->job_description_id);
1205
 
8179 eleazar 1206
            $content = json_decode($testSelf->content, true);
8167 eleazar 1207
 
1208
            foreach ($jobDescriptionCompetency as $record) {
1209
 
1210
                $competency = $competencyMapper->fetchOne($record->competency_id);
1211
                $competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
1212
 
1213
                if ($competency && $competenceType) {
1214
 
1215
                    $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
1216
                    $behaviors = [];
1217
 
1218
                    foreach ($behaviorCompetencies as $rows) {
1219
 
1220
                        $behavior = $behaviorMapper->fetchOne($rows->behavior_id);
8179 eleazar 1221
                        $jobDescriptionBehaviorCompetency = $jobDescriptionBehaviorCompetencyMapper->fetchOneByBehavior($form->job_description_id, $record->competency_id, $rows->behavior_id);
8167 eleazar 1222
 
1223
                        if ($behavior && $jobDescriptionBehaviorCompetency) {
1224
                            $rowData = [
1225
                                'description' => $behavior->description,
1226
                                'level' => $jobDescriptionBehaviorCompetency->level,
1227
                                'comment' => '',
1228
                                'evaluation' => '',
1229
 
1230
                            ];
1231
 
1232
                            foreach($content as $eval) {
1233
                                if ($eval['competencyUuid'] == $competency->uuid &&
1234
                                    $eval['behaviorUuid'] == $behavior->uuid) {
1235
 
1236
                                    $rowData['comment'] = $eval['comment'];
1237
                                    $rowData['evaluation'] = $eval['evaluation'];
1238
 
1239
 
1240
                                    break;
1241
                                }
1242
                            }
1243
 
1244
                            $behaviors []= $rowData;
1245
                        }
1246
                    }
1247
 
1248
                    array_push($competencies, [
1249
                        'name' => $competency->name,
1250
                        'description' => $competency->description,
1251
                        'type' => $competenceType->name,
1252
                        'behaviors' => $behaviors
1253
                    ]);
1254
                }
1255
            }
1256
 
8230 eleazar 1257
            return $this->renderSelfPDF($currentCompany, $testSelf, $competencies);
8167 eleazar 1258
        }
1259
 
1260
        return new JsonModel([
1261
            'success' => false,
1262
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1263
        ]);
1264
    }
1265
 
8179 eleazar 1266
      /**
1267
     * Render PDF
1268
     * @param Company $currentCompany
1269
     * @param recruitmentSelectionInterview $interviewEvaluation
1270
     * @param array $competencies
1271
     * @return mixed
1272
     */
8230 eleazar 1273
    public function renderSelfPDF($currentCompany, $testSelf, $competencies) {
8179 eleazar 1274
 
1275
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1276
        $currentUser = $currentUserPlugin->getUser();
1277
 
1278
        //Generate New PDF
1279
        $pdf = new InterviewPDF();
1280
 
1281
        $pdf->header = '';
1282
        $pdf->footer = '';
1283
 
1284
        if ($currentCompany) {
1285
            //get company Data
1286
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1287
            $company = $companyMapper->fetchOne($currentCompany->id);
1288
 
1289
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1290
 
1291
            $pdf->header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
1292
            $pdf->footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
1293
        }
1294
 
1295
        $pdf->SetMargins(10, 0, 10);
1296
 
1297
        $pdf->AliasNbPages();
1298
        $pdf->AddPage();
1299
 
1300
        $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1301
        $test = $testMapper->fetchOne($testSelf->test_id);
1302
 
1303
        $userMapper = UserMapper::getInstance($this->adapter);
8206 eleazar 1304
        $supervisor = $userMapper->fetchOne($testSelf->supervisor_id);
8179 eleazar 1305
 
1306
        switch ($testSelf->points) {
1307
            case "0":
1308
                $points = "Sugerir otro cargo";
1309
                break;
1310
            case "1":
1311
                $points = "25%";
1312
                break;
1313
            case "2":
1314
                $points = "50%";
1315
                break;
1316
            case "3":
1317
                $points = "75%";
1318
                break;
1319
            case "4":
1320
                $points = "100%";
1321
                break;
1322
            default :
1323
                $points = "ERROR";
1324
                break;
1325
        }
1326
 
1327
        $rows = [
1328
            array(
1329
                'title' => 'Nombre Evaluado: ',
1330
                'content' => $testSelf ? ' ' . $testSelf->first_name . ' ' . $testSelf->last_name : 'No Aplica'
1331
            ),
1332
            array(
1333
                'title' => 'Supervisado por: ',
1334
                'content' => $supervisor ? ' ' . $supervisor->first_name . ' ' . $supervisor->last_name : ' No Aplica '
1335
            ),
1336
            array(
1337
                'title' => 'Comentarios del supervisor: ',
1338
                'content' => $testSelf ? ' ' . $testSelf->comment : 'No Aplica'
1339
            ),
1340
            array(
9429 eleazar 1341
                'title' => 'Porcentage',
8179 eleazar 1342
                'content' => $points
1343
            )
1344
        ];
1345
 
1346
        $pdf->borderTable('DATOS DE LA ENTREVISTA', $rows);
1347
 
1348
        $sections = json_decode($testSelf->content, true);
1349
        /*
1350
                for ($s = 0; $s < count($sections); $s++) {
1351
 
1352
                    $pdf->singleTable($sections[$s]['title'], [
1353
                        array(
1354
                            'content' => $sections[$s]['type'] != 'multiple' ? $sections[$s]['text'] : ''
1355
                    )]);
1356
 
1357
                    if ($sections[$s]['type'] == 'multiple') {
1358
 
1359
                        $pdf->titleOptionTable($sections[$s]['text']);
1360
 
1361
                        for ($o = 0; $o < count($sections[$s]['options']); $o++) {
1362
 
1363
                            $pdf->optionTable($sections[$s]['options'][$o]['title']);
1364
                        }
1365
                        $pdf->Ln();
1366
                    }
1367
                    if ($s % 2 == 0 && $s > 1) {
1368
                        $pdf->AddPage();
1369
                    }
1370
                }*/
1371
 
1372
        // Competencies
1373
        if (count($competencies) != 0) {
1374
 
1375
            // add new page
1376
 
1377
            $pdf->AddPage();
1378
 
1379
            $competencies_header[] = array('content' => 'Indique el nivel de desempeño del evaluado en relación a sus conductas y actitudes frente a cada valor, según la clasificación siguiente:');
1380
 
1381
            $pdf->singleTable('Anexo de valores:', $competencies_header);
1382
 
1383
 
1384
            // Add scale section
1385
            $pdf->sectionScale();
1386
 
1387
            $i = 0;
1388
 
1389
            foreach ($competencies as $record) {
1390
 
1391
                $i = $i + 1;
1392
 
1393
                $pdf->competencyTable($i, $record);
1394
 
1395
                if ($i % 3 == 0 && $i < count($competencies)) {
1396
                    $pdf->AddPage();
1397
                }
1398
            }
1399
 
1400
        }
1401
 
1402
        return $pdf->Output();
1403
 
1404
    }
1405
 
8230 eleazar 1406
    public function reportBothAction() {
1407
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1408
        $currentUser = $currentUserPlugin->getUser();
1409
        $currentCompany = $currentUserPlugin->getCompany();
1410
 
1411
        $uuid = $this->params()->fromRoute('id');
1412
 
1413
        $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1414
        $test = $testMapper->fetchOneByUuid($uuid);
1415
 
1416
        $testBothMapper = CompanyPerformanceEvaluationTestBothMapper::getInstance($this->adapter);
1417
        $testBoth = $testBothMapper->fetchOneByTestId($test->id);
1418
 
1419
        $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
1420
        $form = $formMapper->fetchOne($test->form_id);
1421
 
1422
        if (!$form) {
1423
            return new JsonModel([
1424
                'success' => false,
1425
                'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
1426
            ]);
1427
        }
1428
 
1429
        $request = $this->getRequest();
1430
        if ($request->isGet()) {
1431
            //Competencies
1432
 
1433
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
1434
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
1435
            $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
1436
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
1437
            $jobDescriptionBehaviorCompetencyMapper = JobDescriptionBehaviorCompetencyMapper::getInstance($this->adapter);
1438
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
1439
 
1440
            $competencies = [];
1441
 
1442
            $jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($form->job_description_id);
1443
 
1444
            $content = json_decode($testBoth->content, true);
1445
 
1446
            foreach ($jobDescriptionCompetency as $record) {
1447
 
1448
                $competency = $competencyMapper->fetchOne($record->competency_id);
1449
                $competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
1450
 
1451
                if ($competency && $competenceType) {
1452
 
1453
                    $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
1454
                    $behaviors = [];
1455
 
1456
                    foreach ($behaviorCompetencies as $rows) {
1457
 
1458
                        $behavior = $behaviorMapper->fetchOne($rows->behavior_id);
1459
                        $jobDescriptionBehaviorCompetency = $jobDescriptionBehaviorCompetencyMapper->fetchOneByBehavior($form->job_description_id, $record->competency_id, $rows->behavior_id);
1460
 
1461
                        if ($behavior && $jobDescriptionBehaviorCompetency) {
1462
                            $rowData = [
1463
                                'description' => $behavior->description,
1464
                                'level' => $jobDescriptionBehaviorCompetency->level,
1465
                                'comment' => '',
1466
                                'evaluation' => '',
1467
 
1468
                            ];
1469
 
1470
                            foreach($content as $eval) {
1471
                                if ($eval['competencyUuid'] == $competency->uuid &&
1472
                                    $eval['behaviorUuid'] == $behavior->uuid) {
1473
 
1474
                                    $rowData['comment'] = $eval['comment'];
1475
                                    $rowData['evaluation'] = $eval['evaluation'];
1476
 
1477
 
1478
                                    break;
1479
                                }
1480
                            }
1481
 
1482
                            $behaviors []= $rowData;
1483
                        }
1484
                    }
1485
 
1486
                    array_push($competencies, [
1487
                        'name' => $competency->name,
1488
                        'description' => $competency->description,
1489
                        'type' => $competenceType->name,
1490
                        'behaviors' => $behaviors
1491
                    ]);
1492
                }
1493
            }
1494
 
1495
            return $this->renderBothPDF($currentCompany, $testBoth, $competencies);
1496
        }
1497
 
1498
        return new JsonModel([
1499
            'success' => false,
1500
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1501
        ]);
1502
    }
1503
 
1504
    public function renderBothPDF($currentCompany, $testBoth, $competencies) {
1505
 
1506
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1507
        $currentUser = $currentUserPlugin->getUser();
1508
 
1509
        //Generate New PDF
1510
        $pdf = new InterviewPDF();
1511
 
1512
        $pdf->header = '';
1513
        $pdf->footer = '';
1514
 
1515
        if ($currentCompany) {
1516
            //get company Data
1517
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1518
            $company = $companyMapper->fetchOne($currentCompany->id);
1519
 
1520
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1521
 
1522
            $pdf->header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
1523
            $pdf->footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
1524
        }
1525
 
1526
        $pdf->SetMargins(10, 0, 10);
1527
 
1528
        $pdf->AliasNbPages();
1529
        $pdf->AddPage();
1530
 
1531
        $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1532
        $test = $testMapper->fetchOne($testBoth->test_id);
1533
 
1534
        $userMapper = UserMapper::getInstance($this->adapter);
1535
        $supervisor = $userMapper->fetchOne($testBoth->supervisor_id);
1536
 
1537
        switch ($testBoth->points) {
1538
            case "0":
1539
                $points = "Sugerir otro cargo";
1540
                break;
1541
            case "1":
1542
                $points = "25%";
1543
                break;
1544
            case "2":
1545
                $points = "50%";
1546
                break;
1547
            case "3":
1548
                $points = "75%";
1549
                break;
1550
            case "4":
1551
                $points = "100%";
1552
                break;
1553
            default :
1554
                $points = "ERROR";
1555
                break;
1556
        }
1557
 
1558
        $rows = [
1559
            array(
1560
                'title' => 'Nombre Evaluado: ',
1561
                'content' => $testBoth ? ' ' . $testBoth->first_name . ' ' . $testBoth->last_name : 'No Aplica'
1562
            ),
1563
            array(
1564
                'title' => 'Supervisado por: ',
1565
                'content' => $supervisor ? ' ' . $supervisor->first_name . ' ' . $supervisor->last_name : ' No Aplica '
1566
            ),
1567
            array(
1568
                'title' => 'Comentarios del supervisor: ',
1569
                'content' => $testBoth ? ' ' . $testBoth->comment : 'No Aplica'
1570
            ),
1571
            array(
1572
                'title' => 'Porcentage de adaptibilidad ',
1573
                'content' => $points
1574
            )
1575
        ];
1576
 
1577
        $pdf->borderTable('DATOS DE LA ENTREVISTA', $rows);
1578
 
1579
        $sections = json_decode($testBoth->content, true);
1580
        /*
1581
                for ($s = 0; $s < count($sections); $s++) {
1582
 
1583
                    $pdf->singleTable($sections[$s]['title'], [
1584
                        array(
1585
                            'content' => $sections[$s]['type'] != 'multiple' ? $sections[$s]['text'] : ''
1586
                    )]);
1587
 
1588
                    if ($sections[$s]['type'] == 'multiple') {
1589
 
1590
                        $pdf->titleOptionTable($sections[$s]['text']);
1591
 
1592
                        for ($o = 0; $o < count($sections[$s]['options']); $o++) {
1593
 
1594
                            $pdf->optionTable($sections[$s]['options'][$o]['title']);
1595
                        }
1596
                        $pdf->Ln();
1597
                    }
1598
                    if ($s % 2 == 0 && $s > 1) {
1599
                        $pdf->AddPage();
1600
                    }
1601
                }*/
1602
 
1603
        // Competencies
1604
        if (count($competencies) != 0) {
1605
 
1606
            // add new page
1607
 
1608
            $pdf->AddPage();
1609
 
1610
            $competencies_header[] = array('content' => 'Indique el nivel de desempeño del evaluado en relación a sus conductas y actitudes frente a cada valor, según la clasificación siguiente:');
1611
 
1612
            $pdf->singleTable('Anexo de valores:', $competencies_header);
1613
 
1614
 
1615
            // Add scale section
1616
            $pdf->sectionScale();
1617
 
1618
            $i = 0;
1619
 
1620
            foreach ($competencies as $record) {
1621
 
1622
                $i = $i + 1;
1623
 
1624
                $pdf->competencyTable($i, $record);
1625
 
1626
                if ($i % 3 == 0 && $i < count($competencies)) {
1627
                    $pdf->AddPage();
1628
                }
1629
            }
1630
 
1631
        }
1632
 
1633
        return $pdf->Output();
1634
 
1635
    }
1636
 
1637
    public function reportSupervisorAction() {
1638
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1639
        $currentUser = $currentUserPlugin->getUser();
1640
        $currentCompany = $currentUserPlugin->getCompany();
1641
 
1642
        $uuid = $this->params()->fromRoute('id');
1643
 
1644
        $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1645
        $test = $testMapper->fetchOneByUuid($uuid);
1646
 
1647
        $testSupervisorMapper = CompanyPerformanceEvaluationTestSupervisorMapper::getInstance($this->adapter);
1648
        $testSupervisor = $testSupervisorMapper->fetchOneByTestId($test->id);
1649
 
1650
        $formMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
1651
        $form = $formMapper->fetchOne($test->form_id);
1652
 
1653
        if (!$form) {
1654
            return new JsonModel([
1655
                'success' => false,
1656
                'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
1657
            ]);
1658
        }
1659
 
1660
        $request = $this->getRequest();
1661
        if ($request->isGet()) {
1662
            //Competencies
1663
 
1664
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
1665
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
1666
            $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
1667
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
1668
            $jobDescriptionBehaviorCompetencyMapper = JobDescriptionBehaviorCompetencyMapper::getInstance($this->adapter);
1669
            $behaviorMapper = BehaviorMapper::getInstance($this->adapter);
1670
 
1671
            $competencies = [];
1672
 
1673
            $jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($form->job_description_id);
1674
 
1675
            $content = json_decode($testSupervisor->content, true);
1676
 
1677
            foreach ($jobDescriptionCompetency as $record) {
1678
 
1679
                $competency = $competencyMapper->fetchOne($record->competency_id);
1680
                $competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
1681
 
1682
                if ($competency && $competenceType) {
1683
 
1684
                    $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
1685
                    $behaviors = [];
1686
 
1687
                    foreach ($behaviorCompetencies as $rows) {
1688
 
1689
                        $behavior = $behaviorMapper->fetchOne($rows->behavior_id);
1690
                        $jobDescriptionBehaviorCompetency = $jobDescriptionBehaviorCompetencyMapper->fetchOneByBehavior($form->job_description_id, $record->competency_id, $rows->behavior_id);
1691
 
1692
                        if ($behavior && $jobDescriptionBehaviorCompetency) {
1693
                            $rowData = [
1694
                                'description' => $behavior->description,
1695
                                'level' => $jobDescriptionBehaviorCompetency->level,
1696
                                'comment' => '',
1697
                                'evaluation' => '',
1698
 
1699
                            ];
1700
 
1701
                            foreach($content as $eval) {
1702
                                if ($eval['competencyUuid'] == $competency->uuid &&
1703
                                    $eval['behaviorUuid'] == $behavior->uuid) {
1704
 
1705
                                    $rowData['comment'] = $eval['comment'];
1706
                                    $rowData['evaluation'] = $eval['evaluation'];
1707
 
1708
 
1709
                                    break;
1710
                                }
1711
                            }
1712
 
1713
                            $behaviors []= $rowData;
1714
                        }
1715
                    }
1716
 
1717
                    array_push($competencies, [
1718
                        'name' => $competency->name,
1719
                        'description' => $competency->description,
1720
                        'type' => $competenceType->name,
1721
                        'behaviors' => $behaviors
1722
                    ]);
1723
                }
1724
            }
1725
 
1726
            return $this->renderSupervisorPDF($currentCompany, $testSupervisor, $competencies);
1727
        }
1728
 
1729
        return new JsonModel([
1730
            'success' => false,
1731
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
1732
        ]);
1733
    }
1734
 
1735
      /**
1736
     * Render PDF
1737
     * @param Company $currentCompany
1738
     * @param recruitmentSelectionInterview $interviewEvaluation
1739
     * @param array $competencies
1740
     * @return mixed
1741
     */
1742
    public function renderSupervisorPDF($currentCompany, $testSupervisor, $competencies) {
1743
 
1744
        $currentUserPlugin = $this->plugin('currentUserPlugin');
1745
        $currentUser = $currentUserPlugin->getUser();
1746
 
1747
        //Generate New PDF
1748
        $pdf = new InterviewPDF();
1749
 
1750
        $pdf->header = '';
1751
        $pdf->footer = '';
1752
 
1753
        if ($currentCompany) {
1754
            //get company Data
1755
            $companyMapper = CompanyMapper::getInstance($this->adapter);
1756
            $company = $companyMapper->fetchOne($currentCompany->id);
1757
 
1758
            $target_path = $this->config['leaderslinked.fullpath.company'] . DIRECTORY_SEPARATOR . $company->uuid;
1759
 
1760
            $pdf->header = $company->header ? $target_path . DIRECTORY_SEPARATOR . $company->header : '';
1761
            $pdf->footer = $company->footer ? $target_path . DIRECTORY_SEPARATOR . $company->footer : '';
1762
        }
1763
 
1764
        $pdf->SetMargins(10, 0, 10);
1765
 
1766
        $pdf->AliasNbPages();
1767
        $pdf->AddPage();
1768
 
1769
        $testMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
1770
        $test = $testMapper->fetchOne($testSupervisor->test_id);
1771
 
1772
        $userMapper = UserMapper::getInstance($this->adapter);
1773
        $supervisor = $userMapper->fetchOne($testSupervisor->supervisor_id);
1774
 
1775
        switch ($testSupervisor->points) {
1776
            case "0":
1777
                $points = "Sugerir otro cargo";
1778
                break;
1779
            case "1":
1780
                $points = "25%";
1781
                break;
1782
            case "2":
1783
                $points = "50%";
1784
                break;
1785
            case "3":
1786
                $points = "75%";
1787
                break;
1788
            case "4":
1789
                $points = "100%";
1790
                break;
1791
            default :
1792
                $points = "ERROR";
1793
                break;
1794
        }
1795
 
1796
        $rows = [
1797
            array(
1798
                'title' => 'Nombre Evaluado: ',
1799
                'content' => $testSupervisor ? ' ' . $testSupervisor->first_name . ' ' . $testSupervisor->last_name : 'No Aplica'
1800
            ),
1801
            array(
1802
                'title' => 'Supervisado por: ',
1803
                'content' => $supervisor ? ' ' . $supervisor->first_name . ' ' . $supervisor->last_name : ' No Aplica '
1804
            ),
1805
            array(
1806
                'title' => 'Comentarios del supervisor: ',
1807
                'content' => $testSupervisor ? ' ' . $testSupervisor->comment : 'No Aplica'
1808
            ),
1809
            array(
1810
                'title' => 'Porcentage de adaptibilidad ',
1811
                'content' => $points
1812
            )
1813
        ];
1814
 
1815
        $pdf->borderTable('DATOS DE LA ENTREVISTA', $rows);
1816
 
1817
        $sections = json_decode($testSupervisor->content, true);
1818
        /*
1819
                for ($s = 0; $s < count($sections); $s++) {
1820
 
1821
                    $pdf->singleTable($sections[$s]['title'], [
1822
                        array(
1823
                            'content' => $sections[$s]['type'] != 'multiple' ? $sections[$s]['text'] : ''
1824
                    )]);
1825
 
1826
                    if ($sections[$s]['type'] == 'multiple') {
1827
 
1828
                        $pdf->titleOptionTable($sections[$s]['text']);
1829
 
1830
                        for ($o = 0; $o < count($sections[$s]['options']); $o++) {
1831
 
1832
                            $pdf->optionTable($sections[$s]['options'][$o]['title']);
1833
                        }
1834
                        $pdf->Ln();
1835
                    }
1836
                    if ($s % 2 == 0 && $s > 1) {
1837
                        $pdf->AddPage();
1838
                    }
1839
                }*/
1840
 
1841
        // Competencies
1842
        if (count($competencies) != 0) {
1843
 
1844
            // add new page
1845
 
1846
            $pdf->AddPage();
1847
 
1848
            $competencies_header[] = array('content' => 'Indique el nivel de desempeño del evaluado en relación a sus conductas y actitudes frente a cada valor, según la clasificación siguiente:');
1849
 
1850
            $pdf->singleTable('Anexo de valores:', $competencies_header);
1851
 
1852
 
1853
            // Add scale section
1854
            $pdf->sectionScale();
1855
 
1856
            $i = 0;
1857
 
1858
            foreach ($competencies as $record) {
1859
 
1860
                $i = $i + 1;
1861
 
1862
                $pdf->competencyTable($i, $record);
1863
 
1864
                if ($i % 3 == 0 && $i < count($competencies)) {
1865
                    $pdf->AddPage();
1866
                }
1867
            }
1868
 
1869
        }
1870
 
1871
        return $pdf->Output();
1872
 
1873
    }
1384 efrain 1874
}