Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 2614 Rev 3086
Línea 23... Línea 23...
23
use LeadersLinked\Model\ChatGroup;
23
use LeadersLinked\Model\ChatGroup;
24
use LeadersLinked\Model\ChatUser;
24
use LeadersLinked\Model\ChatUser;
25
use LeadersLinked\Form\Chat\CreateGroupForm;
25
use LeadersLinked\Form\Chat\CreateGroupForm;
26
use LeadersLinked\Mapper\ChatGroupUserMapper;
26
use LeadersLinked\Mapper\ChatGroupUserMapper;
27
use LeadersLinked\Model\ChatGroupUser;
27
use LeadersLinked\Model\ChatGroupUser;
-
 
28
use LeadersLinked\Mapper\UtilMapper;
Línea 28... Línea 29...
28
 
29
 
29
 
30
 
30
class ChatController extends AbstractActionController
31
class ChatController extends AbstractActionController
Línea 90... Línea 91...
90
        $connectionMapper = ConnectionMapper:: getInstance($this->adapter);
91
        $connectionMapper = ConnectionMapper:: getInstance($this->adapter);
91
        $connectionIds = $connectionMapper->fetchAllConnectionsByUserReturnIds( $currentUser->id );
92
        $connectionIds = $connectionMapper->fetchAllConnectionsByUserReturnIds( $currentUser->id );
Línea 92... Línea 93...
92
        
93
        
93
        $contacts = [];
94
        $contacts = [];
-
 
95
        if($connectionIds) {
-
 
96
            
-
 
97
            $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
98
            $now = $utilMapper->getDatebaseNow();
94
        if($connectionIds) {
99
            
95
            $userMapper = UserMapper::getInstance($this->adapter);
100
            $userMapper = UserMapper::getInstance($this->adapter);
Línea 96... Línea 101...
96
            $users = $userMapper->fetchAllByIds($connectionIds);
101
            $users = $userMapper->fetchAllByIds($connectionIds);
97
            
102
            
98
            foreach($users as $user)
103
            foreach($users as $user)
99
            {
-
 
100
                $username = trim($user->first_name . ' ' . $user->last_name);
-
 
101
                
-
 
102
                
104
            {
103
                if($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
104
                    $userMapper->updateChatOfflineStatus($user->id);
-
 
105
                    $status = 'Offline';
-
 
106
                } else {
-
 
107
                    $status = "Online";
-
 
108
                }
105
                $username = trim($user->first_name . ' ' . $user->last_name);
Línea 109... Línea 106...
109
                
106
                $status = $user->online ? 'LABEL_ONLINE' : 'LABEL_OFFLINE';
Línea 110... Línea 107...
110
                $user_image = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]);
107
                $user_image = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]);
Línea 347... Línea 344...
347
                $userMapper = UserMapper::getInstance($this->adapter);
344
                $userMapper = UserMapper::getInstance($this->adapter);
348
                $users = $userMapper->fetchAllByIds($connectionIds);
345
                $users = $userMapper->fetchAllByIds($connectionIds);
Línea 349... Línea 346...
349
 
346
 
350
                foreach ($users as $user) 
347
                foreach ($users as $user) 
351
                {
-
 
352
                    
-
 
353
                    
-
 
354
                    if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
355
                        $userMapper->updateChatOfflineStatus($user->id);
-
 
356
                        $online = false;
-
 
357
                    } else {
-
 
358
                        $online = true;
-
 
359
                    }
-
 
360
                    
-
 
361
         
348
                {
362
                    $chatUser = $chatUserMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
349
                    $chatUser = $chatUserMapper->fetchOneByUserId1AndUserId2($currentUser->id, $user->id);
363
                    if($chatUser) {
350
                    if($chatUser) {
364
                        $count_not_received_messages = $chatMessageMapper->countNotReceivedMessagesByChatIdAndToId($chatUser->id, $currentUser->id);
351
                        $count_not_received_messages = $chatMessageMapper->countNotReceivedMessagesByChatIdAndToId($chatUser->id, $currentUser->id);
365
                        $count_not_seen_messages = $chatMessageMapper->countNotSeenMessagesByChatIdAndToId($chatUser->id, $currentUser->id);
352
                        $count_not_seen_messages = $chatMessageMapper->countNotSeenMessagesByChatIdAndToId($chatUser->id, $currentUser->id);
Línea 403... Línea 390...
403
                        'id'                        => $user->uuid,
390
                        'id'                        => $user->uuid,
404
                        'name'                      => trim($user->first_name . ' ' . $user->last_name),
391
                        'name'                      => trim($user->first_name . ' ' . $user->last_name),
405
                        'image'                     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
392
                        'image'                     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
406
                        'profile'                   => $this->url()->fromRoute('profile/view', ['id' =>$user->uuid]),
393
                        'profile'                   => $this->url()->fromRoute('profile/view', ['id' =>$user->uuid]),
407
                        'type'                      => 'user',
394
                        'type'                      => 'user',
408
                        'online'                    => $online ? 1 : 0,
395
                        'online'                    => $user->online ? 1 : 0,
409
                        'is_open'                   => $is_open ? 1 : 0,
396
                        'is_open'                   => $is_open ? 1 : 0,
410
                        'not_seen_messages'         => $not_seen_messages,
397
                        'not_seen_messages'         => $not_seen_messages,
411
                        'not_received_messages'     => $not_received_messages,
398
                        'not_received_messages'     => $not_received_messages,
412
                        'count_not_seen_messages'       => $count_not_seen_messages,
399
                        'count_not_seen_messages'       => $count_not_seen_messages,
413
                        'count_not_received_messages'   => $count_not_received_messages,
400
                        'count_not_received_messages'   => $count_not_received_messages,
Línea 497... Línea 484...
497
                    
484
                    
498
                    $chatGroupUserMapper = ChatGroupUserMapper::getInstance($this->adapter);
485
                    $chatGroupUserMapper = ChatGroupUserMapper::getInstance($this->adapter);
Línea 499... Línea 486...
499
                    $result = $chatGroupUserMapper->insert($chatGroupUser);
486
                    $result = $chatGroupUserMapper->insert($chatGroupUser);
-
 
487
                    
-
 
488
                    if($result)  {
-
 
489
                        
-
 
490
                        $userMapper = UserMapper::getInstance($this->adapter);
500
                    
491
                        $userMapper->updateLastActivity($currentUser->id);
501
                    if($result)  {
492
                        
502
                        $fullpath_chat = $this->config['leaderslinked.fullpath.chat'];
493
                        $fullpath_chat = $this->config['leaderslinked.fullpath.chat'];
503
                        $dirpath = $fullpath_chat . $chatGroup->uuid;
494
                        $dirpath = $fullpath_chat . $chatGroup->uuid;
504
                        if (! file_exists($dirpath)) {
495
                        if (! file_exists($dirpath)) {
Línea 666... Línea 657...
666
                    'success' => false,
657
                    'success' => false,
667
                    'data' => $chatGroupUserMapper->getError()
658
                    'data' => $chatGroupUserMapper->getError()
668
                ]);
659
                ]);
669
            }
660
            }
Línea 670... Línea -...
670
            
-
 
671
            if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
672
                $userMapper->updateChatOfflineStatus($user->id);
-
 
673
                $online = false;
-
 
674
            } else {
-
 
675
                $online = true;
661
            
676
            }
662
                  
-
 
663
           
Línea 677... Línea 664...
677
                                    
664
            $userMapper->updateLastActivity($currentUser->id);
678
                                    
665
                                    
679
            return new JsonModel([
666
            return new JsonModel([
680
                'success' => true,
667
                'success' => true,
681
                'data' => [
668
                'data' => [
682
                    'url_remove_from_group' => $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid]),
669
                    'url_remove_from_group' => $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid]),
683
                    'id'        => $user->uuid,
670
                    'id'        => $user->uuid,
684
                    'name'      => trim($user->first_name . ' ' . $user->last_name),
671
                    'name'      => trim($user->first_name . ' ' . $user->last_name),
685
                    'image'     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
672
                    'image'     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
686
                    'type'      => 'user',
673
                    'type'      => 'user',
687
                    'online'    => $online,
674
                    'online'    => $user->online ? 1 : 0,
Línea 688... Línea 675...
688
                ]
675
                ]
Línea 782... Línea 769...
782
            }
769
            }
Línea 783... Línea 770...
783
            
770
            
784
 
771
 
-
 
772
            $response = $chatGroupUserMapper->deleteByGroupIdAndUserId($chatGroup->id, $user->id);
-
 
773
            if($response) {
785
            $response = $chatGroupUserMapper->deleteByGroupIdAndUserId($chatGroup->id, $user->id);
774
                $userMapper->updateLastActivity($currentUser->id);
786
            if($response) {
775
                
787
                return new JsonModel([
776
                return new JsonModel([
788
                    'success' => true
777
                    'success' => true
789
                ]);
778
                ]);
Línea 864... Línea 853...
864
            }
853
            }
Línea 865... Línea 854...
865
            
854
            
866
            
855
            
-
 
856
            $result = $chatGroupUserMapper->deleteByGroupIdAndUserId($chatGroupUser->group_id, $chatGroupUser->user_id);
-
 
857
            if($result) {
-
 
858
                
-
 
859
                $userMapper = UserMapper::getInstance($this->adapter);
867
            $result = $chatGroupUserMapper->deleteByGroupIdAndUserId($chatGroupUser->group_id, $chatGroupUser->user_id);
860
                $userMapper->updateLastActivity($currentUser->id);
868
            if($result) {
861
                
869
                return new JsonModel([
862
                return new JsonModel([
870
                    'success' => true
863
                    'success' => true
871
                ]);
864
                ]);
Línea 920... Línea 913...
920
        
913
        
921
        $items = [];
914
        $items = [];
922
        $users = [];
915
        $users = [];
Línea -... Línea 916...
-
 
916
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
917
        
-
 
918
        $utilMapper = UtilMapper::getInstance($this->adapter);
923
        $userMapper = UserMapper::getInstance($this->adapter);
919
        $now = $utilMapper->getDatebaseNow();
924
        
920
        
Línea 925... Línea 921...
925
        foreach ($paginator as $m) 
921
        foreach ($paginator as $m) 
926
        {
922
        {
Línea 942... Línea 938...
942
                $content = $this->sanitize($m->content);
938
                $content = $this->sanitize($m->content);
943
            } else {
939
            } else {
944
                $content = $this->url()->fromRoute('storage', ['code' => $chatGroup->uuid, 'type' => 'chat', 'filename' => $m->content]);
940
                $content = $this->url()->fromRoute('storage', ['code' => $chatGroup->uuid, 'type' => 'chat', 'filename' => $m->content]);
945
            }
941
            }
Línea -... Línea 942...
-
 
942
            
-
 
943
            
946
            
944
            
947
            $msgtime = $this->timeAgo($m->added_on);
945
            $msgtime = $this->timeAgo($m->added_on, $now);
948
            array_push($items, [
946
            array_push($items, [
949
                'user_name' => trim($userdata_from->first_name . ' ' .$userdata_from->last_name) ,
947
                'user_name' => trim($userdata_from->first_name . ' ' .$userdata_from->last_name) ,
950
                'user_id' => $userdata_from->uuid,
948
                'user_id' => $userdata_from->uuid,
951
                'user_image' => $pic_from,
949
                'user_image' => $pic_from,
Línea 991... Línea 989...
991
        
989
        
992
        $items = [];
990
        $items = [];
993
        $users = [];
991
        $users = [];
Línea -... Línea 992...
-
 
992
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
993
        
-
 
994
        $utilMapper = UtilMapper::getInstance($this->adapter);
994
        $userMapper = UserMapper::getInstance($this->adapter);
995
        $now = $utilMapper->getDatebaseNow();
995
        
996
        
996
        $messages = $paginator->getCurrentItems();
997
        $messages = $paginator->getCurrentItems();
997
        foreach ($messages as $m) {
998
        foreach ($messages as $m) {
Línea 1030... Línea 1031...
1030
                $content = $this->sanitize($m->content);
1031
                $content = $this->sanitize($m->content);
1031
            } else {
1032
            } else {
1032
                $content = $this->url()->fromRoute('storage', ['code' => $chatUser->uuid, 'type' => 'chat', 'filename' => $m->content]);
1033
                $content = $this->url()->fromRoute('storage', ['code' => $chatUser->uuid, 'type' => 'chat', 'filename' => $m->content]);
1033
            }
1034
            }
Línea 1034... Línea 1035...
1034
            
1035
            
1035
            $msgtime = $this->timeAgo($m->added_on);
1036
            $msgtime = $this->timeAgo($m->added_on, $now);
1036
            array_push($items, [
1037
            array_push($items, [
1037
                'user_name' => ($userdata_from->first_name . ' ' . $userdata_from->last_name),
1038
                'user_name' => ($userdata_from->first_name . ' ' . $userdata_from->last_name),
1038
                'user_id' => $userdata_from->uuid,
1039
                'user_id' => $userdata_from->uuid,
1039
                'user_image' => $pic_from,
1040
                'user_image' => $pic_from,
Línea 1045... Línea 1046...
1045
                'seen' => $seen,
1046
                'seen' => $seen,
1046
            ]);
1047
            ]);
1047
        }
1048
        }
Línea 1048... Línea -...
1048
        
-
 
1049
        
-
 
1050
        if ($this->isInactiveConnection($currentUser->last_heart_beat_at ? $currentUser->last_heart_beat_at : '')) {
-
 
1051
            $userMapper->updateChatOfflineStatus($currentUser->id);
-
 
1052
            $online = false;
-
 
1053
        } else {
1049
        
Línea 1054... Línea 1050...
1054
            $online = true;
1050
        
1055
        }
1051
        
1056
        
1052
        
1057
        
1053
        
1058
        return [
1054
        return [
1059
            'success' => true,
1055
            'success' => true,
1060
            'data' => [
1056
            'data' => [
1061
                'page' => $page,
1057
                'page' => $page,
1062
                'pages' => $pages,
1058
                'pages' => $pages,
1063
                'items' => $items,
1059
                'items' => $items,
Línea 1064... Línea 1060...
1064
                'online' => $online
1060
                'online' => $currentUser->online ? 1 : 0,
Línea 1306... Línea 1302...
1306
                                'data' => $chatGroupUserMessageMapper->getError()
1302
                                'data' => $chatGroupUserMessageMapper->getError()
1307
                            ]);
1303
                            ]);
1308
                        }
1304
                        }
1309
                    }
1305
                    }
1310
                }
1306
                }
-
 
1307
                
-
 
1308
                $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
1309
                $now = $utilMapper->getDatebaseNow();
Línea 1311... Línea 1310...
1311
                    
1310
                    
1312
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
1311
                $msgtime = $this->timeAgo($now, $now);
1313
                return new JsonModel([
1312
                return new JsonModel([
1314
                    'success' => true,
1313
                    'success' => true,
1315
                    'data' => [
1314
                    'data' => [
1316
                        'user_name'         => $sender_name,
1315
                        'user_name'         => $sender_name,
Línea 1391... Línea 1390...
1391
                        'data' => $chatMessageMapper->getError()
1390
                        'data' => $chatMessageMapper->getError()
1392
                    ]);
1391
                    ]);
1393
                }
1392
                }
Línea 1394... Línea 1393...
1394
                
1393
                
-
 
1394
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
-
 
1395
                
-
 
1396
                $utilMapper = UtilMapper::getInstance($this->adapter);
Línea 1395... Línea 1397...
1395
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
1397
                $now = $utilMapper->getDatebaseNow();
1396
 
1398
 
1397
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
1399
                $msgtime = $this->timeAgo($now, $now);
1398
                return new JsonModel([
1400
                return new JsonModel([
1399
                    'success' => true,
1401
                    'success' => true,
1400
                    'data' => [
1402
                    'data' => [
Línea 1409... Línea 1411...
1409
                    ]
1411
                    ]
1410
                 ]); 
1412
                 ]); 
Línea 1411... Línea 1413...
1411
 
1413
 
-
 
1414
                
-
 
1415
            }
-
 
1416
            
1412
                
1417
            $userMapper->updateLastActivity($currentUser->id);
Línea 1413... Línea 1418...
1413
            }
1418
            
1414
            return new JsonModel($response);
1419
            return new JsonModel($response);
1415
        
1420
        
Línea 1510... Línea 1515...
1510
                $image  = $this->url()->fromRoute('storage', [
1515
                $image  = $this->url()->fromRoute('storage', [
1511
                    'code' => $user->uuid,
1516
                    'code' => $user->uuid,
1512
                    'type' => 'user',
1517
                    'type' => 'user',
1513
                    'filename' => $user->image
1518
                    'filename' => $user->image
1514
                ]);
1519
                ]);
1515
 
-
 
1516
                    
-
 
1517
                if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
1518
                    $userMapper->updateChatOfflineStatus($user->id);
-
 
1519
                    $online = false;
-
 
1520
                } else {
-
 
1521
                    $online = true;
-
 
1522
                }
-
 
Línea 1523... Línea 1520...
1523
                
1520
                
1524
 
1521
 
1525
                array_push($items, [
1522
                array_push($items, [
1526
                    'id'        => $user->uuid,
1523
                    'id'        => $user->uuid,
1527
                    'name'      => $name,
1524
                    'name'      => $name,
1528
                    'image'     => $image,
1525
                    'image'     => $image,
1529
                    'online'    => $online,
1526
                    'online'    => $user->online ? 1 : 0,
Línea -... Línea 1527...
-
 
1527
                ]);
-
 
1528
            } 
-
 
1529
            
1530
                ]);
1530
            
1531
            } 
1531
 
1532
            
1532
            $userMapper->updateLastActivity($currentUser->id);
1533
            
1533
            
Línea 1640... Línea 1640...
1640
                    
1640
                    
1641
                } else {
1641
                } else {
1642
                    $url_remove_from_group = $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid ]);
1642
                    $url_remove_from_group = $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid ]);
Línea 1643... Línea -...
1643
                }
-
 
1644
                    
-
 
1645
 
-
 
1646
                if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
1647
                    $userMapper->updateChatOfflineStatus($user->id);
-
 
1648
                    $online = false;
-
 
1649
                } else {
-
 
Línea 1650... Línea 1643...
1650
                    $online = true;
1643
                }
1651
                }
1644
                    
1652
                    
1645
                    
1653
                array_push($items, [
1646
                array_push($items, [
1654
                    'url_remove_from_group' => $url_remove_from_group,
1647
                    'url_remove_from_group' => $url_remove_from_group,
1655
                    'id'                    => $user->uuid,
1648
                    'id'                    => $user->uuid,
1656
                    'name'                  => $name,
1649
                    'name'                  => $name,
Línea 1657... Línea 1650...
1657
                    'image'                 => $image,
1650
                    'image'                 => $image,
-
 
1651
                    'online'                => $user->online ? 1 : 0,
-
 
1652
                ]);
Línea 1658... Línea 1653...
1658
                    'online'                => $online,
1653
                    
1659
                ]);
1654
            }
1660
                    
1655
 
1661
            }
1656
            $userMapper->updateLastActivity($currentUser->id);
Línea 1769... Línea 1764...
1769
            $fullpath_chat = $this->config['leaderslinked.fullpath.chat'];
1764
            $fullpath_chat = $this->config['leaderslinked.fullpath.chat'];
1770
            $dirpath = $fullpath_chat . $chatGroup->uuid;
1765
            $dirpath = $fullpath_chat . $chatGroup->uuid;
Línea 1771... Línea 1766...
1771
                        
1766
                        
Línea -... Línea 1767...
-
 
1767
            Functions::rmDirRecursive($dirpath);
-
 
1768
                        
-
 
1769
            
-
 
1770
            $userMapper = UserMapper::getInstance($this->adapter);
1772
            Functions::rmDirRecursive($dirpath);
1771
            $userMapper->updateLastActivity($currentUser->id);
1773
                        
1772
            
1774
            return new JsonModel([
1773
            return new JsonModel([
Línea 1846... Línea 1845...
1846
            if($uuid) {
1845
            if($uuid) {
1847
                $_SESSION[self::SESSION_CHAT_OPEN_BOXES] = array_filter($_SESSION[self::SESSION_CHAT_OPEN_BOXES], function($var) use($uuid)  {
1846
                $_SESSION[self::SESSION_CHAT_OPEN_BOXES] = array_filter($_SESSION[self::SESSION_CHAT_OPEN_BOXES], function($var) use($uuid)  {
1848
                    return $uuid != $var;
1847
                    return $uuid != $var;
1849
                });
1848
                });
1850
            }
1849
            }
-
 
1850
            
-
 
1851
 
-
 
1852
            $userMapper->updateLastActivity($currentUser->id);
Línea 1851... Línea 1853...
1851
              
1853
              
1852
            return new JsonModel([
1854
            return new JsonModel([
1853
                'success' => true
1855
                'success' => true
1854
            ]);
1856
            ]);
Línea 1922... Línea 1924...
1922
                $_SESSION[self::SESSION_CHAT_OPEN_BOXES] = array_filter($_SESSION[self::SESSION_CHAT_OPEN_BOXES], function($var) use($uuid)  {
1924
                $_SESSION[self::SESSION_CHAT_OPEN_BOXES] = array_filter($_SESSION[self::SESSION_CHAT_OPEN_BOXES], function($var) use($uuid)  {
1923
                    return $uuid != $var;
1925
                    return $uuid != $var;
1924
                });
1926
                });
1925
            }
1927
            }
Línea -... Línea 1928...
-
 
1928
            
-
 
1929
 
-
 
1930
            $userMapper->updateLastActivity($currentUser->id);
1926
            
1931
            
1927
            return new JsonModel([
1932
            return new JsonModel([
1928
                'success' => true
1933
                'success' => true
1929
            ]);
1934
            ]);
1930
        } else {
1935
        } else {
Línea 2080... Línea 2085...
2080
                        }
2085
                        }
Línea 2081... Línea 2086...
2081
                        
2086
                        
2082
             
2087
             
-
 
2088
                    }
-
 
2089
                }
-
 
2090
                
-
 
2091
  
-
 
2092
                $userMapper->updateLastActivity($currentUser->id);
-
 
2093
                
Línea 2083... Línea 2094...
2083
                    }
2094
                $utilMapper = UtilMapper::getInstance($this->adapter);
2084
                }
2095
                $now = $utilMapper->getDatebaseNow();
2085
                            
2096
                            
2086
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
2097
                $msgtime = $this->timeAgo($now, $now);
2087
                return new JsonModel([
2098
                return new JsonModel([
2088
                    'success' => true,
2099
                    'success' => true,
Línea 2153... Línea 2164...
2153
                    ]);
2164
                    ]);
2154
                }
2165
                }
Línea 2155... Línea 2166...
2155
                
2166
                
Línea -... Línea 2167...
-
 
2167
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
-
 
2168
                
-
 
2169
                $userMapper->updateLastActivity($currentUser->id);
-
 
2170
                
Línea 2156... Línea 2171...
2156
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
2171
                $utilMapper = UtilMapper::getInstance($this->adapter);
2157
                
2172
                $now = $utilMapper->getDatebaseNow();
2158
                
2173
                
2159
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
2174
                $msgtime = $this->timeAgo($chatMessage->added_on, $now);
2160
                return new JsonModel([
2175
                return new JsonModel([
2161
                    'success' => true,
2176
                    'success' => true,
Línea 2426... Línea 2441...
2426
    }
2441
    }
Línea 2427... Línea 2442...
2427
 
2442
 
2428
    /**
2443
    /**
2429
     * 
2444
     * 
-
 
2445
     * @param string $timestamp
2430
     * @param string $timestamp
2446
     * @param string $now
2431
     * @return string
2447
     * @return string
2432
     */
2448
     */
2433
    private function timeAgo($timestamp)
2449
    private function timeAgo($timestamp, $now = '')
-
 
2450
    {
-
 
2451
    
-
 
2452
        if($now) {
-
 
2453
            $datetime1 = \DateTime::createFromFormat('Y-m-d H:i:s', $now); 
-
 
2454
        } else {
2434
    {
2455
            $now = date('Y-m-d H:i:s');
-
 
2456
            $datetime1 = date_create($now);
2435
        $datetime1 = new \DateTime("now");
2457
        }
-
 
2458
        $datetime2 = date_create($timestamp);
2436
        $datetime2 = date_create($timestamp);
2459
 
2437
        $diff = date_diff($datetime1, $datetime2);
2460
        $diff = date_diff($datetime1, $datetime2);
2438
        $timemsg = '';
2461
        $timemsg = '';
2439
        if ($diff->y > 0) {
2462
        if ($diff->y > 0) {
2440
            $timemsg = $diff->y . ' año' . ($diff->y > 1 ? "s" : '');
2463
            $timemsg = $diff->y . ' año' . ($diff->y > 1 ? "s" : '');
Línea 2458... Línea 2481...
2458
    }
2481
    }
Línea 2459... Línea 2482...
2459
 
2482
 
2460
    /**
2483
    /**
2461
     * 
2484
     * 
-
 
2485
     * @param string $timestamp
2462
     * @param string $timestamp
2486
     * @param string $now
2463
     * @return boolean
2487
     * @return boolean
2464
     */
2488
     */
2465
    private function isInactiveConnection($timestamp)
2489
    private function isInactiveConnection($timestamp, $now = '')
-
 
2490
    {
-
 
2491
        if($now) {
-
 
2492
            $datetime1 = \DateTime::createFromFormat('Y-m-d H:i:s', $now);
-
 
2493
        } else {
-
 
2494
            $now = date('Y-m-d H:i:s');
-
 
2495
            $datetime1 = date_create($now);
-
 
2496
        }
-
 
2497
        
2466
    {
2498
        
2467
        if (empty($timestamp)) {
2499
        if (empty($timestamp)) {
2468
            return true;
2500
            return true;
Línea 2469... Línea -...
2469
        }
-
 
2470
 
-
 
-
 
2501
        }
2471
        $now = date('Y-m-d H:i:s');
2502
 
2472
        $datetime1 = date_create($now);
2503
      
Línea 2473... Línea 2504...
2473
        $datetime2 = date_create($timestamp);
2504
        $datetime2 = date_create($timestamp);
2474
        $diff = date_diff($datetime1, $datetime2);
2505
        $diff = date_diff($datetime1, $datetime2);