|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
8
|
|
|
|
|
9
|
|
|
use Chamilo\CoreBundle\Repository\ResourceNodeRepository; |
|
10
|
|
|
use Chamilo\CoreBundle\Traits\ControllerTrait; |
|
11
|
|
|
use Chamilo\CoreBundle\Traits\CourseControllerTrait; |
|
12
|
|
|
use Chamilo\CoreBundle\Traits\ResourceControllerTrait; |
|
13
|
|
|
use Chamilo\CourseBundle\Controller\CourseControllerInterface; |
|
14
|
|
|
use Chamilo\CourseBundle\Repository\CChatConversationRepository; |
|
15
|
|
|
use CourseChatUtils; |
|
16
|
|
|
use Event; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
20
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
21
|
|
|
|
|
22
|
|
|
class ChatController extends AbstractResourceController implements CourseControllerInterface |
|
23
|
|
|
{ |
|
24
|
|
|
use ControllerTrait; |
|
25
|
|
|
use CourseControllerTrait; |
|
26
|
|
|
use ResourceControllerTrait; |
|
27
|
|
|
|
|
28
|
|
|
#[Route(path: '/resources/chat/', name: 'chat_home', options: ['expose' => true])] |
|
29
|
|
|
public function index(): Response |
|
30
|
|
|
{ |
|
31
|
|
|
Event::event_access_tool(TOOL_CHAT); |
|
|
|
|
|
|
32
|
|
|
$logInfo = [ |
|
33
|
|
|
'tool' => TOOL_CHAT, |
|
34
|
|
|
'action' => 'start', |
|
35
|
|
|
'action_details' => 'start-chat', |
|
36
|
|
|
]; |
|
37
|
|
|
Event::registerLog($logInfo); |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
return $this->render( |
|
40
|
|
|
'@ChamiloCore/Chat/chat.html.twig', |
|
41
|
|
|
[ |
|
42
|
|
|
'restrict_to_coach' => ('true' === api_get_setting('chat.course_chat_restrict_to_coach')), |
|
43
|
|
|
'user' => api_get_user_info(), |
|
44
|
|
|
] |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
#[Route(path: '/resources/chat/conversations/', name: 'chat_ajax', options: ['expose' => true])] |
|
49
|
|
|
public function ajax(Request $request, ResourceNodeRepository $repo): Response |
|
50
|
|
|
{ |
|
51
|
|
|
if (!api_protect_course_script(false)) { |
|
52
|
|
|
exit; |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** @var CChatConversationRepository $resourceRepo */ |
|
56
|
|
|
$resourceRepo = $this->getRepository('chat', 'conversations'); |
|
57
|
|
|
|
|
58
|
|
|
$courseId = api_get_course_int_id(); |
|
59
|
|
|
$userId = api_get_user_id(); |
|
60
|
|
|
$sessionId = api_get_session_id(); |
|
61
|
|
|
$groupId = api_get_group_id(); |
|
62
|
|
|
$json = [ |
|
63
|
|
|
'status' => false, |
|
64
|
|
|
]; |
|
65
|
|
|
$parentResourceNode = $this->getParentResourceNode($request); |
|
66
|
|
|
|
|
67
|
|
|
$courseChatUtils = new CourseChatUtils( |
|
68
|
|
|
$courseId, |
|
69
|
|
|
$userId, |
|
70
|
|
|
$sessionId, |
|
71
|
|
|
$groupId, |
|
72
|
|
|
$parentResourceNode, |
|
73
|
|
|
$resourceRepo |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$action = $request->get('action'); |
|
77
|
|
|
|
|
78
|
|
|
switch ($action) { |
|
79
|
|
|
case 'chat_logout': |
|
80
|
|
|
$logInfo = [ |
|
81
|
|
|
'tool' => TOOL_CHAT, |
|
82
|
|
|
'action' => 'exit', |
|
83
|
|
|
'action_details' => 'exit-chat', |
|
84
|
|
|
]; |
|
85
|
|
|
Event::registerLog($logInfo); |
|
86
|
|
|
|
|
87
|
|
|
break; |
|
88
|
|
|
|
|
89
|
|
|
case 'track': |
|
90
|
|
|
$courseChatUtils->keepUserAsConnected(); |
|
91
|
|
|
$courseChatUtils->disconnectInactiveUsers(); |
|
92
|
|
|
|
|
93
|
|
|
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
|
94
|
|
|
// $filePath = $courseChatUtils->getFileName(true, $friend); |
|
95
|
|
|
// $newFileSize = file_exists($filePath) ? filesize($filePath) : 0; |
|
96
|
|
|
// $oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1; |
|
97
|
|
|
$newUsersOnline = $courseChatUtils->countUsersOnline(); |
|
98
|
|
|
$oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; |
|
99
|
|
|
|
|
100
|
|
|
$json = [ |
|
101
|
|
|
'status' => true, |
|
102
|
|
|
'data' => [ |
|
103
|
|
|
// 'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, |
|
104
|
|
|
'oldFileSize' => false, |
|
105
|
|
|
'history' => $courseChatUtils->readMessages(false, $friend), |
|
106
|
|
|
'usersOnline' => $newUsersOnline, |
|
107
|
|
|
'userList' => $newUsersOnline !== $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, |
|
108
|
|
|
'currentFriend' => $friend, |
|
109
|
|
|
], |
|
110
|
|
|
]; |
|
111
|
|
|
|
|
112
|
|
|
break; |
|
113
|
|
|
|
|
114
|
|
|
case 'preview': |
|
115
|
|
|
$json = [ |
|
116
|
|
|
'status' => true, |
|
117
|
|
|
'data' => [ |
|
118
|
|
|
'message' => $courseChatUtils->prepareMessage($_REQUEST['message']), |
|
119
|
|
|
], |
|
120
|
|
|
]; |
|
121
|
|
|
|
|
122
|
|
|
break; |
|
123
|
|
|
|
|
124
|
|
|
case 'reset': |
|
125
|
|
|
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
|
126
|
|
|
|
|
127
|
|
|
$json = [ |
|
128
|
|
|
'status' => true, |
|
129
|
|
|
'data' => $courseChatUtils->readMessages(true, $friend), |
|
130
|
|
|
]; |
|
131
|
|
|
|
|
132
|
|
|
break; |
|
133
|
|
|
|
|
134
|
|
|
case 'write': |
|
135
|
|
|
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
|
136
|
|
|
$status = $courseChatUtils->saveMessage($_REQUEST['message'], $friend); |
|
137
|
|
|
|
|
138
|
|
|
$json = [ |
|
139
|
|
|
'status' => $status, |
|
140
|
|
|
'data' => [ |
|
141
|
|
|
'writed' => $status, |
|
142
|
|
|
], |
|
143
|
|
|
]; |
|
144
|
|
|
|
|
145
|
|
|
break; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
return new JsonResponse($json); |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.