Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5732 | Rev 5775 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5732 Rev 5765
Línea 13... Línea 13...
13
use Laminas\Db\Adapter\AdapterInterface;
13
use Laminas\Db\Adapter\AdapterInterface;
14
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
14
use Laminas\Cache\Storage\Adapter\AbstractAdapter;
15
use Laminas\Mvc\Controller\AbstractActionController;
15
use Laminas\Mvc\Controller\AbstractActionController;
16
use Laminas\Log\LoggerInterface;
16
use Laminas\Log\LoggerInterface;
17
use Laminas\View\Model\JsonModel;
17
use Laminas\View\Model\JsonModel;
18
use Laminas\Paginator\Paginator;
-
 
19
use Laminas\Paginator\Adapter\DbSelect;
-
 
20
use Laminas\View\Model\ViewModel;
18
use Laminas\View\Model\ViewModel;
Línea 21... Línea 19...
21
 
19
 
22
use LeadersLinked\Library\Functions;
-
 
23
use LeadersLinked\Mapper\CompanyUserMapper;
20
use LeadersLinked\Library\Functions;
24
use LeadersLinked\Model\Post;
21
use LeadersLinked\Model\Post;
25
use LeadersLinked\Mapper\PostMapper;
-
 
26
use LeadersLinked\Mapper\GroupMapper;
22
use LeadersLinked\Mapper\PostMapper;
27
use LeadersLinked\Mapper\UserMapper;
23
use LeadersLinked\Mapper\UserMapper;
28
use LeadersLinked\Mapper\CommentMapper;
24
use LeadersLinked\Mapper\CommentMapper;
29
use LeadersLinked\Mapper\ConnectionMapper;
-
 
30
use LeadersLinked\Mapper\CompanyFollowerMapper;
-
 
31
use LeadersLinked\Mapper\QueryMapper;
-
 
32
 
-
 
33
use LeadersLinked\Mapper\LikeMapper;
-
 
34
use LeadersLinked\Model\Like;
25
use LeadersLinked\Model\ContentReaction;
35
use LeadersLinked\Model\Comment;
-
 
36
use LeadersLinked\Model\CompanyUser;
-
 
37
use LeadersLinked\Mapper\CompanyMapper;
-
 
38
use LeadersLinked\Model\Company;
-
 
39
use LeadersLinked\Model\Group;
-
 
40
use LeadersLinked\Mapper\GroupMemberMapper;
-
 
41
use LeadersLinked\Model\GroupMember;
-
 
42
use LeadersLinked\Model\Notification;
-
 
43
use LeadersLinked\Mapper\NotificationMapper;
-
 
44
use LeadersLinked\Mapper\UserNotificationSettingMapper;
-
 
45
use LeadersLinked\Mapper\EmailTemplateMapper;
-
 
46
use LeadersLinked\Model\EmailTemplate;
-
 
47
use LeadersLinked\Library\QueueEmail;
26
use LeadersLinked\Model\Comment;
48
use LeadersLinked\Mapper\UtilMapper;
27
use LeadersLinked\Mapper\UtilMapper;
-
 
28
use LeadersLinked\Form\Post\CommentForm;
Línea 49... Línea 29...
49
use LeadersLinked\Form\Post\CommentForm;
29
use LeadersLinked\Mapper\ContentReactionMapper;
50
 
30
 
Línea 158... Línea 138...
158
            $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params, ['force_canonical' => true]);
138
            $share_increment_external_counter_url = $this->url()->fromRoute('share/increment-external-counter', $share_params, ['force_canonical' => true]);
Línea 159... Línea 139...
159
 
139
 
Línea 160... Línea 140...
160
 
140
 
161
            $share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $post->uuid, 'type' => 'post'], ['force_canonical' => true]);
141
            $share_external_url = $this->url()->fromRoute('shorter/generate', ['code' => $post->uuid, 'type' => 'post'], ['force_canonical' => true]);
162
 
-
 
Línea -... Línea 142...
-
 
142
 
-
 
143
            //$contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
-
 
144
            //$like = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
-
 
145
 
-
 
146
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
163
            $likeMapper = LikeMapper::getInstance($this->adapter);
147
            $reactions = $contentReactionMapper->fetchCountContentReactionsByPostId($post->id);
164
            $like = $likeMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
148
            $reaction = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
165
 
149
            
166
 
150
            
167
            $this->layout()->setTemplate('layout/layout.phtml');
151
            $this->layout()->setTemplate('layout/layout.phtml');
Línea 182... Línea 166...
182
                'share_external_url' =>  $share_external_url,
166
                'share_external_url' =>  $share_external_url,
183
                'total_share_external' => $post->total_external_shared,
167
                'total_share_external' => $post->total_external_shared,
184
                'share_increment_external_counter_url' => $share_increment_external_counter_url,
168
                'share_increment_external_counter_url' => $share_increment_external_counter_url,
185
                'comments_url' => $this->url()->fromRoute('post/comments', ['id' => $post->uuid]),
169
                'comments_url' => $this->url()->fromRoute('post/comments', ['id' => $post->uuid]),
186
                'comments_add_url' => $this->url()->fromRoute('post/comments/add', ['id' => $post->uuid]),
170
                'comments_add_url' => $this->url()->fromRoute('post/comments/add', ['id' => $post->uuid]),
-
 
171
                'save_reaction_recommended_url' => $this->url()->fromRoute('feed/save-reaction', ['id' => $post->uuid, 'reaction' => ContentReaction::REACTION_RECOMMENDED]),
-
 
172
                'save_reaction_support_url' => $this->url()->fromRoute('feed/save-reaction', ['id' => $post->uuid, 'reaction' => ContentReaction::REACTION_SUPPORT]),
-
 
173
                'save_reaction_love_url' => $this->url()->fromRoute('feed/save-reaction', ['id' => $post->uuid, 'reaction' => ContentReaction::REACTION_LOVE]),
-
 
174
                'save_reaction_interest_url' => $this->url()->fromRoute('feed/save-reaction', ['id' => $post->uuid, 'reaction' => ContentReaction::REACTION_INTEREST]),
-
 
175
                'save_reaction_fun_url' => $this->url()->fromRoute('feed/save-reaction', ['id' => $post->uuid, 'reaction' => ContentReaction::REACTION_FUN]),
-
 
176
                'delete_reaction_url' =>  $this->url()->fromRoute('feed/delete-reaction', ['id' => $post->uuid]),
-
 
177
                'my_reaction' => $reaction ? $reaction->reaction : '',
-
 
178
                'reactions' =>  $reactions,
187
                'is_liked' => $like ? 1 : 0,
179
                //'is_liked' => $like ? 1 : 0,
188
                'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
180
                //'like_url' => $this->url()->fromRoute('post/like', ['id' => $post->uuid]),
189
                'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
181
                //'unlike_url' => $this->url()->fromRoute('post/unlike', ['id' => $post->uuid]),
Línea 190... Línea 182...
190
 
182
 
191
            ]);
183
            ]);
192
            return $viewModel;
184
            return $viewModel;
193
        } else {
185
        } else {
Línea 360... Línea 352...
360
        }
352
        }
Línea 361... Línea 353...
361
 
353
 
362
        return new JsonModel($response);
354
        return new JsonModel($response);
Línea -... Línea 355...
-
 
355
    }
363
    }
356
 
364
 
357
    /*
365
    public function likeAction()
358
    public function likeAction()
Línea 366... Línea 359...
366
    {
359
    {
Línea 380... Línea 373...
380
                    'data' => 'ERROR_POST_NOT_FOUND'
373
                    'data' => 'ERROR_POST_NOT_FOUND'
381
                ];
374
                ];
382
                return new JsonModel($response);
375
                return new JsonModel($response);
383
            }
376
            }
Línea 384... Línea 377...
384
 
377
 
385
            $likeMapper = LikeMapper::getInstance($this->adapter);
378
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
Línea 386... Línea 379...
386
            $like = $likeMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
379
            $like = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
387
 
380
 
388
            if ($like) {
381
            if ($like) {
389
                $response = [
382
                $response = [
Línea 396... Línea 389...
396
            $like = new Like();
389
            $like = new Like();
397
            $like->user_id = $currentUser->id;
390
            $like->user_id = $currentUser->id;
398
            $like->post_id = $post->id;
391
            $like->post_id = $post->id;
399
            $like->relational = Like::RELATIONAL_POST;
392
            $like->relational = Like::RELATIONAL_POST;
Línea 400... Línea 393...
400
 
393
 
Línea 401... Línea 394...
401
            if ($likeMapper->insert($like)) {
394
            if ($contentReactionMapper->insert($like)) {
402
 
395
 
403
                $likes = $likeMapper->fetchCountLikeByPostId($post->id);
396
                $likes = $contentReactionMapper->fetchCountLikeByPostId($post->id);
404
                $response = [
397
                $response = [
405
                    'success' => true,
398
                    'success' => true,
406
                    'data' => [
399
                    'data' => [
407
                        'likes' => $likes
400
                        'likes' => $likes
408
                    ]
401
                    ]
409
                ];
402
                ];
410
            } else {
403
            } else {
411
                $response = [
404
                $response = [
412
                    'success' => false,
405
                    'success' => false,
413
                    'data' => $likeMapper->getError()
406
                    'data' => $contentReactionMapper->getError()
414
                ];
407
                ];
415
            }
408
            }
Línea 440... Línea 433...
440
                    'data' => 'ERROR_POST_NOT_FOUND'
433
                    'data' => 'ERROR_POST_NOT_FOUND'
441
                ];
434
                ];
442
                return new JsonModel($response);
435
                return new JsonModel($response);
443
            }
436
            }
Línea 444... Línea 437...
444
 
437
 
445
            $likeMapper = LikeMapper::getInstance($this->adapter);
438
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
Línea 446... Línea 439...
446
            $like = $likeMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
439
            $like = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
447
 
440
 
448
            if (!$like) {
441
            if (!$like) {
449
                $response = [
442
                $response = [
450
                    'success' => false,
443
                    'success' => false,
451
                    'data' => 'ERROR_DUPLICATE_ACTION'
444
                    'data' => 'ERROR_DUPLICATE_ACTION'
452
                ];
445
                ];
Línea 453... Línea 446...
453
                return new JsonModel($response);
446
                return new JsonModel($response);
454
            }
447
            }
Línea 455... Línea 448...
455
 
448
 
456
            if ($likeMapper->deleteByPostIdAndUserId($post->id, $currentUser->id)) {
449
            if ($contentReactionMapper->deleteByPostIdAndUserId($post->id, $currentUser->id)) {
457
                $likes = $likeMapper->fetchCountLikeByPostId($post->id);
450
                $likes = $contentReactionMapper->fetchCountLikeByPostId($post->id);
Línea 464... Línea 457...
464
                    ]
457
                    ]
465
                ];
458
                ];
466
            } else {
459
            } else {
467
                $response = [
460
                $response = [
468
                    'success' => false,
461
                    'success' => false,
469
                    'data' => $likeMapper->getError()
462
                    'data' => $contentReactionMapper->getError()
470
                ];
463
                ];
471
            }
464
            }
472
            return new JsonModel($response);
465
            return new JsonModel($response);
473
        }
466
        }
Línea 474... Línea 467...
474
 
467
 
475
        $response = [
468
        $response = [
476
            'success' => false,
469
            'success' => false,
477
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
470
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
478
        ];
471
        ];
-
 
472
        return new JsonModel($response);
-
 
473
    }*/
-
 
474
    
-
 
475
    public function likeAction()
-
 
476
    {
-
 
477
        $id = $this->params()->fromRoute('id');
-
 
478
        $reaction  = $this->params()->fromRoute('reaction');
-
 
479
        
-
 
480
        $request = $this->getRequest();
-
 
481
        if ($request->isPost()) {
-
 
482
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
483
            $currentUser = $currentUserPlugin->getUser();
-
 
484
            
-
 
485
            
-
 
486
            $postMapper = PostMapper::getInstance($this->adapter);
-
 
487
            $post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
488
            if (!$post) {
-
 
489
                $response = [
-
 
490
                    'success' => false,
-
 
491
                    'data' => 'ERROR_POST_NOT_FOUND'
-
 
492
                ];
-
 
493
                return new JsonModel($response);
-
 
494
            }
-
 
495
            
-
 
496
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
-
 
497
            $contentReaction = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
-
 
498
            
-
 
499
            if ($contentReaction) {
-
 
500
                $response = [
-
 
501
                    'success' => false,
-
 
502
                    'data' => 'ERROR_DUPLICATE_ACTION'
-
 
503
                ];
-
 
504
                return new JsonModel($response);
-
 
505
            }
-
 
506
            
-
 
507
            $contentReaction = new ContentReaction();
-
 
508
            $contentReaction->user_id = $currentUser->id;
-
 
509
            $contentReaction->post_id = $post->id;
-
 
510
            $contentReaction->relational = ContentReaction::RELATIONAL_POST;
-
 
511
            $contentReaction->reaction = $reaction;
-
 
512
            
-
 
513
            if ($contentReactionMapper->insert($contentReaction)) {
-
 
514
                
-
 
515
                $reactions = $contentReactionMapper->fetchCountContentReactionsByPostId($post->id);
-
 
516
                $response = [
-
 
517
                    'success' => true,
-
 
518
                    'data' => [
-
 
519
                        'likes' => $reactions
-
 
520
                    ]
-
 
521
                ];
-
 
522
            } else {
-
 
523
                $response = [
-
 
524
                    'success' => false,
-
 
525
                    'data' => $contentReactionMapper->getError()
-
 
526
                ];
-
 
527
            }
-
 
528
            return new JsonModel($response);
-
 
529
        }
-
 
530
        
-
 
531
        $response = [
-
 
532
            'success' => false,
-
 
533
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
534
        ];
-
 
535
        return new JsonModel($response);
-
 
536
    }
-
 
537
    
-
 
538
    public function deleteAction()
-
 
539
    {
-
 
540
        $id = $this->params()->fromRoute('id');
-
 
541
        
-
 
542
        $request = $this->getRequest();
-
 
543
        if ($request->isPost()) {
-
 
544
            $currentUserPlugin = $this->plugin('currentUserPlugin');
-
 
545
            $currentUser = $currentUserPlugin->getUser();
-
 
546
            
-
 
547
            $postMapper = PostMapper::getInstance($this->adapter);
-
 
548
            $post = $postMapper->fetchOneByUuidAndNetworkId($id, $currentUser->network_id);
-
 
549
            if (!$post) {
-
 
550
                $response = [
-
 
551
                    'success' => false,
-
 
552
                    'data' => 'ERROR_POST_NOT_FOUND'
-
 
553
                ];
-
 
554
                return new JsonModel($response);
-
 
555
            }
-
 
556
            
-
 
557
            $contentReactionMapper = ContentReactionMapper::getInstance($this->adapter);
-
 
558
            $like = $contentReactionMapper->fetchOneByPostIdAndUserId($post->id, $currentUser->id);
-
 
559
            
-
 
560
            if (!$like) {
-
 
561
                $response = [
-
 
562
                    'success' => false,
-
 
563
                    'data' => 'ERROR_DUPLICATE_ACTION'
-
 
564
                ];
-
 
565
                return new JsonModel($response);
-
 
566
            }
-
 
567
            
-
 
568
            if ($contentReactionMapper->deleteByPostIdAndUserId($post->id, $currentUser->id)) {
-
 
569
                $reactions = $contentReactionMapper->fetchCountContentReactionByPostId($post->id);
-
 
570
                
-
 
571
                
-
 
572
                $response = [
-
 
573
                    'success' => true,
-
 
574
                    'data' => [
-
 
575
                        'reactions' => $reactions
-
 
576
                    ]
-
 
577
                ];
-
 
578
            } else {
-
 
579
                $response = [
-
 
580
                    'success' => false,
-
 
581
                    'data' => $contentReactionMapper->getError()
-
 
582
                ];
-
 
583
            }
-
 
584
            return new JsonModel($response);
-
 
585
        }
-
 
586
        
-
 
587
        $response = [
-
 
588
            'success' => false,
-
 
589
            'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
590
        ];
479
        return new JsonModel($response);
591
        return new JsonModel($response);
Línea 480... Línea 592...
480
    }
592
    }
481
 
593
 
482
    public function commentsAction()
594
    public function commentsAction()