src/Controller/UserController.php line 363

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pusher\Pusher;
  4. use App\Entity\Role;
  5. use App\Entity\User;
  6. use App\Entity\Report;
  7. use DateTimeImmutable;
  8. use GuzzleHttp\Client;
  9. use App\Entity\Message;
  10. use App\Entity\Payment;
  11. use App\Entity\Platform;
  12. use App\Entity\WaitMessage;
  13. use App\Entity\Conversation;
  14. use App\Controller\NotificationController;
  15. use App\DBAL\MultiDbConnectionWrapper;
  16. use Psr\Log\LoggerInterface;
  17. use App\Service\EntityService;
  18. use App\Service\PusherService;
  19. use App\Service\ProfileService;
  20. use App\Service\RequestService;
  21. use App\Service\EntityValidator;
  22. use App\Service\LanguageService;
  23. use App\Service\SupAndOpService;
  24. use App\Repository\GifRepository;
  25. use Symfony\Component\Mime\Email;
  26. use App\Repository\NoteRepository;
  27. use App\Repository\RoleRepository;
  28. use App\Repository\UserRepository;
  29. use App\Service\PaginationService;
  30. use Symfony\Component\Yaml\Dumper;
  31. use App\Service\sendMessageService;
  32. use App\Service\WaitMessageService;
  33. use App\Repository\ProfilRepository;
  34. use App\Repository\ReportRepository;
  35. use App\Repository\MeetingRepository;
  36. use App\Repository\MessageRepository;
  37. use App\Repository\PaymentRepository;
  38. use App\Service\MessageOnHoldService;
  39. use App\Repository\LanguageRepository;
  40. use App\Repository\PlatformRepository;
  41. use App\Service\ReceiveMessageService;
  42. use App\Service\EntityValidatorService;
  43. use App\Repository\ProfilTypeRepository;
  44. use Doctrine\ORM\EntityManagerInterface;
  45. use App\Repository\InformationRepository;
  46. use App\Repository\MessageTypeRepository;
  47. use App\Repository\WaitMessageRepository;
  48. use App\Repository\ConversationRepository;
  49. use App\Repository\PhotoRequestRepository;
  50. use Symfony\Component\HttpFoundation\Request;
  51. use Symfony\Component\Mailer\MailerInterface;
  52. use Symfony\Component\HttpFoundation\Response;
  53. use Symfony\Component\Routing\Annotation\Route;
  54. use App\Repository\MessageTeaserOrHoldRepository;
  55. use App\Repository\SentMessageTeaserOrHoldRepository;
  56. use Symfony\Component\Serializer\SerializerInterface;
  57. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  58. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  59. use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
  60. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  61. use App\Repository\PhotoRepository;
  62. use App\Repository\TypeMessageRepository;
  63. use App\Repository\RateRepository;
  64. #[Route('/api'name'api_')]
  65. class UserController extends AbstractController
  66. {
  67.     private $notificationController;
  68.     private $photoRepository;
  69.     private $paymentRepository;
  70.     private $receiveMessageService;
  71.     private $jwtTokenManager;
  72.     private $userRepository;
  73.     private $userPasswordHasherInterface;
  74.     private $roleRepository;
  75.     private $gifRepository;
  76.     private $entityManagerInterface;
  77.     private $entityValidatorService;
  78.     private $profilRepository;
  79.     private $requestService;
  80.     private $conversationRepository;
  81.     private $profileService;
  82.     private $pusherService;
  83.     private $profilTypeRepository;
  84.     private $messageRepository;
  85.     private $serializer;
  86.     private $waitMessageRepository;
  87.     private $photoRequestRepository;
  88.     private $waitMessageService;
  89.     private $entityService;
  90.     private $reportRepository;
  91.     private $logger;
  92.     private $messageOnHoldService;
  93.     private $sendMessageService;
  94.     private $languageRepository;
  95.     private const ADMIN 'administrator';
  96.     private const SUPERVISOR 'supervisor';
  97.     private const OPERATOR 'operator';
  98.     private const QC 'qualitycontroller';
  99.     private const ACCOUNTANT 'accountant';
  100.     private $platformRepository;
  101.     private $languageService;
  102.     private $tokenStorageInterface;
  103.     private $paginator;
  104.     private $sentMessageTeaserOrHoldRepository;
  105.     private $messageTeaserOrHoldRepository;
  106.     private $messageTypeRepository;
  107.     private $sendPusherService;
  108.     private $noteRepository;
  109.     private $meetingRepository;
  110.     private $informationRepository;
  111.     private $typeMessageRepository;
  112.     private $rateRepository;
  113.     public function __construct(RateRepository $rateRepositoryNotificationController $notificationController,TypeMessageRepository $typeMessageRepositoryPhotoRepository $photoRepositoryInformationRepository $informationRepositoryMeetingRepository $meetingRepositoryPaymentRepository $paymentRepositoryNoteRepository $noteRepositorySupAndOpService $sendPusherServicePaginationService $paginatorMessageTeaserOrHoldRepository $messageTeaserOrHoldRepositorySentMessageTeaserOrHoldRepository $sentMessageTeaserOrHoldRepositoryMessageTypeRepository $messageTypeRepositoryReceiveMessageService $receiveMessageServiceJWTTokenManagerInterface $jwtTokenManagerPhotoRequestRepository $photoRequestRepositoryGifRepository $gifRepositoryUserRepository $userRepositoryWaitMessageRepository $waitMessageRepository,  UserPasswordHasherInterface $userPasswordHasherInterface,  RoleRepository $roleRepositoryEntityManagerInterface $entityManagerInterfaceEntityValidatorService $entityValidatorServiceProfilRepository $profilRepositoryMessageRepository $messageRepositoryRequestService $requestServiceConversationRepository $conversationRepositoryProfilTypeRepository $profilTypeRepository,  ProfileService $profileServiceSerializerInterface $serializerPusherService $pusherServiceWaitMessageService $waitMessageServiceEntityService $entityServiceReportRepository $reportRepositoryLoggerInterface $loggerMessageOnHoldService $messageOnHoldServiceSendMessageService $sendMessageServiceLanguageRepository $languageRepositoryPlatformRepository $platformRepositoryLanguageService $languageServiceTokenStorageInterface $tokenStorageInterface)
  114.     {
  115.         $this->notificationController $notificationController;
  116.         $this->photoRepository $photoRepository;
  117.         $this->paymentRepository $paymentRepository;
  118.         $this->messageTypeRepository $messageTypeRepository;
  119.         $this->messageTeaserOrHoldRepository $messageTeaserOrHoldRepository;
  120.         $this->sentMessageTeaserOrHoldRepository $sentMessageTeaserOrHoldRepository;
  121.         $this->jwtTokenManager $jwtTokenManager;
  122.         $this->receiveMessageService $receiveMessageService;
  123.         $this->userRepository $userRepository;
  124.         $this->userPasswordHasherInterface $userPasswordHasherInterface;
  125.         $this->roleRepository $roleRepository;
  126.         $this->entityManagerInterface $entityManagerInterface;
  127.         $this->entityValidatorService $entityValidatorService;
  128.         $this->profilRepository $profilRepository;
  129.         $this->requestService $requestService;
  130.         $this->conversationRepository $conversationRepository;
  131.         $this->profileService $profileService;
  132.         $this->profilTypeRepository $profilTypeRepository;
  133.         $this->messageRepository $messageRepository;
  134.         $this->serializer $serializer;
  135.         $this->waitMessageRepository $waitMessageRepository;
  136.         $this->gifRepository $gifRepository;
  137.         $this->photoRequestRepository $photoRequestRepository;
  138.         $this->pusherService $pusherService;
  139.         $this->waitMessageService $waitMessageService;
  140.         $this->entityService $entityService;
  141.         $this->reportRepository $reportRepository;
  142.         $this->logger $logger;
  143.         $this->messageOnHoldService $messageOnHoldService;
  144.         $this->sendMessageService $sendMessageService;
  145.         $this->languageRepository $languageRepository;
  146.         $this->platformRepository $platformRepository;
  147.         $this->languageService $languageService;
  148.         $this->tokenStorageInterface $tokenStorageInterface;
  149.         $this->paginator $paginator;
  150.         $this->sendPusherService $sendPusherService;
  151.         $this->noteRepository $noteRepository;
  152.         $this->meetingRepository $meetingRepository;
  153.         $this->informationRepository $informationRepository;
  154.         $this->typeMessageRepository $typeMessageRepository;
  155.         $this->rateRepository $rateRepository;
  156.     }
  157.     /**
  158.      * API pour la connexion dans un text moding en fonction du rôle
  159.      * 
  160.      */
  161.     #[Route('/login'name'login'methods: ['POST'])]
  162.     public function login(Request $request)
  163.     {
  164.         [$mail$password$role ] =  $this->requestService->getFromDataRequestBody('mail''password''role');
  165.         
  166.         $user $this->userRepository->findOneBy(['mail' => $mail]);
  167.         if (!$user) return $this->json(['message' => 'Email non trouvé'], Response::HTTP_BAD_REQUEST);
  168.         if ($role != $user->getRoles()[0]) return $this->json(['message' => 'Role non autorisé'], Response::HTTP_UNAUTHORIZED);
  169.         if (!$this->userPasswordHasherInterface->isPasswordValid($user$password)) {
  170.             return $this->json(['message' => 'Mot de passe invalide'], Response::HTTP_FORBIDDEN);
  171.         }
  172.         $currentDate = new \DateTimeImmutable();
  173.         $userSuspendDate $user->getSuspend();
  174.         $userDeleted $user->isDeleted();
  175.         if ($userSuspendDate != null) {
  176.             if ($userSuspendDate $currentDate) {
  177.                 return $this->json(['date' => $userSuspendDate'message' => 'Votre compte a été suspendu pendant 7 jours vous ne pouvez pas accédez'], 403);
  178.             }
  179.         }
  180.         if ($userDeleted == true) {
  181.             return $this->json(['message' => 'Utilisateur renvoyer'], Response::HTTP_UNAUTHORIZED);
  182.         }
  183.         $user->setStatus('free');
  184.         $user->setConv(NULL);
  185.         $user->setAnswer(true);
  186.         $token $this->jwtTokenManager->create($user);
  187.         $this->entityService->saveEntity($user);
  188.         $this->pusherService->createPusher();
  189.         $this->pusherService->triggerEvent('private-conversation''status', [
  190.             'id' => $user->getId(),
  191.             'status' => $user->getStatus()
  192.         ]);
  193.         // changement de statistic new design
  194.         $languageName $user->getLanguage()->getName();
  195.         $statistic2 = [
  196.             "name" => "agents",
  197.             "language" => $languageName,
  198.             "field" => "online",
  199.             "value" => 1
  200.         ];
  201.         // statistic
  202.         $statistic = [
  203.             "name" => "operator",
  204.             "field" => "online",
  205.             "value" => 1
  206.         ];
  207.         $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($languageName);
  208.         foreach ($usersToRealTime as $userReal) {
  209.             $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statistic2);
  210.             $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  211.         }
  212.         return $this->json(['token' => $token"role" => $user->getRoles()[0], "userId" => $user->getId(), "userName" => $user->getName(), 'status' => $user->getStatus(), 'languageName' => $user->getLanguage()->getName(),'accessareas' => json_decode($user->getAccessareas())],  Response::HTTP_OK);
  213.     }
  214.     #[Route('/pusher/user-auth'name"pusher_user_auth"methods: ["GET"])]
  215.     public function userAuth(Request $requestSerializerInterface $serializer)
  216.     {
  217.         $socketId $request->query->get('socket_id');
  218.         $channelName $request->query->get('channel_name');
  219.         $callback $request->query->get('callback');
  220.         $user = [
  221.             'id' => 'id0',
  222.             'channel' => $channelName,
  223.             'user_info' => [
  224.                 'name' => 'test',
  225.             ],
  226.             'watchlist' => ['another_id_1''another_id_2']
  227.         ];
  228.         $pusher $this->pusherService->createPusher();
  229.         if ($socketId) {
  230.             $user json_encode($user);
  231.             $auth $pusher->authorizeChannel($channelName$socketId$user);
  232.             $output $callback "(" $auth ");";
  233.             return new Response($output200);
  234.         } else {
  235.             return $this->json('no id'400);
  236.         }
  237.     }
  238.     /**
  239.      * API pour s'inscrire au text moding
  240.      */
  241.     #[Route('/register'name'register'methods: ['POST'])]
  242.     public function register()
  243.     {
  244.         $userRole $this->getUser();
  245.         if (!$userRole){
  246.             return $this->json(["message" => "Vous n'êtes pas connecté"], 401);
  247.         }
  248.         
  249.         [$email$password$roleName$login$name$country$languageName$paymentName$bankName$iban$bic$paymentMail$fullName$fullAddress$companyname$folder$accessareas$validity] =  $this->requestService->getFromDataRequestBody('mail''password''role''login''name''country''languageName''paymentName''bankname''iban''bic''paymail''fullName''fullAddress''company''folder''accessarea''validity');
  250.         $users $this->userRepository->findOneBy(['login' => $login'mail' => $email]);
  251.         if ($users) return $this->json(['error' => 'Login ou mail déjà utiliser'Response::HTTP_CONFLICT]);
  252.         $allowedRoles = ['operator''supervisor''administrator''accountant''qualitycontroller'];
  253.         $this->languageService->handleEmptyRepository();
  254.         $language $this->languageRepository->findOneBy(['name' => $languageName]);
  255.         if (!in_array($roleName$allowedRoles)) {
  256.             return $this->json(['error' => 'Role non trouvé'], Response::HTTP_NOT_FOUND);
  257.         }
  258.         $role $this->roleRepository->findOneBy(['name' => $roleName]);
  259.         // $folder = $this->platformRepository->findOneBy(['id' => $tmfolder]);
  260.         if (!$role) {
  261.             $role = new Role();
  262.             $role->setName($roleName);
  263.             $this->entityManagerInterface->persist($role);
  264.         }
  265.         if ($role->getName() == 'operator') {
  266.             $payment $this->paymentRepository->findOneBy(['Name' => $paymentName]);
  267.             if (!$payment) {
  268.                 $payment = new Payment();
  269.                 $payment->setName($paymentName);
  270.                 $this->entityManagerInterface->persist($payment);
  271.             }
  272.         }
  273.         $user = new User();
  274.         $hashedPassword $this->userPasswordHasherInterface->hashPassword($user$password);
  275.         $user->setMail($email);
  276.         $user->setLogin($login);
  277.         $user->setPassword($hashedPassword);
  278.         $user->setRole($role);
  279.         $user->setName($name);
  280.         $user->setCountry($country);
  281.         $user->setStatus('disconnect');
  282.         $user->setLanguage($language);
  283.         $user->setDateInscription(new \DateTimeImmutable());
  284.         if ($role->getName() != 'administrator')  
  285.         {   
  286.             $user->setFullName($fullName);
  287.             $user->setAddress($fullAddress);
  288.         };
  289.         if ($role->getName() == 'operator') {
  290.             $user->setPayment($payment);
  291.             $user->setBankname($bankName);
  292.             $user->setIban($iban);
  293.             $user->setBic($bic);
  294.             $user->setPaymail($paymentMail);
  295.         };
  296.         if ($role->getName() == 'administrator') {
  297.             $user->setCompanyname($companyname);
  298.             $user->setTmfolder($folder);
  299.             $user->setAccessareas($accessareas);
  300.             $user->setValidity(new \DateTimeImmutable($validity));
  301.         };
  302.         if($userRole->isIsTest()){
  303.             $dataBaseName "tm_db_" $userRole->getName() . "_" $userRole->getId();
  304.             $user->setDataBaseName($dataBaseName);
  305.         }
  306.         $errors $this->entityValidatorService->validateEntity($user);
  307.         if (count($errors) > 0) {
  308.             return $this->json(['errors' => $this->entityValidatorService->getErrorMessages($errors)], Response::HTTP_BAD_REQUEST);
  309.         }
  310.         $this->entityService->saveEntity($user);
  311.         $typeR null;
  312.         if($role->getName() === self::OPERATOR$typeR 0;
  313.         else if($role->getName() === self::QC$typeR 1;
  314.         if($typeR !== null$this->messageOnHoldService->createNewCntrlArch($user,$typeR);
  315.         $token $this->jwtTokenManager->create($user);
  316.         return $this->json(['message' => 'Utilisateur enregistré avec succés''token' => $token,'id' => $user->getId()], Response::HTTP_OK);
  317.     }
  318.     /**
  319.      * 
  320.      * API pour recevoir le message d'un site
  321.      * 
  322.      */
  323.     #[Route('/receive_message'name'receive_message'methods: ['POST'])]
  324.     public function ReceiveMessage(Request $request)
  325.     {
  326.         //Récupération du message, faux profil et vrai profil
  327.         $datas json_decode($request->getContent(), true);
  328.         $this->logger->info(json_encode($datas));
  329.         $events $datas['events'][0];
  330.         $name $events['name'];
  331.         $channel $events['channel'];
  332.         // Renvoyer immédiatement une réponse 200 OK à Pusher
  333.         $response = new Response();
  334.         $response->setStatusCode(Response::HTTP_OK);
  335.         $response->send();
  336.         if ($name == 'channel_vacated') {
  337.             $id str_replace('private-'''$channel);
  338.             $id intval($id);
  339.             if ($id != 0) {
  340.                 $user $this->userRepository->findOneBy(['id' => $id]);
  341.                 if ($user) {
  342.                     $user->setStatus('disconnect');
  343.                     $this->entityService->saveEntity($user);
  344.                     $conv $user->getConv();
  345.                     $this->pusherService->createPusher();
  346.                     if ($conv) {
  347.                         $role $this->roleRepository->findOneBy(['name' => 'operator']);
  348.                         $users $this->userRepository->findOneBy(['role' => $role'status' => 'free','language' => $user->getLanguage()]);
  349.                         if ($users) {
  350.                             $conv->setPriority($users);
  351.                             $this->entityManagerInterface->persist($conv);
  352.                             $this->pusherService->triggerEvent('private-' $users->getId(), 'onHold', []);
  353.                         }else {
  354.                             $waitMsg $this->waitMessageRepository->findBy(['conv' => $conv'deleted' => true]);
  355.                             $wait_id = [];
  356.                             foreach ($waitMsg as $msg) {
  357.                                 $wait_id[] = $msg->getId();
  358.                                 $msg->setDeleted(false);
  359.                                 $this->entityManagerInterface->persist($msg);
  360.                             }
  361.                             $PusherHoldStatus = [
  362.                                 'id' => $wait_id,
  363.                                 'type' => false
  364.                             ];
  365.                             $this->pusherService->triggerEvent('private-conversation''change-status'$PusherHoldStatus);
  366.                             $conv->setPriority(NULL);
  367.                             $this->entityManagerInterface->persist($conv);
  368.                         }
  369.                     }
  370.                     $user->setConv(NULL);
  371.                     $this->entityService->saveEntity($user);
  372.                     $this->pusherService->triggerEvent('private-conversation''status', [
  373.                         'id' => $user->getId(),
  374.                         'status' => $user->getStatus()
  375.                     ]);
  376.                     // changement de statistic new design
  377.                     $languageName $user->getLanguage()->getName();
  378.                     $statistic2 = [
  379.                         "name" => "agents",
  380.                         "language" => $languageName,
  381.                         "field" => "online",
  382.                         "value" => -1
  383.                     ];
  384.                     // statistic
  385.                     $statistic = [
  386.                         "name" => "operator",
  387.                         "field" => "online",
  388.                         "value" => -1
  389.                     ];
  390.                     $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($languageName);
  391.                     foreach ($usersToRealTime as $userReal) {
  392.                         $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statistic2);
  393.                         $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  394.                     }
  395.                 }
  396.             }
  397.             return $this->json(['success' => true], Response::HTTP_OK);
  398.         } else if ($name == 'channel_occupied') {
  399.             return $this->json(null,200);
  400.         } else {
  401.             $data json_decode($events['data'], true);
  402.             $message $data['content'];
  403.             $realProfilId $data['real_profil'];
  404.             $fakeProfilId $data['fake_profil'];
  405.             $type_mess $data['type_mess'];
  406.             $lastId $data['last_id'];
  407.             
  408.             $this->logger->info($name);
  409.             $realProfil $this->profilRepository->findOneBy(['id' => $realProfilId]);
  410.             $senderMessage $realProfil;
  411.             
  412.             $receiveMessage $this->profilRepository->findOneBy(['id' => $fakeProfilId]);
  413.             $languageName $receiveMessage->getLanguage()->getName();
  414.             $language $this->languageRepository->findOneBy(['name' => $languageName]);
  415.             $rProfil $senderMessage->getProfilType()->getName();
  416.             if ( $rProfil != 'real_profil') {
  417.                 return $this->json(["message" => "Cette message ne peut pas envoyer dans le serveur"], Response::HTTP_UNAUTHORIZED);
  418.             }
  419.             $fprofil $receiveMessage->getProfilType()->getName();
  420.             if ( $fprofil != 'fake_profil') {
  421.                 return $this->json(["message" => "Cette message ne peut pas envoyer dans le serveur"], Response::HTTP_UNAUTHORIZED);
  422.             }
  423.             
  424.             $Conversation $this->conversationRepository->findOneBy([
  425.                 'sender_profil' => $senderMessage,
  426.                 'receive_profil' => $receiveMessage,
  427.             ]);
  428.             
  429.             $this->pusherService->createPusher();
  430.             $messageAt = new DateTimeImmutable();
  431.             $type $this->profilTypeRepository->findOneBy(['name' => 'real_profil']);
  432.             
  433.             // $type = $senderMessage->getProfilType()->getId();
  434.             if ($Conversation) {
  435.                 $dataRealProfil $this->profileService->getProfil($Conversation'vp');
  436.                 $dataFakeProfil $this->profileService->getProfil($Conversation'fp');
  437.                 if ($Conversation->getKickoff()) {
  438.                     return $this->json('kickoff'Response::HTTP_UNAUTHORIZED);
  439.                 } else if ($Conversation->getSuspend()) {
  440.                     $dateSuspend $Conversation->getSuspend();
  441.                     if ($dateSuspend $messageAt) {
  442.                         return $this->json('suspend'Response::HTTP_ALREADY_REPORTED);
  443.                     } else {
  444.                         $Conversation->setSuspend(null);
  445.                         $this->entityManagerInterface->persist($Conversation);
  446.                     }
  447.                 }
  448.                 $convId $Conversation->getId();
  449.                 $typeMess $this->typeMessageRepository->findOneBy(['name' => 'message']);
  450.                 if($type_mess == 'poke' || $type_mess == 'teaser' || $type_mess == 'stop' ){
  451.                     $lastMessage $this->messageRepository->findOneBy([ 'id' => $lastId ]);
  452.                     $content = new WaitMessage($messageAt$message$Conversation$Conversation->getLanguage(), NULL);
  453.                     $content->setMessType($typeMess);
  454.                     $content->setResponseWait($lastMessage);
  455.                     $this->entityManagerInterface->persist($content);
  456.                     $this->entityManagerInterface->flush();
  457.                     // changement de statistic new design
  458.                     $statisticNew = [
  459.                         "name" => $type_mess == 'stop' $type_mess $type_mess "s",
  460.                         "language" => $Conversation->getLanguage()->getName(),
  461.                         "platform" => $Conversation->getPlatform()->getName(),
  462.                         "field" => $type_mess == 'stop' "answer" "answered",
  463.                         "value" => 1
  464.                     ];
  465.                     $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($Conversation->getLanguage()->getName());
  466.                     foreach ($usersToRealTime as $userReal) {
  467.                         $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  468.                     }
  469.                 }else{
  470.                     $content = new WaitMessage($messageAt$message$Conversation$Conversation->getLanguage(), NULL);
  471.                     $content->setMessType($typeMess);
  472.                     $this->entityManagerInterface->persist($content);
  473.                     $this->entityManagerInterface->flush();
  474.                 }
  475.                 
  476.                 $MessHold = [
  477.                     'id' => $content->getId(),
  478.                     'sender_profil' => $content->getConv()->getSenderProfil()->getId(),
  479.                     'receiver_profil' => $content->getConv()->getReceiveProfil()->getId(),
  480.                     'message_at' => $content->getCreatedAt()->format('Y-m-d H:i:s'),
  481.                     'content' => $content->getMessage(),
  482.                     'message_id' => $content->getId(),
  483.                     'type_profil' => $type->getId(),
  484.                     'gifs' => [],
  485.                     'photos' => [],
  486.                     'type_mess' => $content->getMessType()->getName(),
  487.                 ];
  488.                 $this->pusherService->triggerEvent('private-message'"add"$MessHold);
  489.                 $data2 $this->messageOnHoldService->createContent(false$messageAt$message$Conversation$content->getId(), falseNULL$typeNULLNULL);
  490.                 $wait_id[] = $content->getId();
  491.                 $priority $Conversation->getPriority();
  492.                 if ($priority) {
  493.                     if ($priority->getStatus() == 'disconnect') {
  494.                         $Conversation->setPriority(NULL);
  495.                         $this->entityService->saveEntity($Conversation);
  496.                         $priority null;
  497.                     } else {
  498.                         $priority $Conversation->getPriority();
  499.                     }
  500.                 }
  501.                 
  502.                 if ($priority) {
  503.                     if ($priority->getStatus() == 'free') {
  504.                         // $content = new Message($priority, $Conversation, $message,$type, $messageAt, NULL, NULL);
  505.                         $contentData $this->messageOnHoldService->createContent(false$messageAt$message$ConversationNULLfalseNULL$typeNULLNULL);
  506.                         $data2['status'] = true;
  507.                         $this->pusherService->triggerEvent('private-conversation''add-hold'$data2);
  508.                         $Data $this->messageOnHoldService->getConversation($Conversation$wait_id);
  509.                         $messageData[] = $contentData;
  510.                         foreach ($Data['messageData'] as $mess) {
  511.                             $messageData[] = $mess;
  512.                         }
  513.                         $content->setDeleted(true);
  514.                         $priority->setStatus('occuped');
  515.                         $priority->setConv($Conversation);
  516.                         $this->entityService->saveEntity($priority);
  517.                         $Conversation->setPriority($priority);
  518.                         $this->entityService->saveEntity($Conversation);
  519.                         $infos $this->profileService->getInfoMeeting($Conversation);
  520.                         $data = [
  521.                             'wait_id' => $wait_id,
  522.                             'convId' => $convId,
  523.                             'message_data' => $messageData,
  524.                             'real_profil' => $dataRealProfil,
  525.                             'fake_profil' => $dataFakeProfil,
  526.                             'meeting' => $infos['meet'],
  527.                             'info' => $infos['info'],
  528.                             'type_mess' => $content->getMessType()->getName()
  529.                         ];
  530.                         $statistic = [
  531.                             "name" => "conversation",
  532.                             "field" => "onHold",
  533.                             "value" => 1
  534.                         ];
  535.                         $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($priority->getLanguage()->getName());
  536.                         foreach ($usersToRealTime as $userReal) {
  537.                             $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  538.                         }
  539.                         $this->sendPusherService->sendPusher($priority$data);
  540.                     } else { //else free
  541.                         $this->pusherService->triggerEvent('private-conversation''add-hold'$data2);
  542.                         $this->pusherService->triggerEvent('private-' strval($priority->getId()), 'countOnHoldEvent', [
  543.                             'count' => 1,
  544.                         ]);
  545.                         $statistic = [
  546.                             "name" => "conversation",
  547.                             "field" => "onHold",
  548.                             "value" => 1
  549.                         ];
  550.                         $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($priority->getLanguage()->getName());
  551.                         foreach ($usersToRealTime as $userReal) {
  552.                             $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  553.                         }
  554.                     }
  555.                     $this->entityManagerInterface->flush();
  556.                     // changement de statistic new design
  557.                     $statisticNew = [
  558.                         "name" => "trafic",
  559.                         "language" => $Conversation->getLanguage()->getName(),
  560.                         "platform" => $Conversation->getPlatform()->getName(),
  561.                         "field" => "alreadyAllocated",
  562.                         "value" => 1
  563.                     ];
  564.                     $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($Conversation->getLanguage()->getName());
  565.                     foreach ($usersToRealTime as $userReal) {
  566.                         $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  567.                     }
  568.                 } else { // else priority
  569.                     // changement de statistic new design
  570.                     $statisticNew = [
  571.                         "name" => "trafic",
  572.                         "language" => $Conversation->getLanguage()->getName(),
  573.                         "platform" => $Conversation->getPlatform()->getName(),
  574.                         "field" => "notAllocated",
  575.                         "value" => 1
  576.                     ];
  577.                     $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($Conversation->getLanguage()->getName());
  578.                     foreach ($usersToRealTime as $userReal) {
  579.                         $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  580.                     }
  581.                     $this->receiveMessageService->findUser($data2$content$wait_id$dataFakeProfil$dataRealProfil$type$messageAt$Conversation$message$language$senderMessage$receiveMessage);
  582.                 }
  583.             } else { // else conversation
  584.                 $Conversation = new Conversation($senderMessage$receiveMessage$language$senderMessage->getPlatform());
  585.                 $this->entityService->saveEntity($Conversation);
  586.                 $dataRealProfil $this->profileService->getProfil($Conversation'vp');
  587.                 $dataFakeProfil $this->profileService->getProfil($Conversation'fp');
  588.                 $typeMess $this->typeMessageRepository->findOneBy(['name' => 'message']);
  589.                 $newMessage = new WaitMessage($messageAt$message$Conversation$Conversation->getLanguage(), NULL);
  590.                 $newMessage->setMessType($typeMess);
  591.                 $MessHold = [
  592.                     'id' => $newMessage->getId(),
  593.                     'sender_profil' => $newMessage->getConv()->getSenderProfil()->getId(),
  594.                     'receiver_profil' => $newMessage->getConv()->getReceiveProfil()->getId(),
  595.                     'message_at' => $newMessage->getCreatedAt()->format('Y-m-d H:i:s'),
  596.                     'content' => $newMessage->getMessage(),
  597.                     'message_id' => $newMessage->getId(),
  598.                     'type_profil' => $type->getId(),
  599.                     'gifs' => [],
  600.                     'photos' => [],
  601.                     'type_mess' => $newMessage->getMessType()->getName()
  602.                 ];
  603.                 $dataRealProfil $this->profileService->getProfil($Conversation'vp');
  604.                 $dataFakeProfil $this->profileService->getProfil($Conversation'fp');
  605.                 $this->pusherService->triggerEvent('private-message'"add"$MessHold);
  606.                 $this->entityService->saveEntity($newMessage);
  607.                 $data2 $this->messageOnHoldService->createContent(false$messageAt$message$Conversation$newMessage->getId(), falseNULL$typeNULLNULL);
  608.                 $wait_id[] = $newMessage->getId();
  609.                 $this->receiveMessageService->findUser($data2$newMessage$wait_id$dataFakeProfil$dataRealProfil$type$messageAt$Conversation$message$language$senderMessage$receiveMessage);
  610.                 // changement de statistic new design
  611.                 $statisticNew = [
  612.                     "name" => "trafic",
  613.                     "language" => $Conversation->getLanguage()->getName(),
  614.                     "platform" => $Conversation->getPlatform()->getName(),
  615.                     "field" => "notAllocated",
  616.                     "value" => 1
  617.                 ];
  618.                 $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($Conversation->getLanguage()->getName());
  619.                 foreach ($usersToRealTime as $userReal) {
  620.                     $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  621.                 }
  622.             }
  623.             // changement de statistic new design
  624.             $statistic2 = [
  625.                 "name" => "conversations",
  626.                 "language" => $languageName,
  627.                 "platform" => $realProfil->getPlatform()->getName(),
  628.                 "field" => "onHold",
  629.                 "value" => 1
  630.             ];
  631.             $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($languageName);
  632.             foreach ($usersToRealTime as $userReal) {
  633.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statistic2);
  634.             }
  635.             return $this->json(['success' => true], Response::HTTP_OK);
  636.         }
  637.         return $this->json(['message' => 'Service indisponible'], Response::HTTP_SERVICE_UNAVAILABLE);
  638.     }
  639.     /**
  640.      * 
  641.      *  API envoi message du vrai profil au faux profil
  642.      * 
  643.      */
  644.     #[Route('/send_message_fp_to_vp'name'send_message_fp_to_vp'methods: ['POST'])]
  645.     public function sendMessageFpToVp(ProfilRepository $profilRepository)
  646.     {
  647.         $user $this->getUser();
  648.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_METHOD_NOT_ALLOWED);
  649.         $role $user->getRoles()[0];
  650.         if ($role != self::OPERATOR) {
  651.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED);
  652.         }
  653.         $this->pusherService->createPusher();
  654.         // $message = $this->messageRepository->findOneBy(['id' => $messId]);
  655.         $type_real $this->profilTypeRepository->findOneBy(['name' => 'real_profil']);
  656.         $type_fake $this->profilTypeRepository->findOneBy(['name' => 'fake_profil']);
  657.         [$content] = $this->requestService->getFromDataRequestBody('message_content');
  658.         [$answers] = $this->requestService->getFromDataRequestBody('status');
  659.         [$waitStr] = $this->requestService->getFromDataRequestBody('wait_id');
  660.         [$convId] = $this->requestService->getFromDataRequestBody('convId');
  661.         [$photo_id] = $this->requestService->getFromRequestBody('photo_id');
  662.         [$gif_id] = $this->requestService->getFromRequestBody('gif_id');
  663.         [$nbrWait] = $this->requestService->getFromDataRequestBody('nbrWait');
  664.         [$type_mess] = $this->requestService->getFromDataRequestBody('type_mess');
  665.         if ($waitStr) {
  666.             $string trim($waitStr"[]");
  667.             $array explode(","$string);
  668.             $wait_id array_map('intval'$array);
  669.         }
  670.         $contentMessage $content;
  671.         $conv $this->conversationRepository->findOneBy(['id' => $convId]);
  672.         if ($answers == 'true') {
  673.             $data = [];
  674.             $this->logger->info('answer true');
  675.             if (!$user->isAnswer()) {
  676.                 $user->setAnswer(true);
  677.                 $this->entityManagerInterface->persist($user);
  678.             }
  679.             $messageAt = new DateTimeImmutable();
  680.             $images NULL;
  681.             if ($photo_id) {
  682.                 $images = [];
  683.                 foreach ($photo_id as $image_id) {
  684.                     $image $this->photoRepository->findOneBy(['id' => $image_id]);
  685.                     if($image->getTypePhoto() == 'photo'){
  686.                         $image->setDeleted(true);
  687.                     }
  688.                     $this->entityManagerInterface->persist($image);
  689.                     $this->entityManagerInterface->flush();
  690.                     $images[] = $image;
  691.                 }
  692.             }
  693.             $gifs NULL;
  694.             if ($gif_id) {
  695.                 $gifs = [];
  696.                 foreach ($gif_id as $gifs_id) {
  697.                     $gif $this->gifRepository->find($gifs_id);
  698.                     $gifs[] = $gif;
  699.                 }
  700.             }
  701.             if ($type_mess == 'poke' || $type_mess == 'stop' || $type_mess == 'teaser') {
  702.                 $wait $this->waitMessageRepository->findOneBy(['id' => $wait_id[0]]);
  703.                 $idWait $wait->getId();
  704.                 $waitMessage = new Message($user$conv$wait->getMessage(), $type_real$wait->getMessType(), $wait->getCreatedAt(), NULLNULL);
  705.                 $newMessage = new Message($user$conv$contentMessage$type_fake$wait->getMessType(), $messageAt$gifs$images);
  706.                 $this->entityService->saveEntity($waitMessage);
  707.                 $this->entityService->saveEntity($newMessage);
  708.                 $waitMessage->setResponseMess($newMessage);
  709.                 $this->entityService->saveEntity($waitMessage);
  710.                 $this->entityManagerInterface->remove($wait);
  711.                 $this->entityManagerInterface->flush();
  712.                 $data[] = $this->messageOnHoldService->createContent(false$newMessage->getMessageAt(), $newMessage->getContent(), $newMessage->getConversation(), $newMessage->getId(), $newMessage->isEtat(), $newMessage->getOperator()->getName(), $newMessage->getType(), $newMessage->serializeGifs(), $newMessage->serializePhotos());
  713.                 $user->setStatus('free');
  714.                 $user->setConv(NULL);
  715.                 $this->entityManagerInterface->persist($user);
  716.                 $this->entityService->saveEntity($newMessage);
  717.                 $dataPush = [
  718.                     'id' => $idWait,
  719.                     'vprofil' => $waitMessage->getConversation()->getSenderProfil()->getUsername(),
  720.                     'fprofil' => $waitMessage->getConversation()->getReceiveProfil()->getUsername(),
  721.                     'date' => $waitMessage->getMessageAt()->format('Y-m-d H:i:s'),
  722.                     'response' => $newMessage->getContent(),
  723.                     'réresponse' => 'pas encore.'
  724.                 ];
  725.                 $this->pusherService->triggerEvent('private-'.$type_mess "add"$dataPush);
  726.                 // changement de statistic new design
  727.                 $statisticNew = [
  728.                     "name" => $type_mess == 'stop' $type_mess $type_mess "s",
  729.                     "language" => $conv->getLanguage()->getName(),
  730.                     "platform" => $conv->getPlatform()->getName(),
  731.                     "field" => "sent",
  732.                     "value" => 1
  733.                 ];
  734.                 $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($user->getLanguage()->getName());
  735.                 foreach ($usersToRealTime as $userReal) {
  736.                     $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  737.                 }
  738.             }
  739.             else {
  740.                 foreach ($wait_id as $msg_id) {
  741.                     $wait $this->waitMessageRepository->findOneBy(['id' => $msg_id]);
  742.                     $newMessage = new Message($user$conv$wait->getMessage(), $type_real$wait->getMessType(), $wait->getCreatedAt(), NULLNULL);
  743.                     $newMessage->setEtat($wait->isEtatMsg());
  744.                     $this->entityManagerInterface->persist($newMessage);
  745.                     $this->entityManagerInterface->flush();
  746.                     $data[] = $this->messageOnHoldService->createContent(false$newMessage->getMessageAt(), $newMessage->getContent(), $newMessage->getConversation(), $newMessage->getId(), $newMessage->isEtat(), $newMessage->getOperator()->getName(), $newMessage->getType(), $newMessage->serializeGifs(), $newMessage->serializePhotos());
  747.                     $profilInfo $this->messageOnHoldService->getProfilInfo($newMessage);
  748.                     $data[count($data) - 1]['receiver_profil'] = $profilInfo['receive'];
  749.                     $data[count($data) - 1]['sender_profil'] = $profilInfo['sender'];
  750.                     $data[count($data) - 1]['wait_id'] = $msg_id;
  751.                 }
  752.                 $newMessage = new Message($user$conv$contentMessage$type_fake$wait->getMessType(), $messageAt$gifs$images);
  753.                 if($wait->getResponseWait()){
  754.                     $last $this->messageRepository->findOneBy([ 'id' => $wait->getResponseWait()->getId()]);
  755.                     $new $this->messageRepository->findOneBy([ 'id' => $data[0]['message_id']]);
  756.                     $last->setResponseMess($new);
  757.                     $this->entityManagerInterface->persist($last);
  758.                     $this->entityManagerInterface->flush();
  759.                 }
  760.                 foreach ($wait_id as $msg_id) {
  761.                     $wait $this->waitMessageRepository->findOneBy(['id' => $msg_id]);
  762.                     $wait->setResponseWait(null);
  763.                     $this->entityManagerInterface->remove($wait);
  764.                     $this->entityManagerInterface->flush();
  765.                 }
  766.                 $user->setStatus('free');
  767.                 $user->setConv(NULL);
  768.                 $this->entityManagerInterface->persist($user);
  769.                 $this->entityService->saveEntity($newMessage);
  770.                 $this->messageOnHoldService->sendMsgListQC($newMessage);
  771.             }
  772.             $contents $this->messageOnHoldService->createContent(false$newMessage->getMessageAt(), $newMessage->getContent(), $newMessage->getConversation(), $newMessage->getId(), $newMessage->isEtat(), $newMessage->getOperator()->getName(), $newMessage->getType(), $newMessage->serializeGifs(), $newMessage->serializePhotos());
  773.             $profilInfo $this->messageOnHoldService->getProfilInfo($newMessage);
  774.             $contents['receiver_profil'] = $profilInfo['receive'];
  775.             $contents['sender_profil'] = $profilInfo['sender'];
  776.             $data[] = $contents;
  777.             $this->pusherService->createPusher();
  778.             
  779.             $MessHold = [
  780.                 'id' => $newMessage->getId(),
  781.                 'sender_profil' => $newMessage->getConversation()->getSenderProfil()->getId(),
  782.                 'receiver_profil' => $newMessage->getConversation()->getReceiveProfil()->getId(),
  783.                 'message_at' => $newMessage->getMessageAt()->format('Y-m-d H:i:s'),
  784.                 'content' => $newMessage->getContent(),
  785.                 'message_id' => $newMessage->getId(),
  786.                 'type_profil' => $newMessage->getType()->getId(),
  787.                 'gifs' => $newMessage->serializeGifs(),
  788.                 'photos' => $newMessage->serializePhotos(),
  789.                 'type_mess' => $type_mess,
  790.             ];
  791.             $this->pusherService->triggerEvent('private-conversation''add-treated'$data);
  792.             
  793.             $this->pusherService->triggerEvent('private-conversation''status', [
  794.                 'id' => $user->getId(),
  795.                 'status' => $user->getStatus()
  796.             ]);
  797.             
  798.             $MessHold1 = [
  799.                 'id' => $newMessage->getId(),
  800.                 'sender_profil' => $newMessage->getConversation()->getSenderProfil()->getId(),
  801.                 'receiver_profil' => $newMessage->getConversation()->getReceiveProfil()->getId(),
  802.                 'message_at' => $newMessage->getMessageAt()->format('Y-m-d H:i:s'),
  803.                 'content' => $newMessage->getContent(),
  804.                 'message_id' => $newMessage->getId(),
  805.                 'type_profil' => $newMessage->getType()->getId(),
  806.                 'gifs' => $newMessage->serializeGifs(),
  807.                 'photos' => $newMessage->serializePhotos(),
  808.                 'type_mess' => $type_mess
  809.             ];
  810.             $this->pusherService->triggerEvent('private-message'"add"$MessHold1);
  811.             
  812.             
  813.             $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($user->getLanguage()->getName());
  814.             $countHold count($data) - 1;
  815.             
  816.             // changement de statistic new design
  817.             $statisticNew = [
  818.                 "name" => "conversations",
  819.                 "language" => $conv->getLanguage()->getName(),
  820.                 "platform" => $conv->getPlatform()->getName(),
  821.                 "field" => "treated",
  822.                 "value" => count($data)
  823.             ];
  824.             $statistic = [
  825.                 "name" => "conversation",
  826.                 "field" => "treated",
  827.                 "value" => count($data)
  828.             ];
  829.             foreach ($usersToRealTime as $userReal) {
  830.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  831.                 $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  832.             }
  833.             // changement de statistic new design
  834.             $language $conv->getLanguage();
  835.             $platform $conv->getPlatform();
  836.             $now = new \DateTimeImmutable();
  837.             $period $now->format("Y-m");
  838.             $rate $this->rateRepository->findOneBy([ 'platform' => $platform'language' => $language'period' => $period]);
  839.             if($type_mess == 'poke'){
  840.                 $price $rate->getPokeMessage();
  841.             }elseif($type_mess == 'stop'){
  842.                 $price $rate->getStopMessage();
  843.             }elseif($type_mess == 'teaser'){
  844.                 $price $rate->getTeaserMessage();
  845.             }else{
  846.                 $price $rate->getMessage();
  847.             }
  848.             $statisticAccountant = [
  849.                 "name" => "accountant",
  850.                 "language" => $language->getName(),
  851.                 "platform" => $platform->getName(),
  852.                 "field" => $user->getPayment()->getName(),
  853.                 "value" => $price
  854.             ];
  855.             $statisticAccountantTotal = [
  856.                 "name" => "accountant",
  857.                 "language" => $language->getName(),
  858.                 "platform" => $platform->getName(),
  859.                 "field" => 'total',
  860.                 "value" => $price
  861.             ];
  862.             $statisticAlreAll = [
  863.                 "name" => "trafic",
  864.                 "language" => $language->getName(),
  865.                 "platform" => $platform->getName(),
  866.                 "field" => "alreadyAllocated",
  867.                 "value" => -$countHold
  868.             ];
  869.             $statisticQcTotal = [
  870.                 "name" => "qc",
  871.                 "language" => $language->getName(),
  872.                 "platform" => $platform->getName(),
  873.                 "field" => "qcTotal",
  874.                 "value" => 1
  875.             ];
  876.             $statisticQcNot = [
  877.                 "name" => "qc",
  878.                 "language" => $language->getName(),
  879.                 "platform" => $platform->getName(),
  880.                 "field" => "notPassedQc",
  881.                 "value" => 1
  882.             ];
  883.             $statisticNew1 = [
  884.                 "name" => "conversations",
  885.                 "language" => $language->getName(),
  886.                 "platform" => $platform->getName(),
  887.                 "field" => "onHold",
  888.                 "value" => -$countHold
  889.             ];
  890.             $statistic1 = [
  891.                 "name" => "conversation",
  892.                 "field" => "onHold",
  893.                 "value" => -$countHold
  894.             ];
  895.             foreach ($usersToRealTime as $userReal) {
  896.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticAccountantTotal);
  897.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticAccountant);
  898.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew1);
  899.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticQcTotal);
  900.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticQcNot);
  901.                 $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticAlreAll);
  902.                 $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic1);
  903.             }
  904.             
  905.             $users $this->userRepository->findBy(['status' => 'occuped']);
  906.             foreach ($users as $user) {
  907.                 $this->pusherService->triggerEvent('private-' strval($user->getId()), 'countOnHoldEvent', [
  908.                     'count' => -1,
  909.                 ]);
  910.             }
  911.             
  912.             return $this->json(['message' => 'Message envoyé avec succés'$answers], Response::HTTP_OK);
  913.         } else {
  914.             $this->logger->info('answer false');
  915.             return $this->sendMessageService->getMessageService($nbrWait$conv$wait_id$user$type_mess);
  916.         }
  917.     }
  918.     /**
  919.      * 
  920.      ** API message en attente
  921.      * 
  922.      */
  923.     #[Route('/message_on_hold'name'message_on_hold'methods: ['GET'])]
  924.     public function findMessageOnHold()
  925.     {
  926.         $user $this->getUser();
  927.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_METHOD_NOT_ALLOWED);
  928.         $role $user->getRoles()[0];
  929.         if ($role != self::OPERATOR) {
  930.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_NETWORK_AUTHENTICATION_REQUIRED);
  931.         }
  932.         $this->pusherService->createPusher();
  933.         return $this->messageOnHoldService->findMessageOnHold($user);
  934.     }
  935.     /**
  936.      *  
  937.      * API pour la deconnexion d'un opérateur
  938.      * 
  939.      */
  940.     #[Route('/disconnection/{id}'name'deconnection'methods: ['POST'])]
  941.     public function disconnection()
  942.     {
  943.         // dd("test");
  944.         [$id] = $this->requestService->getFromAttributes('id');
  945.         $user $this->userRepository->findOneBy(['id' => $id]);
  946.         $user->setStatus('disconnect');
  947.         $this->entityService->saveEntity($user);
  948.         // changement de statistic new design
  949.         $languageName $user->getLanguage()->getName();
  950.         $statistic2 = [
  951.             "name" => "agents",
  952.             "language" => $languageName,
  953.             "field" => "online",
  954.             "value" => -1
  955.         ];
  956.         // statistic
  957.         $statistic = [
  958.             "name" => "operator",
  959.             "field" => "online",
  960.             "value" => -1
  961.         ];
  962.         $this->pusherService->createPusher();
  963.         $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($languageName);
  964.         foreach ($usersToRealTime as $userReal) {
  965.             $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statistic2);
  966.             $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  967.         }
  968.         return $this->json(['message' => 'Vous êtes déconnectez avec succés'], Response::HTTP_OK);
  969.     }
  970.     private function getMessageComps($senderId$receiverId$operatorId$conversationId)
  971.     {
  972.         // Récupération du sender (faux profil)
  973.         $sender $this->profilRepository->find($senderId);
  974.         if (!$sender) return ['error' => 'Faux profil non trouvé'];
  975.         // Récupération du receiver (vrai profil)  
  976.         $receiver $this->profilRepository->find($receiverId);
  977.         if (!$receiver) return ['error' => 'Vrai profil non trouvé'];
  978.         // Récupération de l'opérateur
  979.         $operator $this->userRepository->find($operatorId);
  980.         if (!$operator) return ['error' => 'Opérateur non trouvé'];
  981.         // Récupération de la conversation
  982.         $conversation $this->conversationRepository->find($conversationId);
  983.         if (!$conversation) return ['error' => 'Conversation non trouvée'];
  984.         return ['data' => [$sender$receiver$operator$conversation]];
  985.     }
  986.     /**
  987.      * API pour envoi message
  988.      */
  989.     #[Route('/send_photo'name'send_photo'methods: ['POST'])]
  990.     public function sendPhoto()
  991.     {
  992.         // Autorisation
  993.         $user $this->getUser();
  994.         if (!$user) return $this->json(["message" => "Vous n'êtes pas connecté"], 401);
  995.         // Récupération des données dans le request body
  996.         [$fp_id$vp_id$conv_id$images_ids$site_id] = $this->requestService->getFromRequestBody('fp_id''vp_id''conversation_id''images_ids''site_id');
  997.         // Récupération des éléments à partir de leurs id respectifs
  998.         $messageComps $this->getMessageComps($fp_id$vp_id$user->getId(), $conv_id);
  999.         if (isset($messageComps['error'])) return $this->json(['message' => $messageComps['error']], 404);
  1000.         [$sender$receiver$operator$conversation] = $messageComps['data'];
  1001.         // Récupération des images
  1002.         $images = [];
  1003.         if ($images_ids) foreach ($images_ids as $image_id) {
  1004.             $image $this->photoRequestRepository->find($image_id);
  1005.             if (!$image) return $this->json(['message' => 'Image ' $image_id ' non trouvé'], 404);
  1006.             if (!$image->getPhotoName()) return $this->json(['message' => 'Image ' $image_id ' non trouvé'], 404);
  1007.             $image->setDeleted(true);
  1008.             $this->entityManagerInterface->persist($image);
  1009.             $this->entityManagerInterface->flush();
  1010.             $images[] = $image;
  1011.         }
  1012.         // Ajout et stockage du message
  1013.         $type $this->profilTypeRepository->findOneBy(["name" => 'fake_profil']);
  1014.         $typeMessType $this->typeMessageRepository->findOneBy(['name' => 'message']);
  1015.         $messageAt = new DateTimeImmutable();
  1016.         $message = new Message($operator$conversationnull$type$typeMessType$messageAtnull$images);
  1017.         $this->entityManagerInterface->persist($message);
  1018.         $this->entityManagerInterface->flush();
  1019.         // Récupération du site
  1020.         $platform 'test'//FIXME $this->platformRepository->find($site_id);
  1021.         if (!$platform) return $this->json(['message' => 'Site non trouvée'], 404);
  1022.         // TODO Envoi du message dans le site
  1023.         // Libérer l'opérateur
  1024.         $operator->setStatus("free");
  1025.         $photos = [];
  1026.         for ($i 0$i count($images); $i++) {
  1027.             $photos[$i] = [
  1028.                 'id' => $images[$i]->getId(),
  1029.                 'photoName' => $images[$i]->getPhotoName()
  1030.             ];
  1031.         }
  1032.         $data = [
  1033.             "sender_profil" => $message->getConversation()->getSenderProfil()->getRealName(),
  1034.             "receiver_profil" => $message->getConversation()->getReceiveProfil()->getRealName(),
  1035.             "message_at" => $message->getMessageAt()->format('Y-m-d H:i:s'),
  1036.             "content" => $message->getContent(),
  1037.             "message_id" => $message->getId(),
  1038.             "type_profil" =>  $message->getType()->getId(),
  1039.             'photos' => $photos,
  1040.             'gifs' => []
  1041.         ];
  1042.         return $this->json(['message' => 'Photo envoyée'"data" => $data], 201);
  1043.     }
  1044.     /**
  1045.      * API pour envoyer un gif: faux profil -> vrai profil
  1046.      * 
  1047.      */
  1048.     #[Route('/send_gif'name'send_gif'methods: ['POST'])]
  1049.     public function sendGif()
  1050.     {
  1051.         // Récupération des données dans le request body
  1052.         [$fp_id$vp_id$conv_id$gifs_ids$site_id] = $this->requestService->getFromRequestBody('fp_id''vp_id''conversation_id''gifs_ids''site_id');
  1053.         $user $this->getUser();
  1054.         if (!$user) return $this->json(["message" => "Vous n'êtes pas connecté"], 401);
  1055.         // Récupération des éléments à partir de leurs id respectifs
  1056.         $messageComps $this->getMessageComps($fp_id$vp_id$user->getId(), $conv_id);
  1057.         if (isset($messageComps['error'])) return $this->json(['message' => $messageComps['error']], 404);
  1058.         [$sender$receiver$operator$conversation] = $messageComps['data'];
  1059.         // Récupération des gifs
  1060.         $gifs = [];
  1061.         if ($gifs_ids) foreach ($gifs_ids as $gif_id) {
  1062.             $gif $this->gifRepository->find($gif_id);
  1063.             if (!$gif) return $this->json(['message' => 'Gif ' $gif_id ' non trouvé'], 404);
  1064.             $gifs[] = $gif;
  1065.         }
  1066.         // Ajout et stockage du message
  1067.         $type $this->profilTypeRepository->findOneBy(["name" => 'fake_profil']);
  1068.         $typeMessType $this->typeMessageRepository->findOneBy(['name' => 'message']);
  1069.         $messageAt = new DateTimeImmutable();
  1070.         $message = new Message($operator$conversationnull$type$typeMessType$messageAt$gifsnull);
  1071.         $this->entityManagerInterface->persist($message);
  1072.         $this->entityManagerInterface->flush();
  1073.         // Récupération du site 
  1074.         $platform 'test'//FIXME $this->platformRepository->find($site_id);
  1075.         if (!$platform) return $this->json(['message' => 'Site non trouvée'], 404);
  1076.         // TODO Envoi du message dans le site
  1077.         // Libérer l'opérateur
  1078.         $operator->setStatus("free");
  1079.         $gifToSend = [];
  1080.         for ($i 0$i count($gifs); $i++) {
  1081.             $gifToSend[$i] = [
  1082.                 'id' => $gifs[$i]->getId(),
  1083.                 'photoName' => $gifs[$i]->getName()
  1084.             ];
  1085.         }
  1086.         $data = [
  1087.             "sender_profil" => $message->getConversation()->getSenderProfil()->getRealName(),
  1088.             "receiver_profil" => $message->getConversation()->getReceiveProfil()->getUsername(),
  1089.             "message_at" => $message->getMessageAt()->format('Y-m-d H:i:s'),
  1090.             "content" => $message->getContent(),
  1091.             "message_id" => $message->getId(),
  1092.             "type_profil" =>  $message->getType()->getId(),
  1093.             'photos' => [],
  1094.             'gifs' => $gifToSend
  1095.         ];
  1096.         return $this->json(['message' => 'Message gif envoyé'"data" => $data], 201);
  1097.     }
  1098.     #[Route('/readconversation/{convId}'name'read_conversation'methods: ['GET'])]
  1099.     public function readConversation($convId)
  1100.     {
  1101.         $conversation $this->conversationRepository->findOneBy(['id' => $convId]);
  1102.         if (!$conversation) {
  1103.             return $this->json(['message' => 'Conversation non trouvée'], Response::HTTP_NOT_FOUND);
  1104.         }
  1105.         $messages $conversation->getMessages();
  1106.         $messageData = [];
  1107.         foreach ($messages as $message) {
  1108.             $senderProfil $message->getConversation()->getSenderProfil()->getRealName();
  1109.             $typeProfil $message->getConversation()->getSenderProfil()->getProfilType()->getId();
  1110.             $receiveProfil $message->getConversation()->getReceiveProfil()->getRealName();
  1111.             $messageAt $message->getMessageAt();
  1112.             $content $message->getContent();
  1113.             $messageId $message->getId();
  1114.             $messageData[] = [
  1115.                 'sender_profil' => $senderProfil,
  1116.                 'receiver_profil' => $receiveProfil,
  1117.                 'message_at' => $messageAt,
  1118.                 'content' => $content,
  1119.                 'message_id' => $messageId,
  1120.                 'type_profil' => $typeProfil,
  1121.             ];
  1122.         }
  1123.         return $this->json($messageDataResponse::HTTP_OK);
  1124.     }
  1125.     #[Route('/conversation/treated'name'get_treated_conversation'methods: ['GET'])]
  1126.     public function getTreatedConversation(Request $request)
  1127.     {
  1128.         //Autorisation
  1129.         $user $this->getUser();
  1130.         if (!$user) {
  1131.             return $this->json("Vous n'êtes pas connecté "401);
  1132.         }
  1133.         $decodedJwtToken $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1134.         if ($decodedJwtToken['roles'][0] !== self::ADMIN && $decodedJwtToken['roles'][0] !== self::SUPERVISOR && $decodedJwtToken['roles'][0] !== self::QC) return $this->json(['message' => 'Accès refusé'], 403);
  1135.         $year $request->query->get('year'date('Y'));
  1136.         $month $request->query->get('month'date('m'));
  1137.         $date $request->query->get('date''');
  1138.         $startingDate $request->query->get('startingDate''');
  1139.         $closingDate $request->query->get('closingDate''');
  1140.         $platforms $request->query->get('platforms''');
  1141.         $agents $request->query->get('agents''');
  1142.         $fakeProfil $request->query->get('fakeProfil''');
  1143.         $conversation $request->query->get('conversation''');
  1144.         $message $request->query->get('message''');
  1145.         $language $request->query->get('language''');
  1146.         $typeMS $request->query->get('type''');
  1147.         $typeMS intval($typeMS);
  1148.         $messages $this->messageRepository->filterConversation(
  1149.             $year,
  1150.             $month,
  1151.             $conversation,
  1152.             $message,
  1153.             $fakeProfil,
  1154.             $startingDate,
  1155.             $date,
  1156.             $closingDate,
  1157.             $platforms,
  1158.             $agents,
  1159.             $language,
  1160.             $user,
  1161.             $typeMS
  1162.         );
  1163.         $paginations $this->paginator->getPagination($request$messages20);
  1164.         $messageData = [];
  1165.         foreach ($paginations->getItems() as $message) {
  1166.             $messageAt $message->getMessageAt();
  1167.             $conv $message->getConversation();
  1168.             $profilInfoData $this->messageOnHoldService->getProfilInfo($message);
  1169.             $senderProfil $profilInfoData['sender'];
  1170.             $receiveProfil $profilInfoData['receive'];
  1171.             $messageId $message->getId();
  1172.             $content $message->getContent();
  1173.             $operator $message->getOperator()->getName();
  1174.             $operator_log $message->getOperator()->getMail();
  1175.             $language $this->languageRepository->findOneById(['id' => $conv->getLanguage()->getId()])->getName();
  1176.             $platform $conv->getSenderProfil()->getPlatform()->getName();
  1177.             $qc_ctr = [];
  1178.             $validation false;
  1179.             $getQcCtr $message->getQcControl();
  1180.             $type_mess $message->getMessType() ? $message->getMessType()->getName() : null;
  1181.             if ($getQcCtr) {
  1182.                 $qc_ctr $getQcCtr;
  1183.                 $validation true;
  1184.             }
  1185.             $messageData[] = [
  1186.                 'message_at' => $messageAt,
  1187.                 'conv_id' => $conv->getId(),
  1188.                 'message_id' => $messageId,
  1189.                 'sender_profil' => $senderProfil,
  1190.                 'receiver_profil' => $receiveProfil,
  1191.                 'gifs' => $message->serializeGifs(),
  1192.                 'photos' => $message->serializePhotos(),
  1193.                 'content' => $content,
  1194.                 'operator' => $operator,
  1195.                 'language' => $language,
  1196.                 'platform' => $platform,
  1197.                 'ag_log' => $operator_log,
  1198.                 'qc_control' => $qc_ctr,
  1199.                 'qc_result' => $message->getQcResult(),
  1200.                 'type_mess' => $type_mess,
  1201.                 'validation' => $validation,
  1202.                 'type' => $profilInfoData['type']
  1203.             ];
  1204.         }
  1205.         return $this->json([
  1206.             'data' => $messageData,
  1207.             'pagination' => [
  1208.                 'page' => $paginations->getCurrentPageNumber(),
  1209.                 'total_pages' => ceil($paginations->getTotalItemCount() / $paginations->getItemNumberPerPage()),
  1210.                 'total_items' => $paginations->getTotalItemCount(),
  1211.             ]
  1212.         ], Response::HTTP_OK);
  1213.     }
  1214.     #[Route('/user/{roleName}'name'user_by_role'methods: ['GET'])]
  1215.     public function getUserByRole(SerializerInterface $serializer$roleNameRequest $request)
  1216.     {
  1217.         $user $this->getUser();
  1218.         if (!$user) {
  1219.             return $this->json("Vous n'êtes pas connecté "401);
  1220.         }
  1221.         $year $request->query->get('year'"");
  1222.         $month $request->query->get('month'"");
  1223.         $date $request->query->get('date''');
  1224.         $startingDate $request->query->get('startingDate''');
  1225.         $closingDate $request->query->get('closingDate''');
  1226.         $agents $request->query->get('agents''');
  1227.         $language $request->query->get('language''');
  1228.         $platforms $request->query->get('platforms''');
  1229.         $roleToken $user->getRoles()[0];
  1230.         $supervisor $this->roleRepository->findOneBy(['name' => 'supervisor']);
  1231.         $operator $this->roleRepository->findOneBy(['name' => 'operator']);
  1232.         $locale $user->getLanguage();
  1233.         if ($roleName == self::OPERATOR && $roleToken == self::SUPERVISOR) {
  1234.             $users $this->userRepository->findUsersByRoleAndStatus($operator$year$locale$month$date$startingDate$closingDate$agents);
  1235.             $paginations $this->paginator->getPagination($request$users5);
  1236.         } elseif ($roleName == self::OPERATOR && $roleToken == self::ADMIN) {
  1237.             $users $this->userRepository->findUsers($operator$year$month$date$startingDate$closingDate$agents$language$platforms);
  1238.             $paginations $this->paginator->getPagination($request$users5);
  1239.         } elseif ($roleName == self::SUPERVISOR && $roleToken == self::ADMIN) {
  1240.             $users $this->userRepository->findUsers($supervisor$year$month$date$startingDate$closingDate$agents$language$platforms);
  1241.             $paginations $this->paginator->getPagination($request$users5);
  1242.         } elseif ($roleName == self::QC && $roleToken == self::ADMIN) {
  1243.             $QC $this->roleRepository->findOneBy(['name' => self::QC]);
  1244.             $users $this->userRepository->findUsers($QC$year$month$date$startingDate$closingDate$agents$language$platforms);
  1245.             $paginations $this->paginator->getPagination($request$users5);
  1246.         } elseif ($roleName == self::ACCOUNTANT && $roleToken == self::ADMIN) {
  1247.             $comptable $this->roleRepository->findOneBy(['name' => self::ACCOUNTANT]);
  1248.             $users $this->userRepository->findUsers($comptable$year$month$date$startingDate$closingDate$agents$language$platforms);
  1249.             $paginations $this->paginator->getPagination($request$users5);
  1250.         } else {
  1251.             return $this->json(['message' => "Inaccessible"], Response::HTTP_NOT_ACCEPTABLE);
  1252.         }
  1253.         $response $serializer->serialize($paginations'json', ['groups' => ['user''language']]);
  1254.         $responseArray json_decode($responsetrue);
  1255.         return $this->json([
  1256.             'data' => $responseArray,
  1257.             'pagination' => [
  1258.                 'page' => $paginations->getCurrentPageNumber(),
  1259.                 'total_pages' => ceil($paginations->getTotalItemCount() / $paginations->getItemNumberPerPage()),
  1260.                 'total_items' => $paginations->getTotalItemCount(),
  1261.             ]
  1262.         ], Response::HTTP_OK);
  1263.     }
  1264.     #[Route('/payment/{paymentName}'name'user_by_payment'methods: ['GET'])]
  1265.     public function getUserByPayment(SerializerInterface $serializer$paymentName)
  1266.     {
  1267.         // Autorisation
  1268.         $user $this->getUser();
  1269.         if (!$user) {
  1270.             return $this->json("Vous n'êtes pas connecté "401);
  1271.         }
  1272.         $decodedJwtToken $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1273.         if ($decodedJwtToken['roles'][0] !== self::ADMIN && $decodedJwtToken['roles'][0] !== self::ACCOUNTANT) return $this->json(['message' => 'Accès refusé'], 403);
  1274.         $payment $this->paymentRepository->findOneBy(['Name' => $paymentName]);
  1275.         $users $this->userRepository->findBy(['payment' => $payment'deleted' => false]);
  1276.         $response $serializer->serialize($users'json', ['groups' => ['user''language']]);
  1277.         return $this->json(json_decode($responsetrue), 200);
  1278.     }
  1279.     #[Route('/report'name'report'methods: ['POST'])]
  1280.     public function createReport()
  1281.     {
  1282.         $user $this->getUser();
  1283.         if (!$user) {
  1284.             return $this->json("Vous n'êtes pas connecté "401);
  1285.         }
  1286.         if ($user->getRoles()[0] !== self::OPERATOR) return $this->json(['message' => 'Accès refusé'], 403);
  1287.         [$id_message$content$id_agent] = $this->requestService->getFromRequestBody('id_message''content''id_agent');
  1288.         $message $this->messageRepository->findOneBy(['id' => $id_message]);
  1289.         $message->setEtat(true);
  1290.         $this->entityManagerInterface->persist($message);
  1291.         $this->pusherService->createPusher();
  1292.         $agent $this->userRepository->findOneBy(['id' => $id_agent]);
  1293.         $report = new Report();
  1294.         $report->setDateReport(new \DateTimeImmutable());
  1295.         $report->setMessageId($message);
  1296.         $report->setContent($content);
  1297.         $report->setAgent($agent);
  1298.         $report->setStatus(false);
  1299.         $errors $this->entityValidatorService->validateEntity($report);
  1300.         if (count($errors) > 0) {
  1301.             return $this->json(['errors' => $this->entityValidatorService->getErrorMessages($errors)], Response::HTTP_BAD_REQUEST);
  1302.         }
  1303.         $this->entityManagerInterface->persist($report);
  1304.         $this->entityManagerInterface->flush();
  1305.         $role self::SUPERVISOR;
  1306.         $role_id $this->roleRepository->findBy(['name' => $role]);
  1307.         $super $this->userRepository->findBy(['role' => $role_id'status' => 'free']);
  1308.         $data = [
  1309.             'role' => 'Agent',
  1310.             'type' => 'Report1',
  1311.             'sender' => $role,
  1312.             'content' => 'New report',
  1313.             'date' => $report->getDateReport()->format('Y-m-d H:i:s'),
  1314.             'checked' => false
  1315.         ];
  1316.         foreach ($super as $superviseur) {
  1317.             $this->pusherService->triggerEvent('private-' $superviseur->getId(), 'Add_Notif'$data);
  1318.         }
  1319.         // changement de statistic new design
  1320.         $conv $report->getMessageId()->getConversation();
  1321.         $statisticNew = [
  1322.             "name" => "report",
  1323.             "language" => $conv->getLanguage()->getName(),
  1324.             "platform" => $conv->getPlatform()->getName(),
  1325.             "field" => "new",
  1326.             "value" => 1
  1327.         ];
  1328.         $statisticTotal = [
  1329.             "name" => "report",
  1330.             "language" => $conv->getLanguage()->getName(),
  1331.             "platform" => $conv->getPlatform()->getName(),
  1332.             "field" => "all",
  1333.             "value" => 1
  1334.         ];
  1335.         // statistic
  1336.         $statistic = [
  1337.             "name" => "Report",
  1338.             "field" => "total",
  1339.             "value" => 1
  1340.         ];
  1341.         $data $this->notificationController->setNotification('report',null,'',$role,false,$user,$user->getName());
  1342.         $usersToRealTime $this->userRepository->findSupervisorsAndAdminsByLanguage($user->getLanguage()->getName());
  1343.         foreach ($usersToRealTime as $userReal) {
  1344.             $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticNew);
  1345.             $this->pusherService->triggerEvent('private-statistic'strval($userReal->getId()), $statistic);
  1346.             $this->pusherService->triggerEvent('private-statistic2'strval($userReal->getId()), $statisticTotal);
  1347.         }
  1348.         return $this->json(Response::HTTP_OK);
  1349.     }
  1350.     #[Route('/all_report'name'all_report'methods: ['GET'])]
  1351.     public function getAllReport()
  1352.     {
  1353.         $user $this->getUser();
  1354.         if (!$user) {
  1355.             return $this->json("Vous n'êtes pas connecté "401);
  1356.         }
  1357.         if ($user->getRoles()[0] !== self::ADMIN && $user->getRoles()[0] !== self::SUPERVISOR) return $this->json(['message' => 'Accès refusé'], 403);
  1358.         $reports $this->reportRepository->findAll();
  1359.         $reportData = [];
  1360.         foreach ($reports as $report) {
  1361.             $reportdate $report->getDateReport();
  1362.             $platform $report->getMessageId()->getConversation()->getSenderProfil()->getPlatform()->getName();
  1363.             $idreport $report->getId();
  1364.             $message $report->getMessageId()->getContent();
  1365.             $idmessage $report->getMessageId()->getId();
  1366.             $senderProfil $this->messageOnHoldService->getInformationProfil($report->getMessageId()->getConversation()->getSenderProfil());
  1367.             $receiveProfil $report->getMessageId()->getConversation()->getReceiveProfil()->getRealName();
  1368.             $operator $report->getMessageId()->getOperator()->getId();
  1369.             $operator $this->userRepository->findOneBy(['id' => $operator]);
  1370.             $reportData[] = [
  1371.                 'reportdate' => $reportdate,
  1372.                 'platform' => $platform,
  1373.                 'id_report' => $idreport,
  1374.                 'message' => $message,
  1375.                 'id_message' => $idmessage,
  1376.                 'sender_profil' => $senderProfil,
  1377.                 'receiver_profil' => $receiveProfil,
  1378.                 'operatorName' => $operator->getName(),
  1379.                 'operatorId' => $operator->getId(),
  1380.                 'agentSign' => $report->getAgent()->getName(),
  1381.                 'content' => $report->getContent(),
  1382.                 'status' => $report->isStatus()
  1383.             ];
  1384.         }
  1385.         return $this->json($reportDataResponse::HTTP_OK);
  1386.     }
  1387.     #[Route('/conversation_on_hold'name'get_on_hold_conversation'methods: ['GET'])] //FIXME
  1388.     public function getConversationOnHold(Request $request)
  1389.     {
  1390.         // Autorisation
  1391.         $user $this->getUser();
  1392.         if (!$user) {
  1393.             return $this->json("Vous n'êtes pas connecté "401);
  1394.         }
  1395.         $decodedJwtToken $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1396.         if ($decodedJwtToken['roles'][0] !== self::ADMIN && $decodedJwtToken['roles'][0] !== self::SUPERVISOR) return $this->json(['message' => 'Accès refusé'], 403);
  1397.         $year $request->query->get('year'date('Y'));
  1398.         $month $request->query->get('month'date('m'));
  1399.         $date $request->query->get('date''');
  1400.         $startingDate $request->query->get('startingDate''');
  1401.         $closingDate $request->query->get('closingDate''');
  1402.         $platforms $request->query->get('platforms''');
  1403.         $fakeProfil $request->query->get('fakeProfil''');
  1404.         $conversation $request->query->get('conversation''');
  1405.         $message $request->query->get('message''');
  1406.         $language $request->query->get('language''');
  1407.         $messages $this->waitMessageRepository->filterOnhold(
  1408.             $year,
  1409.             $month,
  1410.             $conversation,
  1411.             $message,
  1412.             $fakeProfil,
  1413.             $startingDate,
  1414.             $date,
  1415.             $closingDate,
  1416.             $platforms,
  1417.             $language,
  1418.             $user
  1419.         );
  1420.         $paginations $this->paginator->getPagination($request$messages20);
  1421.         $waitmessageData = [];
  1422.         foreach ($paginations as $waitmessage) {
  1423.             $createdAt $waitmessage->getCreatedAt();
  1424.             $messageId $waitmessage->getId();
  1425.             $convId $waitmessage->getConv()->getId();
  1426.             $realProfil $this->messageOnHoldService->getInformationProfil($waitmessage->getConv()->getSenderProfil());
  1427.             $fakeProfil $this->messageOnHoldService->getInformationProfil($waitmessage->getConv()->getReceiveProfil());
  1428.             $content $waitmessage->getMessage();
  1429.             $platform $waitmessage->getConv()->getSenderProfil()->getPlatform()->getName();
  1430.             $priority_name null;
  1431.             $priority_id null;
  1432.             $priority_login null;
  1433.             $userPr $waitmessage->getConv()->getPriority();
  1434.             if ($userPr) {
  1435.                 $priority_name $userPr->getName();
  1436.                 $priority_id $userPr->getId();
  1437.                 $priority_login $userPr->getMail();
  1438.             }
  1439.             $type_mess '';
  1440.             if ($waitmessage->getMessType()) $type_mess $waitmessage->getMessType()->getName();
  1441.             $waitmessageData[] = [
  1442.                 'id' => $waitmessage->getId(),
  1443.                 'message_at' => $createdAt,
  1444.                 'message_id' => $messageId,
  1445.                 'conv_id' => $convId,
  1446.                 'agent' => $priority_name,
  1447.                 'agent_id' => $priority_id,
  1448.                 'agent_log' => $priority_login,
  1449.                 'sender_profil' => $realProfil,
  1450.                 'receiver_profil' => $fakeProfil,
  1451.                 'content' => $content,
  1452.                 'date' => $waitmessage->getCreatedAt(),
  1453.                 'platform' => $platform,
  1454.                 'language' => $waitmessage->getLanguage()->getName(),
  1455.                 'status' => $waitmessage->isDeleted(),
  1456.                 'opAssign' => '',
  1457.                 'type_mess' => $type_mess
  1458.             ];
  1459.         }
  1460.         $operatorList = [];
  1461.         $opRole $this->roleRepository->findOneBy(['name' => self::OPERATOR]);
  1462.         $userL $this->userRepository->findBy(['role' => $opRole]);
  1463.         foreach ($userL as $op) {
  1464.             $operatorList[] = [
  1465.                 'agent' => $op->getName(),
  1466.                 'status' => $op->getStatus(),
  1467.                 'agent_id' => $op->getId(),
  1468.                 'language' => $op->getLanguage()->getName()
  1469.             ];
  1470.         }
  1471.         return $this->json([
  1472.             'data' => $waitmessageData,
  1473.             'operator' => $operatorList,
  1474.             'pagination' => [
  1475.                 'page' => $paginations->getCurrentPageNumber(),
  1476.                 'total_pages' => ceil($paginations->getTotalItemCount() / $paginations->getItemNumberPerPage()),
  1477.                 'total_items' => $paginations->getTotalItemCount(),
  1478.             ]
  1479.         ], Response::HTTP_OK);
  1480.     }
  1481.     #[Route('/platforms_performance'name'get_platforms_performance'methods: ['GET'])]
  1482.     public function getPlatformsPerformance()
  1483.     {
  1484.         // Autorisation
  1485.         $user $this->getUser();
  1486.         if (!$user) {
  1487.             return $this->json("Vous n'êtes pas connecté "401);
  1488.         }
  1489.         $decodedJwtToken $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1490.         if ($decodedJwtToken['roles'][0] !== self::ADMIN && $decodedJwtToken['roles'][0] !== self::SUPERVISOR) return $this->json(['message' => 'Accès refusé'], 403);
  1491.         $profilTypeFake $this->profilTypeRepository->findOneBy(['name' => 'fake_profil']);
  1492.         $profilTypeReal $this->profilTypeRepository->findOneBy(['name' => 'real_profil']);
  1493.         $platforms $this->platformRepository->findAll();
  1494.         $reports $this->reportRepository->findAll();
  1495.         $data = [];
  1496.         foreach ($platforms as $platform) {
  1497.             $fakeProfils $this->profilRepository->findBy(['profilType' => $profilTypeFake'platform' => $platform]);
  1498.             $realProfils $this->profilRepository->findBy(['profilType' => $profilTypeReal'platform' => $platform]);
  1499.             $numberOfFakeProfil count($fakeProfils);
  1500.             $plt $platform->getName();
  1501.             $numberTotalOfMessageSent 0;
  1502.             $numberTotalOfMessageReceived 0;
  1503.             $numberTotalOfReport1 0;
  1504.             $numberTotalOfReport2 0;
  1505.             $numberTotalOfReport 0;
  1506.             foreach ($fakeProfils as $fakeProfil) {
  1507.                 $messageFakeProfils $this->conversationRepository->findBy(['sender_profil' => $fakeProfil]);
  1508.                 $report1 $this->reportRepository->findBy(['message' => $messageFakeProfils]);
  1509.                 $numberOfReport1 count($report1);
  1510.                 $numberTotalOfReport1 += $numberOfReport1;
  1511.                 $numberOfMessageSent count($messageFakeProfils);
  1512.                 $numberTotalOfMessageSent += $numberOfMessageSent;
  1513.             }
  1514.             foreach ($realProfils as $realProfil) {
  1515.                 $messageRealProfils $this->conversationRepository->findBy(['sender_profil' => $realProfil]);
  1516.                 $report2 $this->reportRepository->findBy(['message' => $messageRealProfils]);
  1517.                 $numberOfReport2 count($report2);
  1518.                 $numberTotalOfReport2 += $numberOfReport2;
  1519.                 $numberOfMessageReceived count($messageRealProfils);
  1520.                 $numberTotalOfMessageReceived += $numberOfMessageReceived;
  1521.             }
  1522.             $numberTotalOfReport $numberTotalOfReport1 $numberTotalOfReport2;
  1523.             $data[] = [
  1524.                 'platform' => $plt,
  1525.                 'numberOfFakeProfil' => $numberOfFakeProfil,
  1526.                 'numberOfMessageSent' => $numberTotalOfMessageSent,
  1527.                 'numberOfMessageReceived' => $numberTotalOfMessageReceived,
  1528.                 'numberOfReport' => $numberTotalOfReport,
  1529.             ];
  1530.         }
  1531.         return $this->json($dataResponse::HTTP_OK);
  1532.     }
  1533.     #[Route('/allplatform'name'platform'methods: ['GET'])]
  1534.     public function getAllPlatform(PlatformRepository $platformRepositorySerializerInterface $serializer)
  1535.     {
  1536.         // Autorisation
  1537.         // $user = $this->getUser();
  1538.         // if (!$user) {
  1539.         //     return $this->json("Vous n'êtes pas connecté ", 401);
  1540.         // }
  1541.         // $decodedJwtToken = $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1542.         // if ($decodedJwtToken['roles'][0] !== self::ADMIN ) return $this->json(['message' => 'Accès refusé'], 403);
  1543.         $platforms $platformRepository->findAll();
  1544.         // foreach($platforms as $platform){
  1545.         //     $datas[] = [
  1546.         //         "value" => $platform->getId(),
  1547.         //         "innerHTML" => $platform->getName(),
  1548.         //     ];
  1549.         // }
  1550.         // return $this->json($datas);
  1551.         $response $serializer->serialize($platforms'json', ['groups' => ['platform']]);
  1552.         return $this->json(json_decode($responsetrue), 200);
  1553.     }
  1554.     /**
  1555.      * API pour avoir tous les faux profil et vrai profil
  1556.      * 
  1557.      */
  1558.     #[Route('/profil'name'get_profil'methods: ['GET'])]
  1559.     public function getProfil()
  1560.     {
  1561.         // Recherche type de profil
  1562.         $realProfil $this->profilTypeRepository->findOneBy(['name' => 'real_profil']);
  1563.         $fakeProfil $this->profilTypeRepository->findOneBy(['name' => 'fake_profil']);
  1564.         // Rescherche des faux et vrai profil
  1565.         $ProfilsReal $this->profilRepository->findBy(['profilType' => $realProfil]);
  1566.         $ProfilFake $this->profilRepository->findBy(['profilType' => $fakeProfil]);
  1567.         //Serialisation des Real profil
  1568.         $RealList = [];
  1569.         foreach ($ProfilsReal as $l) {
  1570.             $RealList[] = [
  1571.                 'id' => $l->getId(),
  1572.                 'name' => $l->getUsername(),
  1573.                 'language' => $l->getLanguage()->getName(),
  1574.                 'age' => $l->getAge(),
  1575.                 'sex' => $l->getSex(),
  1576.                 'status' => $l->getMaritalStatus(),
  1577.                 'search' => $l->getResearch(),
  1578.                 'country' => $l->getCountry(),
  1579.                 'city' => $l->getCity(),
  1580.                 'oriatation' => $l->getSexualOrientation(),
  1581.                 'desc' => $l->getDescription(),
  1582.                 'suspendu' => $l->getSuspend(),
  1583.                 'bani' => $l->getKickOff(),
  1584.             ];
  1585.         }
  1586.         //Serialisation des Fake profil
  1587.         $FakeList = [];
  1588.         foreach ($ProfilFake as $l) {
  1589.             $FakeList[] = [
  1590.                 'id' => $l->getId(),
  1591.                 'name' => $l->getUsername(),
  1592.                 'language' => $l->getLanguage()->getName(),
  1593.                 'age' => $l->getAge(),
  1594.                 'sex' => $l->getSex(),
  1595.                 'status' => $l->getMaritalStatus(),
  1596.                 'search' => $l->getResearch(),
  1597.                 'country' => $l->getCountry(),
  1598.                 'city' => $l->getCity(),
  1599.                 'oriatation' => $l->getSexualOrientation(),
  1600.                 'desc' => $l->getDescription(),
  1601.                 'suspendu' => $l->getSuspend(),
  1602.                 'bani' => $l->getKickOff(),
  1603.             ];
  1604.         }
  1605.         // Serialisation du reponse
  1606.         $data = [
  1607.             "realProfil" => $RealList,
  1608.             "fakeProfil" => $FakeList,
  1609.         ];
  1610.         return $this->json($dataResponse::HTTP_OK);
  1611.     }
  1612.     #[Route('/agents_performance'name'get_agents_performance'methods: ['GET'])]
  1613.     public function getAgentsPerformance(SerializerInterface $serializer)
  1614.     {
  1615.         // Autorisation
  1616.         $user $this->getUser();
  1617.         if (!$user) {
  1618.             return $this->json("Vous n'êtes pas connecté "401);
  1619.         }
  1620.         $decodedJwtToken $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1621.         if ($decodedJwtToken['roles'][0] !== self::ADMIN && $decodedJwtToken['roles'][0] !== self::SUPERVISOR) return $this->json(['message' => 'Accès refusé'], 403);
  1622.         $role $this->roleRepository->findOneBy(['name' => 'operator']);
  1623.         $users $this->userRepository->findBy(['role' => $role]);
  1624.         $data = [];
  1625.         foreach ($users as $user) {
  1626.             $name $user->getName();
  1627.             $mail $user->getMail();
  1628.             $language $user->getLanguage()->getName();
  1629.             $messages $this->messageRepository->findBy(['operator' => $users]);
  1630.             $sentMessage 0;
  1631.             $receivedMessage 0;
  1632.             foreach ($messages as $message) {
  1633.                 $type $message->getConversation()->getSenderProfil()->getProfilType();
  1634.                 if ($type == "fake_profil") {
  1635.                     $sentMessage++;
  1636.                 } else {
  1637.                     $receivedMessage++;
  1638.                 }
  1639.             }
  1640.             $data[] = [
  1641.                 'name' => $name,
  1642.                 'mail' => $mail,
  1643.                 'language' => $language,
  1644.                 'sentMessage' => $sentMessage,
  1645.                 'receivedMessage' => $receivedMessage,
  1646.             ];
  1647.         }
  1648.         return $this->json($dataResponse::HTTP_OK);
  1649.     }
  1650.     #[Route('/supervisor/{id}'name'update_password'methods: ['PUT'])]
  1651.     public function editPasswordSupervisor(Request $request)
  1652.     {
  1653.         $user $this->getUser();
  1654.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_NOT_FOUND);
  1655.         if (!($user->getRoles()[0] == self::ADMIN)) {
  1656.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_UNAUTHORIZED);
  1657.         }
  1658.         [$id] = $this->requestService->getFromAttributes('id');
  1659.         [$newPassword] = $this->requestService->getFromDataRequestBody('newPassword');
  1660.         if (!$newPassword) return $this->json(['message' => 'Le mot de passe ne peut pas être vide'], Response::HTTP_NOT_ACCEPTABLE);
  1661.         $role $this->roleRepository->findOneBy(['name' => self::SUPERVISOR]);
  1662.         $supervisor $this->userRepository->findOneBy(['id' => $id'role' => $role]);
  1663.         $hashedPassword $this->userPasswordHasherInterface->hashPassword($supervisor$newPassword);
  1664.         $supervisor->setPassword($hashedPassword);
  1665.         $this->entityService->saveEntity($supervisor);
  1666.         return $this->json(['message' => 'Mot de passe modifié avec succés'], Response::HTTP_OK);
  1667.     }
  1668.     /**
  1669.      *  API pour suppression d'un superviseur
  1670.      * 
  1671.      */
  1672.     #[Route('/supervisor_delete/{id}'name'delete_password'methods: ['DELETE'])]
  1673.     public function deletePasswordSupervisor()
  1674.     {
  1675.         $user $this->getUser();
  1676.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_NOT_FOUND);
  1677.         if (!($user->getRoles()[0] == self::ADMIN)) {
  1678.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_UNAUTHORIZED);
  1679.         }
  1680.         [$id] = $this->requestService->getFromAttributes('id');
  1681.         $role $this->roleRepository->findOneBy(['name' => self::SUPERVISOR]);
  1682.         $supervisor $this->userRepository->findOneBy(['id' => $id'role' => $role]);
  1683.         $supervisor->setDeleted(true);
  1684.         $this->entityService->saveEntity($supervisor);
  1685.         return $this->json(['message' => 'Superviseur supprimé avec succés'], Response::HTTP_OK);
  1686.     }
  1687.     /**
  1688.      *   API Edit Opérateur
  1689.      * 
  1690.      */
  1691.     #[Route('/operator/{id}'name'update_operator'methods: ['PUT'])]
  1692.     public function editPasswordOperator()
  1693.     {
  1694.         $user $this->getUser();
  1695.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_NOT_FOUND);
  1696.         if (!($user->getRoles()[0] == self::ADMIN || $user->getRoles()[0] == self::SUPERVISOR)) {
  1697.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_UNAUTHORIZED);
  1698.         }
  1699.         [$id] = $this->requestService->getFromAttributes('id');
  1700.         [$newPassword] = $this->requestService->getFromDataRequestBody('newPassword');
  1701.         if (!$newPassword) return $this->json(['message' => 'Le mot de passe ne peut pas être vide'], Response::HTTP_NOT_ACCEPTABLE);
  1702.         $role $this->roleRepository->findOneBy(['name' => 'operator']);
  1703.         $operator $this->userRepository->findOneBy(['id' => $id'role' => $role]);
  1704.         $hashedPassword $this->userPasswordHasherInterface->hashPassword($operator$newPassword);
  1705.         $operator->setPassword($hashedPassword);
  1706.         $this->entityService->saveEntity($operator);
  1707.         return $this->json(['message' => 'Mot de passe modifié avec succés'], Response::HTTP_OK);
  1708.     }
  1709.     /**
  1710.      *   API pour suspendre un opérateur
  1711.      */
  1712.     #[Route('/operator/suspend'name'suspend_operator'methods: ['POST'])]
  1713.     public function suspendOperator()
  1714.     {
  1715.         $user $this->getUser();
  1716.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_NOT_FOUND);
  1717.         if (!($user->getRoles()[0] == self::ADMIN || $user->getRoles()[0] == self::SUPERVISOR)) {
  1718.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_UNAUTHORIZED);
  1719.         }
  1720.         [$id] = $this->requestService->getFromDataRequestBody('id');
  1721.         $role $this->roleRepository->findOneBy(['name' => 'operator']);
  1722.         $operator $this->userRepository->findOneBy(['id' => $id'role' => $role]);
  1723.         $currentDate = new \DateTimeImmutable();
  1724.         $newDate $currentDate->add(new \DateInterval('P7D'));
  1725.         // Convertir la chaîne de caractères en un objet DateTimeImmutable
  1726.         $newSuspendDate \DateTimeImmutable::createFromFormat('Y-m-d'$newDate->format('Y-m-d'));
  1727.         $operator->setSuspend($newSuspendDate);
  1728.         $this->entityService->saveEntity($operator);
  1729.         return $this->json(['message' => 'Operateur suspendu avec succés'], Response::HTTP_OK);
  1730.     }
  1731.     /**
  1732.      *  API pour suppression d'un superviseur
  1733.      * 
  1734.      */
  1735.     #[Route('/kickOff_operator/{id}'name'kick_off_operator'methods: ['DELETE'])]
  1736.     public function kickOffOperator()
  1737.     {
  1738.         $user $this->getUser();
  1739.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_NOT_FOUND);
  1740.         if (!($user->getRoles()[0] == self::ADMIN || $user->getRoles()[0] == self::SUPERVISOR)) {
  1741.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_UNAUTHORIZED);
  1742.         }
  1743.         [$id] = $this->requestService->getFromAttributes('id');
  1744.         $role $this->roleRepository->findOneBy(['name' => "operator"]);
  1745.         $operator $this->userRepository->findOneBy(['id' => $id'role' => $role]);
  1746.         $operator->setDeleted(true);
  1747.         $this->entityService->saveEntity($operator);
  1748.         return $this->json(['message' => 'Opérateur renvoyer avec succés'], Response::HTTP_OK);
  1749.     }
  1750.     #[Route('/agent_statistics'name'get_agent_statistics'methods: ['GET'])]
  1751.     public function getAgentStatistics(SerializerInterface $serializer)
  1752.     {
  1753.         // Autorisation
  1754.         $user $this->getUser();
  1755.         if (!$user) {
  1756.             return $this->json("Vous n'êtes pas connecté "401);
  1757.         }
  1758.         $decodedJwtToken $this->jwtTokenManager->decode($this->tokenStorageInterface->getToken());
  1759.         if ($decodedJwtToken['roles'][0] !== self::ADMIN) return $this->json(['message' => 'Accès refusé'], 403);
  1760.         $role $this->roleRepository->findOneBy(['name' => 'operator']);
  1761.         $users $this->userRepository->findBy(['role' => $role]);
  1762.         $data = [];
  1763.         foreach ($users as $user) {
  1764.             $language $user->getLanguage()->getName();
  1765.             $name $user->getName();
  1766.             $date $user->getDateInscription();
  1767.             $messages $this->messageRepository->findBy(['operator' => $users]);
  1768.             $sentMessage 0;
  1769.             foreach ($messages as $message) {
  1770.                 $type $message->getConversation()->getSenderProfil()->getProfilType();
  1771.                 if ($type == "fake_profil") {
  1772.                     $sentMessage++;
  1773.                 }
  1774.             }
  1775.             $data[] = [
  1776.                 'language' => $language,
  1777.                 'name' => $name,
  1778.                 'sentMessage' => $sentMessage,
  1779.                 'date' => $date,
  1780.             ];
  1781.         }
  1782.         return $this->json($dataResponse::HTTP_OK);
  1783.     }
  1784.     /**
  1785.      *  API pour suppression d'un admin
  1786.      * 
  1787.      */
  1788.     #[Route('/admin_delete/{id}'name'delete_admin'methods: ['DELETE'])]
  1789.     public function deleteAdmin()
  1790.     {
  1791.         $user $this->getUser();
  1792.         if (!$user) return $this->json(['message' => "Vous n'êtes pas connécté"], Response::HTTP_NOT_FOUND);
  1793.         if (!($user->getRoles()[0] == self::ADMIN)) {
  1794.             return $this->json(['message' => "Vous n'êtes pas autorisé à accéder à cet API"], Response::HTTP_UNAUTHORIZED);
  1795.         }
  1796.         [$id] = $this->requestService->getFromAttributes('id');
  1797.         $role $this->roleRepository->findOneBy(['name' => self::ADMIN]);
  1798.         $admin $this->userRepository->findOneBy(['id' => $id'role' => $role]);
  1799.         $admin->setDeleted(true);
  1800.         $this->entityService->saveEntity($admin);
  1801.         return $this->json(['message' => 'Admin supprimé avec succés'], Response::HTTP_OK);
  1802.     }
  1803. }