Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 1263 | Rev 1270 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
977 geraldo 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;
13
use LeadersLinked\Library\Functions;
14
use LeadersLinked\Mapper\CompanyPerformanceEvaluationFormMapper;
15
use LeadersLinked\Form\CompanyPerformanceEvaluationFormForm;
16
use LeadersLinked\Model\CompanyPerformanceEvaluationForm;
17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
1052 geraldo 18
use LeadersLinked\Mapper\JobDescriptionMapper;
977 geraldo 19
use LeadersLinked\Mapper\CompanyPerformanceEvaluationFormUserMapper;
20
 
21
class PerformanceEvaluationFormController extends AbstractActionController {
22
 
23
    /**
24
     *
25
     * @var AdapterInterface
26
     */
27
    private $adapter;
28
 
29
    /**
30
     *
31
     * @var AbstractAdapter
32
     */
33
    private $cache;
34
 
35
    /**
36
     *
37
     * @var  LoggerInterface
38
     */
39
    private $logger;
40
 
41
    /**
42
     *
43
     * @var array
44
     */
45
    private $config;
46
 
47
    /**
48
     *
49
     * @param AdapterInterface $adapter
50
     * @param AbstractAdapter $cache
51
     * @param LoggerInterface $logger
52
     * @param array $config
53
     */
54
    public function __construct($adapter, $cache, $logger, $config) {
55
        $this->adapter = $adapter;
56
        $this->cache = $cache;
57
        $this->logger = $logger;
58
        $this->config = $config;
59
    }
60
 
61
    public function indexAction() {
62
        $request = $this->getRequest();
63
        $currentUserPlugin = $this->plugin('currentUserPlugin');
64
        $currentCompany = $currentUserPlugin->getCompany();
65
        $currentUser = $currentUserPlugin->getUser();
66
 
67
 
68
        $request = $this->getRequest();
69
        if ($request->isGet()) {
70
 
71
            $headers = $request->getHeaders();
72
 
73
            $isJson = false;
74
            if ($headers->has('Accept')) {
75
                $accept = $headers->get('Accept');
76
 
77
                $prioritized = $accept->getPrioritized();
78
 
79
                foreach ($prioritized as $key => $value) {
80
                    $raw = trim($value->getRaw());
81
 
82
                    if (!$isJson) {
83
                        $isJson = strpos($raw, 'json');
84
                    }
85
                }
86
            }
87
 
88
            if ($isJson) {
89
                $search = $this->params()->fromQuery('search', []);
90
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
91
 
92
                $page = intval($this->params()->fromQuery('start', 1), 10);
93
                $records_x_page = intval($this->params()->fromQuery('length', 10), 10);
94
                $order = $this->params()->fromQuery('order', []);
95
                $order_field = empty($order[0]['column']) ? 99 : intval($order[0]['column'], 10);
96
                $order_direction = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var($order[0]['dir'], FILTER_SANITIZE_STRING));
97
 
98
                $fields = ['name'];
99
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'name';
100
 
101
                if (!in_array($order_direction, ['ASC', 'DESC'])) {
102
                    $order_direction = 'ASC';
103
                }
104
 
105
                $companyPerformanceEvaluationMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
106
                $paginator = $companyPerformanceEvaluationMapper->fetchAllDataTableByCompanyId($currentCompany->id, $search, $page, $records_x_page, $order_field, $order_direction);
107
 
1078 geraldo 108
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
109
 
977 geraldo 110
                $items = [];
111
                $records = $paginator->getCurrentItems();
112
                foreach ($records as $record) {
113
 
1078 geraldo 114
 
115
 
1098 geraldo 116
                    $jobDescription = $jobDescriptionMapper->fetchOne($record->job_description_id);
117
                    if ($jobDescription) {
977 geraldo 118
 
1098 geraldo 119
                        $item = [
120
                            'id' => $record->id,
121
                            'name' => $record->name,
122
                            'job_description' => $jobDescription->name,
123
                            'status' => $record->status,
124
                            'actions' => [
1263 geraldo 125
                                'link_report' => $this->url()->fromRoute('performance-evaluation/forms/report', ['id' => $record->uuid]),
1098 geraldo 126
                                'link_edit' => $this->url()->fromRoute('performance-evaluation/forms/edit', ['id' => $record->uuid]),
127
                                'link_delete' => $this->url()->fromRoute('performance-evaluation/forms/delete', ['id' => $record->uuid])
128
                            ]
129
                        ];
130
                    }
131
 
977 geraldo 132
                    array_push($items, $item);
133
                }
134
 
135
                return new JsonModel([
136
                    'success' => true,
137
                    'data' => [
138
                        'items' => $items,
139
                        'total' => $paginator->getTotalItemCount(),
140
                    ]
141
                ]);
142
            } else {
143
 
1064 geraldo 144
                $form = new CompanyPerformanceEvaluationFormForm($this->adapter, $currentCompany->id);
977 geraldo 145
 
1051 geraldo 146
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
147
                $jobsDescription = $jobDescriptionMapper->fetchAllByCompanyId($currentCompany->id);
148
 
977 geraldo 149
                $this->layout()->setTemplate('layout/layout-backend');
150
                $viewModel = new ViewModel();
151
                $viewModel->setTemplate('leaders-linked/performance-evaluation-forms/index.phtml');
152
                $viewModel->setVariable('form', $form);
1051 geraldo 153
                $viewModel->setVariable('jobsDescription', $jobsDescription);
977 geraldo 154
                return $viewModel;
155
            }
156
        } else {
157
            return new JsonModel([
158
                'success' => false,
159
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
160
            ]);
161
            ;
162
        }
163
    }
164
 
165
    public function addAction() {
166
        $request = $this->getRequest();
167
        $currentUserPlugin = $this->plugin('currentUserPlugin');
168
        $currentCompany = $currentUserPlugin->getCompany();
169
        $currentUser = $currentUserPlugin->getUser();
170
 
171
        $request = $this->getRequest();
172
 
173
 
174
        if ($request->isPost()) {
1064 geraldo 175
            $form = new CompanyPerformanceEvaluationFormForm($this->adapter, $currentCompany->id);
977 geraldo 176
            $dataPost = $request->getPost()->toArray();
1059 geraldo 177
 
178
 
977 geraldo 179
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : CompanyPerformanceEvaluationForm::STATUS_INACTIVE;
180
 
181
            $form->setData($dataPost);
182
 
183
            if ($form->isValid()) {
1058 geraldo 184
 
185
 
977 geraldo 186
                $dataPost = (array) $form->getData();
187
 
188
                $hydrator = new ObjectPropertyHydrator();
189
                $companyPerformanceEvaluation = new CompanyPerformanceEvaluationForm();
190
                $hydrator->hydrate($dataPost, $companyPerformanceEvaluation);
191
 
192
                if (!$companyPerformanceEvaluation->status) {
193
                    $companyPerformanceEvaluation->status = CompanyPerformanceEvaluationForm::STATUS_INACTIVE;
194
                }
195
                $companyPerformanceEvaluation->company_id = $currentCompany->id;
1075 geraldo 196
 
197
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
198
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
199
                $companyPerformanceEvaluation->job_description_id = $jobDescription->id;
200
 
977 geraldo 201
                $companyPerformanceEvaluationMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
1076 geraldo 202
 
977 geraldo 203
                $result = $companyPerformanceEvaluationMapper->insert($companyPerformanceEvaluation);
204
 
1098 geraldo 205
 
977 geraldo 206
                if ($result) {
207
                    $this->logger->info('Se agrego el tamaño de empresa ' . $companyPerformanceEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
208
 
209
                    // Get record by id
210
                    $record = $companyPerformanceEvaluationMapper->fetchOne($companyPerformanceEvaluation->id);
211
 
212
                    if ($record) {
1098 geraldo 213
 
977 geraldo 214
                        $data = [
215
                            'success' => true,
216
                            'id' => $record->id,
217
                            'action_edit' => $this->url()->fromRoute('performance-evaluation/forms/edit', ['id' => $record->uuid]),
218
                            'data' => 'LABEL_RECORD_ADDED'
219
                        ];
220
                    } else {
1098 geraldo 221
 
977 geraldo 222
                        $data = [
223
                            'success' => false,
224
                            'data' => 'ERROR_RECORD_NOT_FOUND'
225
                        ];
226
                    }
227
                } else {
228
                    $data = [
229
                        'success' => false,
230
                        'data' => $companyPerformanceEvaluationMapper->getError()
231
                    ];
232
                }
233
 
234
                return new JsonModel($data);
235
            } else {
236
                $messages = [];
237
                $form_messages = (array) $form->getMessages();
238
                foreach ($form_messages as $fieldname => $field_messages) {
239
 
240
                    $messages[$fieldname] = array_values($field_messages);
241
                }
242
 
243
                return new JsonModel([
244
                    'success' => false,
245
                    'data' => $messages
246
                ]);
247
            }
248
        } else {
249
            $data = [
250
                'success' => false,
251
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
252
            ];
253
 
254
            return new JsonModel($data);
255
        }
256
 
257
        return new JsonModel($data);
258
    }
259
 
260
    public function editAction() {
261
        $request = $this->getRequest();
262
        $currentUserPlugin = $this->plugin('currentUserPlugin');
263
        $currentCompany = $currentUserPlugin->getCompany();
264
        $currentUser = $currentUserPlugin->getUser();
265
 
266
        $request = $this->getRequest();
267
        $uuid = $this->params()->fromRoute('id');
268
 
269
 
270
        if (!$uuid) {
271
            $data = [
272
                'success' => false,
273
                'data' => 'ERROR_INVALID_PARAMETER'
274
            ];
275
 
276
            return new JsonModel($data);
277
        }
278
 
279
        $companyPerformanceEvaluationMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
280
        $companyPerformanceEvaluation = $companyPerformanceEvaluationMapper->fetchOneByUuid($uuid);
281
        if (!$companyPerformanceEvaluation) {
282
            $data = [
283
                'success' => false,
284
                'data' => 'ERROR_RECORD_NOT_FOUND'
285
            ];
286
 
287
            return new JsonModel($data);
288
        }
289
 
290
        if ($companyPerformanceEvaluation->company_id != $currentCompany->id) {
291
            return new JsonModel([
292
                'success' => false,
293
                'data' => 'ERROR_UNAUTHORIZED'
294
            ]);
295
        }
296
 
297
 
298
        if ($request->isPost()) {
1064 geraldo 299
            $form = new CompanyPerformanceEvaluationFormForm($this->adapter, $currentCompany->id);
977 geraldo 300
            $dataPost = $request->getPost()->toArray();
301
            $dataPost['status'] = isset($dataPost['status']) ? $dataPost['status'] : CompanyPerformanceEvaluationForm::STATUS_INACTIVE;
302
 
303
            $form->setData($dataPost);
304
 
305
            if ($form->isValid()) {
306
                $dataPost = (array) $form->getData();
307
 
308
                $hydrator = new ObjectPropertyHydrator();
309
                $hydrator->hydrate($dataPost, $companyPerformanceEvaluation);
310
 
311
                if (!$companyPerformanceEvaluation->status) {
312
                    $companyPerformanceEvaluation->status = CompanyPerformanceEvaluationForm::STATUS_INACTIVE;
313
                }
314
 
1080 geraldo 315
                $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
316
                $jobDescription = $jobDescriptionMapper->fetchOneByUuid($dataPost['job_description_id']);
317
                $companyPerformanceEvaluation->job_description_id = $jobDescription->id;
318
 
977 geraldo 319
                $result = $companyPerformanceEvaluationMapper->update($companyPerformanceEvaluation);
320
 
321
                if ($result) {
322
                    $this->logger->info('Se actualizo el tamaño de empresa ' . $companyPerformanceEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
323
                    $data = [
324
                        'success' => true,
325
                        'id' => $companyPerformanceEvaluation->id,
326
                        'action_edit' => $this->url()->fromRoute('performance-evaluation/forms/edit', ['id' => $companyPerformanceEvaluation->uuid]),
327
                        'data' => 'LABEL_RECORD_UPDATED'
328
                    ];
329
                } else {
330
                    $data = [
331
                        'success' => false,
332
                        'data' => $companyPerformanceEvaluationMapper->getError()
333
                    ];
334
                }
335
 
336
                return new JsonModel($data);
337
            } else {
338
                $messages = [];
339
                $form_messages = (array) $form->getMessages();
340
                foreach ($form_messages as $fieldname => $field_messages) {
341
                    $messages[$fieldname] = array_values($field_messages);
342
                }
343
 
344
                return new JsonModel([
345
                    'success' => false,
346
                    'data' => $messages
347
                ]);
348
            }
349
        } else if ($request->isGet()) {
350
            $hydrator = new ObjectPropertyHydrator();
351
 
1080 geraldo 352
            $jobDescriptionMapper = JobDescriptionMapper::getInstance($this->adapter);
353
            $jobDescription = $jobDescriptionMapper->fetchOne($companyPerformanceEvaluation->job_description_id);
1098 geraldo 354
            if (!$jobDescription) {
1080 geraldo 355
                $data = [
356
                    'success' => false,
357
                    'data' => 'ERROR_METHOD_NOT_ALLOWED'
358
                ];
1098 geraldo 359
 
1080 geraldo 360
                return new JsonModel($data);
361
            }
362
 
977 geraldo 363
            $data = [
364
                'success' => true,
365
                'data' => [
366
                    'id' => $companyPerformanceEvaluation->uuid,
367
                    'name' => $companyPerformanceEvaluation->name,
1080 geraldo 368
                    'job_description_id' => $jobDescription->uuid,
977 geraldo 369
                    'status' => $companyPerformanceEvaluation->status,
1089 geraldo 370
                    'description' => $companyPerformanceEvaluation->description,
371
                    'text' => $companyPerformanceEvaluation->text,
977 geraldo 372
                    'content' => $companyPerformanceEvaluation->content ? json_decode($companyPerformanceEvaluation->content) : [],
373
                ]
374
            ];
375
 
376
            return new JsonModel($data);
377
        } else {
378
            $data = [
379
                'success' => false,
380
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
381
            ];
382
 
383
            return new JsonModel($data);
384
        }
385
 
386
        return new JsonModel($data);
387
    }
388
 
389
    public function deleteAction() {
390
        $request = $this->getRequest();
391
        $currentUserPlugin = $this->plugin('currentUserPlugin');
392
        $currentCompany = $currentUserPlugin->getCompany();
393
        $currentUser = $currentUserPlugin->getUser();
394
 
395
        $request = $this->getRequest();
396
        $uuid = $this->params()->fromRoute('id');
397
 
398
        if (!$uuid) {
399
            $data = [
400
                'success' => false,
401
                'data' => 'ERROR_INVALID_PARAMETER'
402
            ];
403
 
404
            return new JsonModel($data);
405
        }
406
 
407
        $companyPerformanceEvaluationMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
408
        $companyPerformanceEvaluation = $companyPerformanceEvaluationMapper->fetchOneByUuid($uuid);
409
        if (!$companyPerformanceEvaluation) {
410
            $data = [
411
                'success' => false,
412
                'data' => 'ERROR_RECORD_NOT_FOUND'
413
            ];
414
 
415
            return new JsonModel($data);
416
        }
417
 
418
        if ($companyPerformanceEvaluation->company_id != $currentCompany->id) {
419
            return new JsonModel([
420
                'success' => false,
421
                'data' => 'ERROR_UNAUTHORIZED'
422
            ]);
423
        }
424
 
425
        if ($request->isPost()) {
426
 
427
            //Falta borrar los test  primeramente
428
            $companyPerformanceEvaluationFormUserMapper = CompanyPerformanceEvaluationFormUserMapper::getInstance($this->adapter);
429
            $companyPerformanceEvaluationFormUserMapper->deleteAllByFormId($companyPerformanceEvaluation->id);
430
 
431
 
432
            $result = $companyPerformanceEvaluationMapper->delete($companyPerformanceEvaluation->id);
433
            if ($result) {
434
                $this->logger->info('Se borro el formulario de evaluación de desempeño ' . $companyPerformanceEvaluation->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
435
 
436
                $data = [
437
                    'success' => true,
438
                    'data' => 'LABEL_RECORD_DELETED'
439
                ];
440
            } else {
441
 
442
                $data = [
443
                    'success' => false,
444
                    'data' => $companyPerformanceEvaluationMapper->getError()
445
                ];
446
 
447
                return new JsonModel($data);
448
            }
449
        } else {
450
            $data = [
451
                'success' => false,
452
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
453
            ];
454
 
455
            return new JsonModel($data);
456
        }
457
 
458
        return new JsonModel($data);
459
    }
460
 
1263 geraldo 461
 
1269 geraldo 462
    public function reportAction() {
1263 geraldo 463
        $currentUserPlugin = $this->plugin('currentUserPlugin');
464
        $currentUser = $currentUserPlugin->getUser();
465
 
466
        $uuid = $this->params()->fromRoute('id');
467
 
468
        $companyPerformanceEvaluationFormMapper = CompanyPerformanceEvaluationFormMapper::getInstance($this->adapter);
469
        $companyPerformanceEvaluationForm = $companyPerformanceEvaluationFormMapper->fetchOneByUuid($uuid);
470
 
471
        if (!$companyPerformanceEvaluationForm) {
472
            return new JsonModel([
473
                'success' => false,
474
                'data' => 'ERROR_FORM_EVALUATION_NOT_FOUND'
475
            ]);
476
        }
477
 
478
        if ($companyPerformanceEvaluationForm->status == CompanyPerformanceEvaluationForm::STATUS_INACTIVE) {
479
            return new JsonModel([
480
                'success' => false,
481
                'data' => 'ERROR_FORM_EVALUATION_IS_INACTIVE'
482
            ]);
483
        }
484
 
485
 
486
        $companyPerformanceEvaluationFormUserMapper = CompanyPerformanceEvaluationFormUserMapper::getInstance($this->adapter);
487
        $companyPerformanceEvaluationFormUser = $companyPerformanceEvaluationFormUserMapper->fetchOneByFormIdAndUserId($companyPerformanceEvaluationForm->id, $currentUser->id);
488
        if (!$companyPerformanceEvaluationFormUser) {
489
            return new JsonModel([
490
                'success' => false,
491
                'data' => 'ERROR_FORM_EVALUATION_YOU_CAN_NOT_TAKE'
492
            ]);
493
        }
494
 
495
 
496
        $companyPerformanceEvaluationTestMapper = CompanyPerformanceEvaluationTestMapper::getInstance($this->adapter);
497
        $companyPerformanceEvaluationTest = $companyPerformanceEvaluationTestMapper->fetchOneBy($companyPerformanceEvaluationForm->id, $currentUser->id);
498
 
499
        if ($companyPerformanceEvaluationTest && $companyPerformanceEvaluationTest->status != CompanyPerformanceEvaluationTest::STATUS_DRAFT) {
500
            return new JsonModel([
501
                'success' => false,
502
                'data' => 'ERROR_FORM_EVALUATION_ALREADY_YOUR_APPLICATION_IN_THIS_TEST'
503
            ]);
504
        }
505
 
506
        $request = $this->getRequest();
507
        if ($request->isGet()) {
508
 
509
 
510
 
511
            // set content
512
 
513
            $content = $companyPerformanceEvaluationTest && $companyPerformanceEvaluationTest->status == CompanyPerformanceEvaluationTest::STATUS_DRAFT ?
514
                    json_decode($companyPerformanceEvaluationTest->content, true) :
515
                    json_decode($companyPerformanceEvaluationForm->content, true);
516
 
517
 
518
            //Competencies
519
 
520
            $jobDescriptionCompetencyMapper = JobDescriptionCompetencyMapper::getInstance($this->adapter);
521
            $competencyMapper = CompetencyMapper::getInstance($this->adapter);
522
            $competenceTypeMapper = CompetencyTypeMapper::getInstance($this->adapter);
523
            $behaviorCompetencyMapper = BehaviorCompetencyMapper::getInstance($this->adapter);
524
            $jobDescriptionBehaviorCompetencyMapper = JobDescriptionBehaviorCompetencyMapper::getInstance($this->adapter);
525
            $behaviorMapper = BehaviorsMapper::getInstance($this->adapter);
526
 
527
            $competencies = [];
528
 
529
            $jobDescriptionCompetency = $jobDescriptionCompetencyMapper->fetchByJobDescriptionId($companyPerformanceEvaluationForm->job_description_id);
530
 
531
            foreach ($jobDescriptionCompetency as $record) {
532
 
533
 
534
                $competency = $competencyMapper->fetchOne($record->competency_id);
535
                $competenceType = $competenceTypeMapper->fetchOne($competency->competency_type_id);
536
 
537
                if($competency && $competenceType){
538
 
539
                    $behaviorCompetencies = $behaviorCompetencyMapper->fetchByCompetencyId($competency->id);
540
                    $behaviors = [];
541
 
542
                    foreach ($behaviorCompetencies as $rows) {
543
 
544
                        $behavior = $behaviorMapper->fetchOne($rows->behavior_id);
545
                        $jobDescriptionBehaviorCompetency = $jobDescriptionBehaviorCompetencyMapper->fetchOneByBehavior($companyPerformanceEvaluationForm->job_description_id, $record->competency_id, $rows->behavior_id);
546
 
547
                        if ($behavior && $jobDescriptionBehaviorCompetency) {
548
 
549
                            array_push($behaviors, [
550
                                'id_section' => $competency->uuid,
551
                                'id_option' => $behavior->uuid,
552
                                'title' => $behavior->description,
553
                                'level' => $jobDescriptionBehaviorCompetency->level,
554
                                'answer' => ''
555
                            ]);
556
                        }
557
                    }
558
 
559
                    array_push($competencies, [
560
                        'id_section' => $competency->uuid,
561
                        'title' => $competenceType->name. '  '.$competency->name,
562
                        'text' => $competency->description,
563
                        'type'=>'competency',
564
                        'options' => $behaviors
565
                    ]);
566
 
567
                }
568
 
569
            }
570
 
571
            return new JsonModel([
572
                'success' => true,
573
                'data' => [
574
                    'name' => $companyPerformanceEvaluationForm->name,
575
                    'description' => $companyPerformanceEvaluationForm->description,
576
                    'text' => $companyPerformanceEvaluationForm->text,
577
                    'competencies'=>$competencies,
578
                    'content' => $content,
579
                ]
580
            ]);
581
        }
582
 
583
        if ($request->isPost()) {
584
            $form = new PerformanceEvaluationTestForm();
585
            $dataPost = $request->getPost()->toArray();
586
 
587
            $form->setData($dataPost);
588
 
589
            if ($form->isValid()) {
590
 
591
 
592
                $dataPost = (array) $form->getData();
593
 
594
                $performanceEvaluationTest = new CompanyPerformanceEvaluationTest();
595
                $performanceEvaluationTest->company_id = $companyPerformanceEvaluationForm->company_id;
596
                $performanceEvaluationTest->form_id = $companyPerformanceEvaluationForm->id;
597
                $performanceEvaluationTest->user_id = $currentUser->id;
598
                $performanceEvaluationTest->status = $dataPost['status'];
599
                $performanceEvaluationTest->content = $dataPost['content'];
600
 
601
 
602
                //Check if the form is already registered
603
                $companyPerformanceEvaluationTest = $companyPerformanceEvaluationTestMapper->fetchOneBy($companyPerformanceEvaluationForm->id, $currentUser->id);
604
 
605
 
606
                $result = $companyPerformanceEvaluationTest ?
607
                        $companyPerformanceEvaluationTestMapper->update($performanceEvaluationTest, $companyPerformanceEvaluationTest->id) :
608
                        $companyPerformanceEvaluationTestMapper->insert($performanceEvaluationTest);
609
 
610
 
611
                if ($result) {
612
                    $this->logger->info('Se agrego un nuevo test de auto-evaluación : ' . $companyPerformanceEvaluationForm->name, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
613
 
614
                    $data = [
615
                        'success' => true,
616
                        'data' => $companyPerformanceEvaluationTest ? 'LABEL_RECORD_UPDATED' : 'LABEL_RECORD_ADDED'
617
                    ];
618
                } else {
619
                    $data = [
620
                        'success' => false,
621
                        'data' => $companyPerformanceEvaluationTestMapper->getError()
622
                    ];
623
                }
624
 
625
                return new JsonModel($data);
626
            } else {
627
                $messages = [];
628
                $form_messages = (array) $form->getMessages();
629
                foreach ($form_messages as $fieldname => $field_messages) {
630
 
631
                    $messages[$fieldname] = array_values($field_messages);
632
                }
633
 
634
                return new JsonModel([
635
                    'success' => false,
636
                    'data' => $messages
637
                ]);
638
            }
639
        }
640
 
641
        return new JsonModel([
642
            'success' => false,
643
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
644
        ]);
645
    }
646
 
977 geraldo 647
}