Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
2516 nelberth 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Db\Adapter\AdapterInterface;
7
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
8
use Laminas\Mvc\Controller\AbstractActionController;
9
use Laminas\Log\LoggerInterface;
10
use Laminas\View\Model\ViewModel;
11
use Laminas\View\Model\JsonModel;
12
use LeadersLinked\Model\PlanningObjectivesAndGoalsTask;
13
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
14
use LeadersLinked\Form\PlanningObjectivesAndGoalsTaskForm;
15
use LeadersLinked\Library\Functions;
16
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsTaskMapper;
6271 nelberth 17
use LeadersLinked\Model\PlanningObjectivesAndGoalsTaskMembers;
18
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsTaskMembersMapper;
2565 nelberth 19
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsGoalsMapper;
2516 nelberth 20
use LeadersLinked\Mapper\PlanningObjectivesAndGoalsObjectivesMapper;
3398 nelberth 21
use LeadersLinked\Mapper\CompanyUserMapper;
6241 nelberth 22
use LeadersLinked\Mapper\UserMapper;
2516 nelberth 23
 
24
class PlanningObjectivesAndGoalsTaskController extends AbstractActionController
25
{
26
    /**
27
     *
28
     * @var AdapterInterface
29
     */
30
    private $adapter;
31
 
32
 
33
    /**
34
     *
35
     * @var AbstractAdapter
36
     */
37
    private $cache;
38
 
39
    /**
40
     *
41
     * @var  LoggerInterface
42
     */
43
    private $logger;
44
 
45
    /**
46
     *
47
     * @var array
48
     */
49
    private $config;
50
 
51
 
52
 
53
    /**
54
     *
55
     * @param AdapterInterface $adapter
56
     * @param AbstractAdapter $cache
57
     * @param LoggerInterface $logger
58
     * @param array $config
59
     */
60
    public function __construct($adapter, $cache , $logger, $config)
61
    {
62
        $this->adapter      = $adapter;
63
        $this->cache        = $cache;
64
        $this->logger       = $logger;
65
        $this->config       = $config;
66
 
67
 
68
    }
69
 
2565 nelberth 70
 
2516 nelberth 71
 
72
    public function indexAction()
73
    {
15386 efrain 74
        $currentUserPlugin = $this->plugin('currentUserPlugin');
75
        $currentUser = $currentUserPlugin->getUser();
76
        $currentCompany = $currentUserPlugin->getCompany();
77
 
78
 
11092 nelberth 79
        $objective_uuid = $this->params()->fromRoute('objective_id');
80
        $goal_uuid= $this->params()->fromRoute('goal_id');
2516 nelberth 81
        $request = $this->getRequest();
82
 
83
        if($request->isGet()) {
84
 
85
 
86
            $headers  = $request->getHeaders();
87
 
88
            $isJson = false;
89
            if($headers->has('Accept')) {
90
                $accept = $headers->get('Accept');
91
 
92
                $prioritized = $accept->getPrioritized();
93
 
94
                foreach($prioritized as $key => $value) {
95
                    $raw = trim($value->getRaw());
96
 
97
                    if(!$isJson) {
98
                        $isJson = strpos($raw, 'json');
99
                    }
100
 
101
                }
102
            }
15386 efrain 103
 
6252 nelberth 104
            if($isJson) {
105
 
2824 nelberth 106
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
2823 nelberth 107
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals/task/edit');
108
                $allowDelete = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals/task/delete');
109
                $allowView = $acl->isAllowed($currentUser->usertype_id, 'planning-objectives-and-goals/objectives/goals/task/view');
2516 nelberth 110
 
111
                $search = $this->params()->fromQuery('search', []);
112
                $search = empty($search['value']) ? '' : filter_var($search['value'], FILTER_SANITIZE_STRING);
113
 
114
                $records_x_page     = intval($this->params()->fromQuery('length', 10), 10);
3335 nelberth 115
                $page               = (intval($this->params()->fromQuery('start', 1), 10)/$records_x_page)+1;
2516 nelberth 116
                $order =  $this->params()->fromQuery('order', []);
117
                $order_field        = empty($order[0]['column']) ? 99 :  intval($order[0]['column'], 10);
118
                $order_direction    = empty($order[0]['dir']) ? 'ASC' : strtoupper(filter_var( $order[0]['dir'], FILTER_SANITIZE_STRING));
119
 
120
                $fields =  ['title'];
121
                $order_field = isset($fields[$order_field]) ? $fields[$order_field] : 'title';
122
 
123
                if(!in_array($order_direction, ['ASC', 'DESC'])) {
124
                    $order_direction = 'ASC';
125
                }
2825 nelberth 126
 
2781 nelberth 127
                $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
11092 nelberth 128
                $objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
2781 nelberth 129
 
130
                if (!$objective) {
2516 nelberth 131
                    $data = [
132
                        'success' => false,
2781 nelberth 133
                        'data' => 'ERROR_RECORD_NOT_FOUND'
2516 nelberth 134
                    ];
2781 nelberth 135
 
2516 nelberth 136
 
137
                        return new JsonModel($data);
2781 nelberth 138
 
139
                }else{
6225 nelberth 140
                    if($objective->company_id==$currentCompany->id){
2781 nelberth 141
                        $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
11092 nelberth 142
                        $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
2781 nelberth 143
 
144
                        if(!$goals){
145
                            $data = [
146
                                'success' => false,
147
                                'data' => 'ERROR_RECORD_NOT_FOUND'
148
                            ];
149
 
150
 
151
                                return new JsonModel($data);
152
                        }
153
                    }else{
154
                        $data = [
155
                            'success' => false,
156
                            'data' => 'ERROR_UNAUTHORIZED',
157
                        ];
158
 
159
                            return new JsonModel($data);
160
                    }
161
 
162
 
163
 
2516 nelberth 164
                }
2781 nelberth 165
 
2516 nelberth 166
 
167
                $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
2565 nelberth 168
                $paginator = $planningObjectivesAndGoalsTaskMapper->fetchAllDataTable($search, $page, $records_x_page, $order_field, $order_direction, $goals->id);
2516 nelberth 169
 
170
                $items = [];
171
 
172
                $records = $paginator->getCurrentItems();
3030 nelberth 173
 
3058 nelberth 174
 
2516 nelberth 175
                foreach($records as $record)
176
                {
177
 
178
                    $item = [
179
                        'title' => $record->title,
180
                        'description' => $record->description,
2884 nelberth 181
                        'progress'=> $record->indicator,
2846 nelberth 182
                        'cost'=> $record->cost,
3045 nelberth 183
                        'status' => $record->status,
2516 nelberth 184
                        'actions' => [
11092 nelberth 185
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/task/edit', ['objective_id' => $objective_uuid,'goal_id' => $goal_uuid,'id' => $record->uuid]) : '',
186
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('planning-objectives-and-goals/objectives/goals/task/delete', ['objective_id' => $objective_uuid,'goal_id' => $goal_uuid,'id' => $record->uuid]) : ''
3003 nelberth 187
                            ]
2516 nelberth 188
 
189
                    ];
3058 nelberth 190
                    array_push($items, $item);
191
                }
3065 nelberth 192
 
3303 nelberth 193
                $recordsTask = $planningObjectivesAndGoalsTaskMapper->fetchAll($goals->id);
194
 
3070 nelberth 195
 
3058 nelberth 196
                $costGoals=0;
197
                $indicatorGoals=0;
3311 nelberth 198
 
3171 nelberth 199
                foreach($recordsTask as $record)
3058 nelberth 200
                {
3030 nelberth 201
                    $indicatorGoals=$indicatorGoals+$record->indicator;
202
                    $costGoals=$costGoals+$record->cost;
2516 nelberth 203
                }
3317 nelberth 204
                $countRecordsTask = count($recordsTask);
205
                if($countRecordsTask >0){
3301 nelberth 206
 
3333 nelberth 207
                    $indicatorGoals=round($indicatorGoals/$countRecordsTask, 2);
3193 nelberth 208
                }else{
209
                    $indicatorGoals=-1;
210
                }
3407 nelberth 211
 
212
 
3400 nelberth 213
 
2516 nelberth 214
                return new JsonModel([
215
                    'success' => true,
216
                    'data' => [
217
                        'items' => $items,
218
                        'total' => $paginator->getTotalItemCount(),
3030 nelberth 219
                        'goals' => [
220
                            'titleGoals' =>$goals->title,
221
                            'descriptionGoals' =>$goals->description,
222
                            'costGoals'=>'$'.$costGoals,
3193 nelberth 223
                            'indicatorGoals'=> $indicatorGoals,
3049 nelberth 224
                            'statusGoals'=> $goals->status=='a'?'LABEL_ACTIVE':'LABEL_INACTIVE',
2516 nelberth 225
 
226
                        ]
227
                    ]
228
                ]);
229
            } else  {
6251 nelberth 230
                $formAdd = new PlanningObjectivesAndGoalsTaskForm($this->adapter, $currentCompany->id);
2516 nelberth 231
                $this->layout()->setTemplate('layout/layout-backend');
232
                $viewModel = new ViewModel();
2547 nelberth 233
                $viewModel->setTemplate('leaders-linked/planning-objectives-and-goals-task/index.phtml');
2516 nelberth 234
                $viewModel->setVariables([
235
                    'formAdd' => $formAdd,
11092 nelberth 236
                    'objective_uuid'=> $objective_uuid,
237
                    'goal_uuid'=> $goal_uuid,
2516 nelberth 238
 
2530 nelberth 239
 
2516 nelberth 240
                ]);
241
                return $viewModel ;
242
            }
243
        } else {
244
            return new JsonModel([
245
                'success' => false,
246
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
247
            ]);
248
        }
249
    }
250
    public function addAction()
251
    {
252
      $currentUserPlugin = $this->plugin('currentUserPlugin');
253
        $currentUser = $currentUserPlugin->getUser();
254
        $currentCompany = $currentUserPlugin->getCompany();
11092 nelberth 255
        $objective_uuid = $this->params()->fromRoute('objective_id');
256
        $goal_uuid = $this->params()->fromRoute('goal_id');
2516 nelberth 257
        $request = $this->getRequest();
3411 nelberth 258
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
11092 nelberth 259
        $objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
3407 nelberth 260
 
261
        if (!$objective) {
262
            $data = [
263
                'success' => false,
264
                'data' => 'ERROR_RECORD_NOT_FOUND'
265
            ];
266
 
267
 
268
                return new JsonModel($data);
269
 
270
        }else{
6225 nelberth 271
            if($objective->company_id==$currentCompany->id){
3407 nelberth 272
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
11092 nelberth 273
                $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
3407 nelberth 274
 
275
                if(!$goals){
276
                    $data = [
277
                        'success' => false,
278
                        'data' => 'ERROR_RECORD_NOT_FOUND'
279
                    ];
280
 
281
 
282
                        return new JsonModel($data);
283
                }
284
            }else{
285
                $data = [
286
                    'success' => false,
287
                    'data' => 'ERROR_UNAUTHORIZED',
288
                ];
289
 
290
                    return new JsonModel($data);
291
            }
292
 
293
        }
2516 nelberth 294
        if($request->isPost()) {
6278 nelberth 295
 
296
            $form = new  PlanningObjectivesAndGoalsTaskForm($this->adapter, $currentCompany->id);
2516 nelberth 297
            $dataPost = $request->getPost()->toArray();
2981 nelberth 298
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsTask::STATUS_INACTIVE;
3024 nelberth 299
            if($dataPost['indicator']!=100){
300
                $dataPost['evaluation']='';
301
                $dataPost['detour']='';
302
            }
2516 nelberth 303
            $form->setData($dataPost);
6280 nelberth 304
 
2516 nelberth 305
            if($form->isValid()) {
6277 nelberth 306
 
3407 nelberth 307
 
6281 nelberth 308
 
2516 nelberth 309
                $dataPost = (array) $form->getData();
6271 nelberth 310
                $dataPost['goal_id']=$goals->id;
2516 nelberth 311
 
312
                $hydrator = new ObjectPropertyHydrator();
313
                $planningObjectivesAndGoalsTask = new PlanningObjectivesAndGoalsTask();
314
                $hydrator->hydrate($dataPost, $planningObjectivesAndGoalsTask);
6281 nelberth 315
 
2516 nelberth 316
                $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
317
                $result = $planningObjectivesAndGoalsTaskMapper->insert($planningObjectivesAndGoalsTask);
318
 
6282 nelberth 319
 
2516 nelberth 320
                if($result) {
6271 nelberth 321
                    $userMapper = UserMapper::getInstance($this->adapter);
6286 nelberth 322
 
6285 nelberth 323
                    foreach( $dataPost['who'] as $record2){
6271 nelberth 324
                        $PlanningObjectivesAndGoalsTaskMember = new PlanningObjectivesAndGoalsTaskMembers();
325
                        $datosUser = $userMapper->fetchOneByUuid($record2);
326
                        $PlanningObjectivesAndGoalsTaskMember->task_id = $planningObjectivesAndGoalsTask->id;
327
                        $PlanningObjectivesAndGoalsTaskMember->user_id = $datosUser->id;
328
                        $PlanningObjectivesAndGoalsTaskMember->status = PlanningObjectivesAndGoalsTaskMembers::STATUS_ACTIVE;
329
                        $PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
330
                        $PlanningObjectivesAndGoalsTaskMemberMapper->insert($PlanningObjectivesAndGoalsTaskMember);
331
                    }
6284 nelberth 332
 
6377 nelberth 333
 
2776 nelberth 334
                    $this->logger->info('Se agrego la tarea ' . $planningObjectivesAndGoalsTask->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2516 nelberth 335
 
336
                    $data = [
337
                        'success'   => true,
338
                        'data'   => 'LABEL_RECORD_ADDED'
339
                    ];
340
                } else {
341
                    $data = [
342
                        'success'   => false,
343
                        'data'      => $planningObjectivesAndGoalsTaskMapper->getError()
344
                    ];
345
 
346
                }
347
 
348
                return new JsonModel($data);
349
 
350
            } else {
351
                $messages = [];
352
                $form_messages = (array) $form->getMessages();
353
                foreach($form_messages  as $fieldname => $field_messages)
354
                {
355
 
356
                    $messages[$fieldname] = array_values($field_messages);
357
                }
358
 
359
                return new JsonModel([
360
                    'success'   => false,
361
                    'data'   => $messages
362
                ]);
363
            }
364
 
3407 nelberth 365
        }else if ($request->isGet()) {
6249 nelberth 366
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
3407 nelberth 367
            $userMapper = UserMapper::getInstance($this->adapter);
6249 nelberth 368
            $datosCompanyUser = $companyUserMapper->fetchAllByCompanyId($currentCompany->id);
3407 nelberth 369
 
370
            $users=[];
371
 
372
            foreach($datosCompanyUser as $record){
373
                $datosUser = $userMapper->fetchOne($record->user_id);
3417 nelberth 374
 
3415 nelberth 375
                    $user=[
3417 nelberth 376
                        'uuid'=>$datosUser->uuid,
4305 nelberth 377
                        'email'=>$datosUser->email,
378
                        'first_name'=>$datosUser->first_name,
379
                        'last_name'=>$datosUser->last_name,
380
 
3415 nelberth 381
                    ];
382
                    array_push($users, $user);
3417 nelberth 383
 
3407 nelberth 384
            }
385
 
386
            return new JsonModel([
387
                'success' => true,
3415 nelberth 388
                'data' => $users
389
 
3407 nelberth 390
            ]);
2516 nelberth 391
        } else {
392
            $data = [
393
                'success' => false,
394
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
395
            ];
396
 
397
            return new JsonModel($data);
398
        }
399
 
400
        return new JsonModel($data);
401
 
402
    }
403
 
404
 
405
 
406
     public function editAction(){
407
 
2783 nelberth 408
 
2516 nelberth 409
        $currentUserPlugin = $this->plugin('currentUserPlugin');
410
        $currentUser = $currentUserPlugin->getUser();
411
        $currentCompany = $currentUserPlugin->getCompany();
412
        $request = $this->getRequest();
413
        $uuid = $this->params()->fromRoute('id');
3000 nelberth 414
 
2516 nelberth 415
 
416
        if(!$uuid) {
417
            $data = [
418
                'success'   => false,
419
                'data'   => 'ERROR_INVALID_PARAMETER'
420
            ];
421
 
422
            return new JsonModel($data);
423
        }
424
 
11092 nelberth 425
        $objective_uuid = $this->params()->fromRoute('objective_id');
426
        $goal_uuid = $this->params()->fromRoute('goal_id');
2782 nelberth 427
        $currentUserPlugin = $this->plugin('currentUserPlugin');
428
        $currentCompany = $currentUserPlugin->getCompany();
429
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
11092 nelberth 430
        $objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
2782 nelberth 431
 
432
        if (!$objective) {
2516 nelberth 433
            $data = [
434
                'success' => false,
2782 nelberth 435
                'data' => 'ERROR_RECORD_NOT_FOUND'
2516 nelberth 436
            ];
2782 nelberth 437
 
2516 nelberth 438
 
439
                return new JsonModel($data);
2782 nelberth 440
 
441
        }else{
6225 nelberth 442
            if($objective->company_id==$currentCompany->id){
2782 nelberth 443
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
11092 nelberth 444
                $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
2782 nelberth 445
 
446
                if(!$goals){
447
                    $data = [
448
                        'success' => false,
449
                        'data' => 'ERROR_RECORD_NOT_FOUND'
450
                    ];
451
 
452
 
453
                        return new JsonModel($data);
454
                }
455
            }else{
456
                $data = [
457
                    'success' => false,
458
                    'data' => 'ERROR_UNAUTHORIZED',
459
                ];
460
 
461
                    return new JsonModel($data);
462
            }
463
 
464
 
465
 
2516 nelberth 466
        }
467
        $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
2782 nelberth 468
        $task = $planningObjectivesAndGoalsTaskMapper->fetchOneByUuid($uuid);
2516 nelberth 469
 
2782 nelberth 470
        if (!$task) {
2516 nelberth 471
            $data = [
472
                'success' => false,
473
                'data' => 'ERROR_RECORD_NOT_FOUND'
474
            ];
475
 
476
            return new JsonModel($data);
477
        }
478
 
479
 
480
        if($request->isPost()) {
6278 nelberth 481
            $form = new  PlanningObjectivesAndGoalsTaskForm($this->adapter, $currentCompany->id);
3000 nelberth 482
            $dataPost = $request->getPost()->toArray();
483
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : PlanningObjectivesAndGoalsTask::STATUS_INACTIVE;
2516 nelberth 484
            $form->setData($dataPost);
485
 
486
            if($form->isValid()) {
487
                $dataPost = (array) $form->getData();
488
 
489
                $hydrator = new ObjectPropertyHydrator();
2782 nelberth 490
                $hydrator->hydrate($dataPost, $task);
491
                $result = $planningObjectivesAndGoalsTaskMapper->update($task);
2516 nelberth 492
 
493
                if($result) {
6377 nelberth 494
 
495
                    $userMapper = UserMapper::getInstance($this->adapter);
6379 nelberth 496
                    $PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
497
                    $PlanningObjectivesAndGoalsTaskMemberMapper->dissableMembersTask($task->id);
498
 
6377 nelberth 499
                    foreach( $dataPost['who'] as $record2){
500
                        $PlanningObjectivesAndGoalsTaskMember = new PlanningObjectivesAndGoalsTaskMembers();
501
                        $datosUser = $userMapper->fetchOneByUuid($record2);
6390 nelberth 502
                        $PlanningObjectivesAndGoalsTaskMember->task_id = $task->id;
6377 nelberth 503
                        $PlanningObjectivesAndGoalsTaskMember->user_id = $datosUser->id;
504
                        $PlanningObjectivesAndGoalsTaskMember->status = PlanningObjectivesAndGoalsTaskMembers::STATUS_ACTIVE;
505
                        $PlanningObjectivesAndGoalsTaskMemberMapper->insert($PlanningObjectivesAndGoalsTaskMember);
506
                    }
507
 
508
 
509
 
2782 nelberth 510
                    $this->logger->info('Se actualizo la tarea ' . $task->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2516 nelberth 511
 
512
                    $data = [
513
                        'success' => true,
514
                        'data' => 'LABEL_RECORD_UPDATED'
515
                    ];
516
                } else {
517
                    $data = [
518
                        'success'   => false,
519
                        'data'      => $planningObjectivesAndGoalsTaskMapper->getError()
520
                    ];
521
                }
522
 
523
                return new JsonModel($data);
524
 
525
            } else {
526
                $messages = [];
527
                $form_messages = (array) $form->getMessages();
528
                foreach($form_messages  as $fieldname => $field_messages)
529
                {
530
                    $messages[$fieldname] = array_values($field_messages);
531
                }
532
 
533
                return new JsonModel([
534
                    'success'   => false,
535
                    'data'   => $messages
536
                ]);
537
            }
538
        }else if ($request->isGet()) {
539
            $hydrator = new ObjectPropertyHydrator();
6295 nelberth 540
            $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
541
            $userMapper = UserMapper::getInstance($this->adapter);
542
            $datosCompanyUser = $companyUserMapper->fetchAllByCompanyId($currentCompany->id);
2516 nelberth 543
 
6323 nelberth 544
            $allUsers=[];
6295 nelberth 545
 
546
            foreach($datosCompanyUser as $record){
547
                $datosUser = $userMapper->fetchOne($record->user_id);
548
 
6323 nelberth 549
                    $allUser=[
6295 nelberth 550
                        'uuid'=>$datosUser->uuid,
551
                        'email'=>$datosUser->email,
552
                        'first_name'=>$datosUser->first_name,
553
                        'last_name'=>$datosUser->last_name,
554
 
555
                    ];
6323 nelberth 556
                    array_push($allUsers, $allUser);
6295 nelberth 557
 
558
            }
6314 nelberth 559
            $PlanningObjectivesAndGoalsTaskMemberMapper = PlanningObjectivesAndGoalsTaskMembersMapper::getInstance($this->adapter);
6323 nelberth 560
            $datosUsuarios = $PlanningObjectivesAndGoalsTaskMemberMapper->fetchAll($task->id);
561
            $users=[];
562
            foreach($datosUsuarios as $record){
563
                $datosUser = $userMapper->fetchOne($record->user_id);
564
 
565
                    $user=[
566
                        'uuid'=>$datosUser->uuid,
567
                    ];
568
                    array_push($users, $user);
569
            }
6314 nelberth 570
 
2516 nelberth 571
            $data = [
572
                'success' => true,
6295 nelberth 573
                'data' => $hydrator->extract($task),
6324 nelberth 574
                'all_users'=> $allUsers,
6323 nelberth 575
                'users'=> $users
2516 nelberth 576
            ];
577
 
578
            return new JsonModel($data);
579
        } else {
580
            $data = [
581
                'success' => false,
582
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
583
            ];
584
 
585
            return new JsonModel($data);
586
        }
587
 
588
        return new JsonModel($data);
589
 
590
    }
591
 
592
 
593
 
594
 
595
    public function deleteAction(){
596
        $currentUserPlugin = $this->plugin('currentUserPlugin');
597
        $currentCompany = $currentUserPlugin->getCompany();
598
        $currentUser = $currentUserPlugin->getUser();
599
 
600
        $request = $this->getRequest();
601
        $uuid = $this->params()->fromRoute('id');
602
 
603
 
604
        if (!$uuid) {
605
            $data = [
606
                'success' => false,
607
                'data' => 'ERROR_INVALID_PARAMETER'
608
            ];
609
 
610
            return new JsonModel($data);
611
        }
11092 nelberth 612
        $objective_uuid = $this->params()->fromRoute('objective_id');
613
        $goal_uuid = $this->params()->fromRoute('goal_id');
2782 nelberth 614
        $currentUserPlugin = $this->plugin('currentUserPlugin');
615
        $currentCompany = $currentUserPlugin->getCompany();
616
        $planningObjectivesAndGoalsObjectivesMapper = PlanningObjectivesAndGoalsObjectivesMapper::getInstance($this->adapter);
11092 nelberth 617
        $objective = $planningObjectivesAndGoalsObjectivesMapper->fetchOneByUuid($objective_uuid);
2782 nelberth 618
 
619
        if (!$objective) {
2516 nelberth 620
            $data = [
621
                'success' => false,
2782 nelberth 622
                'data' => 'ERROR_RECORD_NOT_FOUND'
2516 nelberth 623
            ];
624
                return new JsonModel($data);
2782 nelberth 625
 
626
        }else{
6225 nelberth 627
            if($objective->company_id==$currentCompany->id){
2782 nelberth 628
                $planningObjectivesAndGoalsGoalsMapper = PlanningObjectivesAndGoalsGoalsMapper::getInstance($this->adapter);
11092 nelberth 629
                $goals = $planningObjectivesAndGoalsGoalsMapper->fetchOneByUuid($goal_uuid);
2782 nelberth 630
 
631
                if(!$goals){
632
                    $data = [
633
                        'success' => false,
634
                        'data' => 'ERROR_RECORD_NOT_FOUND'
635
                    ];
636
 
637
 
638
                        return new JsonModel($data);
639
                }
640
            }else{
641
                $data = [
642
                    'success' => false,
643
                    'data' => 'ERROR_UNAUTHORIZED',
644
                ];
645
 
646
                    return new JsonModel($data);
3024 nelberth 647
            }
2782 nelberth 648
 
2516 nelberth 649
        }
650
        $planningObjectivesAndGoalsTaskMapper = PlanningObjectivesAndGoalsTaskMapper::getInstance($this->adapter);
2782 nelberth 651
        $task = $planningObjectivesAndGoalsTaskMapper->fetchOneByUuid($uuid);
2516 nelberth 652
 
2782 nelberth 653
        if (!$task) {
2516 nelberth 654
            $data = [
655
                'success' => false,
656
                'data' => 'ERROR_RECORD_NOT_FOUND'
657
            ];
658
 
659
            return new JsonModel($data);
660
        }
661
 
662
 
663
        if ($request->isPost()) {
664
 
665
 
2782 nelberth 666
            $result = $planningObjectivesAndGoalsTaskMapper->delete($task->id);
2516 nelberth 667
            if ($result) {
2782 nelberth 668
                $this->logger->info('Se borro la tarea con el titulo ' . $task->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
2516 nelberth 669
 
670
                $data = [
671
                    'success' => true,
672
                    'data' => 'LABEL_RECORD_DELETED'
673
                ];
674
            } else {
675
 
676
                $data = [
677
                    'success' => false,
678
                    'data' => $planningObjectivesAndGoalsTaskMapper->getError()
679
                ];
680
 
681
                return new JsonModel($data);
682
            }
683
        } else {
684
            $data = [
685
                'success' => false,
686
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
687
            ];
688
 
689
            return new JsonModel($data);
690
        }
691
 
692
        return new JsonModel($data);
693
    }
694
 
695
 
696
 
697
 
698
}