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{
6228 nelberth 81
            if($objectives->company_id==$currentCompany->id){
3183 nelberth 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()
6230 nelberth 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
                }
6231 nelberth 155
 
156
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
157
                $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
6232 nelberth 158
 
3183 nelberth 159
                if (!$objectives) {
2362 nelberth 160
                    $data = [
161
                        'success' => false,
2669 nelberth 162
                        'data' => 'ERROR_RECORD_NOT_FOUND'
2362 nelberth 163
                    ];
2669 nelberth 164
 
2398 nelberth 165
 
166
                        return new JsonModel($data);
2362 nelberth 167
                }
2669 nelberth 168
 
6228 nelberth 169
                if($objectives->company_id!=$currentCompany->id){
2669 nelberth 170
                        $data = [
171
                            'success' => false,
172
                            'data' => 'ERROR_UNAUTHORIZED',
173
                        ];
174
                        return new JsonModel($data);
175
                }
2411 nelberth 176
 
2669 nelberth 177
 
2411 nelberth 178
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
3183 nelberth 179
                $paginator = $planningObjectivesAndGoalsGoalsMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction, $objectives->id);
6233 nelberth 180
 
2412 nelberth 181
                $items = [];
182
 
183
                $records = $paginator->getCurrentItems();
3218 nelberth 184
                $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
2414 nelberth 185
                foreach($records as $record)
2354 nelberth 186
                {
2657 nelberth 187
 
3314 nelberth 188
                    $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record->id);
189
 
3072 nelberth 190
                    $costGoals=0;
191
                    $indicatorGoals=0;
192
                    foreach($recordsTask as $record2){
193
                        $indicatorGoals=$indicatorGoals+$record2->indicator;
194
                        $costGoals=$costGoals+$record2->cost;
195
                    }
3315 nelberth 196
                    $countRecordsTask = count($recordsTask);
197
                    if($countRecordsTask>0){
198
                        $indicatorGoals=round($indicatorGoals/$countRecordsTask, 2);
3190 nelberth 199
                    }else{
200
                        $indicatorGoals=-1;
3188 nelberth 201
                    }
3190 nelberth 202
 
2354 nelberth 203
                    $item = [
204
                        'title' => $record->title,
205
                        'description' => $record->description,
3190 nelberth 206
                        'progress'=>$indicatorGoals,
3072 nelberth 207
                        'cost' => $costGoals,
2657 nelberth 208
                        /*'DT_RowData'=>[
2354 nelberth 209
                            'id' =>$record->uuid,
210
                        ],
2657 nelberth 211
                        'DT_RowClass'=> 'Goals',*/
3057 nelberth 212
                        'status'=>$record->status,
2354 nelberth 213
                        'actions' => [
2657 nelberth 214
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/edit', ['uuid_objective' => $uuid_objetives,'id' => $record->uuid]) : '',
215
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/delete', ['uuid_objective' => $uuid_objetives,'id' => $record->uuid]) : '',
2662 nelberth 216
                            'link_goals' => $allowGoals ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/task', ['uuid_objective' => $uuid_objetives,'uuid_goals' => $record->uuid]) : ''
2354 nelberth 217
                        ]
218
 
219
                    ];
2415 nelberth 220
 
2354 nelberth 221
 
222
                    array_push($items, $item);
223
                }
3171 nelberth 224
 
3315 nelberth 225
                $recordsGoals = $planningObjectivesAndGoalsGoalsMapper->fetchAll($objectives->id);
226
 
3171 nelberth 227
                $costObjective=0;
228
                $indicatorObjective=0;
229
                $contador=0;
3315 nelberth 230
                $countRecordsGoals = count($recordsGoals);
231
                if($countRecordsGoals>0){
3173 nelberth 232
                    $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
3314 nelberth 233
 
3173 nelberth 234
                    foreach($recordsGoals as $record)
235
                    {
3312 nelberth 236
                        $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($record->id);
237
 
3173 nelberth 238
                        $costGoals=0;
239
                        $indicatorGoals=0;
3312 nelberth 240
                        $countRecordsTask = count($recordsTask);
241
                        if($countRecordsTask>0){
3173 nelberth 242
                            foreach($recordsTask as $record2){
243
                                $indicatorGoals=$indicatorGoals+$record2->indicator;
244
                                $costGoals=$costGoals+$record2->cost;
245
                            }
3312 nelberth 246
                            $indicatorObjective=$indicatorObjective+($indicatorGoals/$countRecordsTask);
3173 nelberth 247
                            $costObjective=$costObjective+$costGoals;
248
                            $contador++;
3171 nelberth 249
                        }
250
                    }
3175 nelberth 251
                    if($indicatorObjective==0){
3174 nelberth 252
                        $indicatorObjective=(-1);
3173 nelberth 253
                    }else{
3192 nelberth 254
                        $indicatorObjective=round($indicatorObjective/$contador,2);
255
 
3173 nelberth 256
                    }
257
                }else{
3178 nelberth 258
                    $indicatorObjective=(-2);
3171 nelberth 259
                }
260
                $date='Sin fecha';
3183 nelberth 261
                if($objectives->date!=NULL){
262
                    $dt = \DateTime::createFromFormat('Y-m-d', $objectives->date);
2675 nelberth 263
                    $date =  $dt->format('d/m/Y');
264
                }
3171 nelberth 265
 
266
 
267
 
2354 nelberth 268
                return new JsonModel([
269
                    'success' => true,
270
                    'data' => [
271
                        'items' => $items,
272
                        'total' => $paginator->getTotalItemCount(),
2462 nelberth 273
                        'objective' => [
3183 nelberth 274
                            'titleObjective' =>$objectives->title,
275
                            'descriptionObjective' =>$objectives->description,
3179 nelberth 276
                            'dateObjective' =>$date,
3180 nelberth 277
                            'costObjective' =>'$'.$costObjective,
3179 nelberth 278
                            'indicatorObjective'=>$indicatorObjective,
3184 nelberth 279
                            'statusObjective'=>$objectives->status=='a'?'LABEL_ACTIVE':'LABEL_INACTIVE',
2462 nelberth 280
 
281
                        ]
2354 nelberth 282
                    ]
283
                ]);
284
            } else  {
285
                $formAdd = new PlanningObjectivesAndGoalsGoalsForm();
286
                $this->layout()->setTemplate('layout/layout-backend');
287
                $viewModel = new ViewModel();
2355 nelberth 288
                $viewModel->setTemplate('leaders-linked/planning-objectives-and-goals-goals/index.phtml');
2354 nelberth 289
                $viewModel->setVariables([
2392 nelberth 290
                    'formAdd' => $formAdd,
291
                    'uuid'=> $uuid_objetives
292
 
2354 nelberth 293
                ]);
294
                return $viewModel ;
295
            }
2330 nelberth 296
        } else {
297
            return new JsonModel([
298
                'success' => false,
299
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
2354 nelberth 300
            ]);
2330 nelberth 301
        }
2323 nelberth 302
    }
2354 nelberth 303
    public function addAction()
304
    {
305
      $currentUserPlugin = $this->plugin('currentUserPlugin');
306
        $currentUser = $currentUserPlugin->getUser();
307
        $currentCompany = $currentUserPlugin->getCompany();
2425 nelberth 308
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
3150 nelberth 309
 
2674 nelberth 310
        if(!$uuid_objetives) {
311
            $data = [
312
                'success'   => false,
313
                'data'   => 'ERROR_INVALID_PARAMETER'
314
            ];
315
 
316
            return new JsonModel($data);
317
        }
2354 nelberth 318
 
319
        $request = $this->getRequest();
320
        if($request->isPost()) {
321
            $form = new  PlanningObjectivesAndGoalsGoalsForm();
322
            $dataPost = $request->getPost()->toArray();
323
            $form->setData($dataPost);
324
 
325
            if($form->isValid()) {
2674 nelberth 326
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
327
                $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
328
 
329
                if (!$objectives) {
2407 nelberth 330
                    $data = [
331
                        'success' => false,
2674 nelberth 332
                        'data' => 'ERROR_RECORD_NOT_FOUND'
2407 nelberth 333
                    ];
2674 nelberth 334
 
2407 nelberth 335
 
336
                        return new JsonModel($data);
337
                }
2674 nelberth 338
 
6228 nelberth 339
                if($objectives->company_id!=$currentCompany->id){
2674 nelberth 340
                        $data = [
341
                            'success' => false,
342
                            'data' => 'ERROR_UNAUTHORIZED',
343
                        ];
344
                        return new JsonModel($data);
345
                }
2354 nelberth 346
                $dataPost = (array) $form->getData();
3218 nelberth 347
                $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsGoals::STATUS_INACTIVE;
6236 nelberth 348
                $dataPost['objective_id']=$objectives->id;
2354 nelberth 349
 
350
                $hydrator = new ObjectPropertyHydrator();
351
                $planningObjectivesAndGoalsGoals = new PlanningObjectivesAndGoalsGoals();
352
                $hydrator->hydrate($dataPost, $planningObjectivesAndGoalsGoals);
353
 
354
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
355
                $result = $planningObjectivesAndGoalsGoalsMapper->insert($planningObjectivesAndGoalsGoals);
356
 
357
                if($result) {
2397 nelberth 358
                    $this->logger->info('Se agrego la meta ' . $planningObjectivesAndGoalsGoals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2354 nelberth 359
 
360
                    $data = [
361
                        'success'   => true,
362
                        'data'   => 'LABEL_RECORD_ADDED'
363
                    ];
364
                } else {
365
                    $data = [
366
                        'success'   => false,
367
                        'data'      => $planningObjectivesAndGoalsGoalsMapper->getError()
368
                    ];
369
 
370
                }
371
 
372
                return new JsonModel($data);
373
 
374
            } else {
375
                $messages = [];
376
                $form_messages = (array) $form->getMessages();
377
                foreach($form_messages  as $fieldname => $field_messages)
378
                {
379
 
380
                    $messages[$fieldname] = array_values($field_messages);
381
                }
382
 
383
                return new JsonModel([
384
                    'success'   => false,
385
                    'data'   => $messages
386
                ]);
387
            }
388
 
389
        } else {
390
            $data = [
391
                'success' => false,
392
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
393
            ];
394
 
395
            return new JsonModel($data);
396
        }
397
 
398
        return new JsonModel($data);
399
 
400
 
401
    }
402
 
403
 
404
 
405
     public function editAction(){
2449 nelberth 406
 
2354 nelberth 407
        $currentUserPlugin = $this->plugin('currentUserPlugin');
408
        $currentUser = $currentUserPlugin->getUser();
409
        $currentCompany = $currentUserPlugin->getCompany();
410
        $request = $this->getRequest();
411
        $uuid = $this->params()->fromRoute('id');
412
 
413
 
414
        if(!$uuid) {
415
            $data = [
416
                'success'   => false,
417
                'data'   => 'ERROR_INVALID_PARAMETER'
418
            ];
419
 
420
            return new JsonModel($data);
421
        }
2449 nelberth 422
 
423
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
2674 nelberth 424
        if(!$uuid_objetives) {
2441 nelberth 425
            $data = [
2674 nelberth 426
                'success'   => false,
427
                'data'   => 'ERROR_INVALID_PARAMETER'
428
            ];
429
 
430
            return new JsonModel($data);
431
        }
432
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
433
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
434
 
435
        if (!$objectives) {
436
            $data = [
2441 nelberth 437
                'success' => false,
2674 nelberth 438
                'data' => 'ERROR_RECORD_NOT_FOUND'
2441 nelberth 439
            ];
2674 nelberth 440
 
2441 nelberth 441
 
442
                return new JsonModel($data);
443
        }
2674 nelberth 444
 
6228 nelberth 445
        if($objectives->company_id!=$currentCompany->id){
2674 nelberth 446
                $data = [
447
                    'success' => false,
448
                    'data' => 'ERROR_UNAUTHORIZED',
449
                ];
450
                return new JsonModel($data);
451
        }
2447 nelberth 452
 
2354 nelberth 453
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
454
        $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($uuid);
455
 
456
        if (!$goals) {
457
            $data = [
458
                'success' => false,
459
                'data' => 'ERROR_RECORD_NOT_FOUND'
460
            ];
461
 
462
            return new JsonModel($data);
463
        }
2440 nelberth 464
 
2354 nelberth 465
 
466
        if($request->isPost()) {
467
            $form = new  PlanningObjectivesAndGoalsGoalsForm();
468
            $dataPost = $request->getPost()->toArray();
3151 nelberth 469
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsGoals::STATUS_INACTIVE;
2354 nelberth 470
            $form->setData($dataPost);
471
 
472
            if($form->isValid()) {
473
                $dataPost = (array) $form->getData();
474
 
475
                $hydrator = new ObjectPropertyHydrator();
476
                $hydrator->hydrate($dataPost, $goals);
477
                $result = $planningObjectivesAndGoalsGoalsMapper->update($goals);
478
 
479
                if($result) {
2440 nelberth 480
                    $this->logger->info('Se actualizo la meta ' . $goals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2354 nelberth 481
 
482
                    $data = [
483
                        'success' => true,
484
                        'data' => 'LABEL_RECORD_UPDATED'
485
                    ];
486
                } else {
487
                    $data = [
488
                        'success'   => false,
489
                        'data'      => $planningObjectivesAndGoalsGoalsMapper->getError()
490
                    ];
491
                }
492
 
493
                return new JsonModel($data);
494
 
495
            } else {
496
                $messages = [];
497
                $form_messages = (array) $form->getMessages();
498
                foreach($form_messages  as $fieldname => $field_messages)
499
                {
500
                    $messages[$fieldname] = array_values($field_messages);
501
                }
502
 
503
                return new JsonModel([
504
                    'success'   => false,
505
                    'data'   => $messages
506
                ]);
507
            }
508
        }else if ($request->isGet()) {
509
            $hydrator = new ObjectPropertyHydrator();
510
 
511
            $data = [
512
                'success' => true,
513
                'data' => $hydrator->extract($goals)
514
            ];
515
 
516
            return new JsonModel($data);
517
        } else {
518
            $data = [
519
                'success' => false,
520
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
521
            ];
522
 
523
            return new JsonModel($data);
524
        }
525
 
526
        return new JsonModel($data);
527
 
528
    }
529
 
530
 
531
 
532
 
533
    public function deleteAction(){
534
        $currentUserPlugin = $this->plugin('currentUserPlugin');
535
        $currentCompany = $currentUserPlugin->getCompany();
536
        $currentUser = $currentUserPlugin->getUser();
537
 
538
        $request = $this->getRequest();
539
        $uuid = $this->params()->fromRoute('id');
540
 
541
 
542
        if (!$uuid) {
543
            $data = [
544
                'success' => false,
545
                'data' => 'ERROR_INVALID_PARAMETER'
546
            ];
547
 
548
            return new JsonModel($data);
549
        }
550
 
2449 nelberth 551
        $uuid_objetives = $this->params()->fromRoute('uuid_objective');
2674 nelberth 552
        if(!$uuid_objetives) {
2449 nelberth 553
            $data = [
2674 nelberth 554
                'success'   => false,
555
                'data'   => 'ERROR_INVALID_PARAMETER'
556
            ];
557
 
558
            return new JsonModel($data);
559
        }
560
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
561
        $objectives = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($uuid_objetives);
562
 
563
        if (!$objectives) {
564
            $data = [
2449 nelberth 565
                'success' => false,
2674 nelberth 566
                'data' => 'ERROR_RECORD_NOT_FOUND'
2449 nelberth 567
            ];
2674 nelberth 568
 
2449 nelberth 569
 
570
                return new JsonModel($data);
571
        }
2674 nelberth 572
 
6228 nelberth 573
        if($objectives->company_id!=$currentCompany->id){
2674 nelberth 574
                $data = [
575
                    'success' => false,
576
                    'data' => 'ERROR_UNAUTHORIZED',
577
                ];
578
                return new JsonModel($data);
579
        }
2354 nelberth 580
 
581
 
582
        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
583
        $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($uuid);
584
 
585
        if (!$goals) {
586
            $data = [
587
                'success' => false,
588
                'data' => 'ERROR_RECORD_NOT_FOUND'
589
            ];
590
 
591
            return new JsonModel($data);
592
        }
2449 nelberth 593
 
2354 nelberth 594
 
595
        if ($request->isPost()) {
596
 
597
 
598
            $result = $planningObjectivesAndGoalsGoalsMapper->delete($goals->id);
599
            if ($result) {
2675 nelberth 600
                $this->logger->info('Se borro la meta con el titulo ' . $goals->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2354 nelberth 601
 
602
                $data = [
603
                    'success' => true,
604
                    'data' => 'LABEL_RECORD_DELETED'
605
                ];
606
            } else {
607
 
608
                $data = [
609
                    'success' => false,
610
                    'data' => $planningObjectivesAndGoalsGoalsMapper->getError()
611
                ];
612
 
613
                return new JsonModel($data);
614
            }
615
        } else {
616
            $data = [
617
                'success' => false,
618
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
619
            ];
620
 
621
            return new JsonModel($data);
622
        }
623
 
624
        return new JsonModel($data);
625
    }
626
 
2463 nelberth 627
 
2457 nelberth 628
 
2354 nelberth 629
 
2323 nelberth 630
}