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