Proyectos de Subversion LeadersLinked - Backend

Rev

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

Rev 12666 Rev 14590
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\CreateChatGroupForm;
25
use LeadersLinked\Form\CreateChatGroupForm;
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 96... Línea 97...
96
            $users = $userMapper->fetchAllByIds($connectionIds);
97
            $users = $userMapper->fetchAllByIds($connectionIds);
Línea 97... Línea 98...
97
            
98
            
98
            foreach($users as $user)
99
            foreach($users as $user)
99
            {
100
            {
100
                $username = trim($user->first_name . ' ' . $user->last_name);
-
 
101
                
-
 
102
                
-
 
103
                if($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
101
                $username = trim($user->first_name . ' ' . $user->last_name);
104
                    $userMapper->updateChatOfflineStatus($user->id);
-
 
105
                    $status = 'Offline';
-
 
106
                } else {
-
 
107
                    $status = "Online";
-
 
108
                }
-
 
109
                
102
                $status = $user->online ? 'Online' : 'Offline';
Línea 110... Línea 103...
110
                $user_image = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]);
103
                $user_image = $this->url()->fromRoute('storage', ['type' => 'user', 'code' => $user->uuid, 'filename' => $user->image]);
Línea 111... Línea 104...
111
                
104
                
Línea 336... Línea 329...
336
                $userMapper = UserMapper::getInstance($this->adapter);
329
                $userMapper = UserMapper::getInstance($this->adapter);
337
                $users = $userMapper->fetchAllByIds($connectionIds);
330
                $users = $userMapper->fetchAllByIds($connectionIds);
Línea 338... Línea 331...
338
                
331
                
339
                foreach ($users as $user) 
332
                foreach ($users as $user) 
340
                {
-
 
341
                    
333
                {
342
                   
-
 
343
                    if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
344
                        $userMapper->updateChatOfflineStatus($user->id);
-
 
345
                        $online = false;
-
 
346
                    } else {
-
 
347
                        $online = true;
-
 
Línea 348... Línea 334...
348
                    }
334
 
Línea 373... Línea 359...
373
                        'id'                        => $user->uuid,
359
                        'id'                        => $user->uuid,
374
                        'name'                      => trim($user->first_name . ' ' . $user->last_name),
360
                        'name'                      => trim($user->first_name . ' ' . $user->last_name),
375
                        'image'                     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
361
                        'image'                     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
376
                        /*'profile'                   => $this->url()->fromRoute('profile/view', ['id' =>$user->uuid]),*/
362
                        /*'profile'                   => $this->url()->fromRoute('profile/view', ['id' =>$user->uuid]),*/
377
                        'type'                      => 'user',
363
                        'type'                      => 'user',
378
                        'online'                    => $online ? 1 : 0,
364
                        'online'                    => $user->online ? 1 : 0,
379
                        'is_open'                   => $is_open ? 1 : 0,
365
                        'is_open'                   => $is_open ? 1 : 0,
380
                        'not_seen_messages'         => $not_seen_messages,
366
                        'not_seen_messages'         => $not_seen_messages,
381
                        'not_received_messages'     => $not_received_messages,
367
                        'not_received_messages'     => $not_received_messages,
382
                    ];
368
                    ];
Línea 637... Línea 623...
637
                    'success' => false,
623
                    'success' => false,
638
                    'data' => $chatGroupUserMapper->getError()
624
                    'data' => $chatGroupUserMapper->getError()
639
                ]);
625
                ]);
640
            }
626
            }
Línea 641... Línea -...
641
            
-
 
642
            if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
643
                $userMapper->updateChatOfflineStatus($user->id);
-
 
644
                $online = false;
-
 
645
            } else {
-
 
646
                $online = true;
627
            
Línea 647... Línea 628...
647
            }
628
           
648
                                    
629
                                    
649
                                    
630
                                    
650
            return new JsonModel([
631
            return new JsonModel([
651
                'success' => true,
632
                'success' => true,
652
                'data' => [
633
                'data' => [
653
                    'url_remove_from_group' => $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid]),
634
                    'url_remove_from_group' => $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid]),
654
                    'id'        => $user->uuid,
635
                    'id'        => $user->uuid,
655
                    'name'      => trim($user->first_name . ' ' . $user->last_name),
636
                    'name'      => trim($user->first_name . ' ' . $user->last_name),
656
                    'image'     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
637
                    'image'     => $this->url()->fromRoute('storage', ['code' => $user->uuid, 'type' => 'user', 'filename' => $user->image]),
657
                    'type'      => 'user',
638
                    'type'      => 'user',
Línea 658... Línea 639...
658
                    'online'    => $online,
639
                    'online'    => $user->online,
Línea 901... Línea 882...
901
        
882
        
902
        $items = [];
883
        $items = [];
903
        $users = [];
884
        $users = [];
Línea -... Línea 885...
-
 
885
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
886
        
-
 
887
        $utilMapper = UtilMapper::getInstance($this->adapter);
904
        $userMapper = UserMapper::getInstance($this->adapter);
888
        $now = $utilMapper->getDatebaseNow();
905
        
889
        
Línea 906... Línea 890...
906
        foreach ($paginator as $m) 
890
        foreach ($paginator as $m) 
907
        {
891
        {
Línea 923... Línea 907...
923
                $content = $this->sanitize($m->content);
907
                $content = $this->sanitize($m->content);
924
            } else {
908
            } else {
925
                $content = $this->url()->fromRoute('storage', ['code' => $chatGroup->uuid, 'type' => 'chat', 'filename' => $m->content]);
909
                $content = $this->url()->fromRoute('storage', ['code' => $chatGroup->uuid, 'type' => 'chat', 'filename' => $m->content]);
926
            }
910
            }
Línea 927... Línea 911...
927
            
911
            
928
            $msgtime = $this->timeAgo($m->added_on);
912
            $msgtime = $this->timeAgo($m->added_on, $now);
929
            array_push($items, [
913
            array_push($items, [
930
                'user_name' => trim($userdata_from->first_name . ' ' .$userdata_from->last_name) ,
914
                'user_name' => trim($userdata_from->first_name . ' ' .$userdata_from->last_name) ,
931
                'user_id' => $userdata_from->uuid,
915
                'user_id' => $userdata_from->uuid,
932
                'user_image' => $pic_from,
916
                'user_image' => $pic_from,
Línea 972... Línea 956...
972
        
956
        
973
        $items = [];
957
        $items = [];
974
        $users = [];
958
        $users = [];
Línea -... Línea 959...
-
 
959
        $userMapper = UserMapper::getInstance($this->adapter);
-
 
960
        
-
 
961
        $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
962
        $now = $utilMapper->getDatebaseNow();
975
        $userMapper = UserMapper::getInstance($this->adapter);
963
        
976
        
964
        
977
        $messages = $paginator->getCurrentItems();
965
        $messages = $paginator->getCurrentItems();
978
        foreach ($messages as $m) {
966
        foreach ($messages as $m) {
Línea 1006... Línea 994...
1006
                $content = $this->sanitize($m->content);
994
                $content = $this->sanitize($m->content);
1007
            } else {
995
            } else {
1008
                $content = $this->url()->fromRoute('storage', ['code' => $chatUser->uuid, 'type' => 'chat', 'filename' => $m->content]);
996
                $content = $this->url()->fromRoute('storage', ['code' => $chatUser->uuid, 'type' => 'chat', 'filename' => $m->content]);
1009
            }
997
            }
Línea -... Línea 998...
-
 
998
            
-
 
999
            
1010
            
1000
            
1011
            $msgtime = $this->timeAgo($m->added_on);
1001
            $msgtime = $this->timeAgo($m->added_on, $now);
1012
            array_push($items, [
1002
            array_push($items, [
1013
                'user_name' => ($userdata_from->first_name . ' ' . $userdata_from->last_name),
1003
                'user_name' => ($userdata_from->first_name . ' ' . $userdata_from->last_name),
1014
                'user_id' => $userdata_from->uuid,
1004
                'user_id' => $userdata_from->uuid,
1015
                'user_image' => $pic_from,
1005
                'user_image' => $pic_from,
Línea 1019... Línea 1009...
1019
                'time' => $msgtime,
1009
                'time' => $msgtime,
1020
                'id' => $m->uuid,
1010
                'id' => $m->uuid,
1021
            ]);
1011
            ]);
1022
        }
1012
        }
Línea 1023... Línea 1013...
1023
        
1013
        
1024
        
-
 
1025
        if ($this->isInactiveConnection($currentUser->last_heart_beat_at ? $currentUser->last_heart_beat_at : '')) {
-
 
1026
            $userMapper->updateChatOfflineStatus($currentUser->id);
-
 
1027
            $online = false;
-
 
1028
        } else {
-
 
1029
            $online = true;
-
 
Línea 1030... Línea 1014...
1030
        }
1014
 
1031
        
1015
        
1032
        
1016
        
1033
        return [
1017
        return [
1034
            'success' => true,
1018
            'success' => true,
1035
            'data' => [
1019
            'data' => [
1036
                'page' => $page,
1020
                'page' => $page,
1037
                'pages' => $pages,
1021
                'pages' => $pages,
1038
                'items' => $items,
1022
                'items' => $items,
1039
                'online' => $online
1023
                'online' => 1
Línea 1040... Línea 1024...
1040
            ]
1024
            ]
Línea 1201... Línea 1185...
1201
                    'success' => false,
1185
                    'success' => false,
1202
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
1186
                    'data' => 'ERROR_PARAMETERS_ARE_INVALID'
1203
                ]);
1187
                ]);
1204
            } 
1188
            } 
Línea -... Línea 1189...
-
 
1189
            
-
 
1190
            $utilMapper = UtilMapper::getInstance($this->adapter);
-
 
1191
            $now = $utilMapper->getDatebaseNow();
1205
            
1192
            
1206
            $currentUserPlugin = $this->plugin('currentUserPlugin');
1193
            $currentUserPlugin = $this->plugin('currentUserPlugin');
Línea 1207... Línea 1194...
1207
            $currentUser = $currentUserPlugin->getUser();
1194
            $currentUser = $currentUserPlugin->getUser();
1208
            
1195
            
Línea 1282... Línea 1269...
1282
                            ]);
1269
                            ]);
1283
                        }
1270
                        }
1284
                    }
1271
                    }
1285
                }
1272
                }
Línea 1286... Línea 1273...
1286
                    
1273
                    
1287
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
1274
                $msgtime = $this->timeAgo($now, $now);
1288
                return new JsonModel([
1275
                return new JsonModel([
1289
                    'success' => true,
1276
                    'success' => true,
1290
                    'data' => [
1277
                    'data' => [
1291
                        'user_name'         => $sender_name,
1278
                        'user_name'         => $sender_name,
Línea 1367... Línea 1354...
1367
                    ]);
1354
                    ]);
1368
                }
1355
                }
Línea 1369... Línea 1356...
1369
                
1356
                
Línea 1370... Línea 1357...
1370
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
1357
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
1371
 
1358
 
1372
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
1359
                $msgtime = $this->timeAgo($chatMessage->added_on, $now);
1373
                return new JsonModel([
1360
                return new JsonModel([
1374
                    'success' => true,
1361
                    'success' => true,
1375
                    'data' => [
1362
                    'data' => [
Línea 1486... Línea 1473...
1486
                    'code' => $user->uuid,
1473
                    'code' => $user->uuid,
1487
                    'type' => 'user',
1474
                    'type' => 'user',
1488
                    'filename' => $user->image
1475
                    'filename' => $user->image
1489
                ]);
1476
                ]);
Línea 1490... Línea 1477...
1490
 
1477
 
1491
                    
-
 
1492
                if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
1493
                    $userMapper->updateChatOfflineStatus($user->id);
-
 
1494
                    $online = false;
-
 
1495
                } else {
-
 
1496
                    $online = true;
-
 
Línea 1497... Línea 1478...
1497
                }
1478
 
1498
                
1479
                
1499
 
1480
 
1500
                array_push($items, [
1481
                array_push($items, [
1501
                    'id'        => $user->uuid,
1482
                    'id'        => $user->uuid,
1502
                    'name'      => $name,
1483
                    'name'      => $name,
1503
                    'image'     => $image,
1484
                    'image'     => $image,
Línea 1504... Línea 1485...
1504
                    'online'    => $online,
1485
                    'online'    => $user->online,
Línea 1616... Línea 1597...
1616
                } else {
1597
                } else {
1617
                    $url_remove_from_group = $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid ]);
1598
                    $url_remove_from_group = $this->url()->fromRoute('chat/remove-user-from-group', ['group_id' => $chatGroup->uuid, 'user_id' => $user->uuid ]);
1618
                }
1599
                }
Línea 1619... Línea -...
1619
                    
-
 
1620
 
-
 
1621
                if ($this->isInactiveConnection($user->last_heart_beat_at ? $user->last_heart_beat_at : '')) {
-
 
1622
                    $userMapper->updateChatOfflineStatus($user->id);
-
 
1623
                    $online = false;
-
 
1624
                } else {
-
 
-
 
1600
                    
Línea 1625... Línea 1601...
1625
                    $online = true;
1601
 
1626
                }
1602
 
1627
                    
1603
                    
1628
                array_push($items, [
1604
                array_push($items, [
1629
                    'url_remove_from_group' => $url_remove_from_group,
1605
                    'url_remove_from_group' => $url_remove_from_group,
1630
                    'id'                    => $user->uuid,
1606
                    'id'                    => $user->uuid,
1631
                    'name'                  => $name,
1607
                    'name'                  => $name,
Línea 1632... Línea 1608...
1632
                    'image'                 => $image,
1608
                    'image'                 => $image,
Línea 1633... Línea 1609...
1633
                    'online'                => $online,
1609
                    'online'                => $user->online,
Línea 2055... Línea 2031...
2055
                        }
2031
                        }
Línea 2056... Línea 2032...
2056
                        
2032
                        
2057
             
2033
             
-
 
2034
                    }
-
 
2035
                }
-
 
2036
                
Línea 2058... Línea 2037...
2058
                    }
2037
                $utilMapper = UtilMapper::getInstance($this->adapter);
2059
                }
2038
                $now = $utilMapper->getDatebaseNow();
2060
                            
2039
                            
2061
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
2040
                $msgtime = $this->timeAgo($now, $now);
2062
                return new JsonModel([
2041
                return new JsonModel([
2063
                    'success' => true,
2042
                    'success' => true,
Línea 2128... Línea 2107...
2128
                    ]);
2107
                    ]);
2129
                }
2108
                }
Línea 2130... Línea 2109...
2130
                
2109
                
Línea -... Línea 2110...
-
 
2110
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
-
 
2111
                
Línea 2131... Línea 2112...
2131
                $chatMessage = $chatMessageMapper->fetchOne($chatMessage->id);
2112
                $utilMapper = UtilMapper::getInstance($this->adapter);
2132
                
2113
                $now = $utilMapper->getDatebaseNow();
2133
                
2114
                
2134
                $msgtime = $this->timeAgo(date('Y-m-d H:i:s'));
2115
                $msgtime = $this->timeAgo($chatMessage->added_on, $now);
2135
                return new JsonModel([
2116
                return new JsonModel([
2136
                    'success' => true,
2117
                    'success' => true,
Línea 2399... Línea 2380...
2399
        $text = str_replace("\n", "<br>", $text);
2380
        $text = str_replace("\n", "<br>", $text);
2400
        return $text;
2381
        return $text;
2401
    }
2382
    }
Línea 2402... Línea 2383...
2402
 
2383
 
2403
    /**
2384
    /**
2404
     * 
2385
     *
-
 
2386
     * @param string $timestamp
2405
     * @param string $timestamp
2387
     * @param string $now
2406
     * @return string
2388
     * @return string
2407
     */
2389
     */
2408
    private function timeAgo($timestamp)
2390
    private function timeAgo($timestamp, $now = '')
-
 
2391
    {
-
 
2392
        
-
 
2393
        if($now) {
-
 
2394
            $datetime1 = \DateTime::createFromFormat('Y-m-d H:i:s', $now);
-
 
2395
        } else {
2409
    {
2396
            $now = date('Y-m-d H:i:s');
-
 
2397
            $datetime1 = date_create($now);
2410
        $datetime1 = new \DateTime("now");
2398
        }
-
 
2399
        $datetime2 = date_create($timestamp);
2411
        $datetime2 = date_create($timestamp);
2400
        
2412
        $diff = date_diff($datetime1, $datetime2);
2401
        $diff = date_diff($datetime1, $datetime2);
2413
        $timemsg = '';
2402
        $timemsg = '';
2414
        if ($diff->y > 0) {
2403
        if ($diff->y > 0) {
2415
            $timemsg = $diff->y . ' anio' . ($diff->y > 1 ? "s" : '');
2404
            $timemsg = $diff->y . ' año' . ($diff->y > 1 ? "s" : '');
2416
        } else if ($diff->m > 0) {
2405
        } else if ($diff->m > 0) {
2417
            $timemsg = $diff->m . ' mes' . ($diff->m > 1 ? "s" : '');
2406
            $timemsg = $diff->m . ' mes' . ($diff->m > 1 ? "es" : '');
2418
        } else if ($diff->d > 0) {
2407
        } else if ($diff->d > 0) {
2419
            $timemsg = $diff->d . ' dia' . ($diff->d > 1 ? "s" : '');
2408
            $timemsg = $diff->d . ' dia' . ($diff->d > 1 ? "s" : '');
2420
        } else if ($diff->h > 0) {
2409
        } else if ($diff->h > 0) {
2421
            $timemsg = $diff->h . ' hora' . ($diff->h > 1 ? "s" : '');
2410
            $timemsg = $diff->h . ' hora' . ($diff->h > 1 ? "s" : '');