Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2323 nelberth 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\AuthenticationService;
7
use Laminas\Authentication\Result as AuthResult;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
10
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Mvc\I18n\Translator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\View\Model\ViewModel;
14
use Laminas\View\Model\JsonModel;
2354 nelberth 15
use LeadersLinked\Model\PlanningObjectivesAndGoalsGoals;
2323 nelberth 16
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
2354 nelberth 17
use LeadersLinked\Form\PlanningObjectivesAndGoalsGoalsForm;
2323 nelberth 18
 
2354 nelberth 19
use LeadersLinked\Library\Functions;
20
 
3058 nelberth 21
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsTaskMapper;
2354 nelberth 22
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsGoalsMapper;
2362 nelberth 23
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsObjectivesMapper;
2354 nelberth 24
 
2323 nelberth 25
class PlanningObjectivesAndGoalsGoalsController extends AbstractActionController
26
{
27
    /**
28
     *
29
     * @var AdapterInterface
30
     */
31
    private $adapter;
32
 
33
 
34
    /**
35
     *
36
     * @var AbstractAdapter
37
     */
38
    private $cache;
39
 
40
    /**
41
     *
42
     * @var  LoggerInterface
43
     */
44
    private $logger;
45
 
46
    /**
47
     *
48
     * @var array
49
     */
50
    private $config;
51
 
52
 
53
 
54
    /**
55
     *
56
     * @param AdapterInterface $adapter
57
     * @param AbstractAdapter $cache
58
     * @param LoggerInterface $logger
59
     * @param array $config
60
     */
61
    public function __construct($adapter, $cache , $logger, $config)
62
    {
63
        $this->adapter      = $adapter;
64
        $this->cache        = $cache;
65
        $this->logger       = $logger;
66
        $this->config       = $config;
67
 
68
 
69
    }
2674 nelberth 70
   /*
2401 nelberth 71
  public function idObjective($uuid){
2429 nelberth 72
        $currentUserPlugin = $this->plugin('currentUserPlugin');
2428 nelberth 73
        $currentCompany = $currentUserPlugin->getCompany();
2398 nelberth 74
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
3183 nelberth 75
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid);
2405 nelberth 76
 
3183 nelberth 77
        if (!$objectives) {
2405 nelberth 78
            return false;
79
 
80
        }else{
3183 nelberth 81
            if($objectives->id_company==$currentCompany->id){
82
                return $objectives;
2435 nelberth 83
            }else{
84
                return false;
85
            }
86
 
2430 nelberth 87
 
2428 nelberth 88
 
2405 nelberth 89
        }
2354 nelberth 90
 
91
 
2674 nelberth 92
   }*/
2398 nelberth 93
 
94
 
2323 nelberth 95
    public function indexAction()
96
    {
2425 nelberth 97
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
2669 nelberth 98
 
99
        if(!$uuid_objetives) {
100
            $data = [
101
                'success'   => false,
102
                'data'   => 'ERROR_INVALID_PARAMETER'
103
            ];
104
 
105
            return new JsonModel($data);
106
        }
107
 
2323 nelberth 108
        $request = $this->getRequest();
2407 nelberth 109
 
2330 nelberth 110
        if($request->isGet()) {
2323 nelberth 111
 
112
 
2354 nelberth 113
            $headers  = $request->getHeaders();
2323 nelberth 114
 
2354 nelberth 115
            $isJson = false;
116
            if($headers->has('Accept')) {
117
                $accept = $headers->get('Accept');
118
 
119
                $prioritized = $accept->getPrioritized();
120
 
121
                foreach($prioritized as $key => $value) {
122
                    $raw = trim($value->getRaw());
123
 
124
                    if(!$isJson) {
125
                        $isJson = strpos($raw, 'json');
126
                    }
127
 
128
                }
129
            }
130
 
131
            if($isJson) {
2665 nelberth 132
                $currentUserPlugin = $this->plugin('currentUserPlugin');
2666 nelberth 133
                $currentUser = $currentUserPlugin->getUser();
2665 nelberth 134
                $currentCompany = $currentUserPlugin->getCompany();
2657 nelberth 135
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
2664 nelberth 136
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals/edit');
137
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals/delete');
2657 nelberth 138
                $allowGoals = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals/task');
2354 nelberth 139
 
140
                $search = $this->params()->fromQuery('search', []);
141
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
142
 
143
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
3335 nelberth 144
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
2354 nelberth 145
                $order =  $this->params()->fromQuery('order', []);
146
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
147
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
148
 
149
                $fields =  ['title'];
150
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
151
 
152
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
153
                    $order_direction = 'ASC';
154
                }
2669 nelberth 155
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
3183 nelberth 156
                $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
2402 nelberth 157
 
3183 nelberth 158
                if (!$objectives) {
2362 nelberth 159
                    $data = [
160
                        'success' => false,
2669 nelberth 161
                        'data' => 'ERROR_RECORD_NOT_FOUND'
2362 nelberth 162
                    ];
2669 nelberth 163
 
2398 nelberth 164
 
165
                        return new JsonModel($data);
2362 nelberth 166
                }
2669 nelberth 167
 
3183 nelberth 168
                if($objectives->id_company!=$currentCompany->id){
2669 nelberth 169
                        $data = [
170
                            'success' => false,
171
                            'data' => 'ERROR_UNAUTHORIZED',
172
                        ];
173
                        return new JsonModel($data);
174
                }
2411 nelberth 175
 
2669 nelberth 176
 
2411 nelberth 177
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
3183 nelberth 178
                $paginator = $planningObjectivesAndGoalsGoalsMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction, $objectives->id);
2412 nelberth 179
 
180
                $items = [];
181
 
182
                $records = $paginator->getCurrentItems();
3218 nelberth 183
                $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
2414 nelberth 184
                foreach($records as $record)
2354 nelberth 185
                {
2657 nelberth 186
 
3314 nelberth 187
                    $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record->id);
188
 
3072 nelberth 189
                    $costGoals=0;
190
                    $indicatorGoals=0;
191
                    foreach($recordsTask as $record2){
192
                        $indicatorGoals=$indicatorGoals+$record2->indicator;
193
                        $costGoals=$costGoals+$record2->cost;
194
                    }
3315 nelberth 195
                    $countRecordsTask = count($recordsTask);
196
                    if($countRecordsTask>0){
197
                        $indicatorGoals=round($indicatorGoals/$countRecordsTask, 2);
3190 nelberth 198
                    }else{
199
                        $indicatorGoals=-1;
3188 nelberth 200
                    }
3190 nelberth 201
 
2354 nelberth 202
                    $item = [
203
                        'title' => $record->title,
204
                        'description' => $record->description,
3190 nelberth 205
                        'progress'=>$indicatorGoals,
3072 nelberth 206
                        'cost' => $costGoals,
2657 nelberth 207
                        /*'DT_RowData'=>[
2354 nelberth 208
                            'id' =>$record->uuid,
209
                        ],
2657 nelberth 210
                        'DT_RowClass'=> 'Goals',*/
3057 nelberth 211
                        'status'=>$record->status,
2354 nelberth 212
                        'actions' => [
2657 nelberth 213
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/edit', ['uuid_objective' => $uuid_objetives,'id' => $record->uuid]) : '',
214
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/delete', ['uuid_objective' => $uuid_objetives,'id' => $record->uuid]) : '',
2662 nelberth 215
                            'link_goals' => $allowGoals ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/task', ['uuid_objective' => $uuid_objetives,'uuid_goals' => $record->uuid]) : ''
2354 nelberth 216
                        ]
217
 
218
                    ];
2415 nelberth 219
 
2354 nelberth 220
 
221
                    array_push($items, $item);
222
                }
3171 nelberth 223
 
3315 nelberth 224
                $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($objectives->id);
225
 
3171 nelberth 226
                $costObjective=0;
227
                $indicatorObjective=0;
228
                $contador=0;
3315 nelberth 229
                $countRecordsGoals = count($recordsGoals);
230
                if($countRecordsGoals>0){
3173 nelberth 231
                    $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
3314 nelberth 232
 
3173 nelberth 233
                    foreach($recordsGoals as $record)
234
                    {
3312 nelberth 235
                        $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record->id);
236
 
3173 nelberth 237
                        $costGoals=0;
238
                        $indicatorGoals=0;
3312 nelberth 239
                        $countRecordsTask = count($recordsTask);
240
                        if($countRecordsTask>0){
3173 nelberth 241
                            foreach($recordsTask as $record2){
242
                                $indicatorGoals=$indicatorGoals+$record2->indicator;
243
                                $costGoals=$costGoals+$record2->cost;
244
                            }
3312 nelberth 245
                            $indicatorObjective=$indicatorObjective+($indicatorGoals/$countRecordsTask);
3173 nelberth 246
                            $costObjective=$costObjective+$costGoals;
247
                            $contador++;
3171 nelberth 248
                        }
249
                    }
3175 nelberth 250
                    if($indicatorObjective==0){
3174 nelberth 251
                        $indicatorObjective=(-1);
3173 nelberth 252
                    }else{
3192 nelberth 253
                        $indicatorObjective=round($indicatorObjective/$contador,2);
254
 
3173 nelberth 255
                    }
256
                }else{
3178 nelberth 257
                    $indicatorObjective=(-2);
3171 nelberth 258
                }
259
                $date='Sin fecha';
3183 nelberth 260
                if($objectives->date!=NULL){
261
                    $dt = \DateTime::createFromFormat('Y-m-d', $objectives->date);
2675 nelberth 262
                    $date =  $dt->format('d/m/Y');
263
                }
3171 nelberth 264
 
265
 
266
 
2354 nelberth 267
                return new JsonModel([
268
                    'success' => true,
269
                    'data' => [
270
                        'items' => $items,
271
                        'total' => $paginator->getTotalItemCount(),
2462 nelberth 272
                        'objective' => [
3183 nelberth 273
                            'titleObjective' =>$objectives->title,
274
                            'descriptionObjective' =>$objectives->description,
3179 nelberth 275
                            'dateObjective' =>$date,
3180 nelberth 276
                            'costObjective' =>'$'.$costObjective,
3179 nelberth 277
                            'indicatorObjective'=>$indicatorObjective,
3184 nelberth 278
                            'statusObjective'=>$objectives->status=='a'?'LABEL_ACTIVE':'LABEL_INACTIVE',
2462 nelberth 279
 
280
                        ]
2354 nelberth 281
                    ]
282
                ]);
283
            } else  {
284
                $formAdd = new PlanningObjectivesAndGoalsGoalsForm();
285
                $this->layout()->setTemplate('layout/layout-backend');
286
                $viewModel = new ViewModel();
2355 nelberth 287
                $viewModel->setTemplate('leaders-linked/planning-objectives-and-goals-goals/index.phtml');
2354 nelberth 288
                $viewModel->setVariables([
2392 nelberth 289
                    'formAdd' => $formAdd,
290
                    'uuid'=> $uuid_objetives
291
 
2354 nelberth 292
                ]);
293
                return $viewModel ;
294
            }
2330 nelberth 295
        } else {
296
            return new JsonModel([
297
                'success' => false,
298
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2354 nelberth 299
            ]);
2330 nelberth 300
        }
2323 nelberth 301
    }
2354 nelberth 302
    public function addAction()
303
    {
304
      $currentUserPlugin = $this->plugin('currentUserPlugin');
305
        $currentUser = $currentUserPlugin->getUser();
306
        $currentCompany = $currentUserPlugin->getCompany();
2425 nelberth 307
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
3150 nelberth 308
 
2674 nelberth 309
        if(!$uuid_objetives) {
310
            $data = [
311
                'success'   => false,
312
                'data'   => 'ERROR_INVALID_PARAMETER'
313
            ];
314
 
315
            return new JsonModel($data);
316
        }
2354 nelberth 317
 
318
        $request = $this->getRequest();
319
        if($request->isPost()) {
320
            $form = new  PlanningObjectivesAndGoalsGoalsForm();
321
            $dataPost = $request->getPost()->toArray();
322
            $form->setData($dataPost);
323
 
324
            if($form->isValid()) {
2674 nelberth 325
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
326
                $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
327
 
328
                if (!$objectives) {
2407 nelberth 329
                    $data = [
330
                        'success' => false,
2674 nelberth 331
                        'data' => 'ERROR_RECORD_NOT_FOUND'
2407 nelberth 332
                    ];
2674 nelberth 333
 
2407 nelberth 334
 
335
                        return new JsonModel($data);
336
                }
2674 nelberth 337
 
338
                if($objectives->id_company!=$currentCompany->id){
339
                        $data = [
340
                            'success' => false,
341
                            'data' => 'ERROR_UNAUTHORIZED',
342
                        ];
343
                        return new JsonModel($data);
344
                }
2354 nelberth 345
                $dataPost = (array) $form->getData();
3218 nelberth 346
                $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsGoals::STATUS_INACTIVE;
2674 nelberth 347
                $dataPost['id_objectives']=$objectives->id;
2354 nelberth 348
 
349
                $hydrator = new ObjectPropertyHydrator();
350
                $planningObjectivesAndGoalsGoals = new PlanningObjectivesAndGoalsGoals();
351
                $hydrator->hydrate($dataPost, $planningObjectivesAndGoalsGoals);
352
 
353
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
354
                $result = $planningObjectivesAndGoalsGoalsMapper->insert($planningObjectivesAndGoalsGoals);
355
 
356
                if($result) {
2397 nelberth 357
                    $this->logger->info('Se agrego la meta ' . $planningObjectivesAndGoalsGoals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2354 nelberth 358
 
359
                    $data = [
360
                        'success'   => true,
361
                        'data'   => 'LABEL_RECORD_ADDED'
362
                    ];
363
                } else {
364
                    $data = [
365
                        'success'   => false,
366
                        'data'      => $planningObjectivesAndGoalsGoalsMapper->getError()
367
                    ];
368
 
369
                }
370
 
371
                return new JsonModel($data);
372
 
373
            } else {
374
                $messages = [];
375
                $form_messages = (array) $form->getMessages();
376
                foreach($form_messages  as $fieldname => $field_messages)
377
                {
378
 
379
                    $messages[$fieldname] = array_values($field_messages);
380
                }
381
 
382
                return new JsonModel([
383
                    'success'   => false,
384
                    'data'   => $messages
385
                ]);
386
            }
387
 
388
        } else {
389
            $data = [
390
                'success' => false,
391
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
392
            ];
393
 
394
            return new JsonModel($data);
395
        }
396
 
397
        return new JsonModel($data);
398
 
399
 
400
    }
401
 
402
 
403
 
404
     public function editAction(){
2449 nelberth 405
 
2354 nelberth 406
        $currentUserPlugin = $this->plugin('currentUserPlugin');
407
        $currentUser = $currentUserPlugin->getUser();
408
        $currentCompany = $currentUserPlugin->getCompany();
409
        $request = $this->getRequest();
410
        $uuid = $this->params()->fromRoute('id');
411
 
412
 
413
        if(!$uuid) {
414
            $data = [
415
                'success'   => false,
416
                'data'   => 'ERROR_INVALID_PARAMETER'
417
            ];
418
 
419
            return new JsonModel($data);
420
        }
2449 nelberth 421
 
422
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
2674 nelberth 423
        if(!$uuid_objetives) {
2441 nelberth 424
            $data = [
2674 nelberth 425
                'success'   => false,
426
                'data'   => 'ERROR_INVALID_PARAMETER'
427
            ];
428
 
429
            return new JsonModel($data);
430
        }
431
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
432
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
433
 
434
        if (!$objectives) {
435
            $data = [
2441 nelberth 436
                'success' => false,
2674 nelberth 437
                'data' => 'ERROR_RECORD_NOT_FOUND'
2441 nelberth 438
            ];
2674 nelberth 439
 
2441 nelberth 440
 
441
                return new JsonModel($data);
442
        }
2674 nelberth 443
 
444
        if($objectives->id_company!=$currentCompany->id){
445
                $data = [
446
                    'success' => false,
447
                    'data' => 'ERROR_UNAUTHORIZED',
448
                ];
449
                return new JsonModel($data);
450
        }
2447 nelberth 451
 
2354 nelberth 452
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
453
        $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($uuid);
454
 
455
        if (!$goals) {
456
            $data = [
457
                'success' => false,
458
                'data' => 'ERROR_RECORD_NOT_FOUND'
459
            ];
460
 
461
            return new JsonModel($data);
462
        }
2440 nelberth 463
 
2354 nelberth 464
 
465
        if($request->isPost()) {
466
            $form = new  PlanningObjectivesAndGoalsGoalsForm();
467
            $dataPost = $request->getPost()->toArray();
3151 nelberth 468
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsGoals::STATUS_INACTIVE;
2354 nelberth 469
            $form->setData($dataPost);
470
 
471
            if($form->isValid()) {
472
                $dataPost = (array) $form->getData();
473
 
474
                $hydrator = new ObjectPropertyHydrator();
475
                $hydrator->hydrate($dataPost, $goals);
476
                $result = $planningObjectivesAndGoalsGoalsMapper->update($goals);
477
 
478
                if($result) {
2440 nelberth 479
                    $this->logger->info('Se actualizo la meta ' . $goals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2354 nelberth 480
 
481
                    $data = [
482
                        'success' => true,
483
                        'data' => 'LABEL_RECORD_UPDATED'
484
                    ];
485
                } else {
486
                    $data = [
487
                        'success'   => false,
488
                        'data'      => $planningObjectivesAndGoalsGoalsMapper->getError()
489
                    ];
490
                }
491
 
492
                return new JsonModel($data);
493
 
494
            } else {
495
                $messages = [];
496
                $form_messages = (array) $form->getMessages();
497
                foreach($form_messages  as $fieldname => $field_messages)
498
                {
499
                    $messages[$fieldname] = array_values($field_messages);
500
                }
501
 
502
                return new JsonModel([
503
                    'success'   => false,
504
                    'data'   => $messages
505
                ]);
506
            }
507
        }else if ($request->isGet()) {
508
            $hydrator = new ObjectPropertyHydrator();
509
 
510
            $data = [
511
                'success' => true,
512
                'data' => $hydrator->extract($goals)
513
            ];
514
 
515
            return new JsonModel($data);
516
        } else {
517
            $data = [
518
                'success' => false,
519
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
520
            ];
521
 
522
            return new JsonModel($data);
523
        }
524
 
525
        return new JsonModel($data);
526
 
527
    }
528
 
529
 
530
 
531
 
532
    public function deleteAction(){
533
        $currentUserPlugin = $this->plugin('currentUserPlugin');
534
        $currentCompany = $currentUserPlugin->getCompany();
535
        $currentUser = $currentUserPlugin->getUser();
536
 
537
        $request = $this->getRequest();
538
        $uuid = $this->params()->fromRoute('id');
539
 
540
 
541
        if (!$uuid) {
542
            $data = [
543
                'success' => false,
544
                'data' => 'ERROR_INVALID_PARAMETER'
545
            ];
546
 
547
            return new JsonModel($data);
548
        }
549
 
2449 nelberth 550
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
2674 nelberth 551
        if(!$uuid_objetives) {
2449 nelberth 552
            $data = [
2674 nelberth 553
                'success'   => false,
554
                'data'   => 'ERROR_INVALID_PARAMETER'
555
            ];
556
 
557
            return new JsonModel($data);
558
        }
559
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
560
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
561
 
562
        if (!$objectives) {
563
            $data = [
2449 nelberth 564
                'success' => false,
2674 nelberth 565
                'data' => 'ERROR_RECORD_NOT_FOUND'
2449 nelberth 566
            ];
2674 nelberth 567
 
2449 nelberth 568
 
569
                return new JsonModel($data);
570
        }
2674 nelberth 571
 
572
        if($objectives->id_company!=$currentCompany->id){
573
                $data = [
574
                    'success' => false,
575
                    'data' => 'ERROR_UNAUTHORIZED',
576
                ];
577
                return new JsonModel($data);
578
        }
2354 nelberth 579
 
580
 
581
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
582
        $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($uuid);
583
 
584
        if (!$goals) {
585
            $data = [
586
                'success' => false,
587
                'data' => 'ERROR_RECORD_NOT_FOUND'
588
            ];
589
 
590
            return new JsonModel($data);
591
        }
2449 nelberth 592
 
2354 nelberth 593
 
594
        if ($request->isPost()) {
595
 
596
 
597
            $result = $planningObjectivesAndGoalsGoalsMapper->delete($goals->id);
598
            if ($result) {
2675 nelberth 599
                $this->logger->info('Se borro la meta con el titulo ' . $goals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2354 nelberth 600
 
601
                $data = [
602
                    'success' => true,
603
                    'data' => 'LABEL_RECORD_DELETED'
604
                ];
605
            } else {
606
 
607
                $data = [
608
                    'success' => false,
609
                    'data' => $planningObjectivesAndGoalsGoalsMapper->getError()
610
                ];
611
 
612
                return new JsonModel($data);
613
            }
614
        } else {
615
            $data = [
616
                'success' => false,
617
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
618
            ];
619
 
620
            return new JsonModel($data);
621
        }
622
 
623
        return new JsonModel($data);
624
    }
625
 
2463 nelberth 626
 
2457 nelberth 627
 
2354 nelberth 628
 
2323 nelberth 629
}