Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7811 nelberth 1
<?php
2
declare(strict_types=1);
3
 
4
namespace LeadersLinked\Controller;
5
 
6
use Laminas\Authentication\AuthenticationService;
7
use Laminas\Authentication\Result as AuthResult;
8
use Laminas\Db\Adapter\AdapterInterface;
9
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
10
use Laminas\Mvc\Controller\AbstractActionController;
11
use Laminas\Mvc\I18n\Translator;
12
use Laminas\Log\LoggerInterface;
13
use Laminas\View\Model\ViewModel;
14
use Laminas\View\Model\JsonModel;
7818 nelberth 15
use LeadersLinked\Model\HighPerformanceTeamsGroupsMembers;
7811 nelberth 16
use LeadersLinked\Hydrator\ObjectPropertyHydrator;
7818 nelberth 17
use LeadersLinked\Form\HighPerformanceTeamsGroupsMembersForm;
10313 nelberth 18
 
19
use LeadersLinked\Form\HighPerformanceTeamsGroupsMembersTypeForm;
7811 nelberth 20
use LeadersLinked\Library\Functions;
21
use LeadersLinked\Mapper\UserMapper;
7818 nelberth 22
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMembersMapper;
7811 nelberth 23
use LeadersLinked\Mapper\CompanyMapper;
24
use LeadersLinked\Mapper\CompanyUserMapper;
25
 
7827 nelberth 26
use LeadersLinked\Mapper\HighPerformanceTeamsGroupsMapper;
7811 nelberth 27
 
7827 nelberth 28
class HighPerformanceTeamsGroupsMembersController extends AbstractActionController
7811 nelberth 29
{
30
    /**
31
     *
32
     * @var AdapterInterface
33
     */
34
    private $adapter;
35
 
36
 
37
    /**
38
     *
39
     * @var AbstractAdapter
40
     */
41
    private $cache;
42
 
43
    /**
44
     *
45
     * @var  LoggerInterface
46
     */
47
    private $logger;
48
 
49
    /**
50
     *
51
     * @var array
52
     */
53
    private $config;
54
 
55
 
56
 
57
    /**
58
     *
59
     * @param AdapterInterface $adapter
60
     * @param AbstractAdapter $cache
61
     * @param LoggerInterface $logger
62
     * @param array $config
63
     */
64
    public function __construct($adapter, $cache , $logger, $config)
65
    {
66
        $this->adapter      = $adapter;
67
        $this->cache        = $cache;
68
        $this->logger       = $logger;
69
        $this->config       = $config;
70
 
71
 
72
    }
73
 
74
 
75
 
76
 
77
    public function indexAction()
78
    {
79
 
7829 nelberth 80
 
7827 nelberth 81
 
7811 nelberth 82
        $currentUserPlugin = $this->plugin('currentUserPlugin');
83
        $currentUser = $currentUserPlugin->getUser();
84
        $currentCompany = $currentUserPlugin->getCompany();
11083 nelberth 85
        $group_uuid= $this->params()->fromRoute('group_id');
7811 nelberth 86
 
87
        $request = $this->getRequest();
8053 nelberth 88
        $acl = $this->getEvent()->getViewModel()->getVariable('acl');
89
        $allowInvite = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/members/invite');
10288 nelberth 90
 
91
        $allowDelete = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/members/delete');
10290 nelberth 92
 
10287 nelberth 93
        $allowEdit = $acl->isAllowed($currentUser->usertype_id,'high-performance-teams/groups/view/members/edit');
10286 nelberth 94
 
11169 nelberth 95
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
96
        $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
97
 
98
        if (!$highPerformanceTeamsGroups) {
99
            $data = [
100
                        'success' => false,
101
                        'data' => 'ERROR_RECORD_NOT_FOUND'
102
                    ];
10287 nelberth 103
 
11169 nelberth 104
            return new JsonModel($data);
105
        }
11180 nelberth 106
 
107
        $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
108
        $highPerformanceTeamsGroupsMembers = $highPerformanceTeamsGroupsMembersMapper->fetchAllInnerJoinUser($highPerformanceTeamsGroups->id,UserMapper::_TABLE);
109
        if(!$highPerformanceTeamsGroupsMembers){
110
            return new JsonModel([
111
                'success' => false,
112
                'data' => 'ERROR_RECORD_NOT_FOUND'
113
            ]);
114
        }
115
 
11169 nelberth 116
 
117
        $member = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$currentUser->id);
118
            if(!$member){
119
                return new JsonModel([
120
                    'success' => false,
121
                    'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
122
                ]);
123
            }
124
 
125
        if(!($member->status == HighPerformanceTeamsGroupsMembers::STATUS_ACCEPTED || $member->status == HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN) ){
126
                    return new JsonModel([
127
                        'success' => false,
128
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
129
                    ]);
130
                }
131
 
132
            if($member->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$member->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
133
                    $allowDelete=false;
134
                    $allowEdit=false;
135
                }
136
 
7811 nelberth 137
        if($request->isGet()) {
138
 
139
 
140
            $headers  = $request->getHeaders();
141
 
142
            $isJson = false;
143
            if($headers->has('Accept')) {
144
                $accept = $headers->get('Accept');
145
 
146
                $prioritized = $accept->getPrioritized();
147
 
148
                foreach($prioritized as $key => $value) {
149
                    $raw = trim($value->getRaw());
150
 
151
                    if(!$isJson) {
152
                        $isJson = strpos($raw, 'json');
153
                    }
154
 
155
                }
156
            }
157
 
11169 nelberth 158
 
7811 nelberth 159
            if($isJson) {
160
 
11169 nelberth 161
 
10360 nelberth 162
 
10359 nelberth 163
                $items=[];
10358 nelberth 164
                foreach($highPerformanceTeamsGroupsMembers as $record)
7891 nelberth 165
                {
10320 nelberth 166
                    if($record->id==$currentUser->id){
10339 nelberth 167
                        $contentAllowDelete2=$allowDelete;
10320 nelberth 168
                        $allowDelete=true;
169
                    }
10321 nelberth 170
 
10322 nelberth 171
                    $userType = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$record->id);
10323 nelberth 172
 
10321 nelberth 173
                    if($userType->type==HighPerformanceTeamsGroupsMembers::TYPE_CREATOR){
10323 nelberth 174
                        $contentAllowDelete=$allowDelete;
175
                        $contentAllowEdit=$allowEdit;
10321 nelberth 176
                        $allowDelete=false;
177
                        $allowEdit=false;
178
                    }
7891 nelberth 179
                    $item = [
180
                        'first_name' => $record->first_name,
181
                        'last_name' => $record->last_name,
7910 nelberth 182
                        'image'=>  $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $record->uuid, 'filename' => $record->image]),
11083 nelberth 183
                        'link_delete' => $allowDelete ? $this->url()->fromRoute('high-performance-teams/groups/view/members/delete', ['group_id' => $highPerformanceTeamsGroups->uuid,'user_id'=>$record->uuid]) : '',
184
                        'link_edit' => $allowEdit ? $this->url()->fromRoute('high-performance-teams/groups/view/members/edit', ['group_id' => $highPerformanceTeamsGroups->uuid,'user_id'=>$record->uuid]) : '',
7891 nelberth 185
 
8053 nelberth 186
 
7868 nelberth 187
                    ];
7891 nelberth 188
 
10323 nelberth 189
                    if($userType->type==HighPerformanceTeamsGroupsMembers::TYPE_CREATOR){
190
                        $allowDelete= $contentAllowDelete;
191
                        $allowEdit=$contentAllowEdit;
192
                    }
10339 nelberth 193
                    if($record->id==$currentUser->id){
194
                        $allowDelete=$contentAllowDelete2;
195
                    }
7891 nelberth 196
                    array_push($items, $item);
197
 
7868 nelberth 198
                }
7891 nelberth 199
 
200
 
7811 nelberth 201
 
202
                return new JsonModel([
203
                    'success' => true,
204
                    'data' => [
7818 nelberth 205
                        'items' => $items
7811 nelberth 206
                    ]
207
                ]);
208
 
209
            }
7948 nelberth 210
        }else if($request->isPost()){
7963 nelberth 211
 
7948 nelberth 212
            $headers  = $request->getHeaders();
213
 
214
            $isJson = false;
215
            if($headers->has('Accept')) {
216
                $accept = $headers->get('Accept');
217
 
218
                $prioritized = $accept->getPrioritized();
219
 
220
                foreach($prioritized as $key => $value) {
221
                    $raw = trim($value->getRaw());
222
 
223
                    if(!$isJson) {
224
                        $isJson = strpos($raw, 'json');
225
                    }
226
 
227
                }
228
            }
229
 
230
            if($isJson) {
8053 nelberth 231
 
7973 nelberth 232
                $dataPost = $request->getPost()->toArray();
233
                $search = $dataPost['search'];
7996 nelberth 234
                $search = empty($search) ? '' : filter_var($search, FILTER_SANITIZE_STRING);
7997 nelberth 235
 
7948 nelberth 236
 
237
 
7969 nelberth 238
                $userMapper = UserMapper::getInstance($this->adapter);
7994 nelberth 239
                $records = $userMapper->fetchAllSuggestForInvitationByHptgId($highPerformanceTeamsGroups->id,$search);
7948 nelberth 240
                $items=[];
241
 
242
                foreach($records as $record)
243
                {
244
 
245
                    $item = [
246
                        'first_name' => $record->first_name,
247
                        'last_name' => $record->last_name,
248
                        'image'=>  $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $record->uuid, 'filename' => $record->image]),
7997 nelberth 249
                        'email'=> $record->email,
11083 nelberth 250
                        'link_invite'=> $allowInvite ? $this->url()->fromRoute('high-performance-teams/groups/view/members/invite', ['group_id' => $highPerformanceTeamsGroups->uuid,'user_id'=>$record->uuid]) : '',
7948 nelberth 251
 
252
                    ];
253
 
254
                    array_push($items, $item);
255
 
256
                }
257
 
258
 
259
 
260
                return new JsonModel([
261
                    'success' => true,
262
                    'data' => [
263
                        'items' => $items
264
                    ]
265
                ]);
266
 
267
            }
7811 nelberth 268
        } else {
269
            return new JsonModel([
270
                'success' => false,
271
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
272
            ]);
273
        }
274
    }
275
 
8012 nelberth 276
    public function inviteAction()
7811 nelberth 277
    {
8020 nelberth 278
 
8017 nelberth 279
 
280
 
8020 nelberth 281
        $currentUserPlugin = $this->plugin('currentUserPlugin');
7811 nelberth 282
        $currentUser = $currentUserPlugin->getUser();
283
        $currentCompany = $currentUserPlugin->getCompany();
8028 nelberth 284
 
11097 nelberth 285
        $user_uuid = $this->params()->fromRoute('user_id');
286
        $group_uuid = $this->params()->fromRoute('group_id');
8029 nelberth 287
 
7811 nelberth 288
        $request = $this->getRequest();
289
        if($request->isPost()) {
8031 nelberth 290
 
8047 nelberth 291
 
8023 nelberth 292
                $userMapper = UserMapper::getInstance($this->adapter);
293
                $user = $userMapper->fetchOneByUuid($user_uuid);
294
 
8040 nelberth 295
                if(!$user) {
296
                    return new JsonModel([
297
                        'success' => false,
298
                        'data' => 'ERROR_RECORD_NOT_FOUND'
299
                    ]);
300
                }
301
 
8023 nelberth 302
                $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
303
                $companyUser = $companyUserMapper->fetchOneByCompanyIdAndUserId($currentCompany->id,$user->id);
8048 nelberth 304
 
305
                $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
306
                $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
8049 nelberth 307
 
8050 nelberth 308
                if(!$highPerformanceTeamsGroups) {
8040 nelberth 309
                    return new JsonModel([
310
                        'success' => false,
311
                        'data' => 'ERROR_RECORD_NOT_FOUND'
312
                    ]);
313
                }
8050 nelberth 314
 
10324 nelberth 315
                $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
10325 nelberth 316
 
10324 nelberth 317
                $member = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$currentUser->id);
11170 nelberth 318
                if(!$member){
319
                    return new JsonModel([
320
                        'success' => false,
321
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
322
                    ]);
323
                }
10324 nelberth 324
                if($member->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$member->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
325
                    return new JsonModel([
326
                        'success' => false,
327
                        'data' => 'ERROR_METHOD_NOT_ALLOWED'
328
                    ]);
329
                }
330
 
8044 nelberth 331
                $highPerformanceTeamsGroupsMember = new HighPerformanceTeamsGroupsMembers();
332
                $highPerformanceTeamsGroupsMember->group_id  = $highPerformanceTeamsGroups->id;
333
                $highPerformanceTeamsGroupsMember->user_id = $user->id;
334
                $highPerformanceTeamsGroupsMember->type = HighPerformanceTeamsGroupsMembers::TYPE_USER;
8053 nelberth 335
 
8038 nelberth 336
                if($companyUser){
8044 nelberth 337
                    $highPerformanceTeamsGroupsMember->status = HighPerformanceTeamsGroupsMembers::STATUS_ADDED_BY_ADMIN;
8061 nelberth 338
                    $data = [
339
                        'success'   => true,
340
                        'data'   => 'LABEL_RECORD_ADDED'
341
                    ];
8023 nelberth 342
                }else{
8044 nelberth 343
                    $highPerformanceTeamsGroupsMember->status = HighPerformanceTeamsGroupsMembers::STATUS_INVITED;
8061 nelberth 344
                    $data = [
345
                        'success'   => true,
346
                        'data'   => 'LABEL_USER_COMPANY_HAS_BEEN_REQUESTED'
347
                    ];
8023 nelberth 348
                }
10324 nelberth 349
                $highPerformanceTeamsGroupsMembersMapper->insert($highPerformanceTeamsGroupsMember);
8045 nelberth 350
 
10324 nelberth 351
               if($highPerformanceTeamsGroupsMembersMapper) {
7811 nelberth 352
 
8044 nelberth 353
                    $this->logger->info('Se agrego el miembro de grupo  con el correo: ' . $user->email, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
7811 nelberth 354
 
355
                } else {
356
                    $data = [
357
                        'success'   => false,
7818 nelberth 358
                        'data'      => $highPerformanceTeamsGroupsMembersMapper->getError()
7811 nelberth 359
                    ];
360
 
361
                }
362
 
363
                return new JsonModel($data);
8044 nelberth 364
 
8030 nelberth 365
 
7811 nelberth 366
 
367
        } else {
368
            $data = [
369
                'success' => false,
370
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
371
            ];
372
 
373
            return new JsonModel($data);
374
        }
375
 
376
        return new JsonModel($data);
377
 
378
 
379
    }
380
 
381
 
382
 
383
     public function editAction(){
384
 
385
        $currentUserPlugin = $this->plugin('currentUserPlugin');
386
        $currentUser = $currentUserPlugin->getUser();
387
        $currentCompany = $currentUserPlugin->getCompany();
388
        $request = $this->getRequest();
10283 nelberth 389
 
11097 nelberth 390
        $group_uuid = $this->params()->fromRoute('group_id');
391
        $user_uuid = $this->params()->fromRoute('user_id');
10293 nelberth 392
 
7811 nelberth 393
 
10283 nelberth 394
        if(!$group_uuid) {
7811 nelberth 395
            $data = [
396
                'success'   => false,
397
                'data'   => 'ERROR_INVALID_PARAMETER'
398
            ];
399
 
400
            return new JsonModel($data);
401
        }
402
 
10283 nelberth 403
        if(!$user_uuid) {
404
            $data = [
405
                'success'   => false,
406
                'data'   => 'ERROR_INVALID_PARAMETER'
407
            ];
408
 
409
            return new JsonModel($data);
410
        }
10296 nelberth 411
 
10299 nelberth 412
        $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
10297 nelberth 413
 
10328 nelberth 414
        $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
10301 nelberth 415
 
10328 nelberth 416
        if (!$highPerformanceTeamsGroups) {
7811 nelberth 417
            $data = [
418
                'success' => false,
419
                'data' => 'ERROR_RECORD_NOT_FOUND'
420
            ];
421
 
422
            return new JsonModel($data);
423
        }
10328 nelberth 424
 
425
        $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
426
        $member = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$currentUser->id);
11170 nelberth 427
        if(!$member){
428
            return new JsonModel([
429
                'success' => false,
430
                'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
431
            ]);
432
        }
10328 nelberth 433
        if($member->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$member->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
434
            return new JsonModel([
435
                'success' => false,
436
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
437
            ]);
438
        }
7811 nelberth 439
 
10283 nelberth 440
        $userMapper = UserMapper::getInstance($this->adapter);
441
        $user = $userMapper->fetchOneByUuid($user_uuid);
10302 nelberth 442
 
10328 nelberth 443
 
444
        $highPerformanceTeamsGroupsMembers=$highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$user->id);
445
        if($highPerformanceTeamsGroupsMembers->type==HighPerformanceTeamsGroupsMembers::TYPE_CREATOR){
446
            return new JsonModel([
447
                'success' => false,
448
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
449
            ]);
450
        }
10298 nelberth 451
 
7811 nelberth 452
        if($request->isPost()) {
10330 nelberth 453
 
454
            $form = new  HighPerformanceTeamsGroupsMembersTypeForm($this->adapter, $currentCompany->id);
455
            $dataPost = $request->getPost()->toArray();
456
            $form->setData($dataPost);
10331 nelberth 457
 
7811 nelberth 458
            if($form->isValid()) {
459
                $dataPost = (array) $form->getData();
10332 nelberth 460
 
461
                $hydrator = new ObjectPropertyHydrator();
462
                $hydrator->hydrate($dataPost, $highPerformanceTeamsGroupsMembers);
10333 nelberth 463
 
464
                $result = $highPerformanceTeamsGroupsMembersMapper->update($highPerformanceTeamsGroupsMembers);
10334 nelberth 465
 
7811 nelberth 466
                if($result) {
10336 nelberth 467
 
10337 nelberth 468
                    $this->logger->info('Se actualizo el miembro ' .$user->first_name.' en el grupo '. $highPerformanceTeamsGroups->title, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
469
 
7811 nelberth 470
                    $data = [
471
                        'success' => true,
472
                        'data' => 'LABEL_RECORD_UPDATED'
473
                    ];
474
                } else {
475
                    $data = [
476
                        'success'   => false,
7818 nelberth 477
                        'data'      => $highPerformanceTeamsGroupsMembersMapper->getError()
7811 nelberth 478
                    ];
479
                }
480
 
481
                return new JsonModel($data);
482
 
483
            } else {
484
                $messages = [];
485
                $form_messages = (array) $form->getMessages();
486
                foreach($form_messages  as $fieldname => $field_messages)
487
                {
488
                    $messages[$fieldname] = array_values($field_messages);
489
                }
490
 
491
                return new JsonModel([
492
                    'success'   => false,
493
                    'data'   => $messages
494
                ]);
495
            }
496
        }else if ($request->isGet()) {
497
            $hydrator = new ObjectPropertyHydrator();
498
 
499
            $data = [
500
                'success' => true,
10298 nelberth 501
                'data' => $highPerformanceTeamsGroupsMembers->type
7811 nelberth 502
            ];
503
 
504
            return new JsonModel($data);
505
        } else {
506
            $data = [
507
                'success' => false,
508
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
509
            ];
510
 
511
            return new JsonModel($data);
512
        }
513
 
514
        return new JsonModel($data);
515
 
516
    }
517
 
518
 
519
 
520
 
521
    public function deleteAction(){
8053 nelberth 522
 
523
 
524
 
7811 nelberth 525
        $currentUserPlugin = $this->plugin('currentUserPlugin');
526
        $currentCompany = $currentUserPlugin->getCompany();
527
        $currentUser = $currentUserPlugin->getUser();
528
 
529
        $request = $this->getRequest();
11083 nelberth 530
        $group_uuid = $this->params()->fromRoute('group_id');
531
        $user_uuid = $this->params()->fromRoute('user_id');
8057 nelberth 532
        if (!$group_uuid) {
533
            $data = [
534
                'success' => false,
535
                'data' => 'ERROR_INVALID_PARAMETER'
536
            ];
537
 
538
            return new JsonModel($data);
539
        }
540
 
541
        if (!$user_uuid) {
542
            $data = [
543
                'success' => false,
544
                'data' => 'ERROR_INVALID_PARAMETER'
545
            ];
546
 
547
            return new JsonModel($data);
548
        }
10328 nelberth 549
 
8057 nelberth 550
 
551
        if ($request->isPost()) {
8058 nelberth 552
 
8055 nelberth 553
            $userMapper = UserMapper::getInstance($this->adapter);
554
            $user = $userMapper->fetchOneByUuid($user_uuid);
7811 nelberth 555
 
8055 nelberth 556
            if (!$user) {
557
                $data = [
558
                    'success' => false,
559
                    'data' => 'ERROR_RECORD_NOT_FOUND'
560
                ];
7811 nelberth 561
 
8055 nelberth 562
                return new JsonModel($data);
563
            }
8059 nelberth 564
 
8055 nelberth 565
            $highPerformanceTeamsGroupsMapper = HighPerformanceTeamsGroupsMapper::getInstance($this->adapter);
566
            $highPerformanceTeamsGroups = $highPerformanceTeamsGroupsMapper->fetchOneByUuid($group_uuid);
567
 
8059 nelberth 568
            if (!$highPerformanceTeamsGroups) {
8055 nelberth 569
                $data = [
570
                    'success' => false,
571
                    'data' => 'ERROR_RECORD_NOT_FOUND'
572
                ];
573
 
574
                return new JsonModel($data);
575
            }
10328 nelberth 576
 
577
            $highPerformanceTeamsGroupsMembersMapper = HighPerformanceTeamsGroupsMembersMapper::getInstance($this->adapter);
578
            $highPerformanceTeamsGroupsMembers=$highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$user->id);
10341 nelberth 579
            if($highPerformanceTeamsGroupsMembers->user_id!=$currentUser->id){
580
 
10338 nelberth 581
                $member = $highPerformanceTeamsGroupsMembersMapper->fetchOneByGroupIdAndUserId($highPerformanceTeamsGroups->id,$currentUser->id);
11170 nelberth 582
                if(!$member){
583
                    return new JsonModel([
584
                        'success' => false,
585
                        'data' => 'ERROR_YOU_DO_NOT_HAVE_ACCESS'
586
                    ]);
587
                }
10338 nelberth 588
                if($member->type==HighPerformanceTeamsGroupsMembers::TYPE_MODERATOR||$member->type==HighPerformanceTeamsGroupsMembers::TYPE_USER){
589
                    return new JsonModel([
590
                        'success' => false,
591
                        'data' => 'ERROR_METHOD_NOT_ALLOWED'
592
                    ]);
593
                }
594
 
595
 
596
                if($highPerformanceTeamsGroupsMembers->type==HighPerformanceTeamsGroupsMembers::TYPE_CREATOR){
597
                    return new JsonModel([
598
                        'success' => false,
599
                        'data' => 'ERROR_METHOD_NOT_ALLOWED'
600
                    ]);
601
                }
10328 nelberth 602
            }
10344 nelberth 603
 
8055 nelberth 604
            $result = $highPerformanceTeamsGroupsMembersMapper->delete($highPerformanceTeamsGroupsMembers->id);
8056 nelberth 605
 
7811 nelberth 606
            if ($result) {
10345 nelberth 607
 
608
                $this->logger->info('Se borro el grupo el miembro con el email de  ' . $user->email, ['user_id' => $currentUser->id, 'ip' => Functions::getUserIP()]);
10353 nelberth 609
                if($highPerformanceTeamsGroupsMembers->user_id==$currentUser->id){
10352 nelberth 610
                    return new JsonModel([
611
                        'success' => true,
612
                        'data' => 'LABEL_RECORD_DELETED',
613
                        'reload'=>true
614
                    ]);
615
                }
616
 
10350 nelberth 617
 
7811 nelberth 618
                $data = [
619
                    'success' => true,
10352 nelberth 620
                    'data' => 'LABEL_RECORD_DELETED',
621
                    'reload'=>false
7811 nelberth 622
                ];
623
            } else {
624
 
625
                $data = [
626
                    'success' => false,
7818 nelberth 627
                    'data' => $highPerformanceTeamsGroupsMembersMapper->getError()
7811 nelberth 628
                ];
629
 
630
                return new JsonModel($data);
631
            }
632
        } else {
633
            $data = [
634
                'success' => false,
635
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
636
            ];
637
 
638
            return new JsonModel($data);
639
        }
640
 
641
        return new JsonModel($data);
642
    }
643
 
644
 
645
 
646
 
647
}