parent
45d6994726
commit
0f570fd0b2
@ -1,85 +0,0 @@ |
|||||||
<?php |
|
||||||
/* For licensing terms, see /license.txt */ |
|
||||||
/** |
|
||||||
* Responses to AJAX calls for course chat. |
|
||||||
*/ |
|
||||||
require_once __DIR__.'/../global.inc.php'; |
|
||||||
|
|
||||||
if (!api_protect_course_script(false)) { |
|
||||||
exit; |
|
||||||
} |
|
||||||
|
|
||||||
$courseId = api_get_course_int_id(); |
|
||||||
$userId = api_get_user_id(); |
|
||||||
$sessionId = api_get_session_id(); |
|
||||||
$groupId = api_get_group_id(); |
|
||||||
$json = ['status' => false]; |
|
||||||
|
|
||||||
$courseChatUtils = new CourseChatUtils($courseId, $userId, $sessionId, $groupId); |
|
||||||
|
|
||||||
switch ($_REQUEST['action']) { |
|
||||||
case 'chat_logout': |
|
||||||
$logInfo = [ |
|
||||||
'tool' => TOOL_CHAT, |
|
||||||
'tool_id' => 0, |
|
||||||
'tool_id_detail' => 0, |
|
||||||
'action' => 'exit', |
|
||||||
'action_details' => 'exit-chat', |
|
||||||
'info' => '', |
|
||||||
]; |
|
||||||
Event::registerLog($logInfo); |
|
||||||
break; |
|
||||||
case 'track': |
|
||||||
$courseChatUtils->keepUserAsConnected(); |
|
||||||
$courseChatUtils->disconnectInactiveUsers(); |
|
||||||
|
|
||||||
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
|
||||||
$filePath = $courseChatUtils->getFileName(true, $friend); |
|
||||||
$newFileSize = file_exists($filePath) ? filesize($filePath) : 0; |
|
||||||
$oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1; |
|
||||||
$newUsersOnline = $courseChatUtils->countUsersOnline(); |
|
||||||
$oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; |
|
||||||
|
|
||||||
$json = [ |
|
||||||
'status' => true, |
|
||||||
'data' => [ |
|
||||||
'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, |
|
||||||
'history' => $newFileSize !== $oldFileSize ? $courseChatUtils->readMessages(false, $friend) : null, |
|
||||||
'usersOnline' => $newUsersOnline, |
|
||||||
'userList' => $newUsersOnline != $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, |
|
||||||
'currentFriend' => $friend, |
|
||||||
], |
|
||||||
]; |
|
||||||
|
|
||||||
break; |
|
||||||
case 'preview': |
|
||||||
$json = [ |
|
||||||
'status' => true, |
|
||||||
'data' => [ |
|
||||||
'message' => CourseChatUtils::prepareMessage($_REQUEST['message']), |
|
||||||
], |
|
||||||
]; |
|
||||||
break; |
|
||||||
case 'reset': |
|
||||||
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
|
||||||
|
|
||||||
$json = [ |
|
||||||
'status' => true, |
|
||||||
'data' => $courseChatUtils->readMessages(true, $friend), |
|
||||||
]; |
|
||||||
break; |
|
||||||
case 'write': |
|
||||||
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
|
||||||
$writed = $courseChatUtils->saveMessage($_POST['message'], $friend); |
|
||||||
|
|
||||||
$json = [ |
|
||||||
'status' => $writed, |
|
||||||
'data' => [ |
|
||||||
'writed' => $writed, |
|
||||||
], |
|
||||||
]; |
|
||||||
break; |
|
||||||
} |
|
||||||
|
|
||||||
header('Content-Type: application/json'); |
|
||||||
echo json_encode($json); |
|
||||||
@ -0,0 +1,145 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\CoreBundle\Controller; |
||||||
|
|
||||||
|
use Chamilo\CoreBundle\Repository\ResourceNodeRepository; |
||||||
|
use Chamilo\CourseBundle\Controller\CourseControllerInterface; |
||||||
|
use Chamilo\CourseBundle\Controller\CourseControllerTrait; |
||||||
|
use Chamilo\CourseBundle\Repository\CChatConversationRepository; |
||||||
|
use Event; |
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse; |
||||||
|
use Symfony\Component\HttpFoundation\Request; |
||||||
|
use Symfony\Component\HttpFoundation\Response; |
||||||
|
use Symfony\Component\Routing\Annotation\Route; |
||||||
|
|
||||||
|
/** |
||||||
|
* Class ChatController. |
||||||
|
*/ |
||||||
|
class ChatController extends AbstractResourceController implements CourseControllerInterface |
||||||
|
{ |
||||||
|
use CourseControllerTrait; |
||||||
|
|
||||||
|
/** |
||||||
|
* @Route("/resources/chat/", name="chat_home", options={"expose"=true}) |
||||||
|
*/ |
||||||
|
public function indexAction(Request $request): Response |
||||||
|
{ |
||||||
|
Event::event_access_tool(TOOL_CHAT); |
||||||
|
|
||||||
|
$logInfo = [ |
||||||
|
'tool' => TOOL_CHAT, |
||||||
|
'action' => 'start', |
||||||
|
'action_details' => 'start-chat', |
||||||
|
]; |
||||||
|
Event::registerLog($logInfo); |
||||||
|
|
||||||
|
return $this->render( |
||||||
|
'@ChamiloTheme/Chat/chat.html.twig', |
||||||
|
[ |
||||||
|
'restrict_to_coach' => api_get_configuration_value('course_chat_restrict_to_coach'), |
||||||
|
'user' => api_get_user_info(), |
||||||
|
] |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @Route("/resources/chat/conversations/", name="chat_ajax", options={"expose"=true}) |
||||||
|
*/ |
||||||
|
public function ajaxAction(Request $request, ResourceNodeRepository $repo): Response |
||||||
|
{ |
||||||
|
if (!api_protect_course_script(false)) { |
||||||
|
exit; |
||||||
|
} |
||||||
|
|
||||||
|
/** @var CChatConversationRepository $resourceRepo */ |
||||||
|
$resourceRepo = $this->getRepository('chat', 'conversations'); |
||||||
|
|
||||||
|
$courseId = api_get_course_int_id(); |
||||||
|
$userId = api_get_user_id(); |
||||||
|
$sessionId = api_get_session_id(); |
||||||
|
$groupId = api_get_group_id(); |
||||||
|
$json = ['status' => false]; |
||||||
|
$parentResourceNode = $this->getParentResourceNode($request); |
||||||
|
|
||||||
|
$courseChatUtils = new \CourseChatUtils( |
||||||
|
$courseId, |
||||||
|
$userId, |
||||||
|
$sessionId, |
||||||
|
$groupId, |
||||||
|
$parentResourceNode, |
||||||
|
$resourceRepo |
||||||
|
); |
||||||
|
|
||||||
|
$action = $request->get('action'); |
||||||
|
|
||||||
|
switch ($action) { |
||||||
|
case 'chat_logout': |
||||||
|
$logInfo = [ |
||||||
|
'tool' => TOOL_CHAT, |
||||||
|
'action' => 'exit', |
||||||
|
'action_details' => 'exit-chat', |
||||||
|
]; |
||||||
|
Event::registerLog($logInfo); |
||||||
|
|
||||||
|
break; |
||||||
|
case 'track': |
||||||
|
$courseChatUtils->keepUserAsConnected(); |
||||||
|
$courseChatUtils->disconnectInactiveUsers(); |
||||||
|
|
||||||
|
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||||||
|
//$filePath = $courseChatUtils->getFileName(true, $friend); |
||||||
|
//$newFileSize = file_exists($filePath) ? filesize($filePath) : 0; |
||||||
|
//$oldFileSize = isset($_GET['size']) ? (int) $_GET['size'] : -1; |
||||||
|
$newUsersOnline = $courseChatUtils->countUsersOnline(); |
||||||
|
$oldUsersOnline = isset($_GET['users_online']) ? (int) $_GET['users_online'] : 0; |
||||||
|
|
||||||
|
$json = [ |
||||||
|
'status' => true, |
||||||
|
'data' => [ |
||||||
|
//'oldFileSize' => file_exists($filePath) ? filesize($filePath) : 0, |
||||||
|
'oldFileSize' => false, |
||||||
|
'history' => $courseChatUtils->readMessages(false, $friend), |
||||||
|
'usersOnline' => $newUsersOnline, |
||||||
|
'userList' => $newUsersOnline != $oldUsersOnline ? $courseChatUtils->listUsersOnline() : null, |
||||||
|
'currentFriend' => $friend, |
||||||
|
], |
||||||
|
]; |
||||||
|
|
||||||
|
break; |
||||||
|
case 'preview': |
||||||
|
$json = [ |
||||||
|
'status' => true, |
||||||
|
'data' => [ |
||||||
|
'message' => CourseChatUtils::prepareMessage($_REQUEST['message']), |
||||||
|
], |
||||||
|
]; |
||||||
|
|
||||||
|
break; |
||||||
|
case 'reset': |
||||||
|
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||||||
|
|
||||||
|
$json = [ |
||||||
|
'status' => true, |
||||||
|
'data' => $courseChatUtils->readMessages(true, $friend), |
||||||
|
]; |
||||||
|
|
||||||
|
break; |
||||||
|
case 'write': |
||||||
|
$friend = isset($_REQUEST['friend']) ? (int) $_REQUEST['friend'] : 0; |
||||||
|
$status = $courseChatUtils->saveMessage($_REQUEST['message'], $friend); |
||||||
|
|
||||||
|
$json = [ |
||||||
|
'status' => $status, |
||||||
|
'data' => [ |
||||||
|
'writed' => $status, |
||||||
|
], |
||||||
|
]; |
||||||
|
|
||||||
|
break; |
||||||
|
} |
||||||
|
|
||||||
|
return new JsonResponse($json); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,81 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\CourseBundle\Entity; |
||||||
|
|
||||||
|
use Chamilo\CoreBundle\Entity\Resource\AbstractResource; |
||||||
|
use Chamilo\CoreBundle\Entity\Resource\ResourceInterface; |
||||||
|
use Doctrine\ORM\Mapping as ORM; |
||||||
|
|
||||||
|
/** |
||||||
|
* CChatConversation. |
||||||
|
* |
||||||
|
* @ORM\Table(name="c_chat_conversation") |
||||||
|
* @ORM\Entity |
||||||
|
*/ |
||||||
|
class CChatConversation extends AbstractResource implements ResourceInterface |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @var int |
||||||
|
* |
||||||
|
* @ORM\Column(name="id", type="integer") |
||||||
|
* @ORM\Id |
||||||
|
* @ORM\GeneratedValue |
||||||
|
*/ |
||||||
|
protected $id; |
||||||
|
|
||||||
|
/** |
||||||
|
* @var string |
||||||
|
* |
||||||
|
* @ORM\Column(name="name", type="string", length=255, nullable=true) |
||||||
|
*/ |
||||||
|
protected $name; |
||||||
|
|
||||||
|
public function __toString(): string |
||||||
|
{ |
||||||
|
return $this->getName(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return int |
||||||
|
*/ |
||||||
|
public function getId(): int |
||||||
|
{ |
||||||
|
return $this->id; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getName(): string |
||||||
|
{ |
||||||
|
return $this->name; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @param string $name |
||||||
|
* |
||||||
|
* @return CChatConversation |
||||||
|
*/ |
||||||
|
public function setName(string $name): CChatConversation |
||||||
|
{ |
||||||
|
$this->name = $name; |
||||||
|
|
||||||
|
return $this; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Resource identifier. |
||||||
|
*/ |
||||||
|
public function getResourceIdentifier(): int |
||||||
|
{ |
||||||
|
return $this->getId(); |
||||||
|
} |
||||||
|
|
||||||
|
public function getResourceName(): string |
||||||
|
{ |
||||||
|
return $this->getName(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,54 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/* For licensing terms, see /license.txt */ |
||||||
|
|
||||||
|
namespace Chamilo\CourseBundle\Repository; |
||||||
|
|
||||||
|
use APY\DataGridBundle\Grid\Column\Column; |
||||||
|
use APY\DataGridBundle\Grid\Grid; |
||||||
|
use Chamilo\CoreBundle\Component\Utils\ResourceSettings; |
||||||
|
use Chamilo\CoreBundle\Entity\Course; |
||||||
|
use Chamilo\CoreBundle\Entity\Resource\ResourceNode; |
||||||
|
use Chamilo\CoreBundle\Entity\Session; |
||||||
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
||||||
|
use Chamilo\CoreBundle\Repository\ResourceRepositoryInterface; |
||||||
|
use Chamilo\CourseBundle\Entity\CGroupInfo; |
||||||
|
use Chamilo\UserBundle\Entity\User; |
||||||
|
use Doctrine\ORM\QueryBuilder; |
||||||
|
use Symfony\Component\Form\FormInterface; |
||||||
|
use Symfony\Component\HttpFoundation\File\UploadedFile; |
||||||
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
||||||
|
|
||||||
|
final class CChatConversationRepository extends ResourceRepository implements ResourceRepositoryInterface |
||||||
|
{ |
||||||
|
public function getResourceSettings(): ResourceSettings |
||||||
|
{ |
||||||
|
$settings = new ResourceSettings(); |
||||||
|
$settings |
||||||
|
->setAllowNodeCreation(false) |
||||||
|
->setAllowResourceCreation(false) |
||||||
|
->setAllowResourceUpload(false) |
||||||
|
; |
||||||
|
|
||||||
|
return $settings; |
||||||
|
} |
||||||
|
|
||||||
|
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder |
||||||
|
{ |
||||||
|
return $this->getResourcesByCourse($course, $session, $group, $parentNode); |
||||||
|
} |
||||||
|
|
||||||
|
public function saveUpload(UploadedFile $file) |
||||||
|
{ |
||||||
|
throw new AccessDeniedException(); |
||||||
|
} |
||||||
|
|
||||||
|
public function saveResource(FormInterface $form, $course, $session, $fileType) |
||||||
|
{ |
||||||
|
} |
||||||
|
|
||||||
|
public function getTitleColumn(Grid $grid): Column |
||||||
|
{ |
||||||
|
return $grid->getColumn('name'); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue