Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7489 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;
16768 efrain 9
 
7489 nelberth 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;
9524 nelberth 15
use LeadersLinked\Model\Topic;
10383 nelberth 16
use LeadersLinked\Model\HighPerformanceTeamsGroups;
7489 nelberth 17
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
10369 nelberth 18
use LeadersLinked\Form\HighPerformanceTeamsGroupsViewTopicForm;
7489 nelberth 19
use LeadersLinked\Library\Functions;
20
use LeadersLinked\Mapper\UserMapper;
9513 nelberth 21
use LeadersLinked\Mapper\TopicMapper;
7515 nelberth 22
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
7759 nelberth 23
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
24
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
7489 nelberth 25
use LeadersLinked\Mapper\CompanyMapper;
26
use LeadersLinked\Mapper\CompanyUserMapper;
27
 
28
 
29
 
30
class HighPerformanceTeamsGroupsViewTopicController extends AbstractActionController
31
{
32
    /**
33
     *
16769 efrain 34
     * @var \Laminas\Db\Adapter\AdapterInterface
7489 nelberth 35
     */
36
    private $adapter;
37
 
38
    /**
39
     *
16769 efrain 40
     * @var \LeadersLinked\Cache\CacheInterface
7489 nelberth 41
     */
16769 efrain 42
    private $cache;
43
 
44
 
45
    /**
46
     *
47
     * @var \Laminas\Log\LoggerInterface
48
     */
7489 nelberth 49
    private $logger;
50
 
51
    /**
52
     *
53
     * @var array
54
     */
55
    private $config;
56
 
16769 efrain 57
 
7489 nelberth 58
    /**
59
     *
16769 efrain 60
     * @var \Laminas\Mvc\I18n\Translator
61
     */
62
    private $translator;
63
 
64
 
65
    /**
66
     *
67
     * @param \Laminas\Db\Adapter\AdapterInterface $adapter
68
     * @param \LeadersLinked\Cache\CacheInterface $cache
69
     * @param \Laminas\Log\LoggerInterface LoggerInterface $logger
7489 nelberth 70
     * @param array $config
16769 efrain 71
     * @param \Laminas\Mvc\I18n\Translator $translator
7489 nelberth 72
     */
16769 efrain 73
    public function __construct($adapter, $cache, $logger, $config, $translator)
7489 nelberth 74
    {
16769 efrain 75
        $this->adapter      = $adapter;
76
        $this->cache        = $cache;
77
        $this->logger       = $logger;
78
        $this->config       = $config;
79
        $this->translator   = $translator;
7489 nelberth 80
    }
81
 
82
    public function indexAction()
83
    {
84
 
7713 nelberth 85
 
7489 nelberth 86
        $currentUserPlugin = $this->plugin('currentUserPlugin');
87
        $currentUser = $currentUserPlugin->getUser();
88
        $currentCompany = $currentUserPlugin->getCompany();
89
 
7622 nelberth 90
 
7489 nelberth 91
        $request = $this->getRequest();
92
        if($request->isGet()) {
93
 
94
 
95
            $headers  = $request->getHeaders();
96
 
97
            $isJson = false;
98
            if($headers->has('Accept')) {
99
                $accept = $headers->get('Accept');
100
 
101
                $prioritized = $accept->getPrioritized();
102
 
103
                foreach($prioritized as $key => $value) {
104
                    $raw = trim($value->getRaw());
105
 
106
                    if(!$isJson) {
107
                        $isJson = strpos($raw, 'json');
108
                    }
109
 
110
                }
111
            }
7855 nelberth 112
 
7489 nelberth 113
            if($isJson) {
7621 nelberth 114
 
11086 nelberth 115
                $group_uuid = $this->params()->fromRoute('group_id');
7847 nelberth 116
                if(!$group_uuid) {
7547 nelberth 117
                    $data = [
118
                        'success'   => false,
119
                        'data'   => 'ERROR_INVALID_PARAMETER'
120
                    ];
121
 
122
                    return new JsonModel($data);
123
                }
7856 nelberth 124
 
7547 nelberth 125
                $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
7847 nelberth 126
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
10382 nelberth 127
 
7547 nelberth 128
                if (!$highPerformanceTeamsGroups) {
129
                    $data = [
130
                        'success' => false,
131
                        'data' => 'ERROR_RECORD_NOT_FOUND'
132
                    ];
133
 
134
                    return new JsonModel($data);
135
                }
10374 nelberth 136
                if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
137
 
138
                    return new JsonModel([
139
                        'success' => false,
140
                        'data' => 'ERROR_UNAUTHORIZED'
141
                    ]);
142
 
143
                }
10355 nelberth 144
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
145
                $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
7760 nelberth 146
                if(!$highPerformanceTeamsGroupsMember) {
147
                    return new JsonModel([
148
                        'success' => false,
10366 nelberth 149
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
7760 nelberth 150
                    ]);
151
                }
7763 nelberth 152
                if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
7760 nelberth 153
                    return new JsonModel([
154
                        'success' => false,
155
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
156
                    ]);
157
                }
10355 nelberth 158
 
10366 nelberth 159
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
160
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/view/topic/edit');
161
                $allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/topic/delete');
162
                $allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view');
10369 nelberth 163
 
10355 nelberth 164
                $member = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$currentUser->id);
10372 nelberth 165
 
10355 nelberth 166
                if($member->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$member->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
167
                    $allowDelete=false;
168
                    $allowEdit=false;
169
                }
7551 nelberth 170
 
10366 nelberth 171
 
7760 nelberth 172
 
9519 nelberth 173
 
174
 
175
                $topicMapper = TopicMapper::getInstance($this->adapter);
9522 nelberth 176
 
9523 nelberth 177
                $paginator = $topicMapper->fetchAllHighPerfromanceTeamsGroup($highPerformanceTeamsGroups->id);
9522 nelberth 178
 
7760 nelberth 179
                $items = [];
7554 nelberth 180
 
7760 nelberth 181
 
182
 
183
                foreach($paginator as $record)
184
                {
185
 
186
 
187
                    $item = [
188
                        'title' => $record->title,
189
                        'status'=> $record->status,
190
                        'actions' => [
11086 nelberth 191
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/view/topic/edit', ['group_id' => $highPerformanceTeamsGroups->uuid, 'topic_id' => $record->uuid]) : '',
192
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/view/topic/delete', ['group_id' => $highPerformanceTeamsGroups->uuid,'topic_id' => $record->uuid]) : '',
193
                            'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/topic/view', ['group_id' => $highPerformanceTeamsGroups->uuid,'topic_id' => $record->uuid]) : '',
7760 nelberth 194
                        ]
195
 
196
                    ];
7489 nelberth 197
 
7760 nelberth 198
                    array_push($items, $item);
7489 nelberth 199
 
200
                }
7760 nelberth 201
 
202
                return new JsonModel([
203
                    'success' => true,
204
                    'data' => [
205
                        'items' => $items
206
                    ]
207
                ]);
7489 nelberth 208
 
7500 nelberth 209
            }
7489 nelberth 210
        } else {
211
            return new JsonModel([
212
                'success' => false,
213
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
214
            ]);
215
        }
216
    }
217
 
218
    public function addAction()
219
    {
220
 
11086 nelberth 221
        $group_uuid = $this->params()->fromRoute('group_id');
7857 nelberth 222
        if(!$group_uuid) {
223
            $data = [
224
                'success'   => false,
225
                'data'   => 'ERROR_INVALID_PARAMETER'
226
            ];
227
 
228
            return new JsonModel($data);
229
        }
7717 nelberth 230
 
7514 nelberth 231
        $currentUserPlugin = $this->plugin('currentUserPlugin');
232
        $currentUser = $currentUserPlugin->getUser();
233
        $currentCompany = $currentUserPlugin->getCompany();
7499 nelberth 234
 
7489 nelberth 235
        $request = $this->getRequest();
236
        if($request->isPost()) {
10369 nelberth 237
            $form = new  HighPerformanceTeamsGroupsViewTopicForm();
7489 nelberth 238
            $dataPost = $request->getPost()->toArray();
239
 
240
            $form->setData($dataPost);
241
 
242
            if($form->isValid()) {
243
                $dataPost = (array) $form->getData();
9656 nelberth 244
                $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : Topic::STATUS_INACTIVE;
7514 nelberth 245
 
7489 nelberth 246
 
7514 nelberth 247
                $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
7857 nelberth 248
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
7514 nelberth 249
 
7763 nelberth 250
                if (!$highPerformanceTeamsGroups) {
7514 nelberth 251
                    $data = [
252
                        'success' => false,
253
                        'data' => 'ERROR_RECORD_NOT_FOUND'
254
                    ];
255
 
256
                    return new JsonModel($data);
257
                }
10374 nelberth 258
                if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
259
 
260
                    return new JsonModel([
261
                        'success' => false,
262
                        'data' => 'ERROR_UNAUTHORIZED'
263
                    ]);
264
 
265
                }
9527 nelberth 266
 
10355 nelberth 267
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
268
                $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
7763 nelberth 269
                if(!$highPerformanceTeamsGroupsMember) {
7514 nelberth 270
                    return new JsonModel([
271
                        'success' => false,
7763 nelberth 272
                        'data' => 'ERROR_RECORD_NOT_FOUND'
7514 nelberth 273
                    ]);
7763 nelberth 274
                }
275
                if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
276
                    return new JsonModel([
277
                        'success' => false,
278
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
279
                    ]);
280
                }
7514 nelberth 281
 
9528 nelberth 282
                $hydrator = new ObjectPropertyHydrator();
283
                $topic = new Topic();
284
 
9530 nelberth 285
 
9524 nelberth 286
                $hydrator->hydrate($dataPost, $topic);
9677 nelberth 287
                $topic->type='hptg';
9532 nelberth 288
                $topic->high_performance_group_id=$highPerformanceTeamsGroups->id;
9516 nelberth 289
                $topicMapper = TopicMapper::getInstance($this->adapter);
9533 nelberth 290
 
9524 nelberth 291
                $result = $topicMapper->insert($topic);
7489 nelberth 292
 
293
                if($result) {
294
 
9524 nelberth 295
                    $this->logger->info('Se agrego el topic del grupo ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
7489 nelberth 296
 
297
                    $data = [
298
                        'success'   => true,
299
                        'data'   => 'LABEL_RECORD_ADDED'
300
                    ];
301
                } else {
302
                    $data = [
303
                        'success'   => false,
9516 nelberth 304
                        'data'      => $topicMapper->getError()
7489 nelberth 305
                    ];
306
 
307
                }
308
 
309
                return new JsonModel($data);
310
 
311
            } else {
312
                $messages = [];
313
                $form_messages = (array) $form->getMessages();
314
                foreach($form_messages  as $fieldname => $field_messages)
315
                {
316
 
317
                    $messages[$fieldname] = array_values($field_messages);
318
                }
319
 
320
                return new JsonModel([
321
                    'success'   => false,
322
                    'data'   => $messages
323
                ]);
324
            }
325
 
326
        } else {
327
            $data = [
328
                'success' => false,
7704 nelberth 329
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
7489 nelberth 330
            ];
331
 
332
            return new JsonModel($data);
333
        }
334
 
335
        return new JsonModel($data);
336
 
337
 
338
    }
339
 
340
 
341
 
342
     public function editAction(){
343
 
344
        $currentUserPlugin = $this->plugin('currentUserPlugin');
345
        $currentUser = $currentUserPlugin->getUser();
346
        $currentCompany = $currentUserPlugin->getCompany();
347
        $request = $this->getRequest();
11086 nelberth 348
        $group_uuid = $this->params()->fromRoute('group_id');
7743 nelberth 349
 
11086 nelberth 350
        $topic_uuid = $this->params()->fromRoute('topic_id');
7489 nelberth 351
 
352
 
7847 nelberth 353
        if(!$group_uuid) {
7489 nelberth 354
            $data = [
355
                'success'   => false,
356
                'data'   => 'ERROR_INVALID_PARAMETER'
357
            ];
358
 
359
            return new JsonModel($data);
360
        }
7743 nelberth 361
        if(!$topic_uuid) {
362
            $data = [
363
                'success'   => false,
364
                'data'   => 'ERROR_INVALID_PARAMETER'
365
            ];
366
 
367
            return new JsonModel($data);
368
        }
7750 nelberth 369
 
9536 nelberth 370
 
9516 nelberth 371
        $topicMapper = TopicMapper::getInstance($this->adapter);
372
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
7489 nelberth 373
 
7743 nelberth 374
        if (!$topic) {
7489 nelberth 375
            $data = [
376
                'success' => false,
377
                'data' => 'ERROR_RECORD_NOT_FOUND'
378
            ];
379
 
380
            return new JsonModel($data);
381
        }
382
 
10372 nelberth 383
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
384
        $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
385
 
386
        if (!$highPerformanceTeamsGroups) {
387
            $data = [
388
                'success' => false,
389
                'data' => 'ERROR_RECORD_NOT_FOUND'
390
            ];
7489 nelberth 391
 
10372 nelberth 392
            return new JsonModel($data);
393
        }
10374 nelberth 394
        if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
10372 nelberth 395
 
10374 nelberth 396
            return new JsonModel([
397
                'success' => false,
398
                'data' => 'ERROR_UNAUTHORIZED'
399
            ]);
400
 
401
        }
402
 
10372 nelberth 403
        $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
404
        $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
405
        if(!$highPerformanceTeamsGroupsMember) {
406
            return new JsonModel([
407
                'success' => false,
408
                'data' => 'ERROR_RECORD_NOT_FOUND'
409
            ]);
410
        }
411
        if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
412
            return new JsonModel([
413
                'success' => false,
414
                'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
415
            ]);
416
        }
417
 
418
        if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
419
            return new JsonModel([
420
                'success' => false,
421
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
422
            ]);
423
        }
7489 nelberth 424
        if($request->isPost()) {
10369 nelberth 425
            $form = new  HighPerformanceTeamsGroupsViewTopicForm();
7489 nelberth 426
            $dataPost = $request->getPost()->toArray();
9656 nelberth 427
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : Topic::STATUS_INACTIVE;
7756 nelberth 428
 
7752 nelberth 429
 
7755 nelberth 430
 
7756 nelberth 431
 
7489 nelberth 432
            $form->setData($dataPost);
433
 
434
            if($form->isValid()) {
7757 nelberth 435
                $dataPost = (array) $form->getData();
10372 nelberth 436
 
7756 nelberth 437
 
7489 nelberth 438
                $hydrator = new ObjectPropertyHydrator();
7748 nelberth 439
                $hydrator->hydrate($dataPost, $topic);
7860 nelberth 440
 
9516 nelberth 441
                $result = $topicMapper->update($topic);
7751 nelberth 442
 
7489 nelberth 443
                if($result) {
7744 nelberth 444
                    $this->logger->info('Se actualizo el grupo de alto rendimiento ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
7489 nelberth 445
 
446
                    $data = [
447
                        'success' => true,
448
                        'data' => 'LABEL_RECORD_UPDATED'
449
                    ];
450
                } else {
451
                    $data = [
452
                        'success'   => false,
9516 nelberth 453
                        'data'      => $topicMapper->getError()
7489 nelberth 454
                    ];
455
                }
456
 
457
                return new JsonModel($data);
458
 
459
            } else {
460
                $messages = [];
461
                $form_messages = (array) $form->getMessages();
462
                foreach($form_messages  as $fieldname => $field_messages)
463
                {
464
                    $messages[$fieldname] = array_values($field_messages);
465
                }
466
 
467
                return new JsonModel([
468
                    'success'   => false,
469
                    'data'   => $messages
470
                ]);
471
            }
472
        }else if ($request->isGet()) {
473
            $hydrator = new ObjectPropertyHydrator();
474
 
475
            $data = [
476
                'success' => true,
7743 nelberth 477
                'data' => $hydrator->extract($topic)
7489 nelberth 478
            ];
479
 
480
            return new JsonModel($data);
481
        } else {
482
            $data = [
483
                'success' => false,
484
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
485
            ];
486
 
487
            return new JsonModel($data);
488
        }
489
 
490
        return new JsonModel($data);
491
 
492
    }
493
 
494
 
495
 
496
 
497
    public function deleteAction(){
7737 nelberth 498
 
7489 nelberth 499
        $currentUserPlugin = $this->plugin('currentUserPlugin');
500
        $currentCompany = $currentUserPlugin->getCompany();
501
        $currentUser = $currentUserPlugin->getUser();
502
 
503
        $request = $this->getRequest();
11086 nelberth 504
        $group_uuid = $this->params()->fromRoute('group_id');
505
        $topic_uuid = $this->params()->fromRoute('topic_id');
7489 nelberth 506
 
507
 
7847 nelberth 508
        if (!$group_uuid) {
7489 nelberth 509
            $data = [
510
                'success' => false,
511
                'data' => 'ERROR_INVALID_PARAMETER'
512
            ];
513
 
514
            return new JsonModel($data);
515
        }
7763 nelberth 516
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
7847 nelberth 517
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
7763 nelberth 518
 
519
                if (!$highPerformanceTeamsGroups) {
520
                    $data = [
521
                        'success' => false,
522
                        'data' => 'ERROR_RECORD_NOT_FOUND'
523
                    ];
524
 
525
                    return new JsonModel($data);
526
                }
10374 nelberth 527
                if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
7489 nelberth 528
 
10374 nelberth 529
                    return new JsonModel([
530
                        'success' => false,
531
                        'data' => 'ERROR_UNAUTHORIZED'
532
                    ]);
533
 
534
                }
535
 
10372 nelberth 536
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
537
                $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
538
                if(!$highPerformanceTeamsGroupsMember) {
539
                    return new JsonModel([
540
                        'success' => false,
541
                        'data' => 'ERROR_RECORD_NOT_FOUND'
542
                    ]);
543
                }
544
                if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
545
                    return new JsonModel([
546
                        'success' => false,
547
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
548
                    ]);
549
                }
550
 
551
                if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
552
                    return new JsonModel([
553
                        'success' => false,
554
                        'data' => 'ERROR_METHOD_NOT_ALLOWED'
555
                    ]);
556
                }
7489 nelberth 557
 
558
 
9516 nelberth 559
        $topicMapper = TopicMapper::getInstance($this->adapter);
560
        $topic = $topicMapper->fetchOneByUuid($topic_uuid);
7489 nelberth 561
 
7737 nelberth 562
        if (!$topic) {
7489 nelberth 563
            $data = [
564
                'success' => false,
565
                'data' => 'ERROR_RECORD_NOT_FOUND'
566
            ];
567
 
568
            return new JsonModel($data);
569
        }
570
 
7763 nelberth 571
 
7489 nelberth 572
 
573
        if ($request->isPost()) {
574
 
575
 
9516 nelberth 576
            $result = $topicMapper->delete($topic->id);
7489 nelberth 577
            if ($result) {
7737 nelberth 578
                $this->logger->info('Se borro el grupo de alto rendimiento  ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
7489 nelberth 579
 
580
                $data = [
581
                    'success' => true,
582
                    'data' => 'LABEL_RECORD_DELETED'
583
                ];
584
            } else {
585
 
586
                $data = [
587
                    'success' => false,
9516 nelberth 588
                    'data' => $topicMapper->getError()
7489 nelberth 589
                ];
590
 
591
                return new JsonModel($data);
592
            }
593
        } else {
594
            $data = [
595
                'success' => false,
596
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
597
            ];
598
 
599
            return new JsonModel($data);
600
        }
601
 
602
        return new JsonModel($data);
603
    }
604
 
605
 
606
 
607
 
608
}