Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
9623 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\Log\LoggerInterface;
12
use Laminas\View\Model\ViewModel;
13
use Laminas\View\Model\JsonModel;
14
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
9672 nelberth 15
use LeadersLinked\Model\Topic;
9659 nelberth 16
use LeadersLinked\Mapper\TopicMapper;
9623 nelberth 17
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
18
use LeadersLinked\Model\HighPerformanceTeamsGroups;
19
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
20
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
21
use LeadersLinked\Mapper\UserMapper;
22
 
9632 nelberth 23
use LeadersLinked\Form\TopicForm;
9623 nelberth 24
use LeadersLinked\Library\Functions;
25
 
26
 
27
class HighPerformanceTeamsGroupsViewForoCategoriesController extends AbstractActionController
28
{
29
    /**
30
     *
31
     * @var AdapterInterface
32
     */
33
    private $adapter;
34
 
35
 
36
    /**
37
     *
38
     * @var AbstractAdapter
39
     */
40
    private $cache;
41
 
42
    /**
43
     *
44
     * @var  LoggerInterface
45
     */
46
    private $logger;
47
 
48
    /**
49
     *
50
     * @var array
51
     */
52
    private $config;
53
 
54
 
55
 
56
    /**
57
     *
58
     * @param AdapterInterface $adapter
59
     * @param AbstractAdapter $cache
60
     * @param LoggerInterface $logger
61
     * @param array $config
62
     */
63
    public function __construct($adapter, $cache , $logger, $config)
64
    {
65
        $this->adapter      = $adapter;
66
        $this->cache        = $cache;
67
        $this->logger       = $logger;
68
        $this->config       = $config;
69
 
70
 
71
    }
72
 
73
 
74
    public function indexAction()
75
    {
76
 
77
 
78
        $currentUserPlugin = $this->plugin('currentUserPlugin');
79
        $currentUser = $currentUserPlugin->getUser();
80
        $currentCompany = $currentUserPlugin->getCompany();
11085 nelberth 81
        $group_uuid =  $this->params()->fromRoute('group_id');
9623 nelberth 82
 
9772 nelberth 83
 
9623 nelberth 84
        $request = $this->getRequest();
85
        if($request->isGet()) {
86
 
87
 
88
            $headers  = $request->getHeaders();
9724 nelberth 89
            $isJson = false;
9623 nelberth 90
            if($headers->has('Accept')) {
91
                $accept = $headers->get('Accept');
92
 
93
                $prioritized = $accept->getPrioritized();
94
 
95
                foreach($prioritized as $key => $value) {
96
                    $raw = trim($value->getRaw());
97
 
98
                    if(!$isJson) {
99
                        $isJson = strpos($raw, 'json');
100
                    }
101
 
102
                }
103
            }
11188 nelberth 104
            $this->layout()->setTemplate('layout/layout-backend');
105
            $viewModel = new ViewModel();
9623 nelberth 106
 
107
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
108
            $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
109
 
110
            if (!$highPerformanceTeamsGroups) {
11188 nelberth 111
               $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
112
                return $viewModel;
9623 nelberth 113
            }
114
 
115
            if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
11188 nelberth 116
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
117
                return $viewModel;
9623 nelberth 118
            }
9679 nelberth 119
 
10374 nelberth 120
            $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
121
            $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
122
            if(!$highPerformanceTeamsGroupsMember) {
11188 nelberth 123
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
124
                return $viewModel;
10374 nelberth 125
            }
126
            if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
11188 nelberth 127
                $viewModel->setTemplate('leaders-linked/no-access/index.phtml');
128
                return $viewModel;
10374 nelberth 129
            }
130
            $addTopicBoton=true;
131
            if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
132
                $addTopicBoton=false;
133
            }
134
 
10373 nelberth 135
 
136
 
11188 nelberth 137
 
9623 nelberth 138
 
9632 nelberth 139
                $formTopic = new TopicForm();
140
                $viewModel->setTemplate('leaders-linked/high-performance-teams-groups-view-foro-categories/index.phtml');
9623 nelberth 141
                $viewModel->setVariables([
142
                    'group_uuid'  =>  $group_uuid,
143
                    'group_title'=>$highPerformanceTeamsGroups->title,
144
                    'group_description'=>$highPerformanceTeamsGroups->description,
145
                    'formTopic'=> $formTopic,
10374 nelberth 146
                    'addTopicBoton'=>$addTopicBoton
9623 nelberth 147
                ]);
148
                return $viewModel ;
149
 
150
 
151
 
9721 nelberth 152
 
9623 nelberth 153
        } else {
154
            return new JsonModel([
155
                'success' => false,
156
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
157
            ]);
158
        }
159
    }
9720 nelberth 160
 
161
    public function viewAction(){
162
        $currentUserPlugin = $this->plugin('currentUserPlugin');
163
        $currentUser = $currentUserPlugin->getUser();
164
        $currentCompany = $currentUserPlugin->getCompany();
11085 nelberth 165
        $group_uuid =  $this->params()->fromRoute('group_id');
9720 nelberth 166
 
9772 nelberth 167
 
9720 nelberth 168
        $request = $this->getRequest();
169
        if($request->isGet()) {
170
 
171
 
172
            $headers  = $request->getHeaders();
173
            $isJson = false;
174
            if($headers->has('Accept')) {
175
                $accept = $headers->get('Accept');
176
 
177
                $prioritized = $accept->getPrioritized();
178
 
179
                foreach($prioritized as $key => $value) {
180
                    $raw = trim($value->getRaw());
181
 
182
                    if(!$isJson) {
183
                        $isJson = strpos($raw, 'json');
184
                    }
185
 
186
                }
187
            }
188
 
189
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
190
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
191
 
192
                if (!$highPerformanceTeamsGroups) {
193
                    $data = [
194
                        'success' => false,
195
                        'data' => 'ERROR_RECORD_NOT_FOUND'
196
                    ];
197
 
198
                    return new JsonModel($data);
199
                }
10374 nelberth 200
                if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
201
 
202
                    return new JsonModel([
203
                        'success' => false,
204
                        'data' => 'ERROR_UNAUTHORIZED'
205
                    ]);
206
 
207
                }
208
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
209
                $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
9720 nelberth 210
                if(!$highPerformanceTeamsGroupsMember) {
211
                    return new JsonModel([
212
                        'success' => false,
213
                        'data' => 'ERROR_RECORD_NOT_FOUND'
214
                    ]);
215
                }
216
                if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
217
                    return new JsonModel([
218
                        'success' => false,
219
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
220
                    ]);
221
                }
10374 nelberth 222
 
9720 nelberth 223
                $acl = $this->getEvent()->getViewModel()->getVariable('acl');
224
                $allowEdit = $acl->isAllowed($currentUser->usertype_id, 'high-performance-teams/groups/view/foro/categories/edit');
225
                $allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/foro/categories/delete');
226
                $allowView = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view');
10374 nelberth 227
 
228
                if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
10376 nelberth 229
                    $allowDelete=false;
10374 nelberth 230
                    $allowEdit=false;
231
                }
232
 
233
 
234
            if($isJson) {
9720 nelberth 235
 
11085 nelberth 236
                $group_uuid = $this->params()->fromRoute('group_id');
10374 nelberth 237
                if(!$group_uuid) {
238
                    $data = [
239
                        'success'   => false,
240
                        'data'   => 'ERROR_INVALID_PARAMETER'
241
                    ];
242
 
243
                    return new JsonModel($data);
244
                }
9720 nelberth 245
 
246
 
10374 nelberth 247
 
248
 
249
 
250
 
251
 
9720 nelberth 252
                $topicMapper = TopicMapper::getInstance($this->adapter);
253
 
254
                $paginator = $topicMapper->fetchAllHighPerfromanceTeamsGroupForo($highPerformanceTeamsGroups->id);
255
 
256
                $items = [];
257
 
258
 
259
 
260
                foreach($paginator as $record)
261
                {
262
 
263
 
264
                    $item = [
265
                        'title' => $record->title,
266
                        'description'=>$record->description,
267
                        'status'=> $record->status,
268
                        'actions' => [
11085 nelberth 269
                            'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/edit', ['group_id' => $highPerformanceTeamsGroups->uuid, 'category_id' => $record->uuid]) : '',
270
                            'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/delete', ['group_id' => $highPerformanceTeamsGroups->uuid,'category_id' => $record->uuid]) : '',
271
                            'link_view' => $allowView ? $this->url()->fromRoute('high-performance-teams/groups/view/foro/categories/articles', ['group_id' => $highPerformanceTeamsGroups->uuid,'category_id' => $record->uuid]) : '',
9720 nelberth 272
                        ]
273
 
274
                    ];
275
 
276
                    array_push($items, $item);
277
 
278
                }
279
 
280
                return new JsonModel([
281
                    'success' => true,
282
                    'data' => [
283
                        'items' => $items
284
                    ]
285
                ]);
286
 
287
            }
288
        } else {
289
            return new JsonModel([
290
                'success' => false,
291
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
292
            ]);
293
        }
294
    }
295
 
9656 nelberth 296
    public function addAction()
297
    {
9623 nelberth 298
 
11085 nelberth 299
        $group_uuid = $this->params()->fromRoute('group_id');
9656 nelberth 300
        if(!$group_uuid) {
301
            $data = [
302
                'success'   => false,
303
                'data'   => 'ERROR_INVALID_PARAMETER'
304
            ];
305
 
306
            return new JsonModel($data);
307
        }
9732 nelberth 308
 
9661 nelberth 309
 
9656 nelberth 310
        $currentUserPlugin = $this->plugin('currentUserPlugin');
311
        $currentUser = $currentUserPlugin->getUser();
312
        $currentCompany = $currentUserPlugin->getCompany();
313
 
314
        $request = $this->getRequest();
9662 nelberth 315
 
9666 nelberth 316
 
317
 
9656 nelberth 318
        if($request->isPost()) {
9665 nelberth 319
 
9664 nelberth 320
            $form = new  TopicForm();
9663 nelberth 321
            $dataPost = $request->getPost()->toArray();
9666 nelberth 322
            $form->setData($dataPost);
9667 nelberth 323
 
9656 nelberth 324
            if($form->isValid()) {
325
                $dataPost = (array) $form->getData();
9659 nelberth 326
                $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : Topic::STATUS_INACTIVE;
9656 nelberth 327
 
328
 
329
                $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
330
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
331
 
332
                if (!$highPerformanceTeamsGroups) {
333
                    $data = [
334
                        'success' => false,
335
                        'data' => 'ERROR_RECORD_NOT_FOUND'
336
                    ];
337
 
338
                    return new JsonModel($data);
339
                }
10373 nelberth 340
                if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
341
 
342
                    return new JsonModel([
343
                        'success' => false,
344
                        'data' => 'ERROR_UNAUTHORIZED'
345
                    ]);
346
 
347
                }
348
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
349
                $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
9656 nelberth 350
                if(!$highPerformanceTeamsGroupsMember) {
351
                    return new JsonModel([
352
                        'success' => false,
353
                        'data' => 'ERROR_RECORD_NOT_FOUND'
354
                    ]);
355
                }
356
                if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
357
                    return new JsonModel([
358
                        'success' => false,
359
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
360
                    ]);
361
                }
9671 nelberth 362
 
10373 nelberth 363
                if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
364
                    return new JsonModel([
365
                        'success' => false,
366
                        'data' => 'ERROR_METHOD_NOT_ALLOWED'
367
                    ]);
368
                }
369
 
9671 nelberth 370
                $hydrator = new ObjectPropertyHydrator();
371
                $topic = new Topic();
9676 nelberth 372
 
373
 
374
                $hydrator->hydrate($dataPost, $topic);
9677 nelberth 375
                $topic->type='hptgf';
9676 nelberth 376
                $topic->high_performance_group_id=$highPerformanceTeamsGroups->id;
377
                $topicMapper = TopicMapper::getInstance($this->adapter);
9656 nelberth 378
                $result = $topicMapper->insert($topic);
379
 
380
                if($result) {
381
 
382
                    $this->logger->info('Se agrego la categoria del foro con el titulo ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
383
 
384
                    $data = [
385
                        'success'   => true,
386
                        'data'   => 'LABEL_RECORD_ADDED'
387
                    ];
388
                } else {
389
                    $data = [
390
                        'success'   => false,
391
                        'data'      => $topicMapper->getError()
392
                    ];
393
 
394
                }
395
 
396
                return new JsonModel($data);
397
 
398
            } else {
399
                $messages = [];
400
                $form_messages = (array) $form->getMessages();
401
                foreach($form_messages  as $fieldname => $field_messages)
402
                {
403
 
404
                    $messages[$fieldname] = array_values($field_messages);
405
                }
406
 
407
                return new JsonModel([
408
                    'success'   => false,
409
                    'data'   => $messages
410
                ]);
411
            }
412
 
413
        } else {
414
            $data = [
415
                'success' => false,
416
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
417
            ];
418
 
419
            return new JsonModel($data);
420
        }
421
 
422
        return new JsonModel($data);
423
 
424
 
9640 nelberth 425
    }
9727 nelberth 426
 
9640 nelberth 427
    public function editAction(){
9725 nelberth 428
 
429
        $currentUserPlugin = $this->plugin('currentUserPlugin');
430
        $currentUser = $currentUserPlugin->getUser();
431
        $currentCompany = $currentUserPlugin->getCompany();
432
        $request = $this->getRequest();
11085 nelberth 433
        $group_uuid = $this->params()->fromRoute('group_id');
9640 nelberth 434
 
11085 nelberth 435
        $category_uuid = $this->params()->fromRoute('category_id');
9725 nelberth 436
 
437
 
438
        if(!$group_uuid) {
439
            $data = [
440
                'success'   => false,
441
                'data'   => 'ERROR_INVALID_PARAMETER'
442
            ];
443
 
444
            return new JsonModel($data);
445
        }
9732 nelberth 446
        if(!$category_uuid) {
9725 nelberth 447
            $data = [
448
                'success'   => false,
449
                'data'   => 'ERROR_INVALID_PARAMETER'
450
            ];
451
 
452
            return new JsonModel($data);
453
        }
454
 
455
 
456
        $topicMapper = TopicMapper::getInstance($this->adapter);
9732 nelberth 457
        $topic = $topicMapper->fetchOneByUuid($category_uuid);
9725 nelberth 458
 
459
        if (!$topic) {
460
            $data = [
461
                'success' => false,
462
                'data' => 'ERROR_RECORD_NOT_FOUND'
463
            ];
464
 
465
            return new JsonModel($data);
466
        }
467
 
468
 
469
                $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
470
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
471
 
472
                if (!$highPerformanceTeamsGroups) {
473
                    $data = [
474
                        'success' => false,
475
                        'data' => 'ERROR_RECORD_NOT_FOUND'
476
                    ];
477
 
478
                    return new JsonModel($data);
479
                }
10373 nelberth 480
                if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
9725 nelberth 481
 
10373 nelberth 482
                    return new JsonModel([
483
                        'success' => false,
484
                        'data' => 'ERROR_UNAUTHORIZED'
485
                    ]);
486
 
487
                }
488
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
489
                $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
9725 nelberth 490
                if(!$highPerformanceTeamsGroupsMember) {
491
                    return new JsonModel([
492
                        'success' => false,
493
                        'data' => 'ERROR_RECORD_NOT_FOUND'
494
                    ]);
495
                }
496
                if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
497
                    return new JsonModel([
498
                        'success' => false,
499
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
500
                    ]);
501
                }
10373 nelberth 502
 
503
                if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
504
                    return new JsonModel([
505
                        'success' => false,
506
                        'data' => 'ERROR_METHOD_NOT_ALLOWED'
507
                    ]);
508
                }
509
        if($request->isPost()) {
510
            $form = new  TopicForm();
511
            $dataPost = $request->getPost()->toArray();
512
            $dataPost['status'] =  isset($dataPost['status']) ? $dataPost['status'] : Topic::STATUS_INACTIVE;
513
 
514
 
515
 
516
 
517
            $form->setData($dataPost);
518
 
519
            if($form->isValid()) {
520
                $dataPost = (array) $form->getData();
521
 
9725 nelberth 522
 
523
                $hydrator = new ObjectPropertyHydrator();
524
                $hydrator->hydrate($dataPost, $topic);
525
 
526
                $result = $topicMapper->update($topic);
527
 
528
                if($result) {
9726 nelberth 529
                    $this->logger->info('Se actualizo la categoria del foro de alto rendimiento ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
9725 nelberth 530
 
531
                    $data = [
532
                        'success' => true,
533
                        'data' => 'LABEL_RECORD_UPDATED'
534
                    ];
535
                } else {
536
                    $data = [
537
                        'success'   => false,
538
                        'data'      => $topicMapper->getError()
539
                    ];
540
                }
541
 
542
                return new JsonModel($data);
543
 
544
            } else {
545
                $messages = [];
546
                $form_messages = (array) $form->getMessages();
547
                foreach($form_messages  as $fieldname => $field_messages)
548
                {
549
                    $messages[$fieldname] = array_values($field_messages);
550
                }
551
 
552
                return new JsonModel([
553
                    'success'   => false,
554
                    'data'   => $messages
555
                ]);
556
            }
557
        }else if ($request->isGet()) {
558
            $hydrator = new ObjectPropertyHydrator();
559
 
560
            $data = [
561
                'success' => true,
562
                'data' => $hydrator->extract($topic)
563
            ];
564
 
565
            return new JsonModel($data);
566
        } else {
567
            $data = [
568
                'success' => false,
569
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
570
            ];
571
 
572
            return new JsonModel($data);
573
        }
574
 
575
        return new JsonModel($data);
576
 
9640 nelberth 577
    }
9727 nelberth 578
    public function deleteAction(){
9623 nelberth 579
 
9727 nelberth 580
        $currentUserPlugin = $this->plugin('currentUserPlugin');
581
        $currentCompany = $currentUserPlugin->getCompany();
582
        $currentUser = $currentUserPlugin->getUser();
9623 nelberth 583
 
9727 nelberth 584
        $request = $this->getRequest();
11085 nelberth 585
        $group_uuid = $this->params()->fromRoute('group_id');
586
        $category_uuid = $this->params()->fromRoute('category_id');
9727 nelberth 587
 
9731 nelberth 588
 
9727 nelberth 589
        if (!$group_uuid) {
590
            $data = [
591
                'success' => false,
592
                'data' => 'ERROR_INVALID_PARAMETER'
593
            ];
594
 
595
            return new JsonModel($data);
596
        }
9732 nelberth 597
        if(!$category_uuid) {
598
            $data = [
599
                'success'   => false,
600
                'data'   => 'ERROR_INVALID_PARAMETER'
601
            ];
602
 
603
            return new JsonModel($data);
604
        }
9727 nelberth 605
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
10373 nelberth 606
        $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
607
 
608
        if (!$highPerformanceTeamsGroups) {
609
            $data = [
610
                'success' => false,
611
                'data' => 'ERROR_RECORD_NOT_FOUND'
612
            ];
9727 nelberth 613
 
10373 nelberth 614
            return new JsonModel($data);
615
        }
616
        if($highPerformanceTeamsGroups->status != HighPerformanceTeamsGroups::STATUS_ACTIVE) {
617
 
618
            return new JsonModel([
619
                'success' => false,
620
                'data' => 'ERROR_UNAUTHORIZED'
621
            ]);
622
 
623
        }
624
        $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
625
        $highPerformanceTeamsGroupsMember = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id, $currentUser->id);
9727 nelberth 626
        if(!$highPerformanceTeamsGroupsMember) {
627
            return new JsonModel([
628
                'success' => false,
629
                'data' => 'ERROR_RECORD_NOT_FOUND'
630
            ]);
631
        }
632
        if(!($highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $highPerformanceTeamsGroupsMember->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
633
            return new JsonModel([
634
                'success' => false,
635
                'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
636
            ]);
637
        }
638
 
10373 nelberth 639
        if($highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$highPerformanceTeamsGroupsMember->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
640
            return new JsonModel([
641
                'success' => false,
642
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
643
            ]);
644
        }
645
 
9727 nelberth 646
        $topicMapper = TopicMapper::getInstance($this->adapter);
9728 nelberth 647
        $topic = $topicMapper->fetchOneByUuid($category_uuid);
9727 nelberth 648
 
649
        if (!$topic) {
650
            $data = [
651
                'success' => false,
652
                'data' => 'ERROR_RECORD_NOT_FOUND'
653
            ];
654
 
655
            return new JsonModel($data);
656
        }
657
 
658
 
659
 
660
        if ($request->isPost()) {
661
 
662
 
663
            $result = $topicMapper->delete($topic->id);
664
            if ($result) {
665
                $this->logger->info('Se borro la categoria del foro de alto rendimiento  ' . $topic->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
666
 
667
                $data = [
668
                    'success' => true,
669
                    'data' => 'LABEL_RECORD_DELETED'
670
                ];
671
            } else {
672
 
673
                $data = [
674
                    'success' => false,
675
                    'data' => $topicMapper->getError()
676
                ];
677
 
678
                return new JsonModel($data);
679
            }
680
        } else {
681
            $data = [
682
                'success' => false,
683
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
684
            ];
685
 
686
            return new JsonModel($data);
687
        }
688
 
689
        return new JsonModel($data);
690
    }
691
 
692
 
9623 nelberth 693
}