src/Controller/CentreController.php line 210

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AccessCentre;
  4. use App\Entity\Audio;
  5. use App\Entity\Audiometrie\Setting;
  6. use App\Entity\Factures;
  7. use App\Entity\AudioCentre;
  8. use App\Entity\AudioDiplome;
  9. use App\Entity\AudioMotif;
  10. use App\Entity\AudioSpecialite;
  11. use App\Entity\CenterImported;
  12. use App\Entity\Centre;
  13. use App\Entity\CentreMutuelle;
  14. use App\Entity\SpecificSubscription;
  15. use App\Entity\CentrePrestation;
  16. use App\Entity\CentreTier;
  17. use App\Entity\CenterImage;
  18. use App\Entity\Client;
  19. use App\Entity\Diplome;
  20. use App\Entity\ContractCategory;
  21. use App\Entity\ExperiencePro;
  22. use App\Entity\Lieu;
  23. use App\Entity\Ville;
  24. use App\Entity\LieuPrestation;
  25. use App\Service\Billing\BillingCdaService;
  26. use App\Entity\Motif;
  27. use App\Entity\Station;
  28. use App\Entity\Partner\PartnerSubscription;
  29. use App\Entity\Mutuelle;
  30. use App\Service\Payment\SubscriptionService;
  31. use App\Service\Subscription\StripeService;
  32. use App\Service\Order\OrderPatient;
  33. use App\Entity\Plan;
  34. use App\Entity\Prestation;
  35. use App\Entity\Specialite;
  36. use App\Entity\Tier;
  37. use App\Entity\Payment\Subscription;
  38. use App\Entity\ClientTemp;
  39. use App\Entity\Token;
  40. use App\Entity\Rdv;
  41. use App\Service\FileUploader;
  42. use App\Service\PublicFunction;
  43. use DateInterval;
  44. use DateTimeZone;
  45. use App\Entity\Audio\Role;
  46. use Psr\Log\LoggerInterface;
  47. use Doctrine\Common\Collections\ArrayCollection;
  48. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  49. use Symfony\Component\HttpFoundation\Request;
  50. use Symfony\Component\HttpFoundation\Response;
  51. use Symfony\Component\Routing\Annotation\Route;
  52. use DateTime;
  53. use Symfony\Contracts\HttpClient\HttpClientInterface;
  54. use Symfony\Component\String\Slugger\SluggerInterface;
  55. use App\Service\Notification\EmailNotificationDemoService;
  56. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  57. class CentreController extends AbstractController
  58. {
  59.     private $logger;
  60.     private $slugger;
  61.     private $orderPatient;
  62.     private $emailNotificationDemoService;
  63.     public function __construct(LoggerInterface $loggerOrderPatient $orderPatientEmailNotificationDemoService $emailNotificationDemoServiceHttpClientInterface $clientSluggerInterface $slugger)
  64.     {
  65.         $this->logger $logger;
  66.         $this->client $client;
  67.         $this->slugger $slugger;
  68.         $this->orderPatient $orderPatient;
  69.         $this->emailNotificationDemoService $emailNotificationDemoService;
  70.     }
  71.     /**
  72.      * @Route("/centre/{id}", name="deleteCentreByID", methods={"DELETE"})
  73.      */
  74.     public function deleteCentreByID(Request $requestCentre $centre)
  75.     {
  76.         if (!$request->query->get('token'))
  77.             return new Response(json_encode([
  78.                 "message" => "Pas de token n'a été spécifié",
  79.                 "status" => 401,
  80.             ]), 401);
  81.         $entityManager $this->getDoctrine()->getManager();
  82.         /** @var Token */
  83.         $token $this->getDoctrine()
  84.             ->getRepository(Token::class)
  85.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $centre->getIdGerant()]);
  86.         if (!$token)
  87.             return new Response(json_encode([
  88.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  89.                 "status" => 404,
  90.             ]), 404);
  91.         // get token age
  92.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  93.         // if the token if older than 7 days
  94.         if ($dateDiff->7) {
  95.             $entityManager->remove($token);
  96.             $entityManager->flush();
  97.             return $this->json([
  98.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  99.                 'path' => 'src/Controller/ClientController.php',
  100.                 "status" => 401
  101.             ], 401);
  102.         }
  103.         $accessCentre $this->getDoctrine()->getRepository(AccessCentre::class)
  104.         ->findBy(array('id_centre' => $centre->getId()));
  105.         $centerParent $this->getDoctrine()
  106.             ->getRepository(Centre::class)
  107.             ->findOneBy(['id_gerant' => $centre->getIdGerant()]);
  108.         $meetings $this->getDoctrine()
  109.             ->getRepository(Rdv::class)
  110.             ->findBy(['id_centre' => $centre->getId()]);
  111.         $clients $this->getDoctrine()
  112.             ->getRepository(ClientTemp::class)
  113.             ->findBy(['id_centre' => $centre->getId()]);
  114.         $mutuels $this->getDoctrine()
  115.             ->getRepository(CentreMutuelle::class)
  116.             ->findBy(['id_centre' => $centre->getId()]);
  117.         /*  $tiers = $this->getDoctrine()
  118.         ->getRepository(CentreTier::class)
  119.         ->findBy(['id_centre' => $centre->getId()]);*/
  120.         $prestations $this->getDoctrine()
  121.             ->getRepository(CentrePrestation::class)
  122.             ->findBy(['id_centre' => $centre->getId()]);
  123.         $entityManager $this->getDoctrine()->getManager();
  124.         // return $this->json(["id" => $tiers]);
  125.         /*  foreach ($tiers as $tier) {
  126.             $entityManager->remove($tier);
  127.             }*/
  128.         foreach ($meetings as $meeting) {
  129.             $entityManager->remove($meeting);
  130.         }
  131.         foreach ($mutuels as $mutuel) {
  132.             $entityManager->remove($mutuel);
  133.         }
  134.         foreach ($prestations as $prestation) {
  135.             $entityManager->remove($prestation);
  136.         }
  137.        
  138.         foreach ($accessCentre as $access) {
  139.             $entityManager->remove($access);
  140.         }
  141.         foreach ($clients as $client) {
  142.             $entityManager->remove($client);
  143.         }
  144.         foreach ($meetings as $meeting) {
  145.             $meeting->setIdCentre($centerParent);
  146.             $entityManager->persist($meeting);
  147.         }
  148.         foreach ($clients as $client) {
  149.             $client->setIdCentre($centerParent);
  150.             $entityManager->persist($client);
  151.         }
  152.         $entityManager $this->getDoctrine()->getManager();
  153.         $audioCentres $entityManager->getRepository(AudioCentre::class)->findOneBy(['id_centre' => $centre->getId()]);
  154.         $entityManager->remove($audioCentres);
  155.         $entityManager->remove($centre);
  156.         $entityManager->flush();
  157.         return $this->json(["id" => $centerParent->getId(), "name" => $centerParent->getName()]);
  158.         //  return new Response($centre->getId() . " has been successfully deleted");
  159.     }
  160.     /**
  161.      * @Route("/centres/query", name="getCentresSearchQuery", methods={"GET","HEAD"})
  162.      */
  163.     public function getCentresSearchQuery(Request $request): Response
  164.     {
  165.         /** @var ActivityRepository */
  166.         $activityRepo $this->getDoctrine();
  167.         if (strlen($request->query->get('query')) == && is_numeric($request->query->get('query'))) {
  168.             /** @var Centre[] */
  169.             $centres $this->getDoctrine()->getRepository(Centre::class)
  170.                 ->findBy(["postale" => (int)$request->query->get('query')]);
  171.         } else {
  172.             /** @var Centre[] */
  173.             $centres $this->getDoctrine()->getRepository(Centre::class)
  174.                 ->findByQuery($request->query->get('query'));
  175.         }
  176.         $result = new ArrayCollection();
  177.         foreach ($centres as $centre) {
  178.             $result->add([
  179.                 "id" => $centre->getId(),
  180.                 "name" => $centre->getName() . ", " $centre->getAddress() . ", " $centre->getPostale() . " " $centre->getCity(),
  181.             ]);
  182.         }
  183.         return new Response(json_encode([
  184.             "content" => $result->toArray(),
  185.             "status" => 200,
  186.         ]));
  187.     }
  188.     /**
  189.      * @Route("/centres", name="getCentresSearch", methods={"GET","HEAD"})
  190.      */
  191.     public function getCentresSearch(Request $requestPublicFunction $publicFunction): Response
  192.     {
  193.         // Récupérer les paramètres de la requête
  194.         // $queryParams = $request->query->all();
  195.         // // Ajouter les paramètres dans la réponse pour les afficher
  196.         // return new Response(
  197.         //     json_encode([
  198.         //         'data' => $queryParams, // Afficher les paramètres de la requête
  199.         //     ]),
  200.         //     200
  201.         // );
  202.         /*
  203.         /** @var ActivityRepository */
  204.         $activityRepo $this->getDoctrine();
  205.         $date = new DateTime();
  206.         $centres = [];
  207.         $lieux = [];
  208.         $centreCoord = [];
  209.         $lieuxCoord = [];
  210.         $centreName = [];
  211.         $lieuxName = [];
  212.         setlocale(LC_TIME'fr_FR');
  213.         $city $request->query->get('ville');
  214.         $name $request->query->get('name');
  215.         $address $request->query->get('address');
  216.         $page $request->query->getInt('page'1);
  217.         $limit $request->query->get('limit'); // Number of results per page
  218.         $longitude $request->query->get('longitude');
  219.         $latitude $request->query->get('latitude');
  220.         /*   $formattedAddress = "21,avenue du Maine,70015 Paris";
  221.         $response = $this->client->request('GET','https://maps.googleapis.com/maps/api/geocode/json', [
  222.             'query' => [
  223.                 'address' => $formattedAddress,
  224.                 'key' => 'AIzaSyB-w9vBKJ9IYNPevzRu4sxhfZ2O4FAPOZc'
  225.             ]
  226.         ]);
  227.     
  228.         $data = $response->toArray();
  229.         dd($data);*/
  230.         // $request->query->get('longitude') && $request->query->get('latitude');
  231.         // dd($request->query->get('longitude'));
  232.         $repository $this->getDoctrine()->getRepository(CenterImported::class);
  233.         $resultsImportded $repository->findByCoordinates($name$longitude$latitude$page$limit);
  234.         //   $resultsImportded = $repository->findByCityOrPostalCodeAndName($city, $name, $address, $page, $limit ,$longitude,$latitude);
  235.         $totalResults $repository->getTotalCountByCityOrPostalCodeAndName($name$longitude$latitude$page$limit);
  236.         /*  $repository = $this->getDoctrine()->getRepository(CenterImported::class);
  237.         $resultsImportded = $repository->findByCityOrPostalCodeAndName($city, $name, $address, $page, $limit);
  238.     
  239.         $totalResults = $repository->getTotalCountByCityOrPostalCodeAndName($city, $name, $address);*/
  240.         if (is_numeric($totalResults) && is_numeric($limit) && $limit !== && $totalResults !== 0) {
  241.             $totalPages ceil($totalResults $limit);
  242.         } elseif ($totalResults === 0) {
  243.             $totalPages 0;
  244.         } else {
  245.             $totalPages 1;
  246.         }
  247.         //  dd( ceil($totalResults / $limit));
  248.         $centerImportedArray array_map(function ($session) {
  249.             return [
  250.                 "id" => $session->getId(),
  251.                 "nom" => $session->getNom(),
  252.                 "slug" => $session->getSlug(),
  253.                 "adresse" => $session->getAdresse(),
  254.                 "latitude" => $session->getLatitude(),
  255.                 "longitude" => $session->getLongitude(),
  256.                 "codePostal" => $session->getcodePostal(),
  257.                 "ville" => $session->getVille(),
  258.             ];
  259.         }, $resultsImportded);
  260.         //dd($centerImportedArray);
  261.         //if the user searched by coordinates
  262.         if ($request->query->get('address')) {
  263.             /** @var Centre[] */
  264.             $centreCoord $this->getDoctrine()->getRepository(Centre::class)
  265.                 ->findByAdress($request->query->get('address'));
  266.         }
  267.         if ($request->query->get('longitude') && $request->query->get('latitude')) {
  268.             /** @var Centre[] */
  269.             $centreCoord $this->getDoctrine()->getRepository(Centre::class)
  270.                 ->findByCoordonates($request->query->get('longitude'), $request->query->get('latitude'), $page$limit);
  271.             /** @var Lieu[] */
  272.             $lieuxCoord $this->getDoctrine()->getRepository(Lieu::class)
  273.                 ->findByCoordonates($request->query->get('longitude'), $request->query->get('latitude'), $page$limit);
  274.         }
  275.         if ($request->query->get('name')) {
  276.             $centresID $this->getDoctrine()->getRepository(Centre::class)
  277.                 ->findByName($request->query->get('name'));
  278.             /** @var Centre[] */
  279.             foreach ($centresID as $centreID) {
  280.                 $centre $this->getDoctrine()->getRepository(Centre::class)
  281.                     ->find($centreID);
  282.                 if ($centre)
  283.                     array_push($centreName,  $centre);
  284.             }
  285.             /** @var int[] */
  286.             $lieuxID $this->getDoctrine()->getRepository(Lieu::class)
  287.                 ->findByName($request->query->get('name'));
  288.             /** @var Lieux[] */
  289.             foreach ($lieuxID as $lieuID) {
  290.                 $lieu $this->getDoctrine()->getRepository(Lieu::class)
  291.                     ->find($lieuID);
  292.                 if ($lieu)
  293.                     array_push($lieuxName,  $lieu);
  294.             }
  295.         }
  296.         if ($request->query->get('longitude') &&  $request->query->get('name') && !$request->query->get('address')) {
  297.             //$centres = array_intersect($centreCoord, $centreName);
  298.             $centres array_uintersect($centreName$centreCoord, function ($centreName$centreCoord) {
  299.                 return spl_object_hash($centreName) <=> spl_object_hash($centreCoord);
  300.             });
  301.             $lieux array_uintersect($lieuxName$lieuxCoord, function ($lieuxName$lieuxCoord) {
  302.                 return spl_object_hash($lieuxName) <=> spl_object_hash($lieuxCoord);
  303.             });
  304.         } else {
  305.             if ($request->query->get('name')) {
  306.                 $centres $centreName;
  307.                 $lieux $lieuxName;
  308.             } else {
  309.                 $centres $centreCoord;
  310.                 $lieux $lieuxCoord;
  311.             }
  312.         }
  313.         if (!$request->query->get('longitude') && !$request->query->get('name') && !$request->query->get('address')) {
  314.             // basic search of paris coordinates
  315.             /** @var Centre[] */
  316.             $centres $this->getDoctrine()->getRepository(Centre::class)
  317.                 ->findByCoordonates(2.3448.85$page$limit);
  318.             /** @var Lieu[] */
  319.             $lieux $this->getDoctrine()->getRepository(Lieu::class)
  320.                 ->findByCoordonates(2.3448.85$page$limit);
  321.         }
  322.         if (count($centres) < && count($lieux) < 1) {
  323.             // dd('dd');
  324.             return new Response(json_encode([
  325.                 "content" => [],
  326.                 "centerImported" => $centerImportedArray,
  327.                 "totalPages" => $totalPages,
  328.                 "message" => "Aucun centre/lieu n'a été trouvé avec le nom fournit.",
  329.                 "status" => 404,
  330.             ]), 200);
  331.         }
  332.         // secondly filters all of the other filters
  333.         // checks if there is any result with the search
  334.         if (count($centres) != || count($lieux) != 0) {
  335.             $result = new ArrayCollection();
  336.             $resultAudioMulti = array();
  337.             //gets through all centres given by the function
  338.             foreach ($centres as $centre) {
  339.                 if ($centre->getIsValid() != true)
  340.                     continue;
  341.                 if ($centre->getIsBlocked() == true)
  342.                     continue;
  343.                 //isDomicile filter
  344.                 if (($request->query->get('isDomicile')) && ($request->query->get('isDomicile') == "true")) {
  345.                     if ($centre->getIsRdvDomicile() != true)
  346.                         continue;
  347.                 }
  348.                 // Prestation
  349.                 /** @var CentrePrestation[] */
  350.                 $prestations $this->getDoctrine()->getRepository(CentrePrestation::class)
  351.                     ->findBy(array('id_centre' => $centre->getId()));
  352.                 /** @var Rdv[] */
  353.                 $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  354.                     ->findAllReviewsCentre($centre->getId());
  355.                 //prestation filter
  356.                 if ($request->query->get('prestations') && $request->query->get('prestations') != '') {
  357.                     /** @var int[] */
  358.                     $prestationsToCheck json_decode($request->query->get('prestations'));
  359.                     //test all prestations
  360.                     $allPrestation true;
  361.                     foreach ($prestationsToCheck as $prestationToCheck) {
  362.                         $isContained false;
  363.                         //test if the prestation given is part of the skillset of the centre
  364.                         foreach ($prestations as $prestation) {
  365.                             if ($prestation->getIdPrestation()->getId() == $prestationToCheck) {
  366.                                 $isContained true;
  367.                                 continue;
  368.                             }
  369.                         }
  370.                         // if the prestation isn't contained then stop the loop and toggle the value to false
  371.                         if ($isContained == false) {
  372.                             $allPrestation false;
  373.                             continue;
  374.                         }
  375.                     }
  376.                     // if the user doesn't have all the prestations then skip the work
  377.                     if ($allPrestation == false) continue;
  378.                 }
  379.                 $resultPrestation = new ArrayCollection();
  380.                 foreach ($prestations as $prestation) {
  381.                     $resultPrestation->add([
  382.                         "id" => $prestation->getIdPrestation()->getId(),
  383.                         "titre" => $prestation->getIdPrestation()->getLibelle(),
  384.                     ]);
  385.                 }
  386.                 /** @var AudioCentre[] */
  387.                 $liaisons $this->getDoctrine()->getRepository(AudioCentre::class)
  388.                     ->findBy(array('id_centre' => $centre'isConfirmed' => true));
  389.                 $resultAudio = new ArrayCollection();
  390.                 // goes though the each audio of the center
  391.                 foreach ($liaisons as $liaison) {
  392.                     /** @var Audio */
  393.                     $audio $this->getDoctrine()->getRepository(Audio::class)
  394.                         ->findOneBy(array('id' => $liaison->getIdAudio()));
  395.                     if ($audio->getIsIndieValid() != true && $audio->getIsIndie() != false)
  396.                         continue;
  397.                     /** @var Rdv[] */
  398.                     $audioRdvs $this->getDoctrine()->getRepository(Rdv::class)
  399.                         ->findAllReviewsAudio($audio->getId());
  400.                     // Name filter
  401.                     /*if ($request->query->get('name')) {
  402.                         // if it's the name **isn't** contained in any way, skip the worker
  403.                         $fullname = $publicFunction->normalize($audio->getName() . " " . $audio->getLastname());
  404.                         $namefull = $publicFunction->normalize($audio->getName() . " " . $audio->getLastname());
  405.                         $nameToCheck = $publicFunction->normalize($request->query->get('name'));
  406.                         if (!(str_contains($fullname, $nameToCheck) || str_contains($namefull, $nameToCheck)))
  407.                             continue;
  408.                     }*/
  409.                     // Motif filter
  410.                     /** @var AudioMotif[] */
  411.                     $motifs $this->getDoctrine()->getRepository(AudioMotif::class)
  412.                         ->findBy(array('id_audio' => $liaison->getIdAudio()));
  413.                     // will test whether or not the audio has the necessery motif to be added
  414.                     if ($request->query->get('motif')) {
  415.                         $motifID = (int) $request->query->get('motif');
  416.                         $hasMotif false;
  417.                         foreach ($motifs as $motif) {
  418.                             if ($motif->getIdMotif()->getId() == $motifID$hasMotif true;
  419.                         }
  420.                         if ($hasMotif == false) continue;
  421.                     }
  422.                     $resultMotif = new ArrayCollection();
  423.                     foreach ($motifs as $motif) {
  424.                         $resultMotif->add([
  425.                             "id" => $motif->getIdMotif()->getId(),
  426.                             "titre" => $motif->getIdMotif()->getTitre(),
  427.                             "consigne" => $motif->getConsigne(),
  428.                             "duration" => $motif->getDuration(),
  429.                             "isRdvonline" => $motif->getIsRdvonline(),
  430.                         ]);
  431.                     }
  432.                     // Specialities
  433.                     /** @var AudioSpecialite[] */
  434.                     $specialities $this->getDoctrine()->getRepository(AudioSpecialite::class)
  435.                         ->findBy(array('id_audio' => $liaison->getIdAudio()));
  436.                     //speciality filter
  437.                     if ($request->query->get('specialities') && $request->query->get('specialities') != '') {
  438.                         /** @var int[] */
  439.                         $specialitiesToCheck json_decode($request->query->get('specialities'));
  440.                         //test all specialities
  441.                         $allSpecialities true;
  442.                         foreach ($specialitiesToCheck as $specialityToCheck) {
  443.                             $isContained false;
  444.                             //test if the speciality given is part of the skillset of the audio
  445.                             foreach ($specialities as $speciality) {
  446.                                 if ($speciality->getIdSpecialite()->getId() == $specialityToCheck) {
  447.                                     $isContained true;
  448.                                     continue;
  449.                                 }
  450.                             }
  451.                             // if the speciality isn't contained then stop the loop and toggle the value to false
  452.                             if ($isContained == false) {
  453.                                 $allSpecialities false;
  454.                                 continue;
  455.                             }
  456.                         }
  457.                         // if the user doesn't have all the specialities then skip the work
  458.                         if ($allSpecialities == false) continue;
  459.                     }
  460.                     $resultSpeciality = new ArrayCollection();
  461.                     foreach ($specialities as $speciality) {
  462.                         if ($speciality->getIdSpecialite() !== null) {
  463.                             $resultSpeciality->add([
  464.                                 "id" => $speciality->getIdSpecialite()->getId(),
  465.                                 "titre" => $speciality->getIdSpecialite()->getLibelle(),
  466.                             ]);
  467.                         }
  468.                     }
  469.                     //Filter Day
  470.                     if ($request->query->get('day') && $request->query->get('day') != '0') {
  471.                         $day $request->query->get('day');
  472.                         setlocale(LC_TIME'fr_FR.utf8');
  473.                         if ($day == "1") {
  474.                             $dayDispo $publicFunction->calculSchedule($audio, new \DateTime(), $centre);
  475.                             if (count($dayDispo[strftime('%A')]) == 0) {
  476.                                 continue;
  477.                             }
  478.                         }
  479.                         if ($day == "3") {
  480.                             if ((strftime('%A') == "samedi") || (strftime('%A') == "dimanche")) {
  481.                                 $dateAfterWeek = new DateTime();
  482.                                 $dayDispo $publicFunction->calculSchedule($audio, new \DateTime(), $centre);
  483.                                 $day2Dispo $publicFunction->calculSchedule($audio$dateAfterWeek->add(new DateInterval('P7D')), $centre);
  484.                                 if (strftime('%A') == "samedi") {
  485.                                     $nb count($dayDispo[strftime('%A')]) + count($dayDispo[strftime("%A"strtotime("+1 day"))]);
  486.                                     $nb $nb count($day2Dispo['lundi']);
  487.                                     if ($nb == 0) {
  488.                                         continue;
  489.                                     }
  490.                                 }
  491.                                 if (strftime('%A') == "dimanche") {
  492.                                     $nb count($dayDispo[strftime('%A')]);
  493.                                     $nb $nb count($day2Dispo['lundi']) + count($day2Dispo['mardi']);
  494.                                     if ($nb == 0) {
  495.                                         continue;
  496.                                     }
  497.                                 }
  498.                             } else {
  499.                                 $dayDispo $publicFunction->calculSchedule($audio, new \DateTime(), $centre);
  500.                                 //dd($dayDispo);
  501.                                 $nb count($dayDispo[strftime('%A')]) + count($dayDispo[strftime("%A"strtotime("+1 day"))]) + count($dayDispo[strftime("%A"strtotime("+2 day"))]);
  502.                                 if ($nb == 0) {
  503.                                     continue;
  504.                                 }
  505.                             }
  506.                         }
  507.                     }
  508.                     if ($audio->getIsIndie()) {
  509.                         $isNewWorker true;
  510.                         foreach ($resultAudioMulti as $key => $audioMulti) {
  511.                             if ($audioMulti["id"] == $audio->getId()) {
  512.                                 $isNewWorker false;
  513.                                 break;
  514.                             }
  515.                         }
  516.                         $date1 = new DateTime();
  517.                         $date2 = new DateTime();
  518.                         if ($isNewWorkerarray_push($resultAudioMulti, [
  519.                             "id" => $audio->getId(),
  520.                             "civilite" => $audio->getCivilite(),
  521.                             "name" => $audio->getName(),
  522.                             "lastname" => $audio->getLastname(),
  523.                             "birthdate" => $audio->getBirthdate(),
  524.                             "mail" => $audio->getMail(),
  525.                             "phone" => $audio->getPhone(),
  526.                             "adeli" => $audio->getAdeli(),
  527.                             "pin" => $audio->getPin(),
  528.                             "description" => $audio->getDescription(),
  529.                             "imgUrl" => $audio->getImgUrl(),
  530.                             "isRdvDomicileIndie" => $audio->getIsRdvDomicileIndie(),
  531.                             "averageRating" => $publicFunction->calculateRating($audioRdvs),
  532.                             "nbrReview" => count($audioRdvs),
  533.                             "motifs" => $resultMotif->toArray(),
  534.                             "specialities" => $resultSpeciality->toArray(),
  535.                             "centres" => array([
  536.                                 "id" => $centre->getId(),
  537.                                 "address" => $centre->getAddress(),
  538.                                 "postale" => $centre->getPostale(),
  539.                                 "city" => $centre->getCity(),
  540.                                 "finess" => $centre->getFiness(),
  541.                                 "siret" => $centre->getSiret(),
  542.                                 "website" => $centre->getWebsite(),
  543.                                 "phone" => $centre->getPhone(),
  544.                                 "latitude" => $centre->getLatitude(),
  545.                                 "longitude" => $centre->getLongitude(),
  546.                                 "schedule" => [
  547.                                     $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  548.                                     $publicFunction->calculSchedule($audio$date1->add(new DateInterval('P7D')), $centre),
  549.                                     $publicFunction->calculSchedule($audio$date2->add(new DateInterval('P14D')), $centre)
  550.                                 ],
  551.                                 "isLieu" => false
  552.                             ])
  553.                         ]);
  554.                         else array_push(
  555.                             $resultAudioMulti[$key]["centres"],
  556.                             [
  557.                                 "id" => $centre->getId(),
  558.                                 "address" => $centre->getAddress(),
  559.                                 "postale" => $centre->getPostale(),
  560.                                 "city" => $centre->getCity(),
  561.                                 "finess" => $centre->getFiness(),
  562.                                 "siret" => $centre->getSiret(),
  563.                                 "website" => $centre->getWebsite(),
  564.                                 "phone" => $centre->getPhone(),
  565.                                 "latitude" => $centre->getLatitude(),
  566.                                 "longitude" => $centre->getLongitude(),
  567.                                 "schedule" => [
  568.                                     $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  569.                                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P7D')), $centre),
  570.                                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P14D')), $centre)
  571.                                 ],
  572.                                 "isLieu" => false
  573.                             ]
  574.                         );
  575.                         continue;
  576.                     }
  577.                     //add audio in the result
  578.                     $date1 = new DateTime();
  579.                     $date2 = new DateTime();
  580.                     if ($centre->getHoraire() == null || $centre->getHoraire() == []) continue;
  581.                     $resultAudio->add([
  582.                         "id" => $audio->getId(),
  583.                         "civilite" => $audio->getCivilite(),
  584.                         "name" => $audio->getName(),
  585.                         "lastname" => $audio->getLastname(),
  586.                         "birthdate" => $audio->getBirthdate(),
  587.                         "mail" => $audio->getMail(),
  588.                         "phone" => $audio->getPhone(),
  589.                         "adeli" => $audio->getAdeli(),
  590.                         "pin" => $audio->getPin(),
  591.                         "description" => $audio->getDescription(),
  592.                         "imgUrl" => $audio->getImgUrl(),
  593.                         "averageRating" => $publicFunction->calculateRating($audioRdvs),
  594.                         "nbrReview" => count($audioRdvs),
  595.                         "motifs" => $resultMotif->toArray(),
  596.                         "specialities" => $resultSpeciality->toArray(),
  597.                         "schedule" => [
  598.                             $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  599.                             $publicFunction->calculSchedule($audio$date1->add(new DateInterval('P7D')), $centre),
  600.                             $publicFunction->calculSchedule($audio$date2->add(new DateInterval('P14D')), $centre)
  601.                         ],
  602.                     ]);
  603.                 }
  604.                 if (count($resultAudio) > 0)
  605.                     $result->add([
  606.                         "id" => $centre->getId(),
  607.                         "audio_id" => $centre->getIdGerant()->getId(),
  608.                         "name" => $centre->getName(),
  609.                         "slug" => $centre->getSlug(),
  610.                         "imgUrl" => $centre->getImgUrl(),
  611.                         "isRdvDomicile" => $centre->getIsRdvDomicile(),
  612.                         "address" => $centre->getAddress(),
  613.                         "postale" => $centre->getPostale(),
  614.                         "city" => $centre->getCity(),
  615.                         "finess" => $centre->getFiness(),
  616.                         "siret" => $centre->getSiret(),
  617.                         "website" => $centre->getWebsite(),
  618.                         "phone" => $centre->getPhone(),
  619.                         "isHandicap" => $centre->getIsHandicap(),
  620.                         "latitude" => $centre->getLatitude(),
  621.                         "longitude" => $centre->getLongitude(),
  622.                         "averageRating" => $publicFunction->calculateRating($centreRdvs),
  623.                         "nbrReview" => count($centreRdvs),
  624.                         "prestations" => $resultPrestation->toArray(),
  625.                         "audio" => $resultAudio->toArray(),
  626.                     ]);
  627.             }
  628.             if (count($result) > || count($resultAudioMulti) > 0)
  629.                 return new Response(json_encode([
  630.                     "content" => array_merge($result->toArray(), $resultAudioMulti),
  631.                     "centerImported" => $centerImportedArray,
  632.                     "totalPages" => $totalPages,
  633.                     "day" => strftime("%A"),
  634.                     "status" => 200,
  635.                 ]));
  636.             else
  637.                 return new Response(json_encode([
  638.                     "content" => [],
  639.                     "message" => "Aucun centre n'a été trouvé avec ces critères.",
  640.                     "centerImported" => $centerImportedArray,
  641.                     "totalPages" => $totalPages,
  642.                     "status" => 404,
  643.                 ]), 200);
  644.         } else {
  645.             return new Response(json_encode([
  646.                 "content" => [],
  647.                 "message" => "Aucun centre n'a été trouvé à cette adresse.",
  648.                 "status" => 404,
  649.             ]), 200);
  650.         }
  651.     }
  652.     /**
  653.      * @Route("/centres/client/{id}", name="getCentresByClient", methods={"GET","HEAD"})
  654.      */
  655.     public function getCentresByClient(Request $requestClient $clientPublicFunction $publicFunction): Response
  656.     {
  657.         /** @var ActivityRepository */
  658.         $activityRepo $this->getDoctrine();
  659.         if (!$request->query->get('token'))
  660.             return new Response(json_encode([
  661.                 "message" => "Pas de token n'a été spécifié",
  662.                 "status" => 401,
  663.             ]), 401);
  664.         $entityManager $this->getDoctrine()->getManager();
  665.         /** @var Token */
  666.         $token $this->getDoctrine()
  667.             ->getRepository(Token::class)
  668.             ->findOneBy(['token' => $request->query->get('token'), "id_client" => $client]);
  669.         if (!$token)
  670.             return new Response(json_encode([
  671.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  672.                 "status" => 404,
  673.             ]), 404);
  674.         // get token age
  675.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  676.         // if the token if older than 7 days
  677.         if ($dateDiff->7) {
  678.             $entityManager->remove($token);
  679.             $entityManager->flush();
  680.             return $this->json([
  681.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  682.                 'path' => 'src/Controller/ClientController.php',
  683.                 "status" => 401
  684.             ], 401);
  685.         }
  686.         $resultRdv = new ArrayCollection();
  687.         $resultNear = new ArrayCollection();
  688.         /** @var int[] */
  689.         $centresID $this->getDoctrine()->getRepository(Centre::class)
  690.             ->findByRdvTaken($client);
  691.         foreach ($centresID as $centreID) {
  692.             /** @var Centre[] */
  693.             $centres $this->getDoctrine()->getRepository(Centre::class)
  694.                 ->find($centreID);
  695.         }
  696.         foreach ($centres as $centre) {
  697.             /** @var Rdv[] */
  698.             $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  699.                 ->findAllReviewsCentre($centre->getId());
  700.             $resultRdv->add([
  701.                 "id" => $centre->getId(),
  702.                 "audio_id" => $centre->getIdGerant()->getId(),
  703.                 "name" => $centre->getName(),
  704.                 "imgUrl" => $centre->getImgUrl(),
  705.                 "isRdvDomicile" => $centre->getIsRdvDomicile(),
  706.                 "address" => $centre->getAddress(),
  707.                 "postale" => $centre->getPostale(),
  708.                 "city" => $centre->getCity(),
  709.                 "finess" => $centre->getFiness(),
  710.                 "siret" => $centre->getSiret(),
  711.                 "website" => $centre->getWebsite(),
  712.                 "phone" => $centre->getPhone(),
  713.                 "isHandicap" => $centre->getIsHandicap(),
  714.                 "longitude" => $centre->getLongitude(),
  715.                 "latitude" => $centre->getLatitude(),
  716.                 "averageRating" => $publicFunction->calculateRating($centreRdvs),
  717.                 "nbrReview" => count($centreRdvs),
  718.             ]);
  719.         }
  720.         //if the user searched by coordinates
  721.         if ($request->query->get('longitude') && $request->query->get('latitude')) {
  722.             /** @var Centre[] */
  723.             $centresNear $this->getDoctrine()->getRepository(Centre::class)
  724.                 ->findByCoordonates($request->query->get('longitude'), $request->query->get('latitude'), $page$limit);
  725.             // checks if there is any result with the search
  726.             //gets through all centres given by the function
  727.             foreach ($centresNear as $centre) {
  728.                 /** @var Rdv[] */
  729.                 $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  730.                     ->findAllReviewsCentre($centre->getId());
  731.                 $resultNear->add([
  732.                     "id" => $centre->getId(),
  733.                     "audio_id" => $centre->getIdGerant()->getId(),
  734.                     "name" => $centre->getName(),
  735.                     "imgUrl" => $centre->getImgUrl(),
  736.                     "isRdvDomicile" => $centre->getIsRdvDomicile(),
  737.                     "address" => $centre->getAddress(),
  738.                     "postale" => $centre->getPostale(),
  739.                     "city" => $centre->getCity(),
  740.                     "finess" => $centre->getFiness(),
  741.                     "siret" => $centre->getSiret(),
  742.                     "website" => $centre->getWebsite(),
  743.                     "phone" => $centre->getPhone(),
  744.                     "isHandicap" => $centre->getIsHandicap(),
  745.                     "longitude" => $centre->getLongitude(),
  746.                     "latitude" => $centre->getLatitude(),
  747.                     "averageRating" => $publicFunction->calculateRating($centreRdvs),
  748.                     "nbrReview" => count($centreRdvs),
  749.                 ]);
  750.             }
  751.         }
  752.         if ((count($resultNear) > 0) || (count($resultRdv) > 0)) {
  753.             return new Response(json_encode([
  754.                 "resultNear" => $resultNear->toArray(),
  755.                 "resultRdv" => $resultRdv->toArray(),
  756.                 "status" => 200,
  757.             ]));
  758.         } else {
  759.             return new Response(json_encode([
  760.                 "message" => "Aucun centre n'a été trouvé.",
  761.                 "status" => 404,
  762.             ]), 404);
  763.         }
  764.     }
  765.     /**
  766.      * @Route("/centre/image/{id}", name="getCentreImage", methods={"GET"})
  767.      */
  768.     public function getCentreImage(Centre $centrePublicFunction $publicFunction): Response
  769.     {
  770.         if (!$centre->getImgUrl()) {
  771.             return $publicFunction->replyWithFile('images/centre/'"imgOreille.png");
  772.         }
  773.         return $publicFunction->replyWithFile('images/centre/'$centre->getImgUrl());
  774.     }
  775.     /**
  776.      * @Route("/centre/document/finess/{id}", name="getCentreFinessDocument", methods={"GET"})
  777.      */
  778.     public function getCentreFinessDocument(Centre $centrePublicFunction $publicFunction): Response
  779.     {
  780.         if (!$centre->getFinessUrl()) {
  781.             return $publicFunction->replyWithFile('images/centre/'"imgOreille.png");
  782.         }
  783.         return $publicFunction->replyWithFile('document/centre/finess/'$centre->getFinessUrl());
  784.     }
  785.     /**
  786.      * @Route("/centre/{id}/audios/", name="getAudiosByCentreId", methods={"GET"})
  787.      */
  788.     public function getAudiosByCentreId(Centre $centre): Response
  789.     {
  790.         $audios $this->getDoctrine()
  791.             ->getRepository(AudioCentre::class)
  792.             ->findBy(array('id_centre' => $centre));
  793.         $resultatAudios = new ArrayCollection();
  794.         foreach ($audios as $audio) {
  795.             $resultatAudios->add([
  796.                 "id" => $audio->getIdAudio()->getId(),
  797.                 "nom" => $audio->getIdAudio()->getLastName(),
  798.                 "prenom" => $audio->getIdAudio()->getName()
  799.             ]);
  800.         }
  801.         return $this->json([
  802.             "audios" => $resultatAudios->toArray(),
  803.         ]);
  804.     }
  805.     /**
  806.      * @Route("/centre/horaire/{id}", name="getCentreHoraire", methods={"GET"})
  807.      */
  808.     public function getCentreHoraire(Centre $centrePublicFunction $publicFunction): Response
  809.     {
  810.         return new Response(json_encode($centre->getHoraire()));
  811.     }
  812.     /**
  813.      * @Route("/centre/holiday-horaire/{id}", name="getCentreHolidayHoraire", methods={"GET"})
  814.      */
  815.     public function getCentreHolidayHoraire(Centre $centrePublicFunction $publicFunction): Response
  816.     {
  817.         return new Response(json_encode($centre->getHorairesHoliday()));
  818.     }
  819.     /**
  820.      * @Route("/centre/horaire/{id}", name="setCentreHoraire", methods={"PUT"})
  821.      */
  822.     public function setCentreHoraire(Centre $centrePublicFunction $publicFunctionRequest $request)
  823.     {
  824.         if (!$request->query->get('token')) {
  825.             return new Response(json_encode([
  826.                 "message" => "Pas de token n'a été spécifié",
  827.                 "status" => 401,
  828.             ]), 401);
  829.         }
  830.         $entityManager $this->getDoctrine()->getManager();
  831.         /** @var Token */
  832.         $token $this->getDoctrine()
  833.             ->getRepository(Token::class)
  834.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $request->query->get('audio')]);
  835.         if (!$token) {
  836.             return new Response(json_encode([
  837.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  838.                 "status" => 404,
  839.             ]), 404);
  840.         }
  841.         // get token age
  842.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  843.         // if the token if older than 7 days
  844.         if ($dateDiff->7) {
  845.             $entityManager->remove($token);
  846.             $entityManager->flush();
  847.             return $this->json([
  848.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  849.                 'path' => 'src/Controller/AudioController.php',
  850.                 "status" => 401,
  851.             ], 401);
  852.         }
  853.         $entityManager $this->getDoctrine()->getManager();
  854.         $data json_decode($request->getContent(), true);
  855.         $days = ["lundi""mardi""mercredi""jeudi""vendredi""samedi""dimanche"];
  856.         // Extract center IDs from the "fixed" section
  857.         if (isset($data['horaires']['fixed'])) {
  858.             foreach ($data['horaires']['fixed'] as $dayData) {
  859.                 foreach ($dayData as $timeData) {
  860.                     $centerIds[] = $timeData['centerId'];
  861.                 }
  862.             }
  863.         }
  864.         // Extract color from the "fixed" section
  865.         if (isset($data['horaires']['fixed'])) {
  866.             foreach ($data['horaires']['fixed'] as $dayData) {
  867.                 foreach ($dayData as $timeData) {
  868.                     $centerColors[] = $timeData['centerColor'];
  869.                 }
  870.             }
  871.         }
  872.         //dd($centerIds);
  873.         if (isset($centerIds)) {
  874.             // Remove duplicate center IDs and convert to array
  875.             $centerIds array_values(array_unique($centerIds));
  876.             // Remove duplicate center IDs and convert to array
  877.             $centerColors array_values(array_unique($centerColors));
  878.             // dd( $centerColors);
  879.             // Use $centerIds for further processing
  880.             // Step 1: Clear empty days
  881.             $myCenters $this->getDoctrine()
  882.                 ->getRepository(Centre::class)->findBy(['id_gerant' => $request->query->get('audio')]);
  883.             // dd( $audioCentre);
  884.             $centerIds array_values(array_unique($centerIds));
  885.             //dd($centerIds);
  886.             // Fetch the centers based on id_gerant
  887.             $myCenters $this->getDoctrine()
  888.                 ->getRepository(Centre::class)
  889.                 ->findBy(['id' => $centre]);
  890.             //dd($myCenters);
  891.             // Create an array of center IDs from $myCenters
  892.             $myCenterIds = [];
  893.             foreach ($myCenters as $myCenter) {
  894.                 $myCenterIds[] = $myCenter->getId();
  895.             }
  896.             //dd($myCenterIds);
  897.             // Check for unexisting centers between $centerIds and $myCenterIds
  898.             $unexistingCenters array_diff($myCenterIds$centerIds);
  899.             //dd($unexistingCenters);
  900.             foreach ($unexistingCenters as $centerId) {
  901.                 // Create a new instance of Centre and set its properties
  902.                 $center $this->getDoctrine()
  903.                     ->getRepository(Centre::class)
  904.                     ->find($centerId);
  905.                 $centerAudio $this->getDoctrine()
  906.                     ->getRepository(AudioCentre::class)
  907.                     ->findOneBy(['id_centre' => $centerId]);
  908.                 $horaireArray = [
  909.                     'fixed' => [
  910.                         'lundi' => [],
  911.                         'mardi' => [],
  912.                         'mercredi' => [],
  913.                         'jeudi' => [],
  914.                         'vendredi' => [],
  915.                         'samedi' => [],
  916.                         'dimanche' => [],
  917.                     ],
  918.                     'exceptionalOpened' => [],
  919.                     'exceptionalClosed' => [],
  920.                 ];
  921.                 if ($center) {
  922.                     $center->setHoraire($horaireArray);
  923.                     $entityManager->persist($center);
  924.                 }
  925.                 if ($centerAudio) {
  926.                     $centerAudio->setHoraire($horaireArray);
  927.                     $entityManager->persist($centerAudio);
  928.                 }
  929.                 $entityManager->flush();
  930.             }
  931.             $results = [];
  932.             foreach ($centerIds as $key => $centerId) {
  933.                 // Step 1: Clear empty days
  934.                 $clearedData = ["fixed" => [], "exceptionalOpened" => [], "exceptionalClosed" => []];
  935.                 foreach ($days as $day) {
  936.                     if (isset($data['horaires']['fixed'][$day])) {
  937.                         $clearedData['fixed'][$day] = $data['horaires']['fixed'][$day];
  938.                     } else {
  939.                         $clearedData['fixed'][$day] = [];
  940.                     }
  941.                 }
  942.                 $clearedData['exceptionalOpened'] = $data['horaires']['exceptionalOpened'];
  943.                 $clearedData['exceptionalClosed'] = $data['horaires']['exceptionalClosed'];
  944.                 // Step 2: Find the center by centerId
  945.                 $centerData = [];
  946.                 $centreExist false;
  947.                 foreach ($days as $day) {
  948.                     $centerData[$day] = [];
  949.                     if (isset($clearedData['fixed'][$day])) {
  950.                         foreach ($clearedData['fixed'][$day] as $timeData) {
  951.                             if ($timeData['centerId'] == $centerId) {
  952.                                 $centerData[$day][] = [
  953.                                     'open' => $timeData['open'],
  954.                                     'close' => $timeData['close']
  955.                                 ];
  956.                                 $centreExist true;
  957.                             }
  958.                         }
  959.                     }
  960.                 }
  961.                 $center $this->getDoctrine()
  962.                     ->getRepository(Centre::class)
  963.                     ->find($centerId);
  964.                 $centerAudio $this->getDoctrine()
  965.                     ->getRepository(AudioCentre::class)
  966.                     ->findOneBy(['id_centre' => $centerId]);
  967.                 $result = [
  968.                     'fixed' => $centerData,
  969.                     'exceptionalOpened' => $clearedData['exceptionalOpened'],
  970.                     'exceptionalClosed' => $clearedData['exceptionalClosed']
  971.                 ];
  972.                 $center->setHoraire($result); // Use $result instead of $results
  973.                 $centerAudio->setHoraire($result); // Use $result instead of $results
  974.                 $center->setCalendarColor($centerColors[$key]); // Use $result instead of $results
  975.                 $entityManager->persist($center);
  976.                 $entityManager->persist($centerAudio);
  977.                 $entityManager->flush();
  978.                 $results[$centerId] = $result;
  979.             }
  980.             $resultsJson json_encode($results);
  981.         } else {
  982.             $myCenters $this->getDoctrine()
  983.                 ->getRepository(Centre::class)
  984.                 ->findBy(['id_gerant' => $request->query->get('audio')]);
  985.             foreach ($myCenters as $centerId) {
  986.                 // Create a new instance of Centre and set its properties
  987.                 $center $this->getDoctrine()
  988.                     ->getRepository(Centre::class)
  989.                     ->find($centerId);
  990.                 $centerAudio $this->getDoctrine()
  991.                     ->getRepository(AudioCentre::class)
  992.                     ->findOneBy(['id_centre' => $centerId]);
  993.                 $horaireArray = [
  994.                     'fixed' => [
  995.                         'lundi' => [],
  996.                         'mardi' => [],
  997.                         'mercredi' => [],
  998.                         'jeudi' => [],
  999.                         'vendredi' => [],
  1000.                         'samedi' => [],
  1001.                         'dimanche' => [],
  1002.                     ],
  1003.                     'exceptionalOpened' => [],
  1004.                     'exceptionalClosed' => [],
  1005.                 ];
  1006.                 $center->setHoraire($horaireArray);
  1007.                 $centerAudio->setHoraire($horaireArray);
  1008.                 // Persist the center
  1009.                 $entityManager->persist($center);
  1010.                 $entityManager->persist($centerAudio);
  1011.                 $entityManager->flush();
  1012.             }
  1013.         }
  1014.         // dd($results);
  1015.         //  $centre->setHoraire($data["horaires"]);
  1016.         // $entityManager->flush();
  1017.         return $this->json([
  1018.             "id" => $centre->getId(),
  1019.             "horaires" => $data["horaires"]
  1020.         ]);
  1021.     }
  1022.     /**
  1023.      * @Route("/centre/horaire-holiday/{id}", name="setCentreHoraireHoliday", methods={"PUT"})
  1024.      */
  1025.     public function setCentreHoraireHoliday(Centre $centrePublicFunction $publicFunctionRequest $request)
  1026.     {
  1027.         if (!$request->query->get('token')) {
  1028.             return new Response(json_encode([
  1029.                 "message" => "Pas de token n'a été spécifié",
  1030.                 "status" => 401,
  1031.             ]), 401);
  1032.         }
  1033.         $entityManager $this->getDoctrine()->getManager();
  1034.         /** @var Token */
  1035.         $token $this->getDoctrine()
  1036.             ->getRepository(Token::class)
  1037.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $request->query->get('audio')]);
  1038.         if (!$token) {
  1039.             return new Response(json_encode([
  1040.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  1041.                 "status" => 404,
  1042.             ]), 404);
  1043.         }
  1044.         // get token age
  1045.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  1046.         // if the token if older than 7 days
  1047.         if ($dateDiff->7) {
  1048.             $entityManager->remove($token);
  1049.             $entityManager->flush();
  1050.             return $this->json([
  1051.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  1052.                 'path' => 'src/Controller/AudioController.php',
  1053.                 "status" => 401,
  1054.             ], 401);
  1055.         }
  1056.         $entityManager $this->getDoctrine()->getManager();
  1057.         $data json_decode($request->getContent(), true);
  1058.         //dd($data);
  1059.         //$days = ["lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi", "dimanche"];
  1060.         $days = ["JourdelAn""LundidePâques""FêteduTravail""Victoire1945""Ascension""LundidePentecôte""FêteNationale""Assomption""Toussaint""Armistice1918""Noël"];
  1061.         //dd($data);
  1062.         // Extract center IDs from the "fixed" section
  1063.         if (isset($data['horaires']['fixed'])) {
  1064.             foreach ($data['horaires']['fixed'] as $dayData) {
  1065.                 foreach ($dayData as $timeData) {
  1066.                     $centerIds[] = $timeData['centerId'];
  1067.                 }
  1068.             }
  1069.         }
  1070.         // Extract color from the "fixed" section
  1071.         if (isset($data['horaires']['fixed'])) {
  1072.             foreach ($data['horaires']['fixed'] as $dayData) {
  1073.                 foreach ($dayData as $timeData) {
  1074.                     $centerColors[] = $timeData['centerColor'];
  1075.                 }
  1076.             }
  1077.         }
  1078.         //dd($centerIds);
  1079.         if (isset($centerIds)) {
  1080.             // Remove duplicate center IDs and convert to array
  1081.             $centerIds array_values(array_unique($centerIds));
  1082.             // Remove duplicate center IDs and convert to array
  1083.             $centerColors array_values(array_unique($centerColors));
  1084.             // dd( $centerColors);
  1085.             // Use $centerIds for further processing
  1086.             // Step 1: Clear empty days
  1087.             $myCenters $this->getDoctrine()
  1088.                 ->getRepository(Centre::class)->findBy(['id_gerant' => $request->query->get('audio')]);
  1089.             // dd( $audioCentre);
  1090.             $centerIds array_values(array_unique($centerIds));
  1091.             //dd($centerIds);
  1092.             // Fetch the centers based on id_gerant
  1093.             $myCenters $this->getDoctrine()
  1094.                 ->getRepository(Centre::class)
  1095.                 ->findBy(['id_gerant' => $request->query->get('audio')]);
  1096.             //dd($myCenters);
  1097.             // Create an array of center IDs from $myCenters
  1098.             $myCenterIds = [];
  1099.             foreach ($myCenters as $myCenter) {
  1100.                 $myCenterIds[] = $myCenter->getId();
  1101.             }
  1102.             //dd($myCenterIds);
  1103.             // Check for unexisting centers between $centerIds and $myCenterIds
  1104.             $unexistingCenters array_diff($myCenterIds$centerIds);
  1105.             //dd($unexistingCenters);
  1106.             foreach ($unexistingCenters as $centerId) {
  1107.                 // Create a new instance of Centre and set its properties
  1108.                 $center $this->getDoctrine()
  1109.                     ->getRepository(Centre::class)
  1110.                     ->find($centerId);
  1111.                 $centerAudio $this->getDoctrine()
  1112.                     ->getRepository(AudioCentre::class)
  1113.                     ->findOneBy(['id_centre' => $centerId]);
  1114.                 $horaireArray = [
  1115.                     'fixed' => [
  1116.                         'JourdelAn' => [],
  1117.                         'LundidePâques' => [],
  1118.                         'FêteduTravail' => [],
  1119.                         'Victoire1945' => [],
  1120.                         'Ascension' => [],
  1121.                         'LundidePentecôte' => [],
  1122.                         'FêteNationale' => [],
  1123.                         'Assomption' => [],
  1124.                         'Toussaint' => [],
  1125.                         'Armistice1918' => [],
  1126.                         'Noël' => [],
  1127.                     ],
  1128.                     'exceptionalOpened' => [],
  1129.                     'exceptionalClosed' => [],
  1130.                 ];
  1131.                 if ($center) {
  1132.                     $center->setHorairesHoliday($horaireArray);
  1133.                     $entityManager->persist($center);
  1134.                 }
  1135.                 if ($centerAudio) {
  1136.                     $centerAudio->setHorairesHoliday($horaireArray);
  1137.                     $entityManager->persist($centerAudio);
  1138.                 }
  1139.             }
  1140.             $results = [];
  1141.             foreach ($centerIds as $key => $centerId) {
  1142.                 // Step 1: Clear empty days
  1143.                 $clearedData = ["fixed" => [], "exceptionalOpened" => [], "exceptionalClosed" => []];
  1144.                 foreach ($days as $day) {
  1145.                     if (isset($data['horaires']['fixed'][$day])) {
  1146.                         $clearedData['fixed'][$day] = $data['horaires']['fixed'][$day];
  1147.                     } else {
  1148.                         $clearedData['fixed'][$day] = [];
  1149.                     }
  1150.                 }
  1151.                 $clearedData['exceptionalOpened'] = $data['horaires']['exceptionalOpened'];
  1152.                 $clearedData['exceptionalClosed'] = $data['horaires']['exceptionalClosed'];
  1153.                 // Step 2: Find the center by centerId
  1154.                 $centerData = [];
  1155.                 $centreExist false;
  1156.                 foreach ($days as $day) {
  1157.                     $centerData[$day] = [];
  1158.                     if (isset($clearedData['fixed'][$day])) {
  1159.                         foreach ($clearedData['fixed'][$day] as $timeData) {
  1160.                             if ($timeData['centerId'] == $centerId) {
  1161.                                 $centerData[$day][] = [
  1162.                                     'open' => $timeData['open'],
  1163.                                     'close' => $timeData['close']
  1164.                                 ];
  1165.                                 $centreExist true;
  1166.                             }
  1167.                         }
  1168.                     }
  1169.                 }
  1170.                 $center $this->getDoctrine()
  1171.                     ->getRepository(Centre::class)
  1172.                     ->find($centerId);
  1173.                 $centerAudio $this->getDoctrine()
  1174.                     ->getRepository(AudioCentre::class)
  1175.                     ->findOneBy(['id_centre' => $centerId]);
  1176.                 $result = [
  1177.                     'fixed' => $centerData,
  1178.                     'exceptionalOpened' => $clearedData['exceptionalOpened'],
  1179.                     'exceptionalClosed' => $clearedData['exceptionalClosed']
  1180.                 ];
  1181.                 //dd($result);
  1182.                 $center->setHorairesHoliday($result); // Use $result instead of $results
  1183.                 $centerAudio->setHorairesHoliday($result); // Use $result instead of $results
  1184.                 $center->setCalendarColor($centerColors[$key]); // Use $result instead of $results
  1185.                 $entityManager->persist($center);
  1186.                 $entityManager->persist($centerAudio);
  1187.                 $entityManager->flush();
  1188.                 $results[$centerId] = $result;
  1189.             }
  1190.             $resultsJson json_encode($results);
  1191.         } else {
  1192.             $myCenters $this->getDoctrine()
  1193.                 ->getRepository(Centre::class)
  1194.                 ->findBy(['id_gerant' => $request->query->get('audio')]);
  1195.             foreach ($myCenters as $centerId) {
  1196.                 // Create a new instance of Centre and set its properties
  1197.                 $center $this->getDoctrine()
  1198.                     ->getRepository(Centre::class)
  1199.                     ->find($centerId);
  1200.                 $centerAudio $this->getDoctrine()
  1201.                     ->getRepository(AudioCentre::class)
  1202.                     ->findOneBy(['id_centre' => $centerId]);
  1203.                 $horaireArray = [
  1204.                     'fixed' => [
  1205.                         'JourdelAn' => [],
  1206.                         'LundidePâques' => [],
  1207.                         'FêteduTravail' => [],
  1208.                         'Victoire1945' => [],
  1209.                         'Ascension' => [],
  1210.                         'LundidePentecôte' => [],
  1211.                         'FêteNationale' => [],
  1212.                         'Assomption' => [],
  1213.                         'Toussaint' => [],
  1214.                         'Armistice1918' => [],
  1215.                         'Noël' => [],
  1216.                     ],
  1217.                     'exceptionalOpened' => [],
  1218.                     'exceptionalClosed' => [],
  1219.                 ];
  1220.                 $center->setHorairesHoliday($horaireArray);
  1221.                 $centerAudio->setHorairesHoliday($horaireArray);
  1222.                 // Persist the center
  1223.                 $entityManager->persist($center);
  1224.                 $entityManager->persist($centerAudio);
  1225.                 $entityManager->flush();
  1226.             }
  1227.         }
  1228.         // dd($results);
  1229.         //  $centre->setHoraire($data["horaires"]);
  1230.         // $entityManager->flush();
  1231.         return $this->json([
  1232.             "id" => $centre->getId(),
  1233.             "horaires" => $data["horaires"]
  1234.         ]);
  1235.     }
  1236.     /**
  1237.      * @Route("/centre/image", name="getNewCentreImage", methods={"GET"})
  1238.      */
  1239.     public function getNewCentreImage(PublicFunction $publicFunctionRequest $request): Response
  1240.     {
  1241.         return $publicFunction->replyWithFile('images/centre/'$request->query->get('imgUrl'));
  1242.     }
  1243.     /**
  1244.      * @Route("/centre/{id}", name="getCentre", methods={"GET","HEAD"})
  1245.      */
  1246.     public function getCentre(Centre $centrePublicFunction $publicFunction): Response
  1247.     {
  1248.         /** @var CentrePrestation[]*/
  1249.         $prestations $this->getDoctrine()->getRepository(CentrePrestation::class)
  1250.             ->findBy(array('id_centre' => $centre->getId()));
  1251.         $resultPrestation = new ArrayCollection();
  1252.         foreach ($prestations as $prestation) {
  1253.             $resultPrestation->add([
  1254.                 "id" => $prestation->getIdPrestation()->getId(),
  1255.                 "titre" => $prestation->getIdPrestation()->getLibelle(),
  1256.             ]);
  1257.         }
  1258.         /** @var CentreMutuelle[]*/
  1259.         $mutuelles $this->getDoctrine()->getRepository(CentreMutuelle::class)
  1260.             ->findBy(array('id_centre' => $centre->getId()));
  1261.         $resultMutuelle = new ArrayCollection();
  1262.         foreach ($mutuelles as $mutuelle) {
  1263.             $resultMutuelle->add([
  1264.                 "id" => $mutuelle->getIdMutuelle()->getId(),
  1265.                 "titre" => $mutuelle->getIdMutuelle()->getLibelle(),
  1266.             ]);
  1267.         }
  1268.         /** @var CentreTier[]*/
  1269.         $tiers $this->getDoctrine()->getRepository(CentreTier::class)
  1270.             ->findBy(array('id_centre' => $centre->getId()));
  1271.         $resultTier = new ArrayCollection();
  1272.         foreach ($tiers as $tier) {
  1273.             $resultTier->add([
  1274.                 "id" => $tier->getIdTier()->getId(),
  1275.                 "titre" => $tier->getIdTier()->getLibelle(),
  1276.             ]);
  1277.         }
  1278.         /** @var AudioCentre[] */
  1279.         $liaisons $this->getDoctrine()->getRepository(AudioCentre::class)
  1280.             ->findBy(array('id_centre' => $centre'isConfirmed' => true));
  1281.         $resultAudio = new ArrayCollection();
  1282.         foreach ($liaisons as $liaison) {
  1283.             /** @var Audio */
  1284.             $audio $this->getDoctrine()->getRepository(Audio::class)
  1285.                 ->findOneBy(array('id' => $liaison->getIdAudio()));
  1286.             // Motifs
  1287.             /** @var AudioMotif[] */
  1288.             $motifs $this->getDoctrine()->getRepository(AudioMotif::class)
  1289.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1290.             // will test whether or not the audio has the necessery motif to be added
  1291.             $resultMotif = new ArrayCollection();
  1292.             foreach ($motifs as $motif) {
  1293.                 // ignore deleted motif
  1294.                 if (!$motif->getIsDeleted() && $motif->getType() !== 2)
  1295.                     $resultMotif->add([
  1296.                         "id" => $motif->getIdMotif()->getId(),
  1297.                         "titre" => $motif->getIdMotif()->getTitre(),
  1298.                         "consigne" => $motif->getConsigne(),
  1299.                         "duration" => $motif->getDuration(),
  1300.                     ]);
  1301.             }
  1302.             // Specialities
  1303.             /** @var AudioSpecialite[] */
  1304.             $specialities $this->getDoctrine()->getRepository(AudioSpecialite::class)
  1305.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1306.             //speciality filter
  1307.             $resultSpeciality = new ArrayCollection();
  1308.             foreach ($specialities as $speciality) {
  1309.                 if ($speciality->getIdSpecialite() !== null) {
  1310.                     $resultSpeciality->add([
  1311.                         "id" => $speciality->getIdSpecialite()->getId(),
  1312.                         "titre" => $speciality->getIdSpecialite()->getLibelle(),
  1313.                     ]);
  1314.                 }
  1315.             }
  1316.             //schedule
  1317.             $date = new DateTime();
  1318.             //add audio in the result 
  1319.             if ($centre->getHoraire() == null || $centre->getHoraire() == []) continue;
  1320.             /** @var Rdv[] */
  1321.             $audioRdvs $this->getDoctrine()->getRepository(Rdv::class)
  1322.                 ->findAllReviewsAudio($audio->getId());
  1323.             $resultAudio->add([
  1324.                 "id" => $audio->getId(),
  1325.                 "civilite" => $audio->getCivilite(),
  1326.                 "name" => $audio->getName(),
  1327.                 "lastname" => $audio->getLastname(),
  1328.                 "birthdate" => $audio->getBirthdate(),
  1329.                 "mail" => $audio->getMail(),
  1330.                 "phone" => $audio->getPhone(),
  1331.                 "adeli" => $audio->getAdeli(),
  1332.                 "pin" => $audio->getPin(),
  1333.                 "description" => $audio->getDescription(),
  1334.                 "imgUrl" => $audio->getImgUrl(),
  1335.                 "averageRating" => $publicFunction->calculateRating($audioRdvs),
  1336.                 "nbrReview" => count($audioRdvs),
  1337.                 "motifs" => $resultMotif->toArray(),
  1338.                 "specialities" => $resultSpeciality->toArray(),
  1339.                 "schedule" => [
  1340.                     $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  1341.                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P7D')), $centre),
  1342.                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P14D')), $centre)
  1343.                 ],
  1344.             ]);
  1345.         }
  1346.         /** @var AccessCentre*/
  1347.         $accessCentre $this->getDoctrine()->getRepository(AccessCentre::class)
  1348.             ->findOneBy(array('id_centre' => $centre->getId()));
  1349.         if (!$accessCentre)
  1350.             return new Response(json_encode([
  1351.                 'message' => 'Error, no accessCentre found at this id',
  1352.                 'path' => 'src/Controller/CentreController.php',
  1353.             ]), 404);
  1354.         $metroIDs json_decode($accessCentre->getMetro(), true);
  1355.         $metroNames = array();
  1356.         if ($metroIDs) {
  1357.             foreach ($metroIDs as $key => $stationID) {
  1358.                 $station $this->getDoctrine()->getRepository(Station::class)->find($stationID);
  1359.                 if ($station) {
  1360.                     $metroNames[$key] = $station->getName();
  1361.                 } else {
  1362.                     $metroNames[$key] = "Station Not Found";
  1363.                 }
  1364.             }
  1365.         }
  1366.         /** @var Rdv[] */
  1367.         $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  1368.             ->findAllReviewsCentre($centre->getId());
  1369.         // Comment
  1370.         /** @var Rdv[] */
  1371.         $rdvs $this->getDoctrine()->getRepository(Rdv::class)
  1372.             ->findBy(array('id_centre' => $centre));
  1373.         $comments = [];
  1374.         foreach ($rdvs as $rdv)
  1375.             if ($rdv->getComment() && $rdv->getReview() && $rdv->getIdClient())
  1376.                 array_push($comments, [
  1377.                     "id" => $rdv->getIdClient()->getId(),
  1378.                     "name" => $rdv->getIdClient()->getName() . " " $rdv->getIdClient()->getLastname()[0] . ".",
  1379.                     "comment" => $rdv->getComment(),
  1380.                     "isMale" => $rdv->getIdClient()->getCivilite() == "Monsieur",
  1381.                     "review" => $rdv->getReview(),
  1382.                 ]);
  1383.         return new Response(json_encode([
  1384.             "id" => $centre->getId(),
  1385.             "audio_id" => $centre->getIdGerant()->getId(),
  1386.             "name" => $centre->getName(),
  1387.             "imgUrl" => $centre->getImgUrl(),
  1388.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  1389.             "address" => $centre->getAddress(),
  1390.             "numero" => $centre->getNumero(),
  1391.             "voie" => $centre->getVoie(),
  1392.             "rue" => $centre->getRue(),
  1393.             "description" => $centre->getDescription(),
  1394.             "postale" => $centre->getPostale(),
  1395.             "city" => $centre->getCity(),
  1396.             "finess" => $centre->getFiness(),
  1397.             "siret" => $centre->getSiret(),
  1398.             "website" => $centre->getWebsite(),
  1399.             "phone" => $centre->getPhone(),
  1400.             "isHandicap" => $centre->getIsHandicap(),
  1401.             "longitude" => $centre->getLongitude(),
  1402.             "latitude" => $centre->getLatitude(),
  1403.             "averageRating" => $publicFunction->calculateRating($centreRdvs),
  1404.             "nbrReview" => count($centreRdvs),
  1405.             "tram" => $accessCentre->getTram(),
  1406.             "rer" => $accessCentre->getRer(),
  1407.             "metro" => $metroNames,
  1408.             "bus" => $accessCentre->getBus(),
  1409.             "parking" => $accessCentre->getParkingPublic(),
  1410.             "parkingPrivate" => $accessCentre->getParkingPrivate(),
  1411.             "other" => $accessCentre->getOther(),
  1412.             "comments" => $comments,
  1413.             "mutuelles" => $resultMutuelle->toArray(),
  1414.             "prestations" => $resultPrestation->toArray(),
  1415.             "tiers" => $resultTier->toArray(),
  1416.             "audio" => $resultAudio->toArray(),
  1417.             "schedule" => $centre->getHoraire(),
  1418.             "status" => 200,
  1419.         ]));
  1420.     }
  1421.     /**
  1422.      * @Route("/centre-slug/{slug}", name="getCentreBySlug", methods={"GET","HEAD"})
  1423.      */
  1424.     public function getCentreBySlug(string $slugPublicFunction $publicFunctionRequest $request): Response
  1425.     {
  1426.         $centre $this->getDoctrine()->getRepository(Centre::class)
  1427.             ->findOneBy(array('slug' => $slug));
  1428.         if (!$centre) {
  1429.             $postale $request->query->get('postale');
  1430.             $centre $this->getDoctrine()->getRepository(CenterImported::class)
  1431.                 ->findOneBy(['slug' => $slug'codePostal' => $postale]);
  1432.             /*$repository = $this->getDoctrine()->getRepository(CenterImported::class);
  1433.      
  1434.             $slugify = $this->slugger->slug($slug)->lower();
  1435.             //dd($)
  1436.             $centre = $repository->findOneBySlug(str_replace('-', ' ', $slugify));*/
  1437.             // dd($centre);
  1438.             return new Response(json_encode([
  1439.                 "id" => $centre->getId(),
  1440.                 //"audio_id" => $centre->getIdGerant()->getId(),
  1441.                 "name" => $centre->getNom(),
  1442.                 //"imgUrl" => $centre->getImgUrl(),
  1443.                 //"isRdvDomicile" => $centre->getIsRdvDomicile(),
  1444.                 "address" => $centre->getAdresse(),
  1445.                 //"numero" => $centre->getNumero(),
  1446.                 //"voie" => $centre->getVoie(),
  1447.                 //"rue" => $centre->getRue(),
  1448.                 //"description" => $centre->getDescription(),
  1449.                 "postale" => $centre->getCodePostal(),
  1450.                 "city" => $centre->getVille(),
  1451.                 "siret" => $centre->getSiret(),
  1452.                 "phone" => $centre->getTelephone(),
  1453.                 //"isHandicap" => $centre->getIsHandicap(),
  1454.                 "longitude" => $centre->getLongitude(),
  1455.                 "latitude" => $centre->getLatitude(),
  1456.                 //"averageRating" => $publicFunction->calculateRating($centreRdvs),
  1457.                 //"nbrReview" => count($centreRdvs),
  1458.                 //"tram" => $accessCentre->getTram(),
  1459.                 //"rer" => $accessCentre->getRer(),
  1460.                 //"metro" => $metroNames,
  1461.                 //"bus" => $accessCentre->getBus(),
  1462.                 //"parking" => $accessCentre->getParkingPublic(),
  1463.                 //"parkingPrivate" => $accessCentre->getParkingPrivate(),
  1464.                 //"other" => $accessCentre->getOther(),
  1465.                 //"comments" => $comments,
  1466.                 //"mutuelles" => $resultMutuelle->toArray(),
  1467.                 //"prestations" => $resultPrestation->toArray(),
  1468.                 //"tiers" => $resultTier->toArray(),
  1469.                 //"audio" => $resultAudio->toArray(),
  1470.                 //"schedule" => $centre->getHoraire(),
  1471.                 "status" => 200,
  1472.             ]));
  1473.         }
  1474.         /** @var CentrePrestation[]*/
  1475.         $prestations $this->getDoctrine()->getRepository(CentrePrestation::class)
  1476.             ->findBy(array('id_centre' => $centre->getId()));
  1477.         $resultPrestation = new ArrayCollection();
  1478.         foreach ($prestations as $prestation) {
  1479.             $resultPrestation->add([
  1480.                 "id" => $prestation->getIdPrestation()->getId(),
  1481.                 "titre" => $prestation->getIdPrestation()->getLibelle(),
  1482.             ]);
  1483.         }
  1484.         /** @var CentreMutuelle[]*/
  1485.         $mutuelles $this->getDoctrine()->getRepository(CentreMutuelle::class)
  1486.             ->findBy(array('id_centre' => $centre->getId()));
  1487.         $resultMutuelle = new ArrayCollection();
  1488.         foreach ($mutuelles as $mutuelle) {
  1489.             $resultMutuelle->add([
  1490.                 "id" => $mutuelle->getIdMutuelle()->getId(),
  1491.                 "titre" => $mutuelle->getIdMutuelle()->getLibelle(),
  1492.             ]);
  1493.         }
  1494.         /** @var CentreTier[]*/
  1495.         $tiers $this->getDoctrine()->getRepository(CentreTier::class)
  1496.             ->findBy(array('id_centre' => $centre->getId()));
  1497.         $resultTier = new ArrayCollection();
  1498.         foreach ($tiers as $tier) {
  1499.             $resultTier->add([
  1500.                 "id" => $tier->getIdTier()->getId(),
  1501.                 "titre" => $tier->getIdTier()->getLibelle(),
  1502.             ]);
  1503.         }
  1504.         $resultDiplome = new ArrayCollection();
  1505.         $resultExperience = new ArrayCollection();
  1506.         /** @var AudioCentre[] */
  1507.         $liaisons $this->getDoctrine()->getRepository(AudioCentre::class)
  1508.             ->findBy(array('id_centre' => $centre'isConfirmed' => true));
  1509.         $resultAudio = new ArrayCollection();
  1510.         foreach ($liaisons as $liaison) {
  1511.             /** @var Audio */
  1512.             $audio $this->getDoctrine()->getRepository(Audio::class)
  1513.                 ->findOneBy(array('id' => $liaison->getIdAudio()));
  1514.             // Motifs
  1515.             /** @var AudioMotif[] */
  1516.             $motifs $this->getDoctrine()->getRepository(AudioMotif::class)
  1517.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1518.             // will test whether or not the audio has the necessery motif to be added
  1519.             $resultMotif = new ArrayCollection();
  1520.             foreach ($motifs as $motif) {
  1521.                 // ignore deleted motif
  1522.                 if (!$motif->getIsDeleted() && $motif->getType() !== 2)
  1523.                     $resultMotif->add([
  1524.                         "id" => $motif->getIdMotif()->getId(),
  1525.                         "titre" => $motif->getIdMotif()->getTitre(),
  1526.                         "consigne" => $motif->getConsigne(),
  1527.                         "duration" => $motif->getDuration(),
  1528.                         "isRdvonline" => $motif->getIsRdvonline(),
  1529.                     ]);
  1530.             }
  1531.             // Specialities
  1532.             /** @var AudioSpecialite[] */
  1533.             $specialities $this->getDoctrine()->getRepository(AudioSpecialite::class)
  1534.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1535.             //speciality filter
  1536.             $resultSpeciality = new ArrayCollection();
  1537.             foreach ($specialities as $speciality) {
  1538.                 if ($speciality->getIdSpecialite() !== null) {
  1539.                     $resultSpeciality->add([
  1540.                         "id" => $speciality->getIdSpecialite()->getId(),
  1541.                         "titre" => $speciality->getIdSpecialite()->getLibelle(),
  1542.                     ]);
  1543.                 }
  1544.             }
  1545.             // Experience
  1546.             /** @var AudioExperience[] */
  1547.             $experiences $this->getDoctrine()->getRepository(ExperiencePro::class)
  1548.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1549.             //speciality filter
  1550.             foreach ($experiences as $experience) {
  1551.                 // if ($speciality->getIdSpecialite() !== null) {
  1552.                 $resultExperience->add([
  1553.                     "audioId" => $experience->getIdAudio()->getId(),
  1554.                     "id" => $experience->getId(),
  1555.                     "date" => $experience->getDate(),
  1556.                     "post" => $experience->getPoste(),
  1557.                     "company" => $experience->getCompany()
  1558.                 ]);
  1559.                 //}
  1560.             }
  1561.             //dd($resultExperience);
  1562.             // Diplome
  1563.             /** @var AudioDiplomes[] */
  1564.             $diplomes $this->getDoctrine()->getRepository(AudioDiplome::class)
  1565.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1566.             //speciality filter
  1567.             foreach ($diplomes as $diplome) {
  1568.                 $audioId $liaison->getIdAudio();
  1569.                 // if ($speciality->getIdSpecialite() !== null) {
  1570.                 $resultDiplome->add([
  1571.                     "audioId" => $diplome->getIdAudio()->getId(),
  1572.                     "id" => $diplome->getIdDiplome()->getId(),
  1573.                     "date" => $diplome->getYear(),
  1574.                     "title" => $diplome->getIdDiplome()->getLibelle(),
  1575.                 ]);
  1576.                 //}
  1577.             }
  1578.             /** @var CentreImages[]*/
  1579.             $centerImages $this->getDoctrine()->getRepository(CenterImage::class)
  1580.                 ->findBy(array('center' => $centre->getId()));
  1581.             $resultCenterImage = new ArrayCollection();
  1582.             foreach ($centerImages as $centerImage) {
  1583.                 $resultCenterImage->add([
  1584.                     "id" => $centerImage->getId(),
  1585.                     "url" => $centerImage->getUrl(),
  1586.                     "type" => $centerImage->getType(),
  1587.                 ]);
  1588.             }
  1589.             //schedule
  1590.             $date = new DateTime();
  1591.             //add audio in the result 
  1592.             if ($centre->getHoraire() == null || $centre->getHoraire() == []) continue;
  1593.             /** @var Rdv[] */
  1594.             $audioRdvs $this->getDoctrine()->getRepository(Rdv::class)
  1595.                 ->findAllReviewsAudio($audio->getId());
  1596.             $resultAudio->add([
  1597.                 "id" => $audio->getId(),
  1598.                 "civilite" => $audio->getCivilite(),
  1599.                 "name" => $audio->getName(),
  1600.                 "lastname" => $audio->getLastname(),
  1601.                 "birthdate" => $audio->getBirthdate(),
  1602.                 "mail" => $audio->getMail(),
  1603.                 "phone" => $audio->getPhone(),
  1604.                 "adeli" => $audio->getAdeli(),
  1605.                 "pin" => $audio->getPin(),
  1606.                 "description" => $audio->getDescription(),
  1607.                 "imgUrl" => $audio->getImgUrl(),
  1608.                 "averageRating" => $publicFunction->calculateRating($audioRdvs),
  1609.                 "nbrReview" => count($audioRdvs),
  1610.                 "motifs" => $resultMotif->toArray(),
  1611.                 "specialities" => $resultSpeciality->toArray(),
  1612.                 "experiences" => $resultExperience->toArray(),
  1613.                 "centerImages" => $resultCenterImage->toArray(),
  1614.                 "diplomes" => $resultDiplome->toArray(),
  1615.                 "schedule" => [
  1616.                     $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  1617.                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P7D')), $centre),
  1618.                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P14D')), $centre)
  1619.                 ],
  1620.             ]);
  1621.             //dd($resultDiplome);
  1622.         }
  1623.         /** @var AccessCentre*/
  1624.         $accessCentre $this->getDoctrine()->getRepository(AccessCentre::class)
  1625.             ->findOneBy(array('id_centre' => $centre->getId()));
  1626.         if (!empty($accessCentre)) {
  1627.             /*return new Response(json_encode([
  1628.                 'message' => 'Error, no accessCentre found at this id',
  1629.                 'path' => 'src/Controller/CentreController.php',
  1630.             ]), 404);*/
  1631.             $metroIDs json_decode($accessCentre->getMetro(), true);
  1632.             $metroNames = array();
  1633.             if ($metroIDs) {
  1634.                 foreach ($metroIDs as $key => $stationID) {
  1635.                     $station $this->getDoctrine()->getRepository(Station::class)->find($stationID);
  1636.                     if ($station) {
  1637.                         $metroNames[$key] = $station->getName();
  1638.                     } else {
  1639.                         $metroNames[$key] = "Station Not Found";
  1640.                     }
  1641.                 }
  1642.             }
  1643.         }
  1644.         /** @var Rdv[] */
  1645.         $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  1646.             ->findAllReviewsCentre($centre->getId());
  1647.         // Comment
  1648.         /** @var Rdv[] */
  1649.         $rdvs $this->getDoctrine()->getRepository(Rdv::class)
  1650.             ->findBy(array('id_centre' => $centre));
  1651.         $comments = [];
  1652.         foreach ($rdvs as $rdv)
  1653.             if ($rdv->getComment() && $rdv->getReview() && $rdv->getIdClient())
  1654.                 array_push($comments, [
  1655.                     "id" => $rdv->getIdClient()->getId(),
  1656.                     "name" => $rdv->getIdClient()->getName() . " " $rdv->getIdClient()->getLastname()[0] . ".",
  1657.                     "comment" => $rdv->getComment(),
  1658.                     "isMale" => $rdv->getIdClient()->getCivilite() == "Monsieur",
  1659.                     "review" => $rdv->getReview(),
  1660.                 ]);
  1661.         // dd($resultDiplome->toArray());
  1662.         return new Response(json_encode([
  1663.             "id" => $centre->getId(),
  1664.             "audio_id" => $centre->getIdGerant()->getId(),
  1665.             "name" => $centre->getName(),
  1666.             "imgUrl" => $centre->getImgUrl(),
  1667.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  1668.             "address" => $centre->getAddress(),
  1669.             "numero" => $centre->getNumero(),
  1670.             "voie" => $centre->getVoie(),
  1671.             "rue" => $centre->getRue(),
  1672.             "description" => $centre->getDescription(),
  1673.             "postale" => $centre->getPostale(),
  1674.             "city" => $centre->getCity(),
  1675.             "finess" => $centre->getFiness(),
  1676.             "siret" => $centre->getSiret(),
  1677.             "website" => $centre->getWebsite(),
  1678.             "phone" => $centre->getPhone(),
  1679.             "isHandicap" => $centre->getIsHandicap(),
  1680.             "longitude" => $centre->getLongitude(),
  1681.             "latitude" => $centre->getLatitude(),
  1682.             "averageRating" => $publicFunction->calculateRating($centreRdvs),
  1683.             "nbrReview" => count($centreRdvs),
  1684.             "tram" => !empty($accessCentre) ? $accessCentre->getTram() : null,
  1685.             "rer" => !empty($accessCentre) ? $accessCentre->getRer() : null,
  1686.             "experiences" => $resultExperience->toArray(),
  1687.             "diplomes" => $resultDiplome->toArray(),
  1688.             "centerImages" => $resultCenterImage->toArray(),
  1689.             "metro" => !empty($accessCentre) ? $metroNames null,
  1690.             "bus" => !empty($accessCentre) ? $accessCentre->getBus() : null,
  1691.             "parking" => !empty($accessCentre) ? $accessCentre->getParkingPublic() : null,
  1692.             "parkingPrivate" => !empty($accessCentre) ? $accessCentre->getParkingPrivate() : null,
  1693.             "other" => !empty($accessCentre) ? $accessCentre->getOther() : null,
  1694.             "comments" => $comments,
  1695.             "mutuelles" => $resultMutuelle->toArray(),
  1696.             "prestations" => $resultPrestation->toArray(),
  1697.             "tiers" => $resultTier->toArray(),
  1698.             "audio" => $resultAudio->toArray(),
  1699.             "schedule" => $centre->getHoraire(),
  1700.             "aditionnelInfo" => $centre->getAditionnelInfo(),
  1701.             "status" => 200,
  1702.         ]));
  1703.     }
  1704.     /**
  1705.      * @Route("/centreImported/{id}", name="getCentreimported", methods={"GET","HEAD"})
  1706.      */
  1707.     public function getCentreImorted(CenterImported $centrePublicFunction $publicFunction): Response
  1708.     {
  1709.         if (!$centre) {
  1710.             return $this->json([
  1711.                 'error' => 'Center not found'
  1712.             ], 404);
  1713.         }
  1714.         return $this->json([
  1715.             "center" => $centre,
  1716.             "status" => 200
  1717.         ]);
  1718.     }
  1719.     /**
  1720.      * @Route("/centre/{id}/withoutSchedule", name="getCentreWithoutSchedule", methods={"GET","HEAD"})
  1721.      */
  1722.     public function getCentreWithoutSchedule(Centre $centrePublicFunction $publicFunction): Response
  1723.     {
  1724.         /** @var CentrePrestation[]*/
  1725.         $prestations $this->getDoctrine()->getRepository(CentrePrestation::class)
  1726.             ->findBy(array('id_centre' => $centre->getId()));
  1727.         $resultPrestation = new ArrayCollection();
  1728.         foreach ($prestations as $prestation) {
  1729.             $resultPrestation->add([
  1730.                 "id" => $prestation->getIdPrestation()->getId(),
  1731.                 "titre" => $prestation->getIdPrestation()->getLibelle(),
  1732.             ]);
  1733.         }
  1734.         /** @var CentreMutuelle[]*/
  1735.         $mutuelles $this->getDoctrine()->getRepository(CentreMutuelle::class)
  1736.             ->findBy(array('id_centre' => $centre->getId()));
  1737.         $resultMutuelle = new ArrayCollection();
  1738.         foreach ($mutuelles as $mutuelle) {
  1739.             $resultMutuelle->add([
  1740.                 "id" => $mutuelle->getIdMutuelle()->getId(),
  1741.                 "titre" => $mutuelle->getIdMutuelle()->getLibelle(),
  1742.             ]);
  1743.         }
  1744.         /** @var CentreTier[]*/
  1745.         $tiers $this->getDoctrine()->getRepository(CentreTier::class)
  1746.             ->findBy(array('id_centre' => $centre->getId()));
  1747.         $resultTier = new ArrayCollection();
  1748.         foreach ($tiers as $tier) {
  1749.             $resultTier->add([
  1750.                 "id" => $tier->getIdTier()->getId(),
  1751.                 "titre" => $tier->getIdTier()->getLibelle(),
  1752.             ]);
  1753.         }
  1754.         /** @var AudioCentre[] */
  1755.         $liaisons $this->getDoctrine()->getRepository(AudioCentre::class)
  1756.             ->findBy(array('id_centre' => $centre'isConfirmed' => true));
  1757.         $resultAudio = new ArrayCollection();
  1758.         foreach ($liaisons as $liaison) {
  1759.             /** @var Audio */
  1760.             $audio $this->getDoctrine()->getRepository(Audio::class)
  1761.                 ->findOneBy(array('id' => $liaison->getIdAudio()));
  1762.             // Motifs
  1763.             /** @var AudioMotif[] */
  1764.             $motifs $this->getDoctrine()->getRepository(AudioMotif::class)
  1765.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1766.             // will test whether or not the audio has the necessery motif to be added
  1767.             $resultMotif = new ArrayCollection();
  1768.             foreach ($motifs as $motif) {
  1769.                 $resultMotif->add([
  1770.                     "id" => $motif->getIdMotif()->getId(),
  1771.                     "titre" => $motif->getIdMotif()->getTitre(),
  1772.                     "consigne" => $motif->getConsigne(),
  1773.                     "duration" => $motif->getDuration(),
  1774.                 ]);
  1775.             }
  1776.             // Specialities
  1777.             /** @var AudioSpecialite[] */
  1778.             $specialities $this->getDoctrine()->getRepository(AudioSpecialite::class)
  1779.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  1780.             //speciality filter
  1781.             $resultSpeciality = new ArrayCollection();
  1782.             foreach ($specialities as $speciality) {
  1783.                 if ($speciality->getIdSpecialite() !== null) {
  1784.                     $resultSpeciality->add([
  1785.                         "id" => $speciality->getIdSpecialite()->getId(),
  1786.                         "titre" => $speciality->getIdSpecialite()->getLibelle(),
  1787.                     ]);
  1788.                 }
  1789.             }
  1790.             //schedule
  1791.             $date = new DateTime();
  1792.             //add audio in the result 
  1793.             if ($centre->getHoraire() == null || $centre->getHoraire() == []) continue;
  1794.             /** @var Rdv[] */
  1795.             $audioRdvs $this->getDoctrine()->getRepository(Rdv::class)
  1796.                 ->findAllReviewsAudio($audio->getId());
  1797.             $resultAudio->add([
  1798.                 "id" => $audio->getId(),
  1799.                 "civilite" => $audio->getCivilite(),
  1800.                 "name" => $audio->getName(),
  1801.                 "lastname" => $audio->getLastname(),
  1802.                 "birthdate" => $audio->getBirthdate(),
  1803.                 "mail" => $audio->getMail(),
  1804.                 "phone" => $audio->getPhone(),
  1805.                 "adeli" => $audio->getAdeli(),
  1806.                 "pin" => $audio->getPin(),
  1807.                 "description" => $audio->getDescription(),
  1808.                 "imgUrl" => $audio->getImgUrl(),
  1809.                 "averageRating" => $publicFunction->calculateRating($audioRdvs),
  1810.                 "nbrReview" => count($audioRdvs),
  1811.                 "motifs" => $resultMotif->toArray(),
  1812.                 "specialities" => $resultSpeciality->toArray(),
  1813.             ]);
  1814.         }
  1815.         /** @var AccessCentre*/
  1816.         $accessCentre $this->getDoctrine()->getRepository(AccessCentre::class)
  1817.             ->findOneBy(array('id_centre' => $centre->getId()));
  1818.         if (!$accessCentre)
  1819.             return new Response(json_encode([
  1820.                 'message' => 'Error, no accessCentre found at this id',
  1821.                 'path' => 'src/Controller/CentreController.php',
  1822.             ]), 404);
  1823.         /** @var Rdv[] */
  1824.         $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  1825.             ->findAllReviewsCentre($centre->getId());
  1826.         // Comment
  1827.         /** @var Rdv[] */
  1828.         $rdvs $this->getDoctrine()->getRepository(Rdv::class)
  1829.             ->findBy(array('id_centre' => $centre));
  1830.         $comments = [];
  1831.         foreach ($rdvs as $rdv)
  1832.             if ($rdv->getComment() && $rdv->getReview() && $rdv->getIdClient())
  1833.                 array_push($comments, [
  1834.                     "id" => $rdv->getIdClient()->getId(),
  1835.                     "name" => $rdv->getIdClient()->getName() . " " $rdv->getIdClient()->getLastname()[0] . ".",
  1836.                     "comment" => $rdv->getComment(),
  1837.                     "isMale" => $rdv->getIdClient()->getCivilite() == "Monsieur",
  1838.                     "review" => $rdv->getReview(),
  1839.                 ]);
  1840.         $metroIDs json_decode($accessCentre->getMetro(), true);
  1841.         $metroNames = array();
  1842.         if ($metroIDs) {
  1843.             foreach ($metroIDs as $key => $stationID) {
  1844.                 $station $this->getDoctrine()->getRepository(Station::class)->find($stationID);
  1845.                 if ($station) {
  1846.                     $metroNames[$key]["name"] = $station->getName();
  1847.                     $metroNames[$key]["value"] = $station->getId();
  1848.                 }
  1849.             }
  1850.         }
  1851.         return new Response(json_encode([
  1852.             "id" => $centre->getId(),
  1853.             "audio_id" => $centre->getIdGerant()->getId(),
  1854.             "name" => $centre->getName(),
  1855.             "imgUrl" => $centre->getImgUrl(),
  1856.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  1857.             "address" => $centre->getAddress(),
  1858.             "numero" => $centre->getNumero(),
  1859.             "voie" => $centre->getVoie(),
  1860.             "rue" => $centre->getRue(),
  1861.             "description" => $centre->getDescription(),
  1862.             "postale" => $centre->getPostale(),
  1863.             "city" => $centre->getCity(),
  1864.             "finess" => $centre->getFiness(),
  1865.             "siret" => $centre->getSiret(),
  1866.             "website" => $centre->getWebsite(),
  1867.             "phone" => $centre->getPhone(),
  1868.             "isHandicap" => $centre->getIsHandicap(),
  1869.             "longitude" => $centre->getLongitude(),
  1870.             "latitude" => $centre->getLatitude(),
  1871.             "averageRating" => $publicFunction->calculateRating($centreRdvs),
  1872.             "nbrReview" => count($centreRdvs),
  1873.             "tram" => $accessCentre->getTram(),
  1874.             "rer" => $accessCentre->getRer(),
  1875.             "metro" => $metroNames,
  1876.             "bus" => $accessCentre->getBus(),
  1877.             "parking" => $accessCentre->getParkingPublic(),
  1878.             "parkingPrivate" => $accessCentre->getParkingPrivate(),
  1879.             "other" => $accessCentre->getOther(),
  1880.             "comments" => $comments,
  1881.             "mutuelles" => $resultMutuelle->toArray(),
  1882.             "prestations" => $resultPrestation->toArray(),
  1883.             "tiers" => $resultTier->toArray(),
  1884.             "audio" => $resultAudio->toArray(),
  1885.             "schedule" => $centre->getHoraire(),
  1886.             "status" => 200,
  1887.         ]));
  1888.     }
  1889.     /**
  1890.      * @Route("/centre/{id}/prestations", name="deleteAllCentrePrestations", methods={"DELETE"})
  1891.      */
  1892.     public function deleteAllCentrePrestations(Request $requestCentre $centre): Response
  1893.     {
  1894.         $centrePrestations $this->getDoctrine()
  1895.             ->getRepository(CentrePrestation::class)
  1896.             ->findBy(array('id_centre' => $centre->getId()));
  1897.         if (!$request->query->get('token')) {
  1898.             return new Response(json_encode([
  1899.                 "message" => "Pas de token n'a été spécifié",
  1900.                 "status" => 401,
  1901.             ]), 401);
  1902.         }
  1903.         $entityManager $this->getDoctrine()->getManager();
  1904.         /** @var Token */
  1905.         $token $this->getDoctrine()
  1906.             ->getRepository(Token::class)
  1907.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $centre->getIdGerant()]);
  1908.         if (!$token) {
  1909.             return new Response(json_encode([
  1910.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  1911.                 "status" => 404,
  1912.             ]), 404);
  1913.         }
  1914.         // get token age
  1915.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  1916.         // if the token if older than 7 days
  1917.         if ($dateDiff->7) {
  1918.             $entityManager->remove($token);
  1919.             $entityManager->flush();
  1920.             return $this->json([
  1921.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  1922.                 'path' => 'src/Controller/ClientController.php',
  1923.                 "status" => 401,
  1924.             ], 401);
  1925.         }
  1926.         $entityManager $this->getDoctrine()->getManager();
  1927.         foreach ($centrePrestations as $centrePrestation) {
  1928.             $entityManager->remove($centrePrestation);
  1929.         }
  1930.         $entityManager->flush();
  1931.         return new Response("Prestations from centre " $centre->getId() . " correctly deleted.");
  1932.     }
  1933.     /**
  1934.      * @Route("/centre/prestations", name="postMultipleCentrePrestations", methods={"POST"})
  1935.      */
  1936.     public function postMultipleCentrePrestations(Request $request): Response
  1937.     {
  1938.         $data json_decode($request->getContent(), true);
  1939.         $centre $this->getDoctrine()
  1940.             ->getRepository(Centre::class)
  1941.             ->findOneBy(['id' => $data["id_centre"]]);
  1942.         if (!$centre) {
  1943.             return $this->json([
  1944.                 'message' => 'Error, no Centre found at this id',
  1945.                 'path' => 'src/Controller/CentreController.php',
  1946.             ]);
  1947.         }
  1948.         /** @var Token */
  1949.         $token $this->getDoctrine()
  1950.             ->getRepository(Token::class)
  1951.             ->findOneBy(['token' => $data["token"], 'id_audio' => $centre->getIdGerant()]);
  1952.         if (!$token) {
  1953.             return new Response(json_encode([
  1954.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  1955.                 "status" => 404,
  1956.             ]), 404);
  1957.         }
  1958.         // get token age
  1959.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  1960.         // if the token if older than 7 days
  1961.         if ($dateDiff->7) {
  1962.             $entityManager $this->getDoctrine()->getManager();
  1963.             $entityManager->remove($token);
  1964.             $entityManager->flush();
  1965.             return $this->json([
  1966.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  1967.                 'path' => 'src/Controller/AudioController.php',
  1968.                 "status" => 401,
  1969.             ], 401);
  1970.         }
  1971.         foreach ($data["prestationList"] as $prestation) {
  1972.             $centrePrestation = new centrePrestation();
  1973.             $prestation $this->getDoctrine()
  1974.                 ->getRepository(Prestation::class)
  1975.                 ->findOneBy(['id' => $prestation]);
  1976.             if (!$prestation) {
  1977.                 return $this->json([
  1978.                     'message' => 'Error, no prestation found at this id',
  1979.                     'path' => 'src/Controller/CentreController.php',
  1980.                 ]);
  1981.             }
  1982.             $centrePrestation->setIdPrestation($prestation);
  1983.             $centrePrestation->setIdCentre($centre);
  1984.             $checkIfNull $this->getDoctrine()->getRepository(CentrePrestation::class)
  1985.                 ->findOneBy(['id_prestation' => $prestation'id_centre' => $data["id_centre"]]);
  1986.             if ($checkIfNull) {
  1987.                 return $this->json([
  1988.                     'message' => 'Error, prestation already found at this id',
  1989.                     'path' => 'src/Controller/CentreController.php',
  1990.                 ]);
  1991.             }
  1992.             $entityManager $this->getDoctrine()->getManager();
  1993.             $entityManager->persist($centrePrestation);
  1994.         }
  1995.         $entityManager->flush();
  1996.         return $this->json([
  1997.             "centre" => $centre->getId(),
  1998.             "prestations" => $data["prestationList"],
  1999.         ]);
  2000.     }
  2001.     /**
  2002.      * @Route("/centre/{id}/mutuelles", name="deleteAllCentreMutuelles", methods={"DELETE"})
  2003.      */
  2004.     public function deleteAllCentreMutuelles(Request $requestCentre $centre): Response
  2005.     {
  2006.         $centreMutuelles $this->getDoctrine()
  2007.             ->getRepository(CentreMutuelle::class)
  2008.             ->findBy(array('id_centre' => $centre->getId()));
  2009.         if (!$request->query->get('token')) {
  2010.             return new Response(json_encode([
  2011.                 "message" => "Pas de token n'a été spécifié",
  2012.                 "status" => 401,
  2013.             ]), 401);
  2014.         }
  2015.         $entityManager $this->getDoctrine()->getManager();
  2016.         /** @var Token */
  2017.         $token $this->getDoctrine()
  2018.             ->getRepository(Token::class)
  2019.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $centre->getIdGerant()]);
  2020.         if (!$token) {
  2021.             return new Response(json_encode([
  2022.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  2023.                 "status" => 404,
  2024.             ]), 404);
  2025.         }
  2026.         // get token age
  2027.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  2028.         // if the token if older than 7 days
  2029.         if ($dateDiff->7) {
  2030.             $entityManager->remove($token);
  2031.             $entityManager->flush();
  2032.             return $this->json([
  2033.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  2034.                 'path' => 'src/Controller/ClientController.php',
  2035.                 "status" => 401,
  2036.             ], 401);
  2037.         }
  2038.         $entityManager $this->getDoctrine()->getManager();
  2039.         foreach ($centreMutuelles as $centreMutuelle) {
  2040.             $entityManager->remove($centreMutuelle);
  2041.         }
  2042.         $entityManager->flush();
  2043.         return new Response("Mutuelles from centre " $centre->getId() . " correctly deleted.");
  2044.     }
  2045.     /**
  2046.      * @Route("/centre/mutuelles", name="postMultipleCentreMutuelles", methods={"POST"})
  2047.      */
  2048.     public function postMultipleCentreMutuelles(Request $request): Response
  2049.     {
  2050.         $data json_decode($request->getContent(), true);
  2051.         $centre $this->getDoctrine()
  2052.             ->getRepository(Centre::class)
  2053.             ->findOneBy(['id' => $data["id_centre"]]);
  2054.         if (!$centre) {
  2055.             return $this->json([
  2056.                 'message' => 'Error, no Centre found at this id',
  2057.                 'path' => 'src/Controller/CentreController.php',
  2058.             ]);
  2059.         }
  2060.         /** @var Token */
  2061.         $token $this->getDoctrine()
  2062.             ->getRepository(Token::class)
  2063.             ->findOneBy(['token' => $data["token"], 'id_audio' => $centre->getIdGerant()]);
  2064.         if (!$token) {
  2065.             return new Response(json_encode([
  2066.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  2067.                 "status" => 404,
  2068.             ]), 404);
  2069.         }
  2070.         // get token age
  2071.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  2072.         // if the token if older than 7 days
  2073.         if ($dateDiff->7) {
  2074.             $entityManager $this->getDoctrine()->getManager();
  2075.             $entityManager->remove($token);
  2076.             $entityManager->flush();
  2077.             return $this->json([
  2078.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  2079.                 'path' => 'src/Controller/AudioController.php',
  2080.                 "status" => 401,
  2081.             ], 401);
  2082.         }
  2083.         foreach ($data["mutuelleList"] as $mutuelle) {
  2084.             $centreMutuelle = new centreMutuelle();
  2085.             $mutuelle $this->getDoctrine()
  2086.                 ->getRepository(Mutuelle::class)
  2087.                 ->findOneBy(['id' => $mutuelle]);
  2088.             if (!$mutuelle) {
  2089.                 return $this->json([
  2090.                     'message' => 'Error, no mutuelle found at this id',
  2091.                     'path' => 'src/Controller/CentreController.php',
  2092.                 ]);
  2093.             }
  2094.             $centreMutuelle->setIdMutuelle($mutuelle);
  2095.             $centreMutuelle->setIdCentre($centre);
  2096.             $checkIfNull $this->getDoctrine()->getRepository(CentreMutuelle::class)
  2097.                 ->findOneBy(['id_mutuelle' => $mutuelle'id_centre' => $data["id_centre"]]);
  2098.             if ($checkIfNull) {
  2099.                 return $this->json([
  2100.                     'message' => 'Error, mutuelle already found at this id',
  2101.                     'path' => 'src/Controller/CentreController.php',
  2102.                 ]);
  2103.             }
  2104.             $entityManager $this->getDoctrine()->getManager();
  2105.             $entityManager->persist($centreMutuelle);
  2106.         }
  2107.         $entityManager->flush();
  2108.         return $this->json([
  2109.             "centre" => $centre->getId(),
  2110.             "mutuelles" => $data["mutuelleList"],
  2111.         ]);
  2112.     }
  2113.     /**
  2114.      * @Route("/update/audio-center", name="updateAudioCentre", methods={"POST"})
  2115.      */
  2116.     public function updateAudioCentre(Request $requestPublicFunction $publicFunctionStripeService $stripeService): Response
  2117.     {
  2118.         /*return $this->json([
  2119.             'message' => '',
  2120.             "status" => 200
  2121.         ], 200);
  2122. */
  2123.         $data json_decode($request->getContent(), true);
  2124.         $entityManager $this->getDoctrine()->getManager();
  2125.         /* "adeli": ""!empty,
  2126.             "civilite": "",
  2127.             "lastname": "",
  2128.             "name": "",
  2129.             "imgUrl": "",
  2130. */
  2131.         $audio =  $this->getDoctrine()
  2132.             ->getRepository(Audio::class)
  2133.             ->find($data['audioId']);
  2134.         $centre =  $this->getDoctrine()
  2135.             ->getRepository(Centre::class)
  2136.             ->find($data['centerId']);
  2137.         $audio->setDescription($data['descriptionAudio']);
  2138.         // diplomes
  2139.         if (isset($data["audio"]["0"]["diplome"]) && !empty($data["audio"]["0"]["diplome"])) {
  2140.             foreach ($data["audio"]["0"]["diplome"] as $diplomeObject) {
  2141.                 $diplome $this->getDoctrine()
  2142.                     ->getRepository(Diplome::class)
  2143.                     ->findOneBy(['id' => $diplomeObject["id"]]);
  2144.                 if ($diplome == null) {
  2145.                     /*$audioDiplome = new AudioDiplome();
  2146.                 if(isset($diplomeObject["year"]))
  2147.                 {
  2148.                     if(!empty($diplomeObject["year"]))
  2149.                     {
  2150.                         $audioDiplome->setYear($diplomeObject["year"]);
  2151.                     }
  2152.                 }
  2153.                 $audioDiplome->setUrl($diplomeObject["url"]);
  2154.                 $audioDiplome->setOther($data['otherdDiplom'][$key]);
  2155.                 $audioDiplome->setIdAudio($audio);
  2156.                 $entityManager->persist($audioDiplome);*/
  2157.                     return $this->json([
  2158.                         'message' => 'Error, no diplome found at this id ' $diplomeObject["id"],
  2159.                         'path' => 'src/Controller/AudioController.php',
  2160.                         "status" => 401
  2161.                     ], 401);
  2162.                 } else {
  2163.                     $audioDiplome = new AudioDiplome();
  2164.                     if (isset($diplomeObject["year"])) {
  2165.                         if (!empty($diplomeObject["year"])) {
  2166.                             $audioDiplome->setYear($diplomeObject["year"]);
  2167.                         }
  2168.                     }
  2169.                     //$audioDiplome->setUrl($diplomeObject["url"]);
  2170.                     $audioDiplome->setIdDiplome($diplome);
  2171.                     $audioDiplome->setIdAudio($audio);
  2172.                     $entityManager->persist($audioDiplome);
  2173.                 }
  2174.             }
  2175.         }
  2176.         // experiences
  2177.         if (isset($data["audio"]["0"]["experiences"]) && !empty($data["audio"]["0"]["experiences"])) {
  2178.             foreach ($data["audio"]["0"]["experiences"] as $experience) {
  2179.                 $audioSpecialite = new ExperiencePro();
  2180.                 $audioSpecialite->setDate(\DateTime::createFromFormat("d/m/Y"$experience["date"]));
  2181.                 $audioSpecialite->setPoste($experience["poste"]);
  2182.                 $audioSpecialite->setCompany($experience["company"]);
  2183.                 $audioSpecialite->setIdAudio($audio);
  2184.                 $entityManager->persist($audioSpecialite);
  2185.             }
  2186.         }
  2187.         // prestation
  2188.         if (isset($data["prestation"]) && !empty($data["prestation"])) {
  2189.             foreach ($data["prestation"] as $prestationId) {
  2190.                 $prestation $this->getDoctrine()
  2191.                     ->getRepository(Prestation::class)
  2192.                     ->findOneBy(['id' => $prestationId]);
  2193.                 $centrePrestation = new CentrePrestation();
  2194.                 $centrePrestation->setIdPrestation($prestation);
  2195.                 $centrePrestation->setIdCentre($centre);
  2196.                 $entityManager->persist($centrePrestation);
  2197.             }
  2198.         }
  2199.         // spetialites
  2200.         foreach ($data["audio"]["0"]["specialite"] as $specialiteId) {
  2201.             $specialite $this->getDoctrine()
  2202.                 ->getRepository(Specialite::class)
  2203.                 ->findOneBy(['id' => $specialiteId]);
  2204.             if (isset($data["autre_special_text"]) && !empty($data["autre_special_text"])) {
  2205.                 $audioSpecialite = new AudioSpecialite();
  2206.                 // $audioSpecialite->setIdSpecialite($specialite);
  2207.                 $audioSpecialite->setIdAudio($audio);
  2208.                 $audioSpecialite->setIdAudio($audio);
  2209.                 $entityManager->persist($audioSpecialite);
  2210.             }
  2211.             if ($specialite == null) {
  2212.                 return $this->json([
  2213.                     'message' => 'Error, no specialite found at this id ' $specialiteId,
  2214.                     'path' => 'src/Controller/AudioController.php',
  2215.                     "status" => 401
  2216.                 ], 401);
  2217.             } else {
  2218.                 $audioSpecialite = new AudioSpecialite();
  2219.                 $audioSpecialite->setIdSpecialite($specialite);
  2220.                 $audioSpecialite->setIdAudio($audio);
  2221.                 $entityManager->persist($audioSpecialite);
  2222.             }
  2223.         }
  2224.         if (isset($data["mutuelle"]))
  2225.             foreach ($data["mutuelle"] as $mutuelleObject) {
  2226.                 $mutuelle $this->getDoctrine()
  2227.                     ->getRepository(Mutuelle::class)
  2228.                     ->findOneBy(['id' => $mutuelleObject]);
  2229.                 if ($mutuelle == null) {
  2230.                     return new Response(json_encode([
  2231.                         'message' => 'Error, no mutuelle found at this id ' $mutuelleObject,
  2232.                         'path' => 'src/Controller/CentreController.php',
  2233.                     ]));
  2234.                 } else {
  2235.                     $centreMutuelle = new CentreMutuelle();
  2236.                     $centreMutuelle->setIdMutuelle($mutuelle);
  2237.                     $centreMutuelle->setIdCentre($centre);
  2238.                     if (isset($data["otherMutuelle"]) && $mutuelle->getLibelle() == "Autres")
  2239.                         $centreMutuelle->setOther(json_encode($data["otherMutuelle"], JSON_FORCE_OBJECT));
  2240.                     $entityManager->persist($centreMutuelle);
  2241.                 }
  2242.             }
  2243.         //other spetiality 
  2244.         if (isset($data["otherSpetiality"]) && !empty($data["otherSpetiality"])) {
  2245.             $audioSpecialite = new AudioSpecialite();
  2246.             // $audioSpecialite->setIdSpecialite($specialite);
  2247.             $audioSpecialite->setIdAudio($audio);
  2248.             $audioSpecialite->setOther(json_encode($data["otherSpetiality"], JSON_FORCE_OBJECT));
  2249.             $entityManager->persist($audioSpecialite);
  2250.         }
  2251.         if (isset($data["tier"]))
  2252.             foreach ($data["tier"] as $tierObject) {
  2253.                 $tier $this->getDoctrine()
  2254.                     ->getRepository(Tier::class)
  2255.                     ->findOneBy(['id' => $tierObject]);
  2256.                 if ($tier == null) {
  2257.                     return new Response(json_encode([
  2258.                         'message' => 'Error, no tier found at this id ' $tierObject,
  2259.                         'path' => 'src/Controller/CentreController.php',
  2260.                     ]));
  2261.                 } else {
  2262.                     $centreTier = new CentreTier();
  2263.                     $centreTier->setIdTier($tier);
  2264.                     $centreTier->setIdCentre($centre);
  2265.                     $entityManager->persist($centreTier);
  2266.                 }
  2267.             }
  2268.         if (isset($data["access"]) && !empty($data["access"])) {
  2269.             $accessCentre $this->getDoctrine()
  2270.                 ->getRepository(AccessCentre::class)
  2271.                 ->findOneBy(['id_centre' => $centre]);
  2272.             if (!$accessCentre) {
  2273.                 $accessCentre = new AccessCentre();
  2274.             }                // add the acces to center 
  2275.             foreach ($data["access"] as $accessData) {
  2276.                 if (isset($accessData["metro"]))
  2277.                     $accessCentre->setMetro(json_encode($accessData["metro"], JSON_FORCE_OBJECT));
  2278.                 if (isset($accessData["bus"]))
  2279.                     $accessCentre->setBus(json_encode($accessData["bus"], JSON_FORCE_OBJECT));
  2280.                 if (isset($accessData["tram"]))
  2281.                     $accessCentre->setTram(json_encode($accessData["tram"], JSON_FORCE_OBJECT));
  2282.                 if (isset($accessData["rer"]))
  2283.                     $accessCentre->setRer(json_encode($accessData["rer"], JSON_FORCE_OBJECT));
  2284.                 if (isset($accessData["parkingPublic"]))
  2285.                     $accessCentre->setParkingPublic(json_encode($accessData["parkingPublic"], JSON_FORCE_OBJECT));
  2286.                 if (isset($accessData["parkingPrive"]))
  2287.                     $accessCentre->setParkingPrivate(json_encode($accessData["parkingPrive"], JSON_FORCE_OBJECT));
  2288.                 if (isset($accessData["other"]))
  2289.                     $accessCentre->setOther(json_encode($accessData["other"], JSON_FORCE_OBJECT));
  2290.             }
  2291.             $accessCentre->setIdCentre($centre);
  2292.             $entityManager->persist($accessCentre);
  2293.         }
  2294.         $centre->setDescription($data['descriptionCentre']);
  2295.         $entityManager->persist($audio);
  2296.         $entityManager->flush();
  2297.         return $this->json([
  2298.             'message' => '',
  2299.             "status" => 200
  2300.         ], 200);
  2301.     }
  2302.     /**
  2303.      * @Route("/centre", name="postCentre", methods={"POST"})
  2304.      */
  2305.     public function postCentre(Request $requestPublicFunction $publicFunctionStripeService $stripeService): Response
  2306.     {
  2307.         $data json_decode($request->getContent(), true);
  2308.         $requestData = [
  2309.             "name" => $data["audio"][0]["name"],
  2310.             "email" => $data["audio"][0]["mail"],
  2311.             "address" => $data["address"],
  2312.             "quantity" => $data["quantity"],
  2313.             "price" => $data["price"]["finalPrice"] ?? $data["price"],
  2314.             "recurring" => ($data["price"]["recurring"] === "monthly") ? "month" : (($data["price"]["recurring"] === "yearly") ? "year" $data["price"]["recurring"]),
  2315.             "paymentMethodId" => $data["paymentMethodId"],
  2316.             "offerName" => $data["plan"]["planName"]
  2317.         ];
  2318.         $createSubscription $stripeService->createSubscriptionStripe($requestData);
  2319.         $centre = new Centre();
  2320.         $resultAudio = new ArrayCollection();
  2321.         $gerant null;
  2322.         if ($data['gerant'] !== "") {
  2323.             $gerant $this->getDoctrine()
  2324.                 ->getRepository(Audio::class)
  2325.                 ->find($data['gerant']);
  2326.         }
  2327.         if (isset($data["audio"])) {
  2328.             $entityManager $this->getDoctrine()->getManager();
  2329.             foreach ($data["audio"] as $key => $audioMap) {
  2330.                 // check if audio exist to collect on new center 
  2331.                 if ($audioMap['registredAudio'] !== "") {
  2332.                     $audio $this->getDoctrine()
  2333.                         ->getRepository(Audio::class)
  2334.                         ->find($audioMap['registredAudio']);
  2335.                     $audioCentre = new AudioCentre();
  2336.                     $audioCentre->setIdAudio($audio);
  2337.                     $audioCentre->setIdCentre($centre);
  2338.                     $audioCentre->setIsConfirmed(true);
  2339.                     $audioCentre->setHoraire($publicFunction->centreHoraire2);
  2340.                     $entityManager->persist($audioCentre);
  2341.                 } else {
  2342.                     $role $this->getDoctrine()
  2343.                         ->getRepository(Role::class)
  2344.                         ->find($audioMap["role"]);
  2345.                     $audio = new Audio();
  2346.                     $audio->setCivilite($audioMap["civilite"]);
  2347.                     $audio->setName($audioMap["lastname"]);
  2348.                     $audio->setLastname($audioMap["name"]);
  2349.                     $audio->setBirthdate(\DateTime::createFromFormat("d/m/Y"$audioMap["birthdate"]));
  2350.                     $audio->setRole($role);
  2351.                     $audio->setSignupDate(new \DateTime());
  2352.                     // set notification by default selected
  2353.                     $audio->setConfirmRdvMail(true);
  2354.                     $audio->setConfirmRdvSms(true);
  2355.                     $audio->setModifRdvMail(true);
  2356.                     $audio->setModifRdvSms(true);
  2357.                     $audio->setModifNote(true);
  2358.                     $audioMailTest $this->getDoctrine()
  2359.                         ->getRepository(Audio::class)
  2360.                         ->findOneBy(['mail' => $audioMap["mail"]]);
  2361.                     if ($audioMailTest)
  2362.                         return $this->json([
  2363.                             'message' => 'Audio mail',
  2364.                             'mail' => $audioMap["mail"],
  2365.                             'path' => 'src/Controller/AudioController.php',
  2366.                             "status" => 402
  2367.                         ], 401);
  2368.                     $audio->setMail($audioMap["mail"]);
  2369.                     $audioPhoneTest $this->getDoctrine()
  2370.                         ->getRepository(Audio::class)
  2371.                         ->findOneBy(['phone' => $audioMap["phone"]]);
  2372.                     if ($audioPhoneTest)
  2373.                         return $this->json([
  2374.                             'message' => 'Audio phone',
  2375.                             'phone' => $audioMap["phone"],
  2376.                             'path' => 'src/Controller/AudioController.php',
  2377.                             "status" => 403
  2378.                         ], 401);
  2379.                     $audio->setPhone($audioMap["phone"]);
  2380.                     //$audio->setAdeli($audioMap["adeli"]);
  2381.                     if ($data["isImported"] !== '')
  2382.                         $audio->setCodeParrainage($data["isImported"]);
  2383.                     $audio->setIsIndie(false);
  2384.                     // set default pass for audio inserted
  2385.                     $audioMap["password"] !== "" $audio->setPassword(password_hash($audioMap["password"], PASSWORD_DEFAULT)) : $audio->setPassword(password_hash("myaudio2023"PASSWORD_DEFAULT));
  2386.                     $audio->setPin($audioMap["pin"]);
  2387.                     // $audio->setDescription($audioMap["description"]);
  2388.                     if (isset($audioMap["imgUrl"]))
  2389.                         $audio->setImgUrl($audioMap["imgUrl"]);
  2390.                     $entityManager $this->getDoctrine()->getManager();
  2391.                     foreach ($audioMap["diplome"] as $diplomeObject) {
  2392.                         $diplome $this->getDoctrine()
  2393.                             ->getRepository(Diplome::class)
  2394.                             ->findOneBy(['id' => $diplomeObject["id"]]);
  2395.                         if ($diplome == null) {
  2396.                             /*$audioDiplome = new AudioDiplome();
  2397.                         if(isset($diplomeObject["year"]))
  2398.                         {
  2399.                             if(!empty($diplomeObject["year"]))
  2400.                             {
  2401.                                 $audioDiplome->setYear($diplomeObject["year"]);
  2402.                             }
  2403.                         }
  2404.                         $audioDiplome->setUrl($diplomeObject["url"]);
  2405.                         $audioDiplome->setOther($data['otherdDiplom'][$key]);
  2406.                         $audioDiplome->setIdAudio($audio);
  2407.                         $entityManager->persist($audioDiplome);*/
  2408.                             return $this->json([
  2409.                                 'message' => 'Error, no diplome found at this id ' $diplomeObject["id"],
  2410.                                 'path' => 'src/Controller/AudioController.php',
  2411.                                 "status" => 401
  2412.                             ], 401);
  2413.                         } else {
  2414.                             $audioDiplome = new AudioDiplome();
  2415.                             if (isset($diplomeObject["year"])) {
  2416.                                 if (!empty($diplomeObject["year"])) {
  2417.                                     $audioDiplome->setYear($diplomeObject["year"]);
  2418.                                 }
  2419.                             }
  2420.                             $audioDiplome->setUrl($diplomeObject["url"]);
  2421.                             $audioDiplome->setIdDiplome($diplome);
  2422.                             $audioDiplome->setIdAudio($audio);
  2423.                             $entityManager->persist($audioDiplome);
  2424.                         }
  2425.                     }
  2426.                     foreach ($audioMap["experiences"] as $experience) {
  2427.                         $audioSpecialite = new ExperiencePro();
  2428.                         $audioSpecialite->setDate(\DateTime::createFromFormat("d/m/Y"$experience["date"]));
  2429.                         $audioSpecialite->setPoste($experience["poste"]);
  2430.                         $audioSpecialite->setCompany($experience["company"]);
  2431.                         $audioSpecialite->setIdAudio($audio);
  2432.                         $entityManager->persist($audioSpecialite);
  2433.                     }
  2434.                     foreach ($audioMap["specialite"] as $specialiteId) {
  2435.                         $specialite $this->getDoctrine()
  2436.                             ->getRepository(Specialite::class)
  2437.                             ->findOneBy(['id' => $specialiteId]);
  2438.                         if (isset($audioMap["autre_special_text"])) {
  2439.                             $audioSpecialite = new AudioSpecialite();
  2440.                             // $audioSpecialite->setIdSpecialite($specialite);
  2441.                             $audioSpecialite->setIdAudio($audio);
  2442.                             $audioSpecialite->setIdAudio($audio);
  2443.                             $entityManager->persist($audioSpecialite);
  2444.                         }
  2445.                         if ($specialite == null) {
  2446.                             return $this->json([
  2447.                                 'message' => 'Error, no specialite found at this id ' $specialiteId,
  2448.                                 'path' => 'src/Controller/AudioController.php',
  2449.                                 "status" => 401
  2450.                             ], 401);
  2451.                         } else {
  2452.                             $audioSpecialite = new AudioSpecialite();
  2453.                             $audioSpecialite->setIdSpecialite($specialite);
  2454.                             $audioSpecialite->setIdAudio($audio);
  2455.                             $entityManager->persist($audioSpecialite);
  2456.                         }
  2457.                     }
  2458.                     // $entityManager->persist($audio);
  2459.                     $entityManager->persist($this->createPermanantMotif(60"#FF00FF"$audio,  11));
  2460.                     $entityManager->persist($this->createPermanantMotif(90"#00FFFF"$audio,  21));
  2461.                     $entityManager->persist($this->createPermanantMotif(30"#FFFF00"$audio,  31));
  2462.                     $entityManager->persist($this->createPermanantMotif(60"#FF0000"$audio,  41));
  2463.                     $entityManager->persist($this->createPermanantMotif(60"#FFCC59"$audio692));
  2464.                     $entityManager->persist($this->createPermanantMotif(30"#33B679"$audio1061));
  2465.                     $entityManager->persist($this->createPermanantMotif(30"#F6BF25"$audio1071));
  2466.                     $entityManager->persist($this->createPermanantMotif(30"#E67C73"$audio1081));
  2467.                     $entityManager->persist($this->createPermanantMotif(30"#7886CB"$audio1091));
  2468.                     //  $entityManager->persist($this->createPermanantMotif(60, "#FF0000", $audio,  5));
  2469.                     $entityManager->persist($audio);
  2470.                     if ($gerant == null$gerant $audio;
  2471.                     $audioCentre = new AudioCentre();
  2472.                     $audioCentre->setIdAudio($audio);
  2473.                     $audioCentre->setIdCentre($centre);
  2474.                     $audioCentre->setIsConfirmed(true);
  2475.                     $audioCentre->setHoraire($publicFunction->centreHoraire2);
  2476.                     $centerHoliday json_decode($publicFunction->centreHoraire4true);
  2477.                     $audioCentre->setHorairesHoliday($centerHoliday);
  2478.                     $entityManager->persist($audioCentre);
  2479.                     // SEN MAIL NOTIF JUST FOR AUDIOS ADDED NOT FOR GERANT
  2480.                     if ($key !== 0) {
  2481.                         // GENERATE TOKEN & AUDIO ADDED MAIL CONFIRM
  2482.                         $tokenString $publicFunction->generateRandomString(30);
  2483.                         $params = array(
  2484.                             "lien" => "{$_ENV['BASE_client']}confirmation_email/{$audio->getMail()}?token={$tokenString}",
  2485.                             "nom" => "{$audio->getLastName()}",
  2486.                             "texte" => "Veuillez cliquer sur le bouton ci-dessous pour confirmer votre adresse mail",
  2487.                             "titre" => "Confirmer mon email",
  2488.                             "bouton" => "Confirmer mon Email",
  2489.                         );
  2490.                         $publicFunction->sendEmail($params$audio->getMail(), $audio->getName() . ' ' $audio->getLastName(), "Confirmation d'inscription sur My Audio Pro"122);
  2491.                         $token = new Token();
  2492.                         $token->setCreationDate(new DateTime());
  2493.                         $token->setToken($tokenString);
  2494.                         $token->setMail($audio->getMail());
  2495.                         $entityManager $this->getDoctrine()->getManager();
  2496.                         $entityManager->persist($token);
  2497.                         // $entityManager->flush();
  2498.                     }
  2499.                 }
  2500.                 $resultAudio->add([
  2501.                     "id" => $audio->getId(),
  2502.                     "civilite" => $audio->getCivilite(),
  2503.                     "name" => $audio->getName(),
  2504.                     "lastname" => $audio->getLastname(),
  2505.                     "birthdate" => $audio->getBirthdate(),
  2506.                     "mail" => $audio->getMail(),
  2507.                     "phone" => $audio->getPhone(),
  2508.                     "adeli" => $audio->getAdeli(),
  2509.                     "pin" => $audio->getPin(),
  2510.                     "description" => $audio->getDescription(),
  2511.                     "imgUrl" => $audio->getImgUrl(),
  2512.                 ]);
  2513.             }
  2514.         } else {
  2515.             return new Response(json_encode([
  2516.                 'message' => 'Error, no audio found',
  2517.                 'path' => 'src/Controller/CentreController.php',
  2518.             ]), 404);
  2519.         }
  2520.         // generate color code 
  2521.         $colors = array(
  2522.             "#FFC0CB"// Pink
  2523.             "#FFD700"// Gold
  2524.             "#90EE90"// Light Green
  2525.             "#87CEFA"// Light Sky Blue
  2526.             "#FFA07A"// Light Salmon
  2527.             "#F0E68C"// Khaki
  2528.             "#B0C4DE"// Light Steel Blue
  2529.             "#98FB98"// Pale Green
  2530.             "#FFB6C1"// Light Pink
  2531.             "#ADD8E6"// Light Blue
  2532.             "#FF69B4"// Hot Pink
  2533.             "#FFA500"// Orange
  2534.             "#00FF7F"// Spring Green
  2535.             "#AFEEEE"// Pale Turquoise
  2536.             "#FF8C00"// Dark Orange
  2537.             "#FFE4B5"// Moccasin
  2538.             "#00CED1"// Dark Turquoise
  2539.             "#7FFFD4"// Aquamarine
  2540.             "#FF4500"// Orange Red
  2541.             "#00FA9A"// Medium Spring Green
  2542.             "#FFF0F5"// Lavender Blush
  2543.             "#00BFFF"// Deep Sky Blue
  2544.             "#FF6347"// Tomato
  2545.             "#20B2AA"// Light Sea Green
  2546.             "#FFFF00"// Yellow
  2547.             "#32CD32"// Lime Green
  2548.             "#FFF5EE"// Seashell
  2549.             "#1E90FF"// Dodger Blue
  2550.             "#CD5C5C"// Indian Red
  2551.             "#8FBC8F"// Dark Sea Green
  2552.             "#F0FFFF"// Azure
  2553.             "#4169E1"// Royal Blue
  2554.             "#FF8B00"// Dark Orange
  2555.             "#66CDAA"// Medium Aquamarine
  2556.             "#FFFACD"// Lemon Chiffon
  2557.             "#6495ED"// Cornflower Blue
  2558.             "#FF7F50"// Coral
  2559.             "#00FF00"// Lime
  2560.             "#FAFAD2"// Light Goldenrod Yellow
  2561.             "#87CEEB"// Sky Blue
  2562.             "#DC143C"// Crimson
  2563.             "#2E8B57"// Sea Green
  2564.             "#F5DEB3"// Wheat
  2565.             "#4682B4"// Steel Blue
  2566.             "#CD853F"// Peru
  2567.             "#8A2BE2"// Blue Violet
  2568.             "#D2691E"// Chocolate
  2569.             "#6A5ACD"// Slate Blue
  2570.             "#F5F5DC"// Beige
  2571.             "#7B68EE"// Medium Slate Blue
  2572.         );
  2573.         // short initial 
  2574.         $name $data['name'];
  2575.         $words explode(' '$name);
  2576.         $initials '';
  2577.         foreach ($words as $word) {
  2578.             $initials .= strtoupper(substr($word01));
  2579.         }
  2580.         $initials strtoupper($initials);
  2581.         $shortName substr($initials02);
  2582.         $randomColor $colors[array_rand($colors)];
  2583.         // generate slug url 
  2584.         $slug $this->slugger->slug($data["name"])->lower();
  2585.         $centre->setName($data["name"]);
  2586.         $slugify $this->getDoctrine()
  2587.             ->getRepository(Centre::class)
  2588.             ->findOneBy(array('slug' => $slug));
  2589.         if ($slugify) {
  2590.             $centre->setSlug($slug "-1");
  2591.         } else {
  2592.             $centre->setSlug($slug);
  2593.         }
  2594.         if (isset($data["imgUrl"]))
  2595.             $centre->setImgUrl($data["imgUrl"]);
  2596.         if (isset($data["finessURL"]))
  2597.             $centre->setFinessUrl($data["finessURL"]);
  2598.         $centre->setIsRdvDomicile($data["isRdvDomicile"]);
  2599.         $centre->setIdGerant($gerant);
  2600.         $centre->setAddress($data["address"]);
  2601.         $centre->setPostale($data["postal"]);
  2602.         $centre->setCity($data["city"]);
  2603.         $centre->setFiness($data["finess"]);
  2604.         $centre->setSiret($data["siret"]);
  2605.         $centre->setInitial($shortName);
  2606.         $centre->setWebsite($data["website"]);
  2607.         $centre->setSignupDate(new \DateTime());
  2608.         $centre->setCalendarColor($randomColor);
  2609.         // set the galeries for images by default
  2610.         // Define an array of default image URLs
  2611.         $defaultImages = ["by-default-1.jpeg""by-default-2.jpeg""by-default-3.jpeg"];
  2612.         // Iterate through each default image
  2613.         foreach ($defaultImages as $imageUrl) {
  2614.             $centerImage = new CenterImage();
  2615.             $centerImage->setType("image");
  2616.             $centerImage->setUrl($imageUrl);
  2617.             // Associate the center image with the current center
  2618.             $centerImage->setCenter($centre);
  2619.             $entityManager->persist($centerImage);
  2620.         }
  2621.         /*$centrePhoneTest = $this->getDoctrine()
  2622.             ->getRepository(Centre::class)
  2623.             ->findOneBy(['phone' => $data["phone"]]);
  2624.         if ($centrePhoneTest)
  2625.             return $this->json([
  2626.                 'message' => 'Centre phone',
  2627.                 'path' => 'src/Controller/CentreController.php',
  2628.                 "status" => 401
  2629.             ], 401);*/
  2630.         $centre->setPhone($data["phone"]);
  2631.         $centre->setIsHandicap($data["isHandicap"]);
  2632.         $centre->setLongitude($data["longitude"]);
  2633.         $centre->setLatitude($data["latitude"]);
  2634.         $centre->setHoraire($publicFunction->centreHoraire2);
  2635.         $centerHoliday json_decode($publicFunction->centreHoraire4true);
  2636.         $centre->setHorairesHoliday($centerHoliday);
  2637.         $entityManager $this->getDoctrine()->getManager();
  2638.         //add the centre access
  2639.         if (isset($data["mutuelle"]))
  2640.             foreach ($data["mutuelle"] as $mutuelleObject) {
  2641.                 $mutuelle $this->getDoctrine()
  2642.                     ->getRepository(Mutuelle::class)
  2643.                     ->findOneBy(['id' => $mutuelleObject]);
  2644.                 if ($mutuelle == null) {
  2645.                     return new Response(json_encode([
  2646.                         'message' => 'Error, no mutuelle found at this id ' $mutuelleObject,
  2647.                         'path' => 'src/Controller/CentreController.php',
  2648.                     ]));
  2649.                 } else {
  2650.                     $centreMutuelle = new CentreMutuelle();
  2651.                     $centreMutuelle->setIdMutuelle($mutuelle);
  2652.                     $centreMutuelle->setIdCentre($centre);
  2653.                     if (isset($data["otherMutuelle"]) && $mutuelle->getLibelle() == "Autres")
  2654.                         $centreMutuelle->setOther(json_encode($data["otherMutuelle"], JSON_FORCE_OBJECT));
  2655.                     $entityManager->persist($centreMutuelle);
  2656.                 }
  2657.             }
  2658.         //other spetiality 
  2659.         if (isset($data["otherSpetiality"])) {
  2660.             $audioSpecialite = new AudioSpecialite();
  2661.             // $audioSpecialite->setIdSpecialite($specialite);
  2662.             $audioSpecialite->setIdAudio($audio);
  2663.             $audioSpecialite->setOther(json_encode($data["otherSpetiality"], JSON_FORCE_OBJECT));
  2664.             $entityManager->persist($audioSpecialite);
  2665.         }
  2666.         if (isset($data["tier"]))
  2667.             foreach ($data["tier"] as $tierObject) {
  2668.                 $tier $this->getDoctrine()
  2669.                     ->getRepository(Tier::class)
  2670.                     ->findOneBy(['id' => $tierObject]);
  2671.                 if ($tier == null) {
  2672.                     return new Response(json_encode([
  2673.                         'message' => 'Error, no tier found at this id ' $tierObject,
  2674.                         'path' => 'src/Controller/CentreController.php',
  2675.                     ]));
  2676.                 } else {
  2677.                     $centreTier = new CentreTier();
  2678.                     $centreTier->setIdTier($tier);
  2679.                     $centreTier->setIdCentre($centre);
  2680.                     $entityManager->persist($centreTier);
  2681.                 }
  2682.             }
  2683.         /*  if (isset($data["prestation"]))
  2684.             foreach ($data["prestation"] as $prestationId) {
  2685.                 $prestation = $this->getDoctrine()
  2686.                     ->getRepository(Prestation::class)
  2687.                     ->findOneBy(['id' => $prestationId]);
  2688.                 if ($prestation == null) {
  2689.                     return new Response(json_encode([
  2690.                         'message' => 'Error, no prestation found at this id ' . $prestationId,
  2691.                         'path' => 'src/Controller/CentreController.php',
  2692.                     ]));
  2693.                 } else {
  2694.                     $centrePrestation = new CentrePrestation();
  2695.                     $centrePrestation->setIdPrestation($prestation);
  2696.                     $centrePrestation->setIdCentre($centre);
  2697.                     $entityManager->persist($centrePrestation);
  2698.                 }
  2699.             }*/
  2700.         $entityManager->persist($centre);
  2701.         // for audio on multi centre creation
  2702.         $accessCentre = new AccessCentre();
  2703.         //  $accessData = $data["access"];
  2704.         // add the acces to center 
  2705.         foreach ($data["access"] as $accessData) {
  2706.             if (isset($accessData["metro"]))
  2707.                 $accessCentre->setMetro(json_encode($accessData["metro"], JSON_FORCE_OBJECT));
  2708.             if (isset($accessData["bus"]))
  2709.                 $accessCentre->setBus(json_encode($accessData["bus"], JSON_FORCE_OBJECT));
  2710.             if (isset($accessData["tram"]))
  2711.                 $accessCentre->setTram(json_encode($accessData["tram"], JSON_FORCE_OBJECT));
  2712.             if (isset($accessData["rer"]))
  2713.                 $accessCentre->setRer(json_encode($accessData["rer"], JSON_FORCE_OBJECT));
  2714.             if (isset($accessData["parkingPublic"]))
  2715.                 $accessCentre->setParkingPublic(json_encode($accessData["parkingPublic"], JSON_FORCE_OBJECT));
  2716.             if (isset($accessData["parkingPrivate"]))
  2717.                 $accessCentre->setParkingPrivate(json_encode($accessData["parkingPrivate"], JSON_FORCE_OBJECT));
  2718.             if (isset($accessData["other"]))
  2719.                 $accessCentre->setOther(json_encode($accessData["other"], JSON_FORCE_OBJECT));
  2720.         }
  2721.         $accessCentre->setIdCentre($centre);
  2722.         $entityManager->persist($accessCentre);
  2723.         $entityManager->flush();
  2724.         // save print setting 
  2725.         $setting = new Setting();
  2726.         $setting->setName($data["name"]);
  2727.         $setting->setAddress($data["address"]);
  2728.         $setting->setPhone($data["phone"]);
  2729.         $setting->setLogoUrl($centre->getImgUrl());
  2730.         $setting->setWebsite($data["website"]);
  2731.         $setting->setFirstname($audio->getName());
  2732.         $setting->setLastname($audio->getLastname());
  2733.         $setting->setEmail($gerant->getMail());
  2734.         $setting->setSeuilCaDroite(true);
  2735.         $setting->setSeuilCaGauche(true);
  2736.         $setting->setSeuilConfortDroite(true);
  2737.         $setting->setSeuilConfortGauche(true);
  2738.         $setting->setSeuilinconfortDroite(true);
  2739.         $setting->setSeuilInConfortGauche(true);
  2740.         $setting->setSeuilCoDroite(true);
  2741.         $setting->setSeuilCoGauche(true);
  2742.         $setting->setSeuilCaMaskingDroite(true);
  2743.         $setting->setSeuilCaMaskingGauche(true);
  2744.         $setting->setSeuilCoMaskingDroite(true);
  2745.         $setting->setSeuilCoMaskingGauche(true);
  2746.         /* $setting->setCasqueDroite(false);
  2747.         $setting->setCasqueGauche(false);
  2748.         $setting->setCasqueBinaural(false);
  2749.         $setting->setChampsLibreDroite(false);
  2750.         $setting->setChampsLibreGauche(false);
  2751.         $setting->setChampsLibreBinaural(false);
  2752.         $setting->setChampsLibreAppDroite(false);
  2753.         $setting->setChampsLibreAppGauche(false);
  2754.         $setting->setChampsLibreAppBinaural(false);*/
  2755.         $setting->setCasqueDroite(true);
  2756.         $setting->setCasqueGauche(true);
  2757.         $setting->setCasqueBinaural(true);
  2758.         $setting->setChampsLibreDroite(true);
  2759.         $setting->setChampsLibreGauche(true);
  2760.         $setting->setChampsLibreBinaural(true);
  2761.         $setting->setChampsLibreAppDroite(true);
  2762.         $setting->setChampsLibreAppGauche(true);
  2763.         $setting->setChampsLibreAppBinaural(true);
  2764.         $setting->setCentre($centre);
  2765.         $entityManager->persist($setting);
  2766.         $entityManager->flush();
  2767.         //envoi mail de confirmation d'email au gérant.
  2768.         $tokenString $publicFunction->generateRandomString(30);
  2769.         $params = array(
  2770.             "lien" => "{$_ENV['BASE_client']}confirmation_email/{$gerant->getMail()}?token={$tokenString}",
  2771.             "nom" => "{$gerant->getLastName()}",
  2772.             "texte" => "Veuillez cliquer sur le bouton ci-dessous pour confirmer votre adresse mail",
  2773.             "titre" => "Confirmer mon email",
  2774.             "bouton" => "Confirmer mon Email",
  2775.         );
  2776.         $publicFunction->sendEmail($params$gerant->getMail(), $gerant->getName() . ' ' $gerant->getLastName(), "Confirmation d'inscription sur My Audio Pro"122);
  2777.         $token = new Token();
  2778.         $token->setCreationDate(new DateTime());
  2779.         $token->setToken($tokenString);
  2780.         $token->setMail($gerant->getMail());
  2781.         $entityManager $this->getDoctrine()->getManager();
  2782.         $entityManager->persist($token);
  2783.         $entityManager->flush();
  2784.         $user = [
  2785.             "prenomAudioprothesiste" => $gerant->getName(),
  2786.             "urlDemo" => "https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ0Ry72UDE9m8d2IylSycOMQVerlY0jHt1DLWFD6Pso4hg79sQ9nUAlxtZYOPH6wSubDX4vqVQWh",
  2787.         ];
  2788.         // we send parametre for the trait methid
  2789.         $params $this->emailNotificationDemoService->prepareEmailParams($user);
  2790.         // send email notifcation
  2791.         $this->emailNotificationDemoService->sendEmail($params$gerant->getMail(), 'Organisez votre Démo personnalisée de My Audio Pro'143);
  2792.         // set order datable patient 
  2793.         $this->orderPatient->createOrderPatient($audio);
  2794.         return new Response(json_encode([
  2795.             "id" => $centre->getId(),
  2796.             "name" => $centre->getName(),
  2797.             "imgUrl" => $centre->getImgUrl(),
  2798.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  2799.             "audio_id" => $centre->getIdGerant()->getId(),
  2800.             "address" => $centre->getAddress(),
  2801.             "postale" => $centre->getPostale(),
  2802.             "city" => $centre->getCity(),
  2803.             "finess" => $centre->getFiness(),
  2804.             "siret" => $centre->getSiret(),
  2805.             "website" => $centre->getWebsite(),
  2806.             "phone" => $centre->getPhone(),
  2807.             "isHandicap" => $centre->getIsHandicap(),
  2808.             "audio" => $resultAudio->toArray(),
  2809.             "centerId" => $centre->getId(),
  2810.             "audioId" => $audio->getId(),
  2811.             "status" => 200,
  2812.         ]));
  2813.     }
  2814.     /**
  2815.      * @Route("/centre/new-inscription", name="postCentreNewInscription", methods={"POST"})
  2816.      */
  2817.     public function postCentreNewInscription(Request $requestPublicFunction $publicFunctionStripeService $stripeServiceSubscriptionService $subscrition): Response
  2818.     {
  2819.         $data json_decode($request->getContent(), true);
  2820.         $requestData = [
  2821.             "name" => $data["audio"][0]["name"],
  2822.             "email" => $data["audio"][0]["mail"],
  2823.             "address" => $data["address"],
  2824.             "quantity" => $data["quantity"],
  2825.             "price" => $data["price"]["finalPrice"] ?? $data["price"],
  2826.             "recurring" => ($data["price"]["recurring"] === "monthly") ? "month" : (($data["price"]["recurring"] === "yearly") ? "year" $data["price"]["recurring"]),
  2827.             "paymentMethodId" => $data["paymentMethodId"],
  2828.             "offerName" => $data["plan"]["planName"],
  2829.         ];
  2830.         $createSubscription $stripeService->createSubscriptionStripe($requestData);
  2831.         // dd($createSubscription);
  2832.         $centre = new Centre();
  2833.         $resultAudio = new ArrayCollection();
  2834.         $gerant null;
  2835.         if ($data['gerant'] !== "") {
  2836.             $gerant $this->getDoctrine()
  2837.                 ->getRepository(Audio::class)
  2838.                 ->find($data['gerant']);
  2839.         }
  2840.         if (isset($data["audio"])) {
  2841.             $entityManager $this->getDoctrine()->getManager();
  2842.             foreach ($data["audio"] as $key => $audioMap) {
  2843.                 // check if audio exist to collect on new center 
  2844.                 if ($audioMap['registredAudio'] !== "") {
  2845.                     $audio $this->getDoctrine()
  2846.                         ->getRepository(Audio::class)
  2847.                         ->find($audioMap['registredAudio']);
  2848.                     $audioCentre = new AudioCentre();
  2849.                     $audioCentre->setIdAudio($audio);
  2850.                     $audioCentre->setIdCentre($centre);
  2851.                     $audioCentre->setIsConfirmed(true);
  2852.                     $audioCentre->setHoraire($publicFunction->centreHoraire2);
  2853.                     $entityManager->persist($audioCentre);
  2854.                 } else {
  2855.                     $role $this->getDoctrine()
  2856.                         ->getRepository(Role::class)
  2857.                         ->find($audioMap["role"]);
  2858.                     $audio = new Audio();
  2859.                     $audio->setBirthdate(\DateTime::createFromFormat("d/m/Y"$audioMap["birthdate"]));
  2860.                     $audio->setRole($role);
  2861.                     $audio->setSignupDate(new \DateTime());
  2862.                     $audio->setAdeli($data["audio"]["0"]["adeli"]);
  2863.                     $audio->setCivilite($data["audio"]["0"]["civilite"]);
  2864.                     $audio->setLastName($data["audio"]["0"]["lastname"]);
  2865.                     $audio->setName($data["audio"]["0"]["name"]);
  2866.                     // set notification by default selected
  2867.                     $audio->setConfirmRdvMail(true);
  2868.                     $audio->setConfirmRdvSms(true);
  2869.                     $audio->setModifRdvMail(true);
  2870.                     $audio->setModifRdvSms(true);
  2871.                     $audio->setModifNote(true);
  2872.                     $audioMailTest $this->getDoctrine()
  2873.                         ->getRepository(Audio::class)
  2874.                         ->findOneBy(['mail' => $audioMap["mail"]]);
  2875.                     /*if ($audioMailTest)
  2876.                 return $this->json([
  2877.                     'message' => "L'adresse e-mail est déjà enregistrée.",
  2878.                     'mail' => $audioMap["mail"],
  2879.                     'code' => "mail_exist",
  2880.                     'status' => 409 
  2881.                 ], 500); */
  2882.                     $audio->setMail($audioMap["mail"]);
  2883.                     $audioPhoneTest $this->getDoctrine()
  2884.                         ->getRepository(Audio::class)
  2885.                         ->findOneBy(['phone' => $audioMap["phone"]]);
  2886.                     /*if ($audioPhoneTest)
  2887.                 return $this->json([
  2888.                     'message' => 'Le numéro de téléphone est déjà enregistré.',
  2889.                     'phone' => $audioMap["phone"],
  2890.                     'code' => "phone_exist",
  2891.                     'status' => 409 
  2892.                 ], 500); */
  2893.                     $audio->setPhone($audioMap["phone"]);
  2894.                     //$audio->setAdeli($audioMap["adeli"]);
  2895.                     if ($data["isImported"] !== '')
  2896.                         $audio->setCodeParrainage($data["isImported"]);
  2897.                     $audio->setIsIndie(false);
  2898.                     // set default pass for audio inserted
  2899.                     $audioMap["password"] !== "" $audio->setPassword(password_hash($audioMap["password"], PASSWORD_DEFAULT)) : $audio->setPassword(password_hash("myaudio2023"PASSWORD_DEFAULT));
  2900.                     $audio->setPin($audioMap["pin"]);
  2901.                     // $audio->setDescription($audioMap["description"]);
  2902.                     if (isset($audioMap["imgUrl"]))
  2903.                         $audio->setImgUrl($audioMap["imgUrl"]);
  2904.                     $entityManager $this->getDoctrine()->getManager();
  2905.                     foreach ($audioMap["diplome"] as $diplomeObject) {
  2906.                         $diplome $this->getDoctrine()
  2907.                             ->getRepository(Diplome::class)
  2908.                             ->findOneBy(['id' => $diplomeObject["id"]]);
  2909.                         if ($diplome == null) {
  2910.                             /*$audioDiplome = new AudioDiplome();
  2911.                         if(isset($diplomeObject["year"]))
  2912.                         {
  2913.                             if(!empty($diplomeObject["year"]))
  2914.                             {
  2915.                                 $audioDiplome->setYear($diplomeObject["year"]);
  2916.                             }
  2917.                         }
  2918.                         $audioDiplome->setUrl($diplomeObject["url"]);
  2919.                         $audioDiplome->setOther($data['otherdDiplom'][$key]);
  2920.                         $audioDiplome->setIdAudio($audio);
  2921.                         $entityManager->persist($audioDiplome);*/
  2922.                             return $this->json([
  2923.                                 'message' => 'Error, no diplome found at this id ' $diplomeObject["id"],
  2924.                                 'path' => 'src/Controller/AudioController.php',
  2925.                                 "status" => 401
  2926.                             ], 401);
  2927.                         } else {
  2928.                             $audioDiplome = new AudioDiplome();
  2929.                             if (isset($diplomeObject["year"])) {
  2930.                                 if (!empty($diplomeObject["year"])) {
  2931.                                     $audioDiplome->setYear($diplomeObject["year"]);
  2932.                                 }
  2933.                             }
  2934.                             $audioDiplome->setUrl($diplomeObject["url"]);
  2935.                             $audioDiplome->setIdDiplome($diplome);
  2936.                             $audioDiplome->setIdAudio($audio);
  2937.                             $entityManager->persist($audioDiplome);
  2938.                         }
  2939.                     }
  2940.                     // $entityManager->persist($audio);
  2941.                     $entityManager->persist($this->createPermanantMotif(60"#FF00FF"$audio,  11));
  2942.                     $entityManager->persist($this->createPermanantMotif(90"#00FFFF"$audio,  21));
  2943.                     $entityManager->persist($this->createPermanantMotif(30"#FFFF00"$audio,  31));
  2944.                     $entityManager->persist($this->createPermanantMotif(60"#FF0000"$audio,  41));
  2945.                     $entityManager->persist($this->createPermanantMotif(60"#FFCC59"$audio692));
  2946.                     $entityManager->persist($this->createPermanantMotif(30"#33B679"$audio1061));
  2947.                     $entityManager->persist($this->createPermanantMotif(30"#F6BF25"$audio1071));
  2948.                     $entityManager->persist($this->createPermanantMotif(30"#E67C73"$audio1081));
  2949.                     $entityManager->persist($this->createPermanantMotif(30"#7886CB"$audio1091));
  2950.                     //  $entityManager->persist($this->createPermanantMotif(60, "#FF0000", $audio,  5));
  2951.                     $entityManager->persist($audio);
  2952.                     if ($gerant == null$gerant $audio;
  2953.                     $audioCentre = new AudioCentre();
  2954.                     $audioCentre->setIdAudio($audio);
  2955.                     $audioCentre->setIdCentre($centre);
  2956.                     $audioCentre->setIsConfirmed(true);
  2957.                     $audioCentre->setHoraire($publicFunction->centreHoraire2);
  2958.                     $centerHoliday json_decode($publicFunction->centreHoraire4true);
  2959.                     $audioCentre->setHorairesHoliday($centerHoliday);
  2960.                     $entityManager->persist($audioCentre);
  2961.                     // SEN MAIL NOTIF JUST FOR AUDIOS ADDED NOT FOR GERANT
  2962.                     // $entityManager->flush();
  2963.                 }
  2964.                 $resultAudio->add([
  2965.                     "id" => $audio->getId(),
  2966.                     "civilite" => $audio->getCivilite(),
  2967.                     "name" => $audio->getName(),
  2968.                     "lastname" => $audio->getLastname(),
  2969.                     "birthdate" => $audio->getBirthdate(),
  2970.                     "mail" => $audio->getMail(),
  2971.                     "phone" => $audio->getPhone(),
  2972.                     "adeli" => $audio->getAdeli(),
  2973.                     "pin" => $audio->getPin(),
  2974.                     "description" => $audio->getDescription(),
  2975.                     "imgUrl" => $audio->getImgUrl(),
  2976.                 ]);
  2977.             }
  2978.         } else {
  2979.             return new Response(json_encode([
  2980.                 'message' => 'Error, no audio found',
  2981.                 'path' => 'src/Controller/CentreController.php',
  2982.             ]), 404);
  2983.         }
  2984.         // generate color code 
  2985.         $colors = array(
  2986.             "#FFC0CB"// Pink
  2987.             "#FFD700"// Gold
  2988.             "#90EE90"// Light Green
  2989.             "#87CEFA"// Light Sky Blue
  2990.             "#FFA07A"// Light Salmon
  2991.             "#F0E68C"// Khaki
  2992.             "#B0C4DE"// Light Steel Blue
  2993.             "#98FB98"// Pale Green
  2994.             "#FFB6C1"// Light Pink
  2995.             "#ADD8E6"// Light Blue
  2996.             "#FF69B4"// Hot Pink
  2997.             "#FFA500"// Orange
  2998.             "#00FF7F"// Spring Green
  2999.             "#AFEEEE"// Pale Turquoise
  3000.             "#FF8C00"// Dark Orange
  3001.             "#FFE4B5"// Moccasin
  3002.             "#00CED1"// Dark Turquoise
  3003.             "#7FFFD4"// Aquamarine
  3004.             "#FF4500"// Orange Red
  3005.             "#00FA9A"// Medium Spring Green
  3006.             "#FFF0F5"// Lavender Blush
  3007.             "#00BFFF"// Deep Sky Blue
  3008.             "#FF6347"// Tomato
  3009.             "#20B2AA"// Light Sea Green
  3010.             "#FFFF00"// Yellow
  3011.             "#32CD32"// Lime Green
  3012.             "#FFF5EE"// Seashell
  3013.             "#1E90FF"// Dodger Blue
  3014.             "#CD5C5C"// Indian Red
  3015.             "#8FBC8F"// Dark Sea Green
  3016.             "#F0FFFF"// Azure
  3017.             "#4169E1"// Royal Blue
  3018.             "#FF8B00"// Dark Orange
  3019.             "#66CDAA"// Medium Aquamarine
  3020.             "#FFFACD"// Lemon Chiffon
  3021.             "#6495ED"// Cornflower Blue
  3022.             "#FF7F50"// Coral
  3023.             "#00FF00"// Lime
  3024.             "#FAFAD2"// Light Goldenrod Yellow
  3025.             "#87CEEB"// Sky Blue
  3026.             "#DC143C"// Crimson
  3027.             "#2E8B57"// Sea Green
  3028.             "#F5DEB3"// Wheat
  3029.             "#4682B4"// Steel Blue
  3030.             "#CD853F"// Peru
  3031.             "#8A2BE2"// Blue Violet
  3032.             "#D2691E"// Chocolate
  3033.             "#6A5ACD"// Slate Blue
  3034.             "#F5F5DC"// Beige
  3035.             "#7B68EE"// Medium Slate Blue
  3036.         );
  3037.         // short initial 
  3038.         $name $data['name'];
  3039.         $words explode(' '$name);
  3040.         $initials '';
  3041.         foreach ($words as $word) {
  3042.             $initials .= strtoupper(substr($word01));
  3043.         }
  3044.         $initials strtoupper($initials);
  3045.         $shortName substr($initials02);
  3046.         $randomColor $colors[array_rand($colors)];
  3047.         // generate slug url 
  3048.         $slug $this->slugger->slug($data["name"])->lower();
  3049.         $centre->setName(strtoupper($data["name"]));
  3050.         $slugify $this->getDoctrine()
  3051.             ->getRepository(Centre::class)
  3052.             ->findOneBy(array('slug' => $slug));
  3053.         if ($slugify) {
  3054.             $centre->setSlug($slug "-1");
  3055.         } else {
  3056.             $centre->setSlug($slug);
  3057.         }
  3058.         if (isset($data["imgUrl"]))
  3059.             $centre->setImgUrl($data["imgUrl"]);
  3060.         if (isset($data["finessURL"]))
  3061.             $centre->setFinessUrl($data["finessURL"]);
  3062.         $centre->setIsRdvDomicile($data["isRdvDomicile"]);
  3063.         $centre->setIdGerant($gerant);
  3064.         $centre->setAddress($data["address"]);
  3065.         $centre->setPostale($data["postal"]);
  3066.         $centre->setCity(strtoupper($data["city"]));
  3067.         $centre->setFiness($data["finess"]);
  3068.         $centre->setSocialName($data["companyName"]);
  3069.         $centre->setSiret($data["siret"]);
  3070.         $centre->setInitial($shortName);
  3071.         $centre->setWebsite($data["website"]);
  3072.         $centre->setSignupDate(new \DateTime());
  3073.         $centre->setCalendarColor($randomColor);
  3074.         // set the galeries for images by default
  3075.         // Define an array of default image URLs
  3076.         $defaultImages = ["by-default-1.jpeg""by-default-2.jpeg""by-default-3.jpeg"];
  3077.         // Iterate through each default image
  3078.         foreach ($defaultImages as $imageUrl) {
  3079.             $centerImage = new CenterImage();
  3080.             $centerImage->setType("image");
  3081.             $centerImage->setUrl($imageUrl);
  3082.             // Associate the center image with the current center
  3083.             $centerImage->setCenter($centre);
  3084.             $entityManager->persist($centerImage);
  3085.         }
  3086.         /*$centrePhoneTest = $this->getDoctrine()
  3087.             ->getRepository(Centre::class)
  3088.             ->findOneBy(['phone' => $data["phone"]]);
  3089.         if ($centrePhoneTest)
  3090.             return $this->json([
  3091.                 'message' => 'Centre phone',
  3092.                 'path' => 'src/Controller/CentreController.php',
  3093.                 "status" => 401
  3094.             ], 401);*/
  3095.         $centre->setPhone($data["phone"]);
  3096.         $centre->setIsHandicap($data["isHandicap"]);
  3097.         $centre->setLongitude($data["longitude"]);
  3098.         $centre->setLatitude($data["latitude"]);
  3099.         $centre->setHoraire($publicFunction->centreHoraire2);
  3100.         $centerHoliday json_decode($publicFunction->centreHoraire4true);
  3101.         $centre->setHorairesHoliday($centerHoliday);
  3102.         $entityManager $this->getDoctrine()->getManager();
  3103.         $entityManager->persist($centre);
  3104.         // for audio on multi centre creation
  3105.         $accessCentre = new AccessCentre();
  3106.         //  $accessData = $data["access"];
  3107.         $entityManager->flush();
  3108.         // save print setting 
  3109.         $setting = new Setting();
  3110.         $setting->setName($data["name"]);
  3111.         $setting->setAddress($data["address"]);
  3112.         $setting->setPhone($data["phone"]);
  3113.         $setting->setLogoUrl($centre->getImgUrl());
  3114.         $setting->setWebsite($data["website"]);
  3115.         $setting->setFirstname($audio->getName());
  3116.         $setting->setLastname($audio->getLastname());
  3117.         $setting->setEmail($gerant->getMail());
  3118.         $setting->setSeuilCaDroite(true);
  3119.         $setting->setSeuilCaGauche(true);
  3120.         $setting->setSeuilConfortDroite(true);
  3121.         $setting->setSeuilConfortGauche(true);
  3122.         $setting->setSeuilinconfortDroite(true);
  3123.         $setting->setSeuilInConfortGauche(true);
  3124.         $setting->setSeuilCoDroite(true);
  3125.         $setting->setSeuilCoGauche(true);
  3126.         $setting->setSeuilCaMaskingDroite(true);
  3127.         $setting->setSeuilCaMaskingGauche(true);
  3128.         $setting->setSeuilCoMaskingDroite(true);
  3129.         $setting->setSeuilCoMaskingGauche(true);
  3130.         /* $setting->setCasqueDroite(false);
  3131.         $setting->setCasqueGauche(false);
  3132.         $setting->setCasqueBinaural(false);
  3133.         $setting->setChampsLibreDroite(false);
  3134.         $setting->setChampsLibreGauche(false);
  3135.         $setting->setChampsLibreBinaural(false);
  3136.         $setting->setChampsLibreAppDroite(false);
  3137.         $setting->setChampsLibreAppGauche(false);
  3138.         $setting->setChampsLibreAppBinaural(false);*/
  3139.         $setting->setCasqueDroite(true);
  3140.         $setting->setCasqueGauche(true);
  3141.         $setting->setCasqueBinaural(true);
  3142.         $setting->setChampsLibreDroite(true);
  3143.         $setting->setChampsLibreGauche(true);
  3144.         $setting->setChampsLibreBinaural(true);
  3145.         $setting->setChampsLibreAppDroite(true);
  3146.         $setting->setChampsLibreAppGauche(true);
  3147.         $setting->setChampsLibreAppBinaural(true);
  3148.         $setting->setCentre($centre);
  3149.         $entityManager->persist($setting);
  3150.         $entityManager->flush();
  3151.         $tokenString $publicFunction->generateRandomString(30);
  3152.         $params = array(
  3153.             "lien" => "{$_ENV['BASE_client']}confirmation_email/{$data["audio"][0]["mail"]}?token={$tokenString}",
  3154.             "nom" => "",
  3155.             "texte" => "Veuillez cliquer sur le bouton ci-dessous pour confirmer votre adresse mail",
  3156.             "titre" => "Confirmer mon email",
  3157.             "bouton" => "Confirmer mon Email",
  3158.         );
  3159.         $publicFunction->sendEmail($params$data["audio"][0]["mail"], "myaudio""Confirmation d'inscription sur My Audio Pro"122);
  3160.         $token = new Token();
  3161.         $token->setCreationDate(new DateTime());
  3162.         $token->setToken($tokenString);
  3163.         $token->setMail($audio->getMail());
  3164.         $entityManager $this->getDoctrine()->getManager();
  3165.         $entityManager->persist($token);
  3166.         $entityManager->flush();
  3167.         /* $user = [
  3168.             "prenomAudioprothesiste" => $gerant->getName(),
  3169.             "urlDemo" => "https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ0Ry72UDE9m8d2IylSycOMQVerlY0jHt1DLWFD6Pso4hg79sQ9nUAlxtZYOPH6wSubDX4vqVQWh",
  3170.         ];
  3171.         // we send parametre for the trait methid
  3172.         $params = $this->emailNotificationDemoService->prepareEmailParams($user);
  3173.         // send email notifcation
  3174.         $this->emailNotificationDemoService->sendEmail($params, $gerant->getMail(), 'Organisez votre Démo personnalisée de My Audio Pro', 143);
  3175.         */
  3176.         // set order datable patient 
  3177.         $this->orderPatient->createOrderPatient($audio);
  3178.         $plan $this->getDoctrine()->getRepository(Plan::class)
  3179.             ->findOneBy(["slug" => $data['plan']["planName"]]);
  3180.         $dataSubsc = [];
  3181.         $dataSubsc['created'] = $createSubscription['created'];
  3182.         $dataSubsc['currentPeriodStart'] = $createSubscription['current_period_start'];
  3183.         $dataSubsc['currentPeriodEnd'] = $createSubscription['current_period_end'];
  3184.         $dataSubsc['centerId'] = $centre->getId();
  3185.         $dataSubsc['audioId'] = $audio->getId();
  3186.         $dataSubsc['id'] = $createSubscription['id'];
  3187.         $dataSubsc['invoiceId'] = $createSubscription['latest_invoice']['id'];
  3188.         $dataSubsc['customer'] = $createSubscription['customer'];
  3189.         $dataSubsc['payment_method'] = $createSubscription['default_payment_method'];
  3190.         $dataSubsc['amount'] = $data["price"]["finalPrice"] ?? $data["price"];
  3191.         $dataSubsc['quantity'] = $data["quantity"];
  3192.         $dataSubsc['recurring'] = ($data["price"]["recurring"] === "monthly") ? "month" : (($data["price"]["recurring"] === "yearly") ? "year" $data["price"]["recurring"]);
  3193.         $dataSubsc['planId'] = $plan->getId();
  3194.         $dataSubsc['status'] = "succeeded";
  3195.         //$this->logger->info("stripe end date",["endDate" => $currentPeriodEnd->format('Y-m-d H:i:s')]);
  3196.         $subscrition->createSubscription($dataSubsc);
  3197.         //$this->logger->info("databse end date",["endDate" => $sub]);
  3198.         // generate rdvurl
  3199.         $name $centre->getName();
  3200.         $city $centre->getCity();
  3201.         $postal $centre->getPostale();
  3202.         $nameSlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($name)));
  3203.         $citySlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($city)));
  3204.         $baseClient $_ENV['BASE_client'] ?? 'https://default-client-url.com';
  3205.         $urlRdv "{$baseClient}audioprothesiste/{$citySlug}/{$postal}/{$nameSlug}/prise-de-rdvaudioprothesiste-rapide/{$centre->getId()}";
  3206.         if (!$centre->getUrlRdv() || $centre->getUrlRdv() !== $urlRdv) {
  3207.             $centre->setUrlRdv($urlRdv);
  3208.             $entityManager->persist($centre);
  3209.             $entityManager->flush();
  3210.         }
  3211.         // post categorie de contrat cda
  3212.         $quantity $data["quantity"];
  3213.         $contractCategory $entityManager->getRepository(ContractCategory::class)->find(5);
  3214.         $plan $entityManager->getRepository(Plan::class)->find($plan->getId());
  3215.         if ($contractCategory && $plan && $quantity 0) {
  3216.             $specificSubscription = new SpecificSubscription();
  3217.             $specificSubscription->setContractCategory($contractCategory);
  3218.             $specificSubscription->setPlan($plan);
  3219.             $specificSubscription->setQuantity($quantity);
  3220.             $specificSubscription->setCenter($centre);
  3221.             $specificSubscription->setStatus(false);
  3222.             $specificSubscription->setAudio($audio);
  3223.             $entityManager->persist($specificSubscription);
  3224.             $entityManager->flush();
  3225.         }
  3226.         return $this->json([
  3227.             "audioId" => $audio->getId(),
  3228.             "centerId" => $centre->getId(),
  3229.             "name" => $centre->getName(),
  3230.             "imgUrl" => $centre->getImgUrl(),
  3231.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  3232.             "audio_id" => $centre->getIdGerant()->getId(),
  3233.             "address" => $centre->getAddress(),
  3234.             "postale" => $centre->getPostale(),
  3235.             "city" => $centre->getCity(),
  3236.             "finess" => $centre->getFiness(),
  3237.             "siret" => $centre->getSiret(),
  3238.             "website" => $centre->getWebsite(),
  3239.             "phone" => $centre->getPhone(),
  3240.             "isHandicap" => $centre->getIsHandicap(),
  3241.             //"audio" => $resultAudio->toArray(),
  3242.             "centerId" => $centre->getId(),
  3243.             "audioId" => $audio->getId(),
  3244.             "status" => 200,
  3245.         ]);
  3246.     }
  3247.     
  3248. /**
  3249.      * @Route("/centre/new-inscription-atol", name="postCentreNewInscriptionAtol", methods={"POST"})
  3250.      */
  3251.     public function postCentreNewInscriptionAtol(Request $requestPublicFunction $publicFunctionStripeService $stripeServiceSubscriptionService $subscrition): Response
  3252.     {
  3253.         $data json_decode($request->getContent(), true);
  3254.         $requestData = [
  3255.             "name" => $data["audio"][0]["name"],
  3256.             "email" => $data["audio"][0]["mail"],
  3257.             "address" => $data["address"],
  3258.             "quantity" => $data["quantity"],
  3259.             "price" => $data["price"]["finalPrice"] ?? $data["price"],
  3260.             "recurring" => "atol",
  3261.             "paymentMethodId" => $data["paymentMethodId"],
  3262.             "offerName" => $data["plan"]["planName"],
  3263.         ];
  3264.         
  3265.        $createSubscription $stripeService->createSubscriptionStripe($requestData);
  3266.       // dd($createSubscription);
  3267.         $centre = new Centre();
  3268.         $resultAudio = new ArrayCollection();
  3269.         $gerant null;
  3270.         if($data['gerant'] !== "")
  3271.                {
  3272.                 $gerant $this->getDoctrine()
  3273.                 ->getRepository(Audio::class)
  3274.                 ->find($data['gerant']);
  3275.                }
  3276.         if (isset($data["audio"])) {
  3277.             $entityManager $this->getDoctrine()->getManager();
  3278.             foreach ($data["audio"] as $key=>$audioMap) {
  3279.                // check if audio exist to collect on new center 
  3280.                if($audioMap['registredAudio'] !== "")
  3281.                {
  3282.                    $audio $this->getDoctrine()
  3283.                    ->getRepository(Audio::class)
  3284.                    ->find($audioMap['registredAudio']);
  3285.                    $audioCentre = new AudioCentre();
  3286.                    $audioCentre->setIdAudio($audio);
  3287.                    $audioCentre->setIdCentre($centre);
  3288.                    $audioCentre->setIsConfirmed(true);
  3289.                    $audioCentre->setHoraire($publicFunction->centreHoraire2);
  3290.                    $entityManager->persist($audioCentre);
  3291.                }
  3292.                
  3293.                else {
  3294.                $role $this->getDoctrine()
  3295.                ->getRepository(Role::class)
  3296.                ->find($audioMap["role"]);
  3297.                $audio = new Audio();
  3298.                
  3299.                $audio->setBirthdate(\DateTime::createFromFormat("d/m/Y"$audioMap["birthdate"]));
  3300.                $audio->setRole($role);
  3301.                $audio->setSignupDate(new \DateTime());
  3302.                $audio->setAdeli($data["audio"]["0"]["adeli"]);
  3303.                $audio->setCivilite($data["audio"]["0"]["civilite"]);
  3304.                $audio->setLastName($data["audio"]["0"]["lastname"]);
  3305.                $audio->setName($data["audio"]["0"]["name"]);
  3306.                // set notification by default selected
  3307.                $audio->setConfirmRdvMail(true);
  3308.                $audio->setConfirmRdvSms(true);
  3309.                $audio->setModifRdvMail(true);
  3310.                $audio->setModifRdvSms(true);
  3311.                $audio->setModifNote(true);
  3312.                $audioMailTest $this->getDoctrine()
  3313.                    ->getRepository(Audio::class)
  3314.                    ->findOneBy(['mail' => $audioMap["mail"]]);
  3315.                 /*if ($audioMailTest)
  3316.                 return $this->json([
  3317.                     'message' => "L'adresse e-mail est déjà enregistrée.",
  3318.                     'mail' => $audioMap["mail"],
  3319.                     'code' => "mail_exist",
  3320.                     'status' => 409 
  3321.                 ], 500); */
  3322.                 
  3323.                 $audio->setMail($audioMap["mail"]);
  3324.                 $audioPhoneTest $this->getDoctrine()
  3325.                     ->getRepository(Audio::class)
  3326.                     ->findOneBy(['phone' => $audioMap["phone"]]);
  3327.                 /*if ($audioPhoneTest)
  3328.                 return $this->json([
  3329.                     'message' => 'Le numéro de téléphone est déjà enregistré.',
  3330.                     'phone' => $audioMap["phone"],
  3331.                     'code' => "phone_exist",
  3332.                     'status' => 409 
  3333.                 ], 500); */
  3334.                 
  3335.                 $audio->setPhone($audioMap["phone"]);
  3336.                 //$audio->setAdeli($audioMap["adeli"]);
  3337.                 if($data["isImported"] !== '')
  3338.                 $audio->setCodeParrainage($data["isImported"]);
  3339.                 $audio->setIsIndie(false);
  3340.                 // set default pass for audio inserted
  3341.                 $audioMap["password"] !== "" $audio->setPassword(password_hash($audioMap["password"], PASSWORD_DEFAULT)) : $audio->setPassword(password_hash("myaudio2023"PASSWORD_DEFAULT));
  3342.                 $audio->setPin($audioMap["pin"]);
  3343.                // $audio->setDescription($audioMap["description"]);
  3344.                 if (isset($audioMap["imgUrl"]))
  3345.                     $audio->setImgUrl($audioMap["imgUrl"]);
  3346.                 $entityManager $this->getDoctrine()->getManager();
  3347.                 foreach ($audioMap["diplome"] as $diplomeObject) {
  3348.                     $diplome $this->getDoctrine()
  3349.                         ->getRepository(Diplome::class)
  3350.                         ->findOneBy(['id' => $diplomeObject["id"]]);
  3351.                     if ($diplome == null) {
  3352.                         /*$audioDiplome = new AudioDiplome();
  3353.                         if(isset($diplomeObject["year"]))
  3354.                         {
  3355.                             if(!empty($diplomeObject["year"]))
  3356.                             {
  3357.                                 $audioDiplome->setYear($diplomeObject["year"]);
  3358.                             }
  3359.                         }
  3360.                         $audioDiplome->setUrl($diplomeObject["url"]);
  3361.                         $audioDiplome->setOther($data['otherdDiplom'][$key]);
  3362.                         $audioDiplome->setIdAudio($audio);
  3363.                         $entityManager->persist($audioDiplome);*/
  3364.                         return $this->json([
  3365.                             'message' => 'Error, no diplome found at this id ' $diplomeObject["id"],
  3366.                             'path' => 'src/Controller/AudioController.php',
  3367.                             "status" => 401
  3368.                         ], 401);
  3369.                     } else {
  3370.                         $audioDiplome = new AudioDiplome();
  3371.                         if(isset($diplomeObject["year"]))
  3372.                         {
  3373.                             if(!empty($diplomeObject["year"]))
  3374.                             {
  3375.                                 $audioDiplome->setYear($diplomeObject["year"]);
  3376.                             }
  3377.                         }
  3378.                         $audioDiplome->setUrl($diplomeObject["url"]);
  3379.                         $audioDiplome->setIdDiplome($diplome);
  3380.                         $audioDiplome->setIdAudio($audio);
  3381.                         $entityManager->persist($audioDiplome);
  3382.                     }
  3383.                 }
  3384.                
  3385.                 
  3386.       
  3387.                // $entityManager->persist($audio);
  3388.                $entityManager->persist($this->createPermanantMotif(60"#FF00FF"$audio,  11));
  3389.                 $entityManager->persist($this->createPermanantMotif(90"#00FFFF"$audio,  21));
  3390.                 $entityManager->persist($this->createPermanantMotif(30"#FFFF00"$audio,  31));
  3391.                 $entityManager->persist($this->createPermanantMotif(60"#FF0000"$audio,  41));
  3392.                 $entityManager->persist($this->createPermanantMotif(60"#FFCC59"$audio692));
  3393.                 $entityManager->persist($this->createPermanantMotif(30"#33B679"$audio1061));
  3394.                 $entityManager->persist($this->createPermanantMotif(30"#F6BF25"$audio1071));
  3395.                 $entityManager->persist($this->createPermanantMotif(30"#E67C73"$audio1081));
  3396.                 $entityManager->persist($this->createPermanantMotif(30"#7886CB"$audio1091));
  3397.               //  $entityManager->persist($this->createPermanantMotif(60, "#FF0000", $audio,  5));
  3398.                 $entityManager->persist($audio);
  3399.                 if ($gerant == null$gerant $audio;
  3400.                 $audioCentre = new AudioCentre();
  3401.                 $audioCentre->setIdAudio($audio);
  3402.                 $audioCentre->setIdCentre($centre);
  3403.                 $audioCentre->setIsConfirmed(true);
  3404.                 $audioCentre->setHoraire($publicFunction->centreHoraire2);
  3405.                 $centerHoliday json_decode($publicFunction->centreHoraire4true);
  3406.                 $audioCentre->setHorairesHoliday($centerHoliday);
  3407.                 $entityManager->persist($audioCentre);
  3408.                 // SEN MAIL NOTIF JUST FOR AUDIOS ADDED NOT FOR GERANT
  3409.                
  3410.                 
  3411.        // $entityManager->flush();
  3412.                
  3413.             }
  3414.                 $resultAudio->add([
  3415.                     "id" => $audio->getId(),
  3416.                     "civilite" => $audio->getCivilite(),
  3417.                     "name" => $audio->getName(),
  3418.                     "lastname" => $audio->getLastname(),
  3419.                     "birthdate" => $audio->getBirthdate(),
  3420.                     "mail" => $audio->getMail(),
  3421.                     "phone" => $audio->getPhone(),
  3422.                     "adeli" => $audio->getAdeli(),
  3423.                     "pin" => $audio->getPin(),
  3424.                     "description" => $audio->getDescription(),
  3425.                     "imgUrl" => $audio->getImgUrl(),
  3426.                 ]);
  3427.             }
  3428.         } else {
  3429.             return new Response(json_encode([
  3430.                 'message' => 'Error, no audio found',
  3431.                 'path' => 'src/Controller/CentreController.php',
  3432.             ]), 404);
  3433.         }
  3434.         // generate color code 
  3435.         $colors = array(
  3436.             "#FFC0CB"// Pink
  3437.             "#FFD700"// Gold
  3438.             "#90EE90"// Light Green
  3439.             "#87CEFA"// Light Sky Blue
  3440.             "#FFA07A"// Light Salmon
  3441.             "#F0E68C"// Khaki
  3442.             "#B0C4DE"// Light Steel Blue
  3443.             "#98FB98"// Pale Green
  3444.             "#FFB6C1"// Light Pink
  3445.             "#ADD8E6"// Light Blue
  3446.             "#FF69B4"// Hot Pink
  3447.             "#FFA500"// Orange
  3448.             "#00FF7F"// Spring Green
  3449.             "#AFEEEE"// Pale Turquoise
  3450.             "#FF8C00"// Dark Orange
  3451.             "#FFE4B5"// Moccasin
  3452.             "#00CED1"// Dark Turquoise
  3453.             "#7FFFD4"// Aquamarine
  3454.             "#FF4500"// Orange Red
  3455.             "#00FA9A"// Medium Spring Green
  3456.             "#FFF0F5"// Lavender Blush
  3457.             "#00BFFF"// Deep Sky Blue
  3458.             "#FF6347"// Tomato
  3459.             "#20B2AA"// Light Sea Green
  3460.             "#FFFF00"// Yellow
  3461.             "#32CD32"// Lime Green
  3462.             "#FFF5EE"// Seashell
  3463.             "#1E90FF"// Dodger Blue
  3464.             "#CD5C5C"// Indian Red
  3465.             "#8FBC8F"// Dark Sea Green
  3466.             "#F0FFFF"// Azure
  3467.             "#4169E1"// Royal Blue
  3468.             "#FF8B00"// Dark Orange
  3469.             "#66CDAA"// Medium Aquamarine
  3470.             "#FFFACD"// Lemon Chiffon
  3471.             "#6495ED"// Cornflower Blue
  3472.             "#FF7F50"// Coral
  3473.             "#00FF00"// Lime
  3474.             "#FAFAD2"// Light Goldenrod Yellow
  3475.             "#87CEEB"// Sky Blue
  3476.             "#DC143C"// Crimson
  3477.             "#2E8B57"// Sea Green
  3478.             "#F5DEB3"// Wheat
  3479.             "#4682B4"// Steel Blue
  3480.             "#CD853F"// Peru
  3481.             "#8A2BE2"// Blue Violet
  3482.             "#D2691E"// Chocolate
  3483.             "#6A5ACD"// Slate Blue
  3484.             "#F5F5DC"// Beige
  3485.             "#7B68EE"// Medium Slate Blue
  3486.         );
  3487.         // short initial 
  3488.         $name $data['name'];
  3489. $words explode(' '$name);
  3490. $initials '';
  3491. foreach ($words as $word) {
  3492.     $initials .= strtoupper(substr($word01));
  3493. }
  3494. $initials strtoupper($initials);
  3495. $shortName substr($initials02);
  3496.         $randomColor $colors[array_rand($colors)];
  3497.         // generate slug url 
  3498.         $slug $this->slugger->slug($data["name"])->lower();
  3499.         $centre->setName(strtoupper($data["name"]));
  3500.         $slugify $this->getDoctrine() 
  3501.         ->getRepository(Centre::class)
  3502.         ->findOneBy(array('slug' => $slug));
  3503.         
  3504.         if($slugify)
  3505.         {
  3506.             $centre->setSlug($slug."-1");
  3507.         }
  3508.         else 
  3509.         {
  3510.             $centre->setSlug($slug);
  3511.         }
  3512.         if (isset($data["imgUrl"]))
  3513.             $centre->setImgUrl($data["imgUrl"]);
  3514.         if (isset($data["finessURL"]))
  3515.         $centre->setFinessUrl($data["finessURL"]);
  3516.         $centre->setIsRdvDomicile($data["isRdvDomicile"]);
  3517.         $centre->setIdGerant($gerant);
  3518.         $centre->setAddress($data["address"]);
  3519.         $centre->setPostale($data["postal"]);
  3520.         $centre->setCity(strtoupper($data["city"]));
  3521.         $centre->setFiness($data["finess"]);
  3522.         $centre->setSocialName($data["companyName"]);
  3523.         $centre->setSiret($data["siret"]);
  3524.         $centre->setInitial($shortName);
  3525.         $centre->setWebsite($data["website"]);
  3526.         $centre->setSignupDate(new \DateTime());
  3527.         $centre->setCalendarColor($randomColor);
  3528.         
  3529.         // set the galeries for images by default
  3530.         // Define an array of default image URLs
  3531.         $defaultImages = ["by-default-1.jpeg""by-default-2.jpeg""by-default-3.jpeg"];
  3532.         // Iterate through each default image
  3533.        foreach ($defaultImages as $imageUrl) {
  3534.         $centerImage = new CenterImage();
  3535.         $centerImage->setType("image");
  3536.         $centerImage->setUrl($imageUrl);
  3537.         // Associate the center image with the current center
  3538.         $centerImage->setCenter($centre);
  3539.         $entityManager->persist($centerImage);
  3540.          }
  3541.         /*$centrePhoneTest = $this->getDoctrine()
  3542.             ->getRepository(Centre::class)
  3543.             ->findOneBy(['phone' => $data["phone"]]);
  3544.         if ($centrePhoneTest)
  3545.             return $this->json([
  3546.                 'message' => 'Centre phone',
  3547.                 'path' => 'src/Controller/CentreController.php',
  3548.                 "status" => 401
  3549.             ], 401);*/
  3550.         $centre->setPhone($data["phone"]);
  3551.         $centre->setIsHandicap($data["isHandicap"]);
  3552.         $centre->setLongitude($data["longitude"]);
  3553.         $centre->setLatitude($data["latitude"]);
  3554.         $centre->setHoraire($publicFunction->centreHoraire2);
  3555.         $centerHoliday json_decode($publicFunction->centreHoraire4true);
  3556.         $centre->setHorairesHoliday($centerHoliday);
  3557.         $entityManager $this->getDoctrine()->getManager();
  3558.         
  3559.             
  3560.         $entityManager->persist($centre);
  3561.         // for audio on multi centre creation
  3562.         $accessCentre = new AccessCentre();
  3563.         
  3564.         //  $accessData = $data["access"];
  3565.   
  3566.         $entityManager->flush();
  3567.         // save print setting 
  3568.  
  3569.         $setting = new Setting();
  3570.         $setting->setName($data["name"]);
  3571.         $setting->setAddress($data["address"]);
  3572.         $setting->setPhone($data["phone"]);
  3573.         $setting->setLogoUrl($centre->getImgUrl());
  3574.         $setting->setWebsite($data["website"]);
  3575.         $setting->setFirstname($audio->getName());
  3576.         $setting->setLastname($audio->getLastname());
  3577.         $setting->setEmail($gerant->getMail());
  3578.         $setting->setSeuilCaDroite(true);
  3579.         $setting->setSeuilCaGauche(true);
  3580.         $setting->setSeuilConfortDroite(true);
  3581.         $setting->setSeuilConfortGauche(true);
  3582.         $setting->setSeuilinconfortDroite(true);
  3583.         $setting->setSeuilInConfortGauche(true);
  3584.         $setting->setSeuilCoDroite(true);
  3585.         $setting->setSeuilCoGauche(true);
  3586.         $setting->setSeuilCaMaskingDroite(true);
  3587.         $setting->setSeuilCaMaskingGauche(true);
  3588.         $setting->setSeuilCoMaskingDroite(true);
  3589.         $setting->setSeuilCoMaskingGauche(true);
  3590.        /* $setting->setCasqueDroite(false);
  3591.         $setting->setCasqueGauche(false);
  3592.         $setting->setCasqueBinaural(false);
  3593.         $setting->setChampsLibreDroite(false);
  3594.         $setting->setChampsLibreGauche(false);
  3595.         $setting->setChampsLibreBinaural(false);
  3596.         $setting->setChampsLibreAppDroite(false);
  3597.         $setting->setChampsLibreAppGauche(false);
  3598.         $setting->setChampsLibreAppBinaural(false);*/
  3599.         $setting->setCasqueDroite(true);
  3600.         $setting->setCasqueGauche(true);
  3601.         $setting->setCasqueBinaural(true);
  3602.         $setting->setChampsLibreDroite(true);
  3603.         $setting->setChampsLibreGauche(true);
  3604.         $setting->setChampsLibreBinaural(true);
  3605.         $setting->setChampsLibreAppDroite(true);
  3606.         $setting->setChampsLibreAppGauche(true);
  3607.         $setting->setChampsLibreAppBinaural(true);
  3608.         $setting->setCentre($centre);
  3609.         $entityManager->persist($setting);
  3610.         $entityManager->flush();
  3611.  $tokenString $publicFunction->generateRandomString(30);
  3612.         $params = array(  
  3613.             "lien" =>"{$_ENV['BASE_client']}confirmation_email/{$data["audio"][0]["mail"]}?token={$tokenString}",
  3614.             "nom" =>"",
  3615.             "texte" =>"Veuillez cliquer sur le bouton ci-dessous pour confirmer votre adresse mail",
  3616.             "titre"=> "Confirmer mon email",
  3617.             "bouton"=> "Confirmer mon Email",
  3618.         );
  3619.         $publicFunction->sendEmail($params$data["audio"][0]["mail"],"myaudio""Confirmation d'inscription sur My Audio Pro"122 );
  3620.         $token = new Token();
  3621.         $token->setCreationDate(new DateTime());
  3622.         $token->setToken($tokenString);
  3623.         $token->setMail($audio->getMail());
  3624.         $entityManager $this->getDoctrine()->getManager();
  3625.         $entityManager->persist($token);
  3626.         
  3627.         $entityManager->flush();     
  3628.        /* $user = [
  3629.             "prenomAudioprothesiste" => $gerant->getName(),
  3630.             "urlDemo" => "https://calendar.google.com/calendar/u/0/appointments/schedules/AcZssZ0Ry72UDE9m8d2IylSycOMQVerlY0jHt1DLWFD6Pso4hg79sQ9nUAlxtZYOPH6wSubDX4vqVQWh",
  3631.         ];
  3632.         // we send parametre for the trait methid
  3633.         $params = $this->emailNotificationDemoService->prepareEmailParams($user);
  3634.         // send email notifcation
  3635.         $this->emailNotificationDemoService->sendEmail($params, $gerant->getMail(), 'Organisez votre Démo personnalisée de My Audio Pro', 143);
  3636.         */
  3637.         // set order datable patient 
  3638.         $this->orderPatient->createOrderPatient($audio);
  3639.         $plan $this->getDoctrine()->getRepository(Plan::class)
  3640.         ->findOneBy(["slug" => $data['plan']["planName"]] );
  3641.         $dataSubsc = [];
  3642.         $dataSubsc['created'] = $createSubscription['created'];
  3643.         $dataSubsc['currentPeriodStart'] = $createSubscription['current_period_start'];
  3644.         $dataSubsc['currentPeriodEnd'] = $createSubscription['current_period_end'];
  3645.         $dataSubsc['centerId'] = $centre->getId();
  3646.         $dataSubsc['audioId'] = $audio->getId();
  3647.         $dataSubsc['id'] = $createSubscription['id'];
  3648.         $dataSubsc['invoiceId'] = $createSubscription['latest_invoice']['id'];
  3649.         $dataSubsc['customer'] = $createSubscription['customer'];
  3650.         $dataSubsc['payment_method'] = $createSubscription['default_payment_method'];
  3651.         $dataSubsc['amount'] = $data["price"]["finalPrice"] ?? $data["price"];
  3652.         $dataSubsc['quantity'] = $data["quantity"];
  3653.         $dataSubsc['recurring'] = ($data["price"]["recurring"] === "monthly") ? "month" 
  3654.         (($data["price"]["recurring"] === "yearly") ? "year" $data["price"]["recurring"]);
  3655.         $dataSubsc['planId'] = $plan->getId();
  3656.         $dataSubsc['status'] = "succeeded";
  3657.                        
  3658.       
  3659.         //$this->logger->info("stripe end date",["endDate" => $currentPeriodEnd->format('Y-m-d H:i:s')]);
  3660.         $subscrition->createSubscription($dataSubsc);
  3661.         //$this->logger->info("databse end date",["endDate" => $sub]);
  3662.         // generate rdvurl
  3663.         $name $centre->getName();
  3664.         $city $centre->getCity();
  3665.         $postal $centre->getPostale();
  3666.         $nameSlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($name)));
  3667.         $citySlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($city)));
  3668.         $baseClient $_ENV['BASE_client'] ?? 'https://default-client-url.com';
  3669.         $urlRdv "{$baseClient}audioprothesiste/{$citySlug}/{$postal}/{$nameSlug}/prise-de-rdvaudioprothesiste-rapide/{$centre->getId()}";
  3670.         if (!$centre->getUrlRdv() || $centre->getUrlRdv() !== $urlRdv) {
  3671.             $centre->setUrlRdv($urlRdv);
  3672.             $entityManager->persist($centre);
  3673.             $entityManager->flush();
  3674.         }
  3675.          // post categorie de contrat cda
  3676.          $quantity $data["quantity"];
  3677.          $contractCategory $entityManager->getRepository(ContractCategory::class)->find(7);
  3678.          $plan $entityManager->getRepository(Plan::class)->find($plan->getId());
  3679.          if ($contractCategory && $plan && $quantity 0) {
  3680.              $specificSubscription = new SpecificSubscription();
  3681.              $specificSubscription->setContractCategory($contractCategory);
  3682.              $specificSubscription->setPlan($plan);
  3683.              $specificSubscription->setQuantity($quantity);
  3684.              $specificSubscription->setCenter($centre);
  3685.              $specificSubscription->setStatus(false);
  3686.              $specificSubscription->setAudio($audio);
  3687.              $entityManager->persist($specificSubscription);
  3688.              $entityManager->flush();     
  3689.          }
  3690.          
  3691.         return $this->json([
  3692.             "audioId" => $audio->getId(),
  3693.             "centerId" => $centre->getId(),
  3694.             "name" => $centre->getName(),
  3695.             "imgUrl" => $centre->getImgUrl(),
  3696.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  3697.             "audio_id" => $centre->getIdGerant()->getId(),
  3698.             "address" => $centre->getAddress(),
  3699.             "postale" => $centre->getPostale(),
  3700.             "city" => $centre->getCity(),
  3701.             "finess" => $centre->getFiness(),
  3702.             "siret" => $centre->getSiret(),
  3703.             "website" => $centre->getWebsite(),
  3704.             "phone" => $centre->getPhone(),
  3705.             "isHandicap" => $centre->getIsHandicap(),
  3706.             //"audio" => $resultAudio->toArray(),
  3707.             "centerId" => $centre->getId(),
  3708.             "audioId" => $audio->getId(),
  3709.             "status" => 200,
  3710.         ]);
  3711.     }
  3712.   /**
  3713.      * @Route("/relance/valide/mail/token", name="relancerValidationMail", methods={"POST"})
  3714.      */
  3715.     public function relancerValidationMail(Request $requestPublicFunction $publicFunction)
  3716.     {
  3717.         $entityManager $this->getDoctrine()->getManager();
  3718.         $data json_decode($request->getContent(), true);
  3719.         $tokenString $publicFunction->generateRandomString(30);
  3720.         $params = array(
  3721.             "lien" => "{$_ENV['BASE_client']}confirmation_email/{$data['mail']}?token={$tokenString}",
  3722.             "nom" => "",
  3723.             "texte" => "Veuillez cliquer sur le bouton ci-dessous pour confirmer votre adresse mail",
  3724.             "titre" => "Confirmer mon email",
  3725.             "bouton" => "Confirmer mon Email",
  3726.         );
  3727.         $publicFunction->sendEmail($params$data['mail'], $data['mail'], "Confirmation d'inscription sur My Audio Pro"122);
  3728.         $token = new Token();
  3729.         $token->setCreationDate(new DateTime());
  3730.         $token->setToken($tokenString);
  3731.         $token->setMail($data['mail']);
  3732.         $entityManager $this->getDoctrine()->getManager();
  3733.         $entityManager->persist($token);
  3734.         $entityManager->flush();
  3735.         return new Response(json_encode([
  3736.             "message" => "Un mail viens de vous etre envoyé",
  3737.             "status" => 200,
  3738.         ]));
  3739.     }
  3740.     /**
  3741.      * @Route("/valider/mail/token", name="validerMailGerant", methods={"POST"})
  3742.      */
  3743.     public function validerMailGerant(Request $request)
  3744.     {
  3745.         // get all data including the client that matches the mail stored in the token
  3746.         $entityManager $this->getDoctrine()->getManager();
  3747.         $data json_decode($request->getContent(), true);
  3748.         if (isset($data["token"])) {
  3749.             $token $this->getDoctrine()
  3750.                 ->getRepository(Token::class)
  3751.                 ->findOneBy(['token' => $data["token"]]);
  3752.             if (!$token) {
  3753.                 return new Response(json_encode([
  3754.                     'message' => 'Erreur',
  3755.                     'path' => 'src/Controller/CentreController.php',
  3756.                 ]), 200);
  3757.             }
  3758.         } else {
  3759.             return new Response(json_encode([
  3760.                 "message" => "Erreur",
  3761.                 "status" => 401,
  3762.             ]), 200);
  3763.         }
  3764.         $audio $this->getDoctrine()
  3765.             ->getRepository(Audio::class)
  3766.             ->findOneBy(['mail' => $token->getMail()]);
  3767.         if (!$audio) {
  3768.             return new Response(json_encode([
  3769.                 'message' => 'Erreur',
  3770.                 'path' => 'src/Controller/CentreController.php',
  3771.             ]), 200);
  3772.         }
  3773.         $start_date $token->getCreationDate();
  3774.         $since_start $start_date->diff(new DateTime());
  3775.         if ($since_start->10) {
  3776.             //success
  3777.             $audio->setMailValid(1);
  3778.             $audio->getAudioCentre()[0]->getIdCentre()->setIsValid(1);
  3779.             $entityManager->remove($token);
  3780.             $entityManager->flush();
  3781.             //TODO envoyer un mail avec lien pro
  3782.             return new Response(json_encode([
  3783.                 "message" => "ok",
  3784.                 "status" => 200,
  3785.             ]));
  3786.             // if it's more than 01 minutes
  3787.         } else {
  3788.             $entityManager->remove($token);
  3789.             $entityManager->flush();
  3790.             return new Response(json_encode([
  3791.                 "message" => "nok",
  3792.                 "status" => 401,
  3793.             ]), 200);
  3794.         }
  3795.     }
  3796.     /**
  3797.      * @Route("/centre/image", name="postCentreImage", methods={"POST"})
  3798.      */
  3799.     public function postCentreImage(Request $requestFileUploader $fileUploader): Response
  3800.     {
  3801.         $image $request->files->get('image');
  3802.         $fileUploader->upload($image"images/setting/");
  3803.         return new Response(json_encode([
  3804.             "imgUrl" => $fileUploader->upload($image"images/centre/"),
  3805.             "status" => 200,
  3806.         ]));
  3807.     }
  3808.     /**
  3809.      * @Route("/centre/image/fData-newinscription", name="postCentreImageByFormDataNewInscription", methods={"POST"})
  3810.      */
  3811.     public function postCentreImageByFormDataNewInscription(Request $requestFileUploader $fileUploader): Response
  3812.     {
  3813.         $newfilename "";
  3814.         $audioFile "";
  3815.         $diplomeFile "";
  3816.         $finessfilename "";
  3817.         $audioId $request->request->get('audioId');
  3818.         $centreId $request->request->get('centreId');
  3819.         $facadeFile $request->files->get('image_facade');
  3820.         $fitnessFile $request->files->get('image_interieur');
  3821.         $profilFile $request->files->get('image_profil');
  3822.         $diplomeFile $request->files->get('image_diplome');
  3823.         $audio =  $this->getDoctrine()
  3824.             ->getRepository(Audio::class)
  3825.             ->find($audioId);
  3826.         $center =  $this->getDoctrine()
  3827.             ->getRepository(Centre::class)
  3828.             ->find($centreId);
  3829.         $entityManager $this->getDoctrine()->getManager();
  3830.         // add image galerie
  3831.         // delete the default image united 
  3832.         if ($facadeFile || $fitnessFile || $diplomeFile) {
  3833.             $oldImages $this->getDoctrine()
  3834.                 ->getRepository(CenterImage::class)
  3835.                 ->findBy(["center" => $center]);
  3836.             if ($oldImages) {
  3837.                 foreach ($oldImages as $image) {
  3838.                     $entityManager->remove($image);
  3839.                 }
  3840.                 $entityManager->flush();
  3841.             }
  3842.         }
  3843.         // Post image centre
  3844.         $facadeFile $request->files->get('image_facade');
  3845.         if ($facadeFile) {
  3846.             $fileArray = [
  3847.                 'name' => $facadeFile->getClientOriginalName(),
  3848.                 'type' => $facadeFile->getMimeType(),
  3849.                 'tmp_name' => $facadeFile->getPathname(),
  3850.                 'error' => $facadeFile->getError(),
  3851.                 'size' => $facadeFile->getSize(),
  3852.             ];
  3853.             $newfilename $fileUploader->uploadFormData($fileArray"images/centre/""images/centres/");
  3854.             $center->setImgUrl($newfilename);
  3855.             $entityManager->persist($center);
  3856.             $image = new CenterImage();
  3857.             $image->setCenter($center);
  3858.             $image->setType('image');
  3859.             if ($newfilename) {
  3860.                 $image->setUrl($newfilename);
  3861.                 $entityManager->persist($image);
  3862.             }
  3863.             $entityManager->flush();
  3864.             $publicImagePath $this->getParameter('kernel.project_dir') . '/public/assets/images/centre/' $newfilename;
  3865.             $assetsImagePath $this->getParameter('kernel.project_dir') . '/assets/images/centre/' $newfilename;
  3866.             if (file_exists($assetsImagePath)) {
  3867.                 copy($assetsImagePath$publicImagePath);
  3868.             }
  3869.             $publicImagePathCtrs $this->getParameter('kernel.project_dir') . '/public/assets/images/centres/' $newfilename;
  3870.             $assetsImagePathCtrs $this->getParameter('kernel.project_dir') . '/assets/images/centres/' $newfilename;
  3871.             if (file_exists($assetsImagePathCtrs)) {
  3872.                 copy($assetsImagePathCtrs$publicImagePathCtrs);
  3873.             }
  3874.         }
  3875.         // Post FINESS centre
  3876.         $fitnessFile $request->files->get('image_interieur');
  3877.         if ($fitnessFile) {
  3878.             $fileArray = [
  3879.                 'name' => $fitnessFile->getClientOriginalName(),
  3880.                 'type' => $fitnessFile->getMimeType(),
  3881.                 'tmp_name' => $fitnessFile->getPathname(),
  3882.                 'error' => $fitnessFile->getError(),
  3883.                 'size' => $fitnessFile->getSize(),
  3884.             ];
  3885.             $finessfilename $fileUploader->uploadFormData($fileArray"images/centres/");
  3886.             $image = new CenterImage();
  3887.             $image->setCenter($center);
  3888.             $image->setType('image');
  3889.             if ($finessfilename) {
  3890.                 $image->setUrl($finessfilename);
  3891.                 $entityManager->persist($image);
  3892.             }
  3893.             $entityManager->flush();
  3894.             $publicImagePath $this->getParameter('kernel.project_dir') . '/public/assets/images/centres/' $finessfilename;
  3895.             $assetsImagePath $this->getParameter('kernel.project_dir') . '/assets/images/centres/' $finessfilename;
  3896.             if (file_exists($assetsImagePath)) {
  3897.                 copy($assetsImagePath$publicImagePath);
  3898.             }
  3899.         }
  3900.         // Post audio profile
  3901.         $profilFile $request->files->get('image_profil');
  3902.         if ($profilFile) {
  3903.             $fileArray = [
  3904.                 'name' => $profilFile->getClientOriginalName(),
  3905.                 'type' => $profilFile->getMimeType(),
  3906.                 'tmp_name' => $profilFile->getPathname(),
  3907.                 'error' => $profilFile->getError(),
  3908.                 'size' => $profilFile->getSize(),
  3909.             ];
  3910.             $audioFilename $fileUploader->uploadFormData($fileArray"images/audio/");
  3911.             $audio->setImgUrl($audioFilename);
  3912.             $entityManager->persist($audio);
  3913.             $publicImagePath $this->getParameter('kernel.project_dir') . '/public/assets/images/audio/' $audioFilename;
  3914.             $assetsImagePath $this->getParameter('kernel.project_dir') . '/assets/images/audio/' $audioFilename;
  3915.             if (file_exists($assetsImagePath)) {
  3916.                 copy($assetsImagePath$publicImagePath);
  3917.             }
  3918.         }
  3919.         // Post audio diplome
  3920.         $diplomeFile $request->files->get('image_diplome');
  3921.         if ($diplomeFile) {
  3922.             $fileArray = [
  3923.                 'name' => $diplomeFile->getClientOriginalName(),
  3924.                 'type' => $diplomeFile->getMimeType(),
  3925.                 'tmp_name' => $diplomeFile->getPathname(),
  3926.                 'error' => $diplomeFile->getError(),
  3927.                 'size' => $diplomeFile->getSize(),
  3928.             ];
  3929.             $d $fileUploader->uploadFormData($fileArray"document/audio/""images/centres/");
  3930.             $audioDiplome = new AudioDiplome();
  3931.             $image = new CenterImage();
  3932.             $image->setCenter($center);
  3933.             $image->setType('image');
  3934.             $newfilename $d;
  3935.             if ($newfilename) {
  3936.                 $image->setUrl($newfilename);
  3937.                 $entityManager->persist($image);
  3938.             }
  3939.             $entityManager->flush();
  3940.         }
  3941.         $entityManager->flush();
  3942.         return new Response(json_encode([
  3943.             "message" => "updated succesfully"
  3944.         ]));
  3945.     }
  3946.     /**
  3947.      * @Route("/centre/image/fData", name="postCentreImageByFormDataInscription", methods={"POST"})
  3948.      */
  3949.     public function postCentreImageByFormDataInscription(Request $requestFileUploader $fileUploader): Response
  3950.     {
  3951.         $newfilename "";
  3952.         $audioFile "";
  3953.         $diplomeFile "";
  3954.         $finessfilename "";
  3955.         $entityManager $this->getDoctrine()->getManager();
  3956.         //post image centre
  3957.         if (isset($_FILES["picCentre"]) && $_FILES["picCentre"]["size"] != 0) {
  3958.             $newfilename $fileUploader->uploadFormData($_FILES["picCentre"], "images/setting/""images/centre/");
  3959.             $publicImagePath $this->getParameter('kernel.project_dir') . '/public/assets/images/centre/' $newfilename;
  3960.             $assetsImagePath $this->getParameter('kernel.project_dir') . '/assets/images/centre/' $newfilename;
  3961.             if (file_exists($assetsImagePath)) {
  3962.                 copy($assetsImagePath$publicImagePath);
  3963.             }
  3964.         } else {
  3965.             $publicImagePath $this->getParameter('kernel.project_dir') . '/public/assets/images/centre/imgOreille.png';
  3966.             $assetsImagePath $this->getParameter('kernel.project_dir') . '/assets/images/centre/imgOreille.png';
  3967.             if (file_exists($assetsImagePath)) {
  3968.                 copy($assetsImagePath$publicImagePath);
  3969.             }
  3970.             $newfilename 'imgOreille.png';
  3971.         }
  3972.         //post FINESS centre
  3973.         if (isset($_FILES["fileFiness"]) && $_FILES["fileFiness"]["size"] != 0) {
  3974.             $finessfilename $fileUploader->uploadFormData($_FILES["fileFiness"], "document/centre/finess");
  3975.         }
  3976.         $audioFile = array();
  3977.         $diplomeFile = array();
  3978.         //post image audio
  3979.         if (isset($_POST['nombreAudio'])) {
  3980.             for ($i 1$i <= $_POST['nombreAudio']; $i++) {
  3981.                 if (isset($_FILES["picAudio" $i]) && $_FILES["picAudio" $i]["size"] != 0) {
  3982.                     $audioFilename $fileUploader->uploadFormData($_FILES["picAudio" $i], "images/audio/");
  3983.                     array_push($audioFile$audioFilename);
  3984.                 }
  3985.                 // post audio diplome
  3986.                 $dip = array();
  3987.                 for ($j 1$j <= 5$j++) {
  3988.                     if (isset($_FILES["fileDilpomeA" $i $j]) && $_FILES["fileDilpomeA" $i $j]["size"] != 0) {
  3989.                         $d $fileUploader->uploadFormData($_FILES["fileDilpomeA" $i $j], "document/audio/");
  3990.                         array_push($dip$d);
  3991.                     }
  3992.                 }
  3993.                 array_push($diplomeFile$dip);
  3994.             }
  3995.         }
  3996.         $entityManager->flush();
  3997.         return new Response(json_encode([
  3998.             "fileName" => $newfilename,
  3999.             "audioFile" => $audioFile,
  4000.             "diplomeFile" => $diplomeFile,
  4001.             "finessfilename" => $finessfilename
  4002.         ]));
  4003.     }
  4004.     /**
  4005.      * @Route("/centre/fData/{id}", name="postCentreImageByFormData", methods={"POST"})
  4006.      */
  4007.     public function postCentreImageByFormData(Centre $centreRequest $requestFileUploader $fileUploader): Response
  4008.     {
  4009.         if (!$request->query->get('token')) {
  4010.             return new Response(json_encode([
  4011.                 "message" => "Pas de token n'a été spécifié",
  4012.                 "status" => 401,
  4013.             ]), 401);
  4014.         }
  4015.         $entityManager $this->getDoctrine()->getManager();
  4016.         /** @var Token */
  4017.         $token $this->getDoctrine()
  4018.             ->getRepository(Token::class)
  4019.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $centre->getIdGerant()]);
  4020.         if (!$token) {
  4021.             return new Response(json_encode([
  4022.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  4023.                 "status" => 404,
  4024.             ]), 404);
  4025.         }
  4026.         // get token age
  4027.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  4028.         // if the token if older than 7 days
  4029.         if ($dateDiff->7) {
  4030.             $entityManager $this->getDoctrine()->getManager();
  4031.             $entityManager->remove($token);
  4032.             $entityManager->flush();
  4033.             return $this->json([
  4034.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  4035.                 'path' => 'src/Controller/AudioController.php',
  4036.                 "status" => 401,
  4037.             ], 401);
  4038.         }
  4039.         if (isset($_FILES["pic"]) && $_FILES["pic"]["size"] != 0) {
  4040.             $newfilename $fileUploader->uploadFormData($_FILES["pic"], "images/centre/");
  4041.             $centre->setImgUrl($newfilename);
  4042.         }
  4043.         $entityManager->flush();
  4044.         return $this->json([
  4045.             "imgUrl" => $centre->getImgUrl(),
  4046.         ]);
  4047.     }
  4048.     /**
  4049.      * @Route("/centre/{id}/access", name="editAccessByCentreByID", methods={"PUT"})
  4050.      */
  4051.     public function editAccessCentreByCentreID(Centre $centreRequest $request)
  4052.     {
  4053.         $entityManager $this->getDoctrine()->getManager();
  4054.         $data json_decode($request->getContent(), true);
  4055.         if (!isset($data['token']))
  4056.             return new Response(json_encode([
  4057.                 "message" => "Pas de token n'a été spécifié",
  4058.                 "status" => 401,
  4059.             ]), 401);
  4060.         $entityManager $this->getDoctrine()->getManager();
  4061.         /** @var Token */
  4062.         $token $this->getDoctrine()
  4063.             ->getRepository(Token::class)
  4064.             ->findOneBy(['token' => $data['token'], 'id_audio' => $centre->getIdGerant()]);
  4065.         if (!$token)
  4066.             return new Response(json_encode([
  4067.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  4068.                 "status" => 404,
  4069.             ]), 404);
  4070.         // get token age
  4071.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  4072.         // if the token if older than 7 days
  4073.         if ($dateDiff->7) {
  4074.             $entityManager->remove($token);
  4075.             $entityManager->flush();
  4076.             return $this->json([
  4077.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  4078.                 'path' => 'src/Controller/ClientController.php',
  4079.                 "status" => 401
  4080.             ], 401);
  4081.         }
  4082.         $centre $this->getDoctrine()
  4083.             ->getRepository(Centre::class)
  4084.             ->findOneBy(['id' => $centre->getId()]);
  4085.         if (!$centre) {
  4086.             return new Response(json_encode([
  4087.                 'message' => 'Error, no Centre found at this id',
  4088.                 'path' => 'src/Controller/CentreController.php',
  4089.             ]));
  4090.         } else {
  4091.             $accessCentre $this->getDoctrine()
  4092.                 ->getRepository(AccessCentre::class)
  4093.                 ->findOneBy(['id_centre' => $centre->getId()]);
  4094.             if (isset($data["Métro"]))
  4095.                 $accessCentre->setMetro($data["Métro"]);
  4096.             if (isset($data["Bus"]))
  4097.                 $accessCentre->setBus($data["Bus"]);
  4098.             if (isset($data["Tram"]))
  4099.                 $accessCentre->setTram($data["Tram"]);
  4100.             if (isset($data["RER"]))
  4101.                 $accessCentre->setRer($data["RER"]);
  4102.             if (isset($data["Parking Public"]))
  4103.                 $accessCentre->setParkingPublic($data["Parking Public"]);
  4104.             if (isset($data["Parking Privé"]))
  4105.                 $accessCentre->setParkingPrivate($data["Parking Privé"]);
  4106.             if (isset($data["Autre"]))
  4107.                 $accessCentre->setOther($data["Autre"]);
  4108.             $entityManager->persist($accessCentre);
  4109.             $entityManager->flush();
  4110.             return new Response(json_encode([
  4111.                 "idCentre" => $centre->getId(),
  4112.                 "metro" => $accessCentre->getMetro(),
  4113.                 "tram" => $accessCentre->getTram(),
  4114.                 "bus" => $accessCentre->getBus(),
  4115.                 "rer" => $accessCentre->getRer(),
  4116.                 "Parking Public" => $accessCentre->getParkingPublic(),
  4117.                 "Parking Privé" => $accessCentre->getParkingPrivate(),
  4118.                 "autre" => $accessCentre->getOther(),
  4119.             ]));
  4120.         }
  4121.     }
  4122.     /**
  4123.      * @Route("/centre/{id}", name="editCentreByID", methods={"PUT"})
  4124.      */
  4125.     public function editCentreByID(Centre $centreRequest $request)
  4126.     {
  4127.         $entityManager $this->getDoctrine()->getManager();
  4128.         $data json_decode($request->getContent(), true);
  4129.         if (!isset($data['token']))
  4130.             return new Response(json_encode([
  4131.                 "message" => "Pas de token n'a été spécifié",
  4132.                 "status" => 401,
  4133.             ]), 401);
  4134.         $entityManager $this->getDoctrine()->getManager();
  4135.         /** @var Token */
  4136.         $token $this->getDoctrine()
  4137.             ->getRepository(Token::class)
  4138.             ->findOneBy(['token' => $data['token'], 'id_audio' => $centre->getIdGerant()]);
  4139.         if (!$token)
  4140.             return new Response(json_encode([
  4141.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  4142.                 "status" => 404,
  4143.             ]), 404);
  4144.         // get token age
  4145.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  4146.         // if the token if older than 7 days
  4147.         if ($dateDiff->7) {
  4148.             $entityManager->remove($token);
  4149.             $entityManager->flush();
  4150.             return $this->json([
  4151.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  4152.                 'path' => 'src/Controller/ClientController.php',
  4153.                 "status" => 401
  4154.             ], 401);
  4155.         }
  4156.         if (isset($data["audio_id"])) {
  4157.             $audio $this->getDoctrine()
  4158.                 ->getRepository(Audio::class)
  4159.                 ->findOneBy(['id' => $data["audio_id"]]);
  4160.             if (!$audio)
  4161.                 return new Response(json_encode([
  4162.                     'message' => 'Error, no Audio found at this id',
  4163.                     'path' => 'src/Controller/AudioController.php',
  4164.                 ]));
  4165.             $centre->setIdGerant($audio);
  4166.         }
  4167.         if (isset($data["name"]))
  4168.             $centre->setName($data["name"]);
  4169.         if (isset($data["imgUrl"]))
  4170.             $centre->setImgUrl($data["imgUrl"]);
  4171.         if (isset($data["isRdvDomicile"]))
  4172.             $centre->setIsRdvDomicile($data["isRdvDomicile"]);
  4173.         if (isset($data["address"]))
  4174.             $centre->setAddress($data["address"]);
  4175.         if (isset($data["numero"]))
  4176.             $centre->setNumero($data["numero"]);
  4177.         if (isset($data["voie"]))
  4178.             $centre->setVoie($data["voie"]);
  4179.         if (isset($data["rue"]))
  4180.             $centre->setRue($data["rue"]);
  4181.         if (isset($data["description"]))
  4182.             $centre->setDescription($data["description"]);
  4183.         if (isset($data["longitude"]))
  4184.             $centre->setLongitude($data["longitude"]);
  4185.         if (isset($data["latitude"]))
  4186.             $centre->setLatitude($data["latitude"]);
  4187.         if (isset($data["postale"]))
  4188.             $centre->setPostale($data["postale"]);
  4189.         if (isset($data["city"]))
  4190.             $centre->setCity($data["city"]);
  4191.         if (isset($data["finess"]))
  4192.             $centre->setFiness($data["finess"]);
  4193.         if (isset($data["siret"]))
  4194.             $centre->setSiret($data["siret"]);
  4195.         if (isset($data["website"]))
  4196.             $centre->setWebsite($data["website"]);
  4197.         if (isset($data["phone"])) {
  4198.             $centrePhoneTest $this->getDoctrine()
  4199.                 ->getRepository(Centre::class)
  4200.                 ->findOneBy(['phone' => $data["phone"]]);
  4201.             if ($centrePhoneTest)
  4202.                 return $this->json([
  4203.                     'message' => 'Ce numéro de téléphone est déjà attribué.',
  4204.                     'path' => 'src/Controller/CentreController.php',
  4205.                     "status" => 401
  4206.                 ], 401);
  4207.             $centre->setPhone($data["phone"]);
  4208.         }
  4209.         if (isset($data["isHandicap"]))
  4210.             $centre->setIsHandicap($data["isHandicap"]);
  4211.         $entityManager->flush();
  4212.         return new Response(json_encode([
  4213.             "id" => $centre->getId(),
  4214.             "audio_id" => $centre->getIdGerant()->getId(),
  4215.             "name" => $centre->getName(),
  4216.             "imgUrl" => $centre->getImgUrl(),
  4217.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  4218.             "address" => $centre->getAddress(),
  4219.             "numero" => $centre->getNumero(),
  4220.             "voie" => $centre->getVoie(),
  4221.             "rue" => $centre->getRue(),
  4222.             "postale" => $centre->getPostale(),
  4223.             "city" => $centre->getCity(),
  4224.             "finess" => $centre->getFiness(),
  4225.             "siret" => $centre->getSiret(),
  4226.             "website" => $centre->getWebsite(),
  4227.             "phone" => $centre->getPhone(),
  4228.             "isHandicap" => $centre->getIsHandicap(),
  4229.         ]));
  4230.     }
  4231.     public function createPermanantMotif(int $durationString $colorAudio $audioint $id_motifint $type): AudioMotif
  4232.     {
  4233.         $audioMotif = new AudioMotif();
  4234.         $audioMotif->setDuration($duration);
  4235.         $audioMotif->setColor($color);
  4236.         $audioMotif->setIsRDVonline(true);
  4237.         $audioMotif->setIsDeleted(false);
  4238.         $audioMotif->setType($type);
  4239.         // change when that feature will be implemented.
  4240.         $audioMotif->setIdAudio($audio);
  4241.         $motif $this->getDoctrine()
  4242.             ->getRepository(Motif::class)
  4243.             ->findOneBy(['id' => $id_motif]);
  4244.         $audioMotif->setIdMotif($motif);
  4245.         return $audioMotif;
  4246.     }
  4247.     /**
  4248.      * @Route("centre/{id}/dockage/", name="callDocages", methods={"GET"})
  4249.      */
  4250.     public function callDocage(Centre $centre)
  4251.     {
  4252.         $entityManager $this->getDoctrine()->getManager();
  4253.         /** @var Token */
  4254.         $centre $this->getDoctrine()
  4255.             ->getRepository(Centre::class)
  4256.             ->findOneBy(['id' => $centre->getId()]);
  4257.         if ($centre->getIdDockage() != null) {
  4258.             $transaction $this->lancementSignatureDocument($centre$centre->getIdDockage());
  4259.         } else {
  4260.             $idDocage $this->createContactDockage($centre);
  4261.             $transaction $this->lancementSignatureDocument($centre$idDocage);
  4262.         }
  4263.         return new Response(json_encode([
  4264.             "response" => $transaction,
  4265.             "transactionId" => $centre->getTransactionId(),
  4266.             "documentId" => $centre->getDocumentId(),
  4267.             "isSign" => $centre->getIsSign(),
  4268.             "gerant" => $centre->getIdGerant()->getMail()
  4269.         ]));
  4270.     }
  4271.     /**
  4272.      * @Route("centre/{id}/dockage-ATOL/", name="callAtolDocages", methods={"GET"})
  4273.      */
  4274.     public function callAtolDocage(Centre $centre)
  4275.     {
  4276.         $entityManager $this->getDoctrine()->getManager();
  4277.         /** @var Token */
  4278.         $centre $this->getDoctrine()
  4279.             ->getRepository(Centre::class)
  4280.             ->findOneBy(['id' => $centre->getId()]);
  4281.         
  4282.         if($centre->getIdDockage() != null)
  4283.         {
  4284.             $transaction $this->lancementSignatureAtolDocument($centre$centre->getIdDockage());
  4285.            
  4286.         } else {
  4287.             $idDocage $this->createContactDockage($centre);
  4288.             $transaction $this->lancementSignatureAtolDocument($centre$idDocage);
  4289.         }
  4290.     
  4291.         
  4292.         return new Response(json_encode([
  4293.             "response" => $transaction,
  4294.             "transactionId" => $centre->getTransactionId(),
  4295.             "documentId" => $centre->getDocumentId(),
  4296.             "isSign" => $centre->getIsSign(),
  4297.             "gerant" => $centre->getIdGerant()->getMail()
  4298.         ]));
  4299.     }
  4300.     public function createContactDockage($centre){
  4301.             $entityManager $this->getDoctrine()->getManager();
  4302.         $emailGerant $centre->getIdGerant()->getMail();
  4303.         $firstName $centre->getIdGerant()->getName();
  4304.         $lastName $centre->getIdGerant()->getLastName();
  4305.         $address $centre->getAddress();
  4306.         $phone $centre->getIdGerant()->getPhone();
  4307.         $city $centre->getCity();
  4308.         $imgUrl $centre->getImgUrl();
  4309.         $centreName $centre->getName();
  4310.         $postal $centre->getPostale();
  4311.         $civilite $centre->getIdGerant()->getCivilite();
  4312.         if ($civilite == "Monsieur") {
  4313.             $genre 1;
  4314.         } elseif ($civilite "Madame") {
  4315.             $genre 2;
  4316.         } else {
  4317.             $genre 3;
  4318.         }
  4319.         $curl curl_init();
  4320.         curl_setopt_array($curl, array(
  4321.             CURLOPT_URL => 'https://api.docage.com/Contacts',
  4322.             CURLOPT_RETURNTRANSFER => true,
  4323.             CURLOPT_ENCODING => '',
  4324.             CURLOPT_MAXREDIRS => 10,
  4325.             CURLOPT_TIMEOUT => 0,
  4326.             CURLOPT_FOLLOWLOCATION => true,
  4327.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4328.             CURLOPT_CUSTOMREQUEST => 'POST',
  4329.             CURLOPT_USERPWD => 'contact@myaudio.fr' ":" 'f32c08a2-7f91-4aa4-a88d-1acc5bdd97f3',
  4330.             CURLOPT_POSTFIELDS => '{
  4331.                 "Email": "' $emailGerant '",
  4332.                 "FirstName": "' $firstName '",
  4333.                 "LastName": "' $lastName '",
  4334.                 "Address1": "' $address '",
  4335.                 "Address2": "",
  4336.                 "City": "' $city '",
  4337.                 "State": "",
  4338.                 "ZipCode": "' $postal '",
  4339.                 "Country": "France",
  4340.                 "Notes": "",
  4341.                 "Phone": "' $phone '",
  4342.                 "Mobile": "",
  4343.                 "Company": "' $centreName '",
  4344.                 "Gender": "' $genre '",
  4345.                 "Civility": "",
  4346.                 "ProfilePictureSmall": "' $imgUrl '",
  4347.                 "ProfilePictureMedium": "JVBERi0xLjQNCiXi48 [...] VPRgo=",
  4348.                 "ProfilePictureLarge": "JVBERi0xLjQNCiXi48 [...] VPRgo="
  4349.             }',
  4350.             CURLOPT_HTTPHEADER => array(
  4351.                 'Content-Type: application/json'
  4352.             ),
  4353.         ));
  4354.         $response1 curl_exec($curl);
  4355.         curl_close($curl);
  4356.         $idDocage json_decode($response1);
  4357.         $centre->setIdDockage($idDocage);
  4358.         $entityManager->flush();
  4359.         return $idDocage;
  4360.     }
  4361.     public function lancementSignatureDocument($centre$idDockage)
  4362.     {
  4363.         $entityManager $this->getDoctrine()->getManager();
  4364.         // $idDockage = $centre->getIdDockage();
  4365.         $curl curl_init();
  4366.         curl_setopt_array($curl, array(
  4367.             CURLOPT_URL => 'https://api.docage.com/Transactions/CreateFullTransaction',
  4368.             CURLOPT_RETURNTRANSFER => true,
  4369.             CURLOPT_ENCODING => '',
  4370.             CURLOPT_MAXREDIRS => 10,
  4371.             CURLOPT_TIMEOUT => 0,
  4372.             CURLOPT_FOLLOWLOCATION => true,
  4373.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4374.             CURLOPT_CUSTOMREQUEST => 'POST',
  4375.             CURLOPT_USERPWD => 'contact@myaudio.fr' ":" 'f32c08a2-7f91-4aa4-a88d-1acc5bdd97f3',
  4376.             CURLOPT_POSTFIELDS => array('TemplateId' => 'd6fa147a-2bda-437f-8e1f-ce470b59aa06''Client' => $idDockage),
  4377.         ));
  4378.         $response1 curl_exec($curl);
  4379.         $transaction json_decode($response1);
  4380.         $centre->setDocumentId($transaction->TransactionFiles[0]->Id);
  4381.         $centre->setTransactionId($transaction->TransactionFiles[0]->TransactionId);
  4382.         $centre->setIsSign(0);
  4383.         $entityManager->flush();
  4384.         curl_close($curl);
  4385.         return json_decode($response1);
  4386.     }
  4387.     public function lancementSignatureAtolDocument($centre$idDockage)
  4388.     {
  4389.         $entityManager $this->getDoctrine()->getManager();
  4390.        // $idDockage = $centre->getIdDockage();
  4391.         $curl curl_init();
  4392.         curl_setopt_array($curl, array(
  4393.         CURLOPT_URL => 'https://api.docage.com/Transactions/CreateFullTransaction',
  4394.         CURLOPT_RETURNTRANSFER => true,
  4395.         CURLOPT_ENCODING => '',
  4396.         CURLOPT_MAXREDIRS => 10,
  4397.         CURLOPT_TIMEOUT => 0,
  4398.         CURLOPT_FOLLOWLOCATION => true,
  4399.         CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4400.         CURLOPT_CUSTOMREQUEST => 'POST',
  4401.         CURLOPT_USERPWD => 'contact@myaudio.fr' ":" 'f32c08a2-7f91-4aa4-a88d-1acc5bdd97f3',
  4402.         CURLOPT_POSTFIELDS => array('TemplateId' => 'aac5b1ca-fa3d-438d-9e1d-e45d7032281f''Client' => $idDockage),
  4403.         ));
  4404.         $response1 curl_exec($curl);
  4405.         $transaction json_decode($response1);
  4406.         $centre->setDocumentId($transaction->TransactionFiles[0]->Id);
  4407.         $centre->setTransactionId($transaction->TransactionFiles[0]->TransactionId);
  4408.         $centre->setIsSign(0);
  4409.         $entityManager->flush();
  4410.         curl_close($curl);
  4411.         return json_decode($response1);
  4412.     }
  4413.     
  4414.     /**
  4415.      * @Route("centre/{id}/relance/dockage", name="relanceDocage", methods={"GET"})
  4416.      */
  4417.     public function relanceDocage(Centre $centre)
  4418.     {
  4419.         $output null;
  4420.         $retval null;
  4421.         //exec("curl --location --request GET 'https://api.docage.com/SendReminders/".$centre->getTransactionId()."'", $output, $retval);
  4422.         $curl curl_init();
  4423.         curl_setopt_array($curl, array(
  4424.             CURLOPT_URL => 'https://api.docage.com/SendReminders/' $centre->getTransactionId(),
  4425.             CURLOPT_RETURNTRANSFER => true,
  4426.             CURLOPT_ENCODING => '',
  4427.             CURLOPT_MAXREDIRS => 10,
  4428.             CURLOPT_TIMEOUT => 0,
  4429.             CURLOPT_FOLLOWLOCATION => true,
  4430.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4431.             CURLOPT_CUSTOMREQUEST => 'GET',
  4432.             CURLOPT_USERPWD => 'contact@myaudio.fr' ":" 'f32c08a2-7f91-4aa4-a88d-1acc5bdd97f3',
  4433.         ));
  4434.         $response1 curl_exec($curl);
  4435.         curl_close($curl);
  4436.         return new Response(json_encode([
  4437.             "response" => $response1,
  4438.             "transactionId" => $centre->getTransactionId(),
  4439.             "documentId" => $centre->getDocumentId(),
  4440.             "isSign" => $centre->getIsSign(),
  4441.         ]));
  4442.     }
  4443.     /**
  4444.      * @Route("centre/{id}/get/document", name="getDocumentDocage", methods={"GET"})
  4445.      */
  4446.     public function getDocumentDocage(Centre $centre)
  4447.     {
  4448.         $output null;
  4449.         $retval null;
  4450.         $curl curl_init();
  4451.         curl_setopt_array($curl, array(
  4452.             CURLOPT_URL => 'https://api.docage.com/TransactionFiles/Download/' $centre->getDocumentId(),
  4453.             CURLOPT_RETURNTRANSFER => true,
  4454.             CURLOPT_ENCODING => '',
  4455.             CURLOPT_MAXREDIRS => 10,
  4456.             CURLOPT_TIMEOUT => 0,
  4457.             CURLOPT_FOLLOWLOCATION => true,
  4458.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4459.             CURLOPT_CUSTOMREQUEST => 'GET',
  4460.             CURLOPT_USERPWD => 'contact@myaudio.fr' ":" 'f32c08a2-7f91-4aa4-a88d-1acc5bdd97f3',
  4461.         ));
  4462.         $response1 curl_exec($curl);
  4463.         curl_close($curl);
  4464.         $r str_replace('"'''$response1);
  4465.         $pdf_decoded base64_decode($r);
  4466.         //Write data back to pdf file
  4467.         $projectDir $this->getParameter('kernel.project_dir');
  4468.         //$pdfFilePath = $projectDir . '/assets/partner/facture' . $invoice->getToken() . '.pdf';
  4469.         $pdf fopen($projectDir '/assets/pdf/cga_' $centre->getId() . '.pdf''w');
  4470.         fwrite($pdf$pdf_decoded);
  4471.         //close output file
  4472.         fclose($pdf);
  4473.         return new Response($response1);
  4474.     }
  4475.     /**
  4476.      * @Route("centre/{id}/checkisSign", name="checkValid", methods={"GET"})
  4477.      */
  4478.     public function checkisSign(Centre $centre)
  4479.     {
  4480.         $entityManager $this->getDoctrine()->getManager();
  4481.         $curl curl_init();
  4482.         curl_setopt_array($curl, array(
  4483.             CURLOPT_URL => 'https://api.docage.com/Transactions/Status/' $centre->getTransactionId(),
  4484.             CURLOPT_RETURNTRANSFER => true,
  4485.             CURLOPT_ENCODING => '',
  4486.             CURLOPT_MAXREDIRS => 10,
  4487.             CURLOPT_TIMEOUT => 0,
  4488.             CURLOPT_FOLLOWLOCATION => true,
  4489.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4490.             CURLOPT_CUSTOMREQUEST => 'GET',
  4491.             CURLOPT_USERPWD => 'contact@myaudio.fr' ":" 'f32c08a2-7f91-4aa4-a88d-1acc5bdd97f3',
  4492.         ));
  4493.         $response1 curl_exec($curl);
  4494.         curl_close($curl);
  4495.         if ($response1 == "Done") {
  4496.             $centre->setIsSign(1);
  4497.             $entityManager->flush();
  4498.         }
  4499.         return new Response($centre->getIsSign());
  4500.     }
  4501.     /**
  4502.      * @Route("/mandat/create", name="mandatCreate", methods={"GET"})
  4503.      */
  4504.     public function sendToCreateMandat(Request $request)
  4505.     {
  4506.         //live : live_jk-8FCTbZ0ydYSvXNeT4P8MCGO__VM9Vb2c1-teG
  4507.         $token $request->query->get('token');
  4508.         $centreId $request->query->get('centre');
  4509.         $access_token "{$_ENV['goCardless_api']}";
  4510.         $client = new \GoCardlessPro\Client([
  4511.             'access_token' => $access_token,
  4512.             'environment'  => \GoCardlessPro\Environment::LIVE,
  4513.         ]);
  4514.         $centre $this->getDoctrine()
  4515.             ->getRepository(Centre::class)
  4516.             ->findOneBy(['id' => $centreId]);
  4517.         $gerant $centre->getIdGerant();
  4518.         $redirectFlow $client->redirectFlows()->create([
  4519.             "params" => [
  4520.                 // This will be shown on the payment pages
  4521.                 "description" => "Abonnement My Audio",
  4522.                 // Not the access token
  4523.                 "session_token" => $token,
  4524.                 "success_redirect_url" => "{$_ENV['BASE_logiciel']}mandat/loading",
  4525.                 // Optionally, prefill customer details on the payment page
  4526.                 "prefilled_customer" => [
  4527.                     "given_name" => $gerant->getName(),
  4528.                     "family_name" => $gerant->getLastname(),
  4529.                     "email" => $gerant->getMail(),
  4530.                     "address_line1" => $centre->getAddress(),
  4531.                     "city" => $centre->getCity(),
  4532.                     "postal_code" => strval($centre->getPostale()),
  4533.                 ],
  4534.             ]
  4535.         ]);
  4536.         return $this->json([
  4537.             'idflow' => $redirectFlow->id,
  4538.             'url' => $redirectFlow->redirect_url,
  4539.             'redirect' => $redirectFlow
  4540.         ]);
  4541.     }
  4542.     /**
  4543.      * @Route("/mandat/validate", name="mandatValidate", methods={"GET"})
  4544.      */
  4545.     public function validateMandat(Request $request)
  4546.     {
  4547.         $entityManager $this->getDoctrine()->getManager();
  4548.         $token $request->query->get('token');
  4549.         $url $request->query->get('url');
  4550.         $centreId $request->query->get('centre');
  4551.         $access_token "{$_ENV['goCardless_api']}";
  4552.         $client = new \GoCardlessPro\Client([
  4553.             'access_token' => $access_token,
  4554.             'environment'  => \GoCardlessPro\Environment::LIVE,
  4555.         ]);
  4556.         $redirectFlow $client->redirectFlows()->complete(
  4557.             $url//The redirect flow ID from above.
  4558.             ["params" => ["session_token" => $token]]
  4559.         );
  4560.         $customers $client->customers()->list()->records;
  4561.         $mandats $client->mandates()->list();
  4562.         $confirmation $redirectFlow->confirmation_url;
  4563.         $client $this->getDoctrine()
  4564.             ->getRepository(Centre::class)
  4565.             ->findOneBy(['id' => $centreId]);
  4566.         $client->setMandat($redirectFlow->links->mandate);
  4567.         $entityManager->flush();
  4568.         return $this->json([
  4569.             'confirmation' => $confirmation,
  4570.             'clients' => $customers,
  4571.             'mandats' => $mandats,
  4572.             'mandatId' => $redirectFlow->links->mandate
  4573.         ]);
  4574.     }
  4575.     /**
  4576.      * @Route("/centre/{id}/mandat/", name="getCentreMandatById", methods={"GET"})
  4577.      */
  4578.     public function getCentreMandatGyId(Centre $centreRequest $request)
  4579.     {
  4580.         $mandat $centre->getMandat();
  4581.         if ($mandat != null) {
  4582.             $client = new \GoCardlessPro\Client(array(
  4583.                 'access_token' => "{$_ENV['goCardless_api']}",
  4584.                 'environment'  => \GoCardlessPro\Environment::LIVE,
  4585.             ));
  4586.             $infoMandat =  $client->mandates()->get($mandat);
  4587.         } else {
  4588.             $infoMandat "";
  4589.         }
  4590.         return $this->json([
  4591.             'mandat' => $infoMandat,
  4592.         ]);
  4593.     }
  4594.     /**
  4595.      * @Route("/checkFacturation/centres", name="checkFacturation", methods={"GET"})
  4596.      */
  4597.     public function checkFacturation()
  4598.     {
  4599.         $centres $this->getDoctrine()
  4600.             ->getRepository(Centre::class)
  4601.             ->findAll();
  4602.         foreach ($centres as $centre) {
  4603.             $inscription $centre->getSignupDate();
  4604.             $origin = new DateTime(date_format($inscription'Y-m-d'));
  4605.             $target = new DateTime('now');
  4606.             $interval $origin->diff($target);
  4607.             $month $interval->format('%m');
  4608.             if ($month 0) {
  4609.                 $dayNow $target->format("d");
  4610.                 $day $origin->format("d");
  4611.                 if ($day == $dayNow) {
  4612.                     $this->getFacturationByCentre($centre);
  4613.                 }
  4614.             }
  4615.         }
  4616.         return $this->json([
  4617.             'mandat' => $month,
  4618.         ]);
  4619.     }
  4620.     /**
  4621.      * @Route("/facturation/centre/{id}", name="getFacturationByCentre", methods={"GET"})
  4622.      */
  4623.     public function getFacturationByCentre(Centre $centre)
  4624.     {
  4625.         $entityManager $this->getDoctrine()->getManager();
  4626.         /**** ABONNEMENT ****/
  4627.         $dateInscription $centre->getSignupDate();
  4628.         $origin = new DateTime(date_format($dateInscription'Y-m-d'));
  4629.         $target = new DateTime('now');
  4630.         $interval $origin->diff($target);
  4631.         $month $interval->format('%m');
  4632.         if (intval($month) > 12) {
  4633.             $abonnement 49.90;
  4634.             $reduction 0.00;
  4635.         } elseif (intval($month) == 1) {
  4636.             $abonnement 49.90;
  4637.             $reduction 59.88;
  4638.         } else {
  4639.             $abonnement 39.90;
  4640.             $reduction 12.00;
  4641.         }
  4642.         /**** NOMBRE D'AUDIOS ****/
  4643.         $audios $this->getDoctrine()
  4644.             ->getRepository(AudioCentre::class)
  4645.             ->findBy(['id_centre' => $centre]);
  4646.         $audioSupplementaire count($audios) - 1;
  4647.         $audioAbonnement 19.90 $audioSupplementaire;
  4648.         $jour date("Y-m-d");
  4649.         $dateFin = new DateTime($jour);
  4650.         $dateDebut  strtotime($jour "- 1 months");
  4651.         $dateDebut date("Y-m-d"$dateDebut);
  4652.         $dateDebut = new DateTime($dateDebut);
  4653.         /**** MY RDV ****/
  4654.         $myrdv 0;
  4655.         $rdvs $this->getDoctrine()
  4656.             ->getRepository(Rdv::class)
  4657.             ->findRDVCentreBetweenDateWithoutTest($dateDebut$dateFin$centre->getID());
  4658.         $myrdv $myrdv + (50 count($rdvs));
  4659.         /**** MY RDV ADVANCED ****/
  4660.         $myRdvAdvanced 0;
  4661.         $rdvsA $this->getDoctrine()
  4662.             ->getRepository(Rdv::class)
  4663.             ->findRDVCentreBetweenDateWithTestId($dateDebut$dateFin$centre->getID());
  4664.         $myRdvAdvanced $myRdvAdvanced + (100 count($rdvsA));
  4665.         /**** MY LEAD ****/
  4666.         $mylead 0;
  4667.         $nbMyLead 0;
  4668.         $rdvsCanceled $this->getDoctrine()
  4669.             ->getRepository(Rdv::class)
  4670.             ->findCanceledRdvCentreBetweenDateWithoutTest($dateDebut$dateFin$centre->getID());
  4671.         foreach ($rdvsCanceled as $rdvc) {
  4672.             if (!is_null($rdvc->getIdClient())) {
  4673.                 $rdvClient $this->getDoctrine()
  4674.                     ->getRepository(Rdv::class)
  4675.                     ->findRDVLeadByClient($dateDebut$centre->getID(), $rdvc->getIdClient()->getID());
  4676.                 if (count($rdvClient) == 0) {
  4677.                     $mylead $mylead 35;
  4678.                     $nbMyLead $nbMyLead 1;
  4679.                 }
  4680.             }
  4681.         }
  4682.         /**** MY LEAD ADVANCED****/
  4683.         $myleadAdvanced 0;
  4684.         $nbMyLeadAdvanced 0;
  4685.         $rdvsCanceledA $this->getDoctrine()
  4686.             ->getRepository(Rdv::class)
  4687.             ->findCanceledRdvCentreBetweenDateWithTest($dateDebut$dateFin$centre->getID());
  4688.         foreach ($rdvsCanceledA as $rdvc) {
  4689.             if (!is_null($rdvc->getIdClient())) {
  4690.                 $rdvClient $this->getDoctrine()
  4691.                     ->getRepository(Rdv::class)
  4692.                     ->findRDVLeadByClient($dateDebut$centre->getID(), $rdvc->getIdClient()->getID());
  4693.                 if (count($rdvClient) == 0) {
  4694.                     $myleadAdvanced $myleadAdvanced 35;
  4695.                     $nbMyLeadAdvanced $nbMyLeadAdvanced 1;
  4696.                 }
  4697.             }
  4698.         }
  4699.         // Recuperation de l'ID vos facture ou creation 
  4700.         if (!is_null($centre->getFactureId())) {
  4701.             $factureId $centre->getFactureId();
  4702.         } else {
  4703.             $curl curl_init();
  4704.             curl_setopt_array($curl, array(
  4705.                 CURLOPT_URL => 'https://myaudio.vosfactures.fr/clients.json',
  4706.                 CURLOPT_RETURNTRANSFER => true,
  4707.                 CURLOPT_ENCODING => '',
  4708.                 CURLOPT_MAXREDIRS => 10,
  4709.                 CURLOPT_TIMEOUT => 0,
  4710.                 CURLOPT_FOLLOWLOCATION => true,
  4711.                 CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4712.                 CURLOPT_CUSTOMREQUEST => 'POST',
  4713.                 CURLOPT_POSTFIELDS => '{ 
  4714.                 "api_token": "pRHakmigmSJuVSYbcBS",
  4715.                 "client": { 
  4716.                     "name":"' $centre->getName() . '", 
  4717.                     "city": "' $centre->getCity() . '", 
  4718.                     "country": "France", 
  4719.                     "email": "' $centre->getIdGerant()->getMail() . '", 
  4720.                     "post_code": "' $centre->getPostale() . '", 
  4721.                     "street":"' $centre->getAddress() . '",
  4722.                     "phone": "' $centre->getPhone() . '"
  4723.                 }
  4724.             }',
  4725.                 CURLOPT_HTTPHEADER => array(
  4726.                     'Accept: application/json',
  4727.                     'Content-Type: application/json'
  4728.                 ),
  4729.             ));
  4730.             $response1 curl_exec($curl);
  4731.             $rep =  json_decode($response1);
  4732.             $factureId $rep->{'id'};
  4733.             $centre->setFactureId($rep->{'id'});
  4734.             $entityManager->flush();
  4735.         }
  4736.         // Création de la nouvelle facture 
  4737.         $curl curl_init();
  4738.         curl_setopt_array($curl, array(
  4739.             CURLOPT_URL => 'https://myaudio.vosfactures.fr/invoices.json',
  4740.             CURLOPT_RETURNTRANSFER => true,
  4741.             CURLOPT_ENCODING => '',
  4742.             CURLOPT_MAXREDIRS => 10,
  4743.             CURLOPT_TIMEOUT => 0,
  4744.             CURLOPT_FOLLOWLOCATION => true,
  4745.             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  4746.             CURLOPT_CUSTOMREQUEST => 'POST',
  4747.             CURLOPT_POSTFIELDS => '{ 
  4748.               "api_token": "pRHakmigmSJuVSYbcBS",
  4749.               "invoice": {
  4750.                 "department_id": 937362, 
  4751.                 "client_id": ' intval($centre->getFactureId()) . ',
  4752.                 "test": true,
  4753.                 "discount_kind":"amount",
  4754.                 "show_discount":true,
  4755.                 "positions":[
  4756.                     {"product_id": 102520343, "quantity":1, "discount": "' $reduction '"}, 
  4757.                     {"product_id": 103129798, "quantity": ' $audioSupplementaire '},
  4758.                     {"product_id": 102520426, "quantity": ' $nbMyLead '},
  4759.                     {"product_id": 102520439, "quantity": ' $nbMyLeadAdvanced '},
  4760.                     {"product_id": 102520392, "quantity": ' count($rdvs) . '},
  4761.                     {"product_id": 102520413, "quantity": ' count($rdvsA) . '}
  4762.                 ]
  4763.             }
  4764.           }',
  4765.             CURLOPT_HTTPHEADER => array(
  4766.                 'Accept: application/json',
  4767.                 'Content-Type: application/json'
  4768.             ),
  4769.         ));
  4770.         $fact curl_exec($curl);
  4771.         $fact =  json_decode($fact);
  4772.         $factId $fact->{'id'};
  4773.         $tokenId $fact->{'token'};
  4774.         $numeroFact $fact->{'number'};
  4775.         $montantHT $fact->{'price_net'};
  4776.         $montantTTC $fact->{'price_gross'};
  4777.         $dateFact $target;
  4778.         //POST FACTURE 
  4779.         $facture = new Factures();
  4780.         $facture->setId(intval($factId));
  4781.         $facture->setToken($tokenId);
  4782.         $facture->setDate($dateFact);
  4783.         $facture->setCentre($centre);
  4784.         $facture->setNumero($numeroFact);
  4785.         $facture->setPrixHT($montantHT);
  4786.         $facture->setPrixTTC($montantTTC);
  4787.         $entityManager->persist($facture);
  4788.         $entityManager->flush();
  4789.         $centimes floatval($montantTTC) * 100;
  4790.         //Envoi a Gocardless
  4791.         if (!is_null($centre->getMandat())) {
  4792.             $access_token "{$_ENV['goCardless_api']}";
  4793.             $client = new \GoCardlessPro\Client([
  4794.                 'access_token' => $access_token,
  4795.                 'environment'  => \GoCardlessPro\Environment::LIVE,
  4796.             ]);
  4797.             $redirectFlow $client->payments()->create([
  4798.                 "params" => [
  4799.                     "amount" => $centimes,
  4800.                     "currency" => "EUR",
  4801.                     "metadata" => [
  4802.                         "order_dispatch_date" => date("Y-m-d")
  4803.                     ],
  4804.                     "links" => [
  4805.                         "mandate" => $centre->getMandat()
  4806.                     ]
  4807.                 ]
  4808.             ]);
  4809.             $paiementId $redirectFlow->{'api_response'}->{'body'}->{'payments'}->{'id'};
  4810.             $facture->setPaiement($paiementId);
  4811.             $entityManager->persist($facture);
  4812.             $entityManager->flush();
  4813.         } else {
  4814.             $paiementId 0;
  4815.             $redirectFlow "";
  4816.         }
  4817.         return $this->json([
  4818.             'centre' => $centre->getID(),
  4819.             'reduction' => $reduction,
  4820.             'mandat' =>  $interval->format('%m mois'),
  4821.             'audio' => count($audios),
  4822.             'date_debut' => $dateDebut,
  4823.             'date_fin' => $dateFin,
  4824.             'MyRDV' => $myrdv,
  4825.             'MyRDVAdvanced' => $myRdvAdvanced,
  4826.             'MyLead' => $mylead,
  4827.             'MyLeadAdvanced' => $myleadAdvanced,
  4828.             'idFact' => $factureId,
  4829.             'factureId' => $factId,
  4830.             'tokenFact' => $tokenId,
  4831.             'dateFacture' => $dateFact,
  4832.             'numeroFact' => $numeroFact,
  4833.             'paiementId' => $paiementId,
  4834.             'redirect' => $redirectFlow
  4835.         ]);
  4836.     }
  4837.     /**
  4838.      * @Route("/getPaiement/", name="getPaiement", methods={"GET"})
  4839.      */
  4840.     public function getPaiement()
  4841.     {
  4842.         //Envoi a Gocardless
  4843.         $access_token "{$_ENV['goCardless_api']}";
  4844.         $client = new \GoCardlessPro\Client([
  4845.             'access_token' => $access_token,
  4846.             'environment'  => \GoCardlessPro\Environment::LIVE,
  4847.         ]);
  4848.         $redirectFlow $client->payments()->get("PM004RNN4TTSXJ");
  4849.         return $this->json([
  4850.             'redirect' => $redirectFlow
  4851.         ]);
  4852.     }
  4853.     /**
  4854.      * @Route("/gerantCenter/{id}/", name="getGerantCentre", methods={"GET","HEAD"})
  4855.      */
  4856.     public function getGerantCentres(Request $requestAudio $audio)
  4857.     {
  4858.         if (!$request->query->get('token')) {
  4859.             return new Response(json_encode([
  4860.                 "message" => "Pas de token n'a été spécifié",
  4861.                 "status" => 401,
  4862.             ]), 401);
  4863.         }
  4864.         $entityManager $this->getDoctrine()->getManager();
  4865.         $audioCentre $this->getDoctrine()
  4866.             ->getRepository(Centre::class)->findBy(['id_gerant' => $audio->getId()]);
  4867.         //dd($audioCentre);
  4868.         /** @var Token */
  4869.         $token $this->getDoctrine()
  4870.             ->getRepository(Token::class)
  4871.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $audio]);
  4872.         if (!$token) {
  4873.             return new Response(json_encode([
  4874.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  4875.                 "status" => 404,
  4876.             ]), 404);
  4877.         }
  4878.         // get token age
  4879.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  4880.         // if the token if older than 7 days
  4881.         if ($dateDiff->7) {
  4882.             $entityManager->remove($token);
  4883.             $entityManager->flush();
  4884.             return $this->json([
  4885.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  4886.                 'path' => 'src/Controller/ClientController.php',
  4887.                 "status" => 401,
  4888.             ], 401);
  4889.         }
  4890.         // get plan 
  4891.         $planAudio $this->getDoctrine()
  4892.             ->getRepository(Subscription::class)
  4893.             ->findOneBy(['audio' => $audio->getId()]);
  4894.         if ($planAudio) {
  4895.             $planQuanity $planAudio->getPlan()->getId();
  4896.         } else {
  4897.             $planAudio $this->getDoctrine()
  4898.                 ->getRepository(SpecificSubscription::class)
  4899.                 ->findOneBy(['audio' => $audio->getId()]);
  4900.             if ($planAudio) {
  4901.                 $planQuanity $planAudio->getPlan()->getId();
  4902.             } else {
  4903.                 $planAudio $this->getDoctrine()
  4904.                     ->getRepository(PartnerSubscription::class)
  4905.                     ->findOneBy(['audio' => $audio->getId()]);
  4906.                 $planQuanity $planAudio->getPlan()->getId();
  4907.             }
  4908.         }
  4909.         if ($audio->getIsPartner()) {
  4910.             // get plan 
  4911.             $planAudio $this->getDoctrine()
  4912.                 ->getRepository(PartnerSubscription::class)
  4913.                 ->findOneBy(['audio' => $audio->getId()]);
  4914.         } else {
  4915.             // get plan 
  4916.             $planAudio $this->getDoctrine()
  4917.                 ->getRepository(Subscription::class)
  4918.                 ->findOneBy(['audio' => $audio->getId()]);
  4919.             if (!$planAudio) {
  4920.                 $planAudio $this->getDoctrine()
  4921.                     ->getRepository(SpecificSubscription::class)
  4922.                     ->findOneBy(['audio' => $audio->getId()]);
  4923.             }
  4924.         }
  4925.         if (!$planAudio)
  4926.             return $this->json([
  4927.                 "message" => "Plan nexiste pas",
  4928.                 "status" => 404,
  4929.             ]);
  4930.         if ($planAudio) {
  4931.             $planQuanity $planAudio->getQuantity();
  4932.             $planAmount $planAudio->getPaidAmount();
  4933.             $planName $planAudio->getPlan()->getName();
  4934.             $planInterval $planAudio->getPlanInterval();
  4935.             $planId $planAudio->getPlan()->getId();
  4936.         }
  4937.         $centers array_map(function ($centre) {
  4938.             return [
  4939.                 "id" => $centre->getId(),
  4940.                 "address" => $centre->getAddress(),
  4941.                 "city" => $centre->getCity(),
  4942.                 "name" => $centre->getName(),
  4943.                 "website" => $centre->getWebsite(),
  4944.                 "isSign" => $centre->getIsSign(),
  4945.                 'urlRdv' => $centre->getUrlRdv()
  4946.             ];
  4947.         }, $audioCentre);
  4948.         return $this->json([
  4949.             "centers" => $centers,
  4950.             "planId" => $planId,
  4951.             "planQuantity" => $planQuanity,
  4952.             "planAmount" => $planAmount,
  4953.             "planName" => $planName,
  4954.             "planInterval" => $planInterval,
  4955.             "status" => 200
  4956.         ]);
  4957.     }
  4958.     /**
  4959.      * @Route("/center/add", name="postCenterAudio", methods={"POST"})
  4960.      */
  4961.     public function postCenterPro(Request $requestPublicFunction $publicFunctionStripeService $stripeService): Response
  4962.     {
  4963.         $data json_decode($request->getContent(), true);
  4964.         $audioCheckTel $this->getDoctrine()
  4965.             ->getRepository(Centre::class)
  4966.             ->findOneBy(["phone" => $data['phone']]);
  4967.         if ($audioCheckTel && !$data['isSamePhone']) {
  4968.             return $this->json([
  4969.                 "message" => "Le numéro de téléphone existe déjà",
  4970.                 "status" => 404,
  4971.             ]);
  4972.         }
  4973.         if (!isset($data["token"])) {
  4974.             return new Response(json_encode([
  4975.                 "message" => "Pas de token n'a été spécifié",
  4976.                 "status" => 401,
  4977.             ]), 401);
  4978.         }
  4979.         $entityManager $this->getDoctrine()->getManager();
  4980.         /** @var Token */
  4981.         $token $this->getDoctrine()
  4982.             ->getRepository(Token::class)
  4983.             ->findOneBy(['token' => $data["token"], 'id_audio' => $data["gerant"]]);
  4984.         if (!$token) {
  4985.             return new Response(json_encode([
  4986.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  4987.                 "status" => 404,
  4988.             ]), 404);
  4989.         }
  4990.         // get token age
  4991.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  4992.         // if the token if older than 7 days
  4993.         if ($dateDiff->7) {
  4994.             $entityManager->remove($token);
  4995.             $entityManager->flush();
  4996.             return $this->json([
  4997.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  4998.                 'path' => 'src/Controller/ClientController.php',
  4999.                 "status" => 401,
  5000.             ], 401);
  5001.         }
  5002.         $entityManager $this->getDoctrine()->getManager();
  5003.         // update subscription 
  5004.         if (isset($data["subscriptionId"])) {
  5005.             $planAudio $this->getDoctrine()
  5006.                 ->getRepository(Subscription::class)
  5007.                 ->find($data["subscriptionId"]);
  5008.             $quantity $planAudio->getQuantity() + 1;
  5009.             if ($planAudio->getPlanInterval() == "year") {
  5010.                 $discountPercentage 15.8;
  5011.                 $pricePerMonth $planAudio->getPlan()->getPrice();
  5012.                 $discountAnnual = ($pricePerMonth 12) * (- ($discountPercentage 100));
  5013.                 $amount $planAudio->getPaidAmount() + number_format($discountAnnual1);
  5014.             } else {
  5015.                 $amount $planAudio->getPaidAmount() + $planAudio->getPlan()->getPrice();
  5016.             }
  5017.             $planAudio->setQuantity($quantity);
  5018.             $planAudio->setPaidAmount($amount);
  5019.             $entityManager->persist($planAudio);
  5020.             if ($_ENV['APP_ENV']  === 'dev') {
  5021.                 $privateKey $_ENV['STRIPE_SECRET_KEY_TEST'];
  5022.             } else {
  5023.                 $privateKey $_ENV['STRIPE_SECRET_KEY_LIVE'];
  5024.             }
  5025.             $stripeProduct $stripeService->getPriceIdMap();
  5026.             \Stripe\Stripe::setApiKey($privateKey);
  5027.             $cusId $planAudio->getStripeCustomerId();
  5028.             // Retrieve the existing subscription
  5029.             $subscriptions \Stripe\Subscription::all(['customer' => $cusId]);
  5030.             $subscription $subscriptions->data[0];
  5031.             // Determine the price ID for the new product
  5032.             $newPriceId = ($planAudio->getPlanInterval() == "year") ? $stripeProduct['additionnalCenterYearly'] : $stripeProduct['additionnalCenter'];
  5033.             // Find if the price ID already exists in the subscription items
  5034.             $existingItem null;
  5035.             foreach ($subscription->items->data as $item) {
  5036.                 if ($item->price->id == $newPriceId) {
  5037.                     $existingItem $item;
  5038.                     break;
  5039.                 }
  5040.             }
  5041.             // Update quantity if the item exists, otherwise create a new item
  5042.             if ($planAudio->getQuantity() > 2) {
  5043.                 // Update the quantity of the existing item
  5044.                 $newQuantity $existingItem->quantity 1;
  5045.                 \Stripe\SubscriptionItem::update($existingItem->id, [
  5046.                     'quantity' => $newQuantity,
  5047.                 ]);
  5048.             } else {
  5049.                 // Create a new subscription item
  5050.                 \Stripe\SubscriptionItem::create([
  5051.                     'subscription' => $subscription->id,
  5052.                     'price' => $newPriceId,
  5053.                     'quantity' => 1,
  5054.                 ]);
  5055.             }
  5056.         }
  5057.         // generate color code 
  5058.         $colors = array(
  5059.             "#FFC0CB"// Pink
  5060.             "#FFD700"// Gold
  5061.             "#90EE90"// Light Green
  5062.             "#87CEFA"// Light Sky Blue
  5063.             "#FFA07A"// Light Salmon
  5064.             "#F0E68C"// Khaki
  5065.             "#B0C4DE"// Light Steel Blue
  5066.             "#98FB98"// Pale Green
  5067.             "#FFB6C1"// Light Pink
  5068.             "#ADD8E6"// Light Blue
  5069.             "#FF69B4"// Hot Pink
  5070.             "#FFA500"// Orange
  5071.             "#00FF7F"// Spring Green
  5072.             "#AFEEEE"// Pale Turquoise
  5073.             "#FF8C00"// Dark Orange
  5074.             "#FFE4B5"// Moccasin
  5075.             "#00CED1"// Dark Turquoise
  5076.             "#7FFFD4"// Aquamarine
  5077.             "#FF4500"// Orange Red
  5078.             "#00FA9A"// Medium Spring Green
  5079.             "#FFF0F5"// Lavender Blush
  5080.             "#00BFFF"// Deep Sky Blue
  5081.             "#FF6347"// Tomato
  5082.             "#20B2AA"// Light Sea Green
  5083.             "#FFFF00"// Yellow
  5084.             "#32CD32"// Lime Green
  5085.             "#FFF5EE"// Seashell
  5086.             "#1E90FF"// Dodger Blue
  5087.             "#CD5C5C"// Indian Red
  5088.             "#8FBC8F"// Dark Sea Green
  5089.             "#F0FFFF"// Azure
  5090.             "#4169E1"// Royal Blue
  5091.             "#FF8B00"// Dark Orange
  5092.             "#66CDAA"// Medium Aquamarine
  5093.             "#FFFACD"// Lemon Chiffon
  5094.             "#6495ED"// Cornflower Blue
  5095.             "#FF7F50"// Coral
  5096.             "#00FF00"// Lime
  5097.             "#FAFAD2"// Light Goldenrod Yellow
  5098.             "#87CEEB"// Sky Blue
  5099.             "#DC143C"// Crimson
  5100.             "#2E8B57"// Sea Green
  5101.             "#F5DEB3"// Wheat
  5102.             "#4682B4"// Steel Blue
  5103.             "#CD853F"// Peru
  5104.             "#8A2BE2"// Blue Violet
  5105.             "#D2691E"// Chocolate
  5106.             "#6A5ACD"// Slate Blue
  5107.             "#F5F5DC"// Beige
  5108.             "#7B68EE"// Medium Slate Blue
  5109.         );
  5110.         // short initial 
  5111.         $name $data['name'];
  5112.         $words explode(' '$name);
  5113.         $initials '';
  5114.         foreach ($words as $word) {
  5115.             $initials .= strtoupper(substr($word01));
  5116.         }
  5117.         $initials strtoupper($initials);
  5118.         $shortName substr($initials02);
  5119.         $randomColor $colors[array_rand($colors)];
  5120.         // get gerant
  5121.         $gerant $this->getDoctrine()
  5122.             ->getRepository(Audio::class)
  5123.             ->find($data['gerant']);
  5124.         // set center
  5125.         $centre = new Centre();
  5126.         // generate slug url 
  5127.         $slug $this->slugger->slug($data["name"])->lower();
  5128.         $slugify $this->getDoctrine()
  5129.             ->getRepository(Centre::class)
  5130.             ->findOneBy(array('slug' => $slug));
  5131.         if ($slugify) {
  5132.             $centre->setSlug($slug "-1");
  5133.         } else {
  5134.             $centre->setSlug($slug);
  5135.         }
  5136.         $centre->setName($data["name"]);
  5137.         if (isset($data["imgUrl"]))
  5138.             $centre->setImgUrl($data["imgUrl"]);
  5139.         if (isset($data["finessURL"]))
  5140.             $centre->setFinessUrl($data["finessURL"]);
  5141.         $centre->setIsRdvDomicile($data["isRdvDomicile"]);
  5142.         $centre->setIdGerant($gerant);
  5143.         $centre->setAddress($data["address"]);
  5144.         $centre->setPostale($data["postal"]);
  5145.         $centre->setCity($data["city"]);
  5146.         $centre->setFiness($data["finess"]);
  5147.         $centre->setIsValid(true);
  5148.         $centre->setSiret($data["siret"]);
  5149.         $centre->setWebsite($data["website"]);
  5150.         $centre->setSignupDate(new \DateTime());
  5151.         if ($data['isSamePhone']) {
  5152.             $principalCenter $this->getDoctrine()
  5153.                 ->getRepository(AudioCentre::class)
  5154.                 ->findOneBy(['id_audio' => $gerant]);
  5155.             $phone $principalCenter $principalCenter->getIdCentre()->getPhone() : "";
  5156.             $centre->setPhone($phone);
  5157.         } else {
  5158.             $centre->setPhone($data['phone']);
  5159.         }
  5160.         $centre->setIsHandicap($data["isHandicap"]);
  5161.         $centre->setInitial($shortName);
  5162.         $centre->setLongitude($data["longitude"]);
  5163.         $centre->setLatitude($data["latitude"]);
  5164.         $centre->setCalendarColor($randomColor);
  5165.         $centre->setHoraire($publicFunction->centreHoraire2);
  5166.         $centerHoliday json_decode($publicFunction->centreHoraire4true);
  5167.         $centre->setHorairesHoliday($centerHoliday);
  5168.         $entityManager->persist($centre);
  5169.         // set audio center
  5170.         $audioCentre = new AudioCentre();
  5171.         $audioCentre->setIdAudio($gerant);
  5172.         $audioCentre->setIdCentre($centre);
  5173.         $audioCentre->setIsConfirmed(true);
  5174.         $audioCentre->setHoraire($publicFunction->centreHoraire2);
  5175.         $centerHoliday json_decode($publicFunction->centreHoraire4true);
  5176.         $audioCentre->setHorairesHoliday($centerHoliday);
  5177.         $entityManager->persist($audioCentre);
  5178.         // set access to center
  5179.         $accessCentre = new AccessCentre();
  5180.         foreach ($data["access"] as $accessData) {
  5181.             if (isset($accessData["metro"]))
  5182.                 $accessCentre->setMetro(json_encode($accessData["metro"], JSON_FORCE_OBJECT));
  5183.             if (isset($accessData["bus"]))
  5184.                 $accessCentre->setBus(json_encode($accessData["bus"], JSON_FORCE_OBJECT));
  5185.             if (isset($accessData["tram"]))
  5186.                 $accessCentre->setTram(json_encode($accessData["tram"], JSON_FORCE_OBJECT));
  5187.             if (isset($accessData["rer"]))
  5188.                 $accessCentre->setRer(json_encode($accessData["rer"], JSON_FORCE_OBJECT));
  5189.             if (isset($accessData["parkingPublic"]))
  5190.                 $accessCentre->setParkingPublic(json_encode($accessData["parkingPublic"], JSON_FORCE_OBJECT));
  5191.             if (isset($accessData["parkingPrivate"]))
  5192.                 $accessCentre->setParkingPrivate(json_encode($accessData["parkingPrivate"], JSON_FORCE_OBJECT));
  5193.             if (isset($accessData["other"]))
  5194.                 $accessCentre->setOther(json_encode($accessData["other"], JSON_FORCE_OBJECT));
  5195.         }
  5196.         $accessCentre->setIdCentre($centre);
  5197.         $entityManager->persist($accessCentre);
  5198.         // save print setting 
  5199.         $setting = new Setting();
  5200.         $setting->setName($data["name"]);
  5201.         $setting->setAddress($data["address"]);
  5202.         $setting->setPhone($data["phone"]);
  5203.         $setting->setLogoUrl($centre->getImgUrl());
  5204.         $setting->setWebsite($data["website"]);
  5205.         $setting->setFirstname($gerant->getName());
  5206.         $setting->setLastname($gerant->getLastname());
  5207.         $setting->setEmail($gerant->getMail());
  5208.         $setting->setSeuilCaDroite(true);
  5209.         $setting->setSeuilCaGauche(true);
  5210.         $setting->setSeuilConfortDroite(true);
  5211.         $setting->setSeuilinconfortDroite(true);
  5212.         $setting->setSeuilInConfortGauche(true);
  5213.         $setting->setSeuilConfortGauche(true);
  5214.         $setting->setSeuilCoDroite(true);
  5215.         $setting->setSeuilCoGauche(true);
  5216.         $setting->setSeuilCaMaskingDroite(true);
  5217.         $setting->setSeuilCaMaskingGauche(true);
  5218.         $setting->setSeuilCoMaskingDroite(true);
  5219.         $setting->setSeuilCoMaskingGauche(true);
  5220.         /*
  5221.          $setting->setCasqueDroite(false);
  5222.          $setting->setCasqueGauche(false);
  5223.          $setting->setCasqueBinaural(false);
  5224.          $setting->setChampsLibreDroite(false);
  5225.          $setting->setChampsLibreGauche(false);
  5226.          $setting->setChampsLibreBinaural(false);
  5227.          $setting->setChampsLibreAppDroite(false);
  5228.          $setting->setChampsLibreAppGauche(false);
  5229.          $setting->setChampsLibreAppBinaural(false);*/
  5230.         $setting->setCasqueDroite(true);
  5231.         $setting->setCasqueGauche(true);
  5232.         $setting->setCasqueBinaural(true);
  5233.         $setting->setChampsLibreDroite(true);
  5234.         $setting->setChampsLibreGauche(true);
  5235.         $setting->setChampsLibreBinaural(true);
  5236.         $setting->setChampsLibreAppDroite(true);
  5237.         $setting->setChampsLibreAppGauche(true);
  5238.         $setting->setChampsLibreAppBinaural(true);
  5239.         $setting->setCentre($centre);
  5240.         $entityManager->persist($setting);
  5241.         //add the centre access
  5242.         if (isset($data["mutuelle"]))
  5243.             foreach ($data["mutuelle"] as $mutuelleObject) {
  5244.                 $mutuelle $this->getDoctrine()
  5245.                     ->getRepository(Mutuelle::class)
  5246.                     ->findOneBy(['id' => $mutuelleObject]);
  5247.                 if ($mutuelle == null) {
  5248.                     return new Response(json_encode([
  5249.                         'message' => 'Error, no mutuelle found at this id ' $mutuelleObject,
  5250.                         'path' => 'src/Controller/CentreController.php',
  5251.                     ]));
  5252.                 } else {
  5253.                     $centreMutuelle = new CentreMutuelle();
  5254.                     $centreMutuelle->setIdMutuelle($mutuelle);
  5255.                     $centreMutuelle->setIdCentre($centre);
  5256.                     if (isset($data["otherMutuelle"]) && $mutuelle->getLibelle() == "Autres")
  5257.                         $centreMutuelle->setOther(json_encode($data["otherMutuelle"], JSON_FORCE_OBJECT));
  5258.                     $entityManager->persist($centreMutuelle);
  5259.                 }
  5260.             }
  5261.         //other spetiality 
  5262.         if (isset($data["otherSpetiality"])) {
  5263.             $audioSpecialite = new AudioSpecialite();
  5264.             // $audioSpecialite->setIdSpecialite($specialite);
  5265.             $audioSpecialite->setIdAudio($audio);
  5266.             $audioSpecialite->setOther(json_encode($data["otherSpetiality"], JSON_FORCE_OBJECT));
  5267.             $entityManager->persist($audioSpecialite);
  5268.         }
  5269.         if (isset($data["prestation"]))
  5270.             foreach ($data["prestation"] as $prestationId) {
  5271.                 $prestation $this->getDoctrine()
  5272.                     ->getRepository(Prestation::class)
  5273.                     ->findOneBy(['id' => $prestationId]);
  5274.                 if ($prestation == null) {
  5275.                     return new Response(json_encode([
  5276.                         'message' => 'Error, no prestation found at this id ' $prestationId,
  5277.                         'path' => 'src/Controller/CentreController.php',
  5278.                     ]));
  5279.                 } else {
  5280.                     $centrePrestation = new CentrePrestation();
  5281.                     $centrePrestation->setIdPrestation($prestation);
  5282.                     $centrePrestation->setIdCentre($centre);
  5283.                     $entityManager->persist($centrePrestation);
  5284.                 }
  5285.             }
  5286.         // set the galeries for images by default
  5287.         // Define an array of default image URLs
  5288.         $defaultImages = ["by-default-1.jpeg""by-default-2.jpeg""by-default-3.jpeg"];
  5289.         // Iterate through each default image
  5290.         foreach ($defaultImages as $imageUrl) {
  5291.             $centerImage = new CenterImage();
  5292.             $centerImage->setType("image");
  5293.             $centerImage->setUrl($imageUrl);
  5294.             // Associate the center image with the current center
  5295.             $centerImage->setCenter($centre);
  5296.             $entityManager->persist($centerImage);
  5297.         }
  5298.         /* if (isset($data["tier"]))
  5299.         foreach ($data["tier"] as $tierObject) {
  5300.             $tier = $this->getDoctrine()
  5301.                 ->getRepository(Tier::class)
  5302.                 ->findOneBy(['id' => $tierObject]);
  5303.             if ($tier == null) {
  5304.                 return new Response(json_encode([
  5305.                     'message' => 'Error, no tier found at this id ' . $tierObject,
  5306.                     'path' => 'src/Controller/CentreController.php',
  5307.                 ]));
  5308.             } else {
  5309.                 $centreTier = new CentreTier();
  5310.                 $centreTier->setIdTier($tier);
  5311.                 $centreTier->setIdCentre($centre);
  5312.                 $entityManager->persist($centreTier);
  5313.             }
  5314.         }*/
  5315.         $entityManager->flush();
  5316.         $name $centre->getName();
  5317.         $city $centre->getCity();
  5318.         $postal $centre->getPostale();
  5319.         $nameSlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($name)));
  5320.         $citySlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($city)));
  5321.         $baseClient $_ENV['BASE_client'] ?? 'https://default-client-url.com';
  5322.         $urlRdv "{$baseClient}audioprothesiste/{$citySlug}/{$postal}/{$nameSlug}/prise-de-rdvaudioprothesiste-rapide/{$centre->getId()}";
  5323.         if (!$centre->getUrlRdv() || $centre->getUrlRdv() !== $urlRdv) {
  5324.             $centre->setUrlRdv($urlRdv);
  5325.             $entityManager->persist($centre);
  5326.             $entityManager->flush();
  5327.         }
  5328.         return $this->json([
  5329.             'message' => 'centre a été ajouté',
  5330.             "status" => 200
  5331.         ]);
  5332.     }
  5333.     /**
  5334.      * @Route("/getcentre/{id}", name="getCentreId", methods={"GET","HEAD"})
  5335.      */
  5336.     public function getCentreId(Centre $centrePublicFunction $publicFunction): Response
  5337.     {
  5338.         $accessCentre $this->getDoctrine()->getRepository(AccessCentre::class)
  5339.             ->findOneBy(array('id_centre' => $centre->getId()));
  5340.         /*if (!$accessCentre)
  5341.             return new Response(json_encode([
  5342.                 'message' => 'Error, no accessCentre found at this id',
  5343.                 'path' => 'src/Controller/CentreController.php',
  5344.             ]), 404);
  5345.        */
  5346.         /** @var CentrePrestation[]*/
  5347.         $prestations $this->getDoctrine()->getRepository(CentrePrestation::class)
  5348.             ->findBy(array('id_centre' => $centre->getId()));
  5349.         $resultPrestation = new ArrayCollection();
  5350.         foreach ($prestations as $prestation) {
  5351.             $resultPrestation->add([
  5352.                 "id" => $prestation->getIdPrestation()->getId(),
  5353.                 "titre" => $prestation->getIdPrestation()->getLibelle(),
  5354.             ]);
  5355.         }
  5356.         /** @var CentreMutuelle[]*/
  5357.         $mutuelles $this->getDoctrine()->getRepository(CentreMutuelle::class)
  5358.             ->findBy(array('id_centre' => $centre->getId()));
  5359.         $resultMutuelle = new ArrayCollection();
  5360.         foreach ($mutuelles as $mutuelle) {
  5361.             $resultMutuelle->add([
  5362.                 "id" => $mutuelle->getIdMutuelle()->getId(),
  5363.                 "titre" => $mutuelle->getIdMutuelle()->getLibelle(),
  5364.             ]);
  5365.         }
  5366.         if ($accessCentre) {
  5367.             $metroIDs json_decode($accessCentre->getMetro(), true);
  5368.             $metroNames = [];
  5369.             if (is_array($metroIDs)) {
  5370.                 $stations $this->getDoctrine()->getRepository(Station::class)->findBy(['id' => $metroIDs]);
  5371.                 foreach ($stations as $station) {
  5372.                     $metroNames[] = [
  5373.                         "name" => $station->getName(),
  5374.                         "value" => $station->getId(),
  5375.                     ];
  5376.                 }
  5377.             }
  5378.             return $this->json([
  5379.                 "tram" => json_decode($accessCentre->getTram(), true),
  5380.                 "rer" => json_decode($accessCentre->getRer(), true),
  5381.                 "metro" => $metroNames,
  5382.                 "bus" => json_decode($accessCentre->getBus(), true),
  5383.                 "parking" => json_decode($accessCentre->getParkingPublic(), true),
  5384.                 "parkingPrivate" => json_decode($accessCentre->getParkingPrivate(), true),
  5385.                 "other" => json_decode($accessCentre->getOther(), true),
  5386.                 "id" => $centre->getId(),
  5387.                 "audio_id" => $centre->getIdGerant()->getId(),
  5388.                 "name" => $centre->getName(),
  5389.                 "imgUrl" => $centre->getImgUrl(),
  5390.                 "isRdvDomicile" => $centre->getIsRdvDomicile(),
  5391.                 "address" => $centre->getAddress(),
  5392.                 "numero" => $centre->getNumero(),
  5393.                 "voie" => $centre->getVoie(),
  5394.                 "rue" => $centre->getRue(),
  5395.                 "description" => $centre->getDescription(),
  5396.                 "postale" => $centre->getPostale(),
  5397.                 "city" => $centre->getCity(),
  5398.                 "finess" => $centre->getFiness(),
  5399.                 "siret" => $centre->getSiret(),
  5400.                 "website" => $centre->getWebsite(),
  5401.                 "phone" => $centre->getPhone(),
  5402.                 "imgUrl" => $centre->getImgUrl(),
  5403.                 "aditionnelInfo" => $centre->getAditionnelInfo(),
  5404.                 "initial" => $centre->getInitial(),
  5405.                 "calendarColor" => $centre->getCalendarColor(),
  5406.                 "isHandicap" => $centre->getIsHandicap(),
  5407.                 "longitude" => $centre->getLongitude(),
  5408.                 "latitude" => $centre->getLatitude(),
  5409.                 "isSign" => $centre->getIsSign(),
  5410.                 //"comments" => $comments,
  5411.                 "mutuelles" => $resultMutuelle->toArray(),
  5412.                 "prestations" => $resultPrestation->toArray(),
  5413.                 //"tiers" => $resultTier->toArray(),
  5414.                 //"audio" => $resultAudio->toArray(),
  5415.                 "schedule" => $centre->getHoraire(),
  5416.                 "status" => 200,
  5417.             ]);
  5418.         } else {
  5419.             return $this->json([
  5420.                 "id" => $centre->getId(),
  5421.                 "audio_id" => $centre->getIdGerant()->getId(),
  5422.                 "name" => $centre->getName(),
  5423.                 "imgUrl" => $centre->getImgUrl(),
  5424.                 "isRdvDomicile" => $centre->getIsRdvDomicile(),
  5425.                 "address" => $centre->getAddress(),
  5426.                 "numero" => $centre->getNumero(),
  5427.                 "voie" => $centre->getVoie(),
  5428.                 "rue" => $centre->getRue(),
  5429.                 "description" => $centre->getDescription(),
  5430.                 "postale" => $centre->getPostale(),
  5431.                 "city" => $centre->getCity(),
  5432.                 "finess" => $centre->getFiness(),
  5433.                 "siret" => $centre->getSiret(),
  5434.                 "website" => $centre->getWebsite(),
  5435.                 "phone" => $centre->getPhone(),
  5436.                 "imgUrl" => $centre->getImgUrl(),
  5437.                 "aditionnelInfo" => $centre->getAditionnelInfo(),
  5438.                 "initial" => $centre->getInitial(),
  5439.                 "calendarColor" => $centre->getCalendarColor(),
  5440.                 "isHandicap" => $centre->getIsHandicap(),
  5441.                 "longitude" => $centre->getLongitude(),
  5442.                 "latitude" => $centre->getLatitude(),
  5443.                 // "averageRating" => $publicFunction->calculateRating($centreRdvs),
  5444.                 //"nbrReview" => count($centreRdvs),
  5445.                 "tram" => null,
  5446.                 "rer" => null,
  5447.                 "metro" => null,
  5448.                 "bus" => null,
  5449.                 "parking" => null,
  5450.                 "parkingPrivate" => null,
  5451.                 "other" => null,
  5452.                 "isSign" => $centre->getIsSign(),
  5453.                 //"comments" => $comments,
  5454.                 "mutuelles" => $resultMutuelle->toArray(),
  5455.                 "prestations" => $resultPrestation->toArray(),
  5456.                 //"tiers" => $resultTier->toArray(),
  5457.                 //"audio" => $resultAudio->toArray(),
  5458.                 "schedule" => $centre->getHoraire(),
  5459.                 "status" => 200,
  5460.             ]);
  5461.         }
  5462.     }
  5463.     /**
  5464.      * @Route("/center/update/{id}", name="updateCenterAudio", methods={"POST"})
  5465.      */
  5466.     public function EditCentreBy(Request $requestCentre $centrePublicFunction $publicFunction): Response
  5467.     {
  5468.         $data json_decode($request->getContent(), true);
  5469.         if (!isset($data["token"])) {
  5470.             return new Response(json_encode([
  5471.                 "message" => "Pas de token n'a été spécifié",
  5472.                 "status" => 401,
  5473.             ]), 401);
  5474.         }
  5475.         $audioCheckTel $this->getDoctrine()
  5476.             ->getRepository(Centre::class)
  5477.             ->findOneBy(["phone" => $data['phone']]);
  5478.         /* if ($audioCheckTel)
  5479.         return $this->json([
  5480.             "message" => "Le numéro de téléphone existe déjà",
  5481.             "status" => 404,
  5482.         ]);
  5483.         */
  5484.         $entityManager $this->getDoctrine()->getManager();
  5485.         /** @var Token */
  5486.         $token $this->getDoctrine()
  5487.             ->getRepository(Token::class)
  5488.             ->findOneBy(['token' => $data["token"], 'id_audio' => $data["gerant"]]);
  5489.         if (!$token) {
  5490.             return new Response(json_encode([
  5491.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  5492.                 "status" => 404,
  5493.             ]), 404);
  5494.         }
  5495.         // get token age
  5496.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  5497.         // if the token if older than 7 days
  5498.         if ($dateDiff->7) {
  5499.             $entityManager->remove($token);
  5500.             $entityManager->flush();
  5501.             return $this->json([
  5502.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  5503.                 'path' => 'src/Controller/ClientController.php',
  5504.                 "status" => 401,
  5505.             ], 401);
  5506.         }
  5507.         $entityManager $this->getDoctrine()->getManager();
  5508.         if (isset($data["name"]))
  5509.             $centre->setName($data["name"]);
  5510.         if (isset($data["imgUrl"]))
  5511.             $centre->setImgUrl($data["imgUrl"]);
  5512.         if (isset($data["finessURL"]))
  5513.             $centre->setFinessUrl($data["finessURL"]);
  5514.         if (isset($data["isRdvDomicile"]))
  5515.             $centre->setIsRdvDomicile($data["isRdvDomicile"]);
  5516.         if (isset($data["address"]))
  5517.             $centre->setAddress($data["address"]);
  5518.         if (isset($data["postal"]))
  5519.             $centre->setPostale($data["postal"]);
  5520.         if (isset($data["city"]))
  5521.             $centre->setCity($data["city"]);
  5522.         if (isset($data["finess"]))
  5523.             $centre->setFiness($data["finess"]);
  5524.         if (isset($data["siret"]))
  5525.             $centre->setSiret($data["siret"]);
  5526.         if (isset($data["description"]))
  5527.             $centre->setDescription($data["description"]);
  5528.         if (isset($data["initial"]))
  5529.             $centre->setInitial($data["initial"]);
  5530.         if (isset($data["calendarColor"]))
  5531.             $centre->setCalendarColor($data["calendarColor"]);
  5532.         if (isset($data["website"]))
  5533.             $centre->setWebsite($data["website"]);
  5534.         if (isset($data["aditionnelInfo"]))
  5535.             $centre->setAditionnelInfo($data["aditionnelInfo"]);
  5536.         // Toujours défini à la date actuelle
  5537.         $centre->setSignupDate(new \DateTime());
  5538.         if (isset($data["phone"]))
  5539.             $centre->setPhone($data["phone"]);
  5540.         if (isset($data["isHandicap"]))
  5541.             $centre->setIsHandicap($data["isHandicap"]);
  5542.         if (isset($data["longitude"]))
  5543.             $centre->setLongitude($data["longitude"]);
  5544.         if (isset($data["latitude"]))
  5545.             $centre->setLatitude($data["latitude"]);
  5546.         //  $centre->setHoraire($publicFunction->centreHoraire2);
  5547.         $entityManager->persist($centre);
  5548.         // Fetch access centre data
  5549.         // Fetch access centre data
  5550.         $accessCentre $entityManager->getRepository(AccessCentre::class)->findOneBy(['id_centre' => $centre->getId()]);
  5551.         if ($accessCentre) {
  5552.             // Set the values from the form inputs
  5553.             foreach ($data["access"] as $accessData) {
  5554.                 if (isset($accessData["metro"]))
  5555.                     $accessCentre->setMetro(json_encode($accessData["metro"], JSON_FORCE_OBJECT));
  5556.                 if (isset($accessData["bus"]))
  5557.                     $accessCentre->setBus(json_encode($accessData["bus"], JSON_FORCE_OBJECT));
  5558.                 if (isset($accessData["tram"]))
  5559.                     $accessCentre->setTram(json_encode($accessData["tram"], JSON_FORCE_OBJECT));
  5560.                 if (isset($accessData["rer"]))
  5561.                     $accessCentre->setRer(json_encode($accessData["rer"], JSON_FORCE_OBJECT));
  5562.                 if (isset($accessData["parkingPublic"]))
  5563.                     $accessCentre->setParkingPublic(json_encode($accessData["parkingPublic"], JSON_FORCE_OBJECT));
  5564.                 if (isset($accessData["parkingPrivate"]))
  5565.                     $accessCentre->setParkingPrivate(json_encode($accessData["parkingPrivate"], JSON_FORCE_OBJECT));
  5566.                 if (isset($accessData["other"]))
  5567.                     $accessCentre->setOther(json_encode($accessData["other"], JSON_FORCE_OBJECT));
  5568.             }
  5569.             //$accessCentre->setIdCentre($centre);
  5570.             /*if (isset($data['metro'])) {
  5571.     $metroValues = explode(',', $data['metro']);
  5572.     $accessCentre->setMetro(json_encode($metroValues, JSON_FORCE_OBJECT));
  5573. }
  5574. if (isset($data['bus'])) {
  5575.     $busValues = explode(',', $data['bus']);
  5576.     $accessCentre->setBus(json_encode($busValues, JSON_FORCE_OBJECT));
  5577. }
  5578. if (isset($data['tram'])) {
  5579.     $tramValues = explode(',', $data['tram']);
  5580.     $accessCentre->setTram(json_encode($tramValues, JSON_FORCE_OBJECT));
  5581. }
  5582. if (isset($data['rer'])) {
  5583.     $rerValues = explode(',', $data['rer']);
  5584.     $accessCentre->setRer(json_encode($rerValues, JSON_FORCE_OBJECT));
  5585. }
  5586. if (isset($data['parking'])) {
  5587.     $parkingValues = explode(',', $data['parking']);
  5588.     $accessCentre->setParkingPublic(json_encode($parkingValues, JSON_FORCE_OBJECT));
  5589. }
  5590. if (isset($data['parkingPrivate'])) {
  5591.     $parkingPrivateValues = explode(',', $data['parkingPrivate']);
  5592.     $accessCentre->setParkingPrivate(json_encode($parkingPrivateValues, JSON_FORCE_OBJECT));
  5593. }
  5594. if (isset($data['other'])) {
  5595.     $otherValues = explode(',', $data['other']);
  5596.     $accessCentre->setOther(json_encode($otherValues, JSON_FORCE_OBJECT));
  5597. }*/
  5598.         } else {
  5599.             // Create an instance of AccessCentre
  5600.             $accessCentre = new AccessCentre();
  5601.             // Set the values from the form inputs
  5602.             if (isset($accessData["metro"]))
  5603.                 $accessCentre->setMetro(json_encode($accessData["metro"], JSON_FORCE_OBJECT));
  5604.             if (isset($accessData["bus"]))
  5605.                 $accessCentre->setBus(json_encode($accessData["bus"], JSON_FORCE_OBJECT));
  5606.             if (isset($accessData["tram"]))
  5607.                 $accessCentre->setTram(json_encode($accessData["tram"], JSON_FORCE_OBJECT));
  5608.             if (isset($accessData["rer"]))
  5609.                 $accessCentre->setRer(json_encode($accessData["rer"], JSON_FORCE_OBJECT));
  5610.             if (isset($accessData["parkingPublic"]))
  5611.                 $accessCentre->setParkingPublic(json_encode($accessData["parkingPublic"], JSON_FORCE_OBJECT));
  5612.             if (isset($accessData["parkingPrivate"]))
  5613.                 $accessCentre->setParkingPrivate(json_encode($accessData["parkingPrivate"], JSON_FORCE_OBJECT));
  5614.             if (isset($accessData["other"]))
  5615.                 $accessCentre->setOther(json_encode($accessData["other"], JSON_FORCE_OBJECT));
  5616.             if (isset($data['other'])) {
  5617.                 $otherValues explode(','$data['other']);
  5618.                 $accessCentre->setOther(json_encode($otherValuesJSON_FORCE_OBJECT));
  5619.             }
  5620.         }
  5621.         $mutuels $this->getDoctrine()
  5622.             ->getRepository(CentreMutuelle::class)
  5623.             ->findBy(['id_centre' => $centre->getId()]);
  5624.         $prestations $this->getDoctrine()
  5625.             ->getRepository(CentrePrestation::class)
  5626.             ->findBy(['id_centre' => $centre->getId()]);
  5627.         $entityManager $this->getDoctrine()->getManager();
  5628.         foreach ($mutuels as $mutuel) {
  5629.             $entityManager->remove($mutuel);
  5630.         }
  5631.         foreach ($prestations as $prestation) {
  5632.             $entityManager->remove($prestation);
  5633.         }
  5634.         if (isset($data["mutuelle"]))
  5635.             foreach ($data["mutuelle"] as $mutuelleObject) {
  5636.                 $mutuelle $this->getDoctrine()
  5637.                     ->getRepository(Mutuelle::class)
  5638.                     ->findOneBy(['id' => $mutuelleObject]);
  5639.                 if ($mutuelle == null) {
  5640.                     return new Response(json_encode([
  5641.                         'message' => 'Error, no mutuelle found at this id ' $mutuelleObject,
  5642.                         'path' => 'src/Controller/CentreController.php',
  5643.                     ]));
  5644.                 } else {
  5645.                     $centreMutuelle = new CentreMutuelle();
  5646.                     $centreMutuelle->setIdMutuelle($mutuelle);
  5647.                     $centreMutuelle->setIdCentre($centre);
  5648.                     if (isset($data["otherMutuelle"]) && $mutuelle->getLibelle() == "Autres")
  5649.                         $centreMutuelle->setOther(json_encode($data["otherMutuelle"], JSON_FORCE_OBJECT));
  5650.                     $entityManager->persist($centreMutuelle);
  5651.                 }
  5652.             }
  5653.         //other spetiality 
  5654.         if (isset($data["otherSpetiality"])) {
  5655.             $audioSpecialite = new AudioSpecialite();
  5656.             // $audioSpecialite->setIdSpecialite($specialite);
  5657.             $audioSpecialite->setIdAudio($audio);
  5658.             $audioSpecialite->setOther(json_encode($data["otherSpetiality"], JSON_FORCE_OBJECT));
  5659.             $entityManager->persist($audioSpecialite);
  5660.         }
  5661.         if (isset($data["prestation"]))
  5662.             foreach ($data["prestation"] as $prestationId) {
  5663.                 $prestation $this->getDoctrine()
  5664.                     ->getRepository(Prestation::class)
  5665.                     ->findOneBy(['id' => $prestationId]);
  5666.                 if ($prestation == null) {
  5667.                     return new Response(json_encode([
  5668.                         'message' => 'Error, no prestation found at this id ' $prestationId,
  5669.                         'path' => 'src/Controller/CentreController.php',
  5670.                     ]));
  5671.                 } else {
  5672.                     $centrePrestation = new CentrePrestation();
  5673.                     $centrePrestation->setIdPrestation($prestation);
  5674.                     $centrePrestation->setIdCentre($centre);
  5675.                     $entityManager->persist($centrePrestation);
  5676.                 }
  5677.             }
  5678.         // Set the centre ID
  5679.         $accessCentre->setIdCentre($centre);
  5680.         // Persist the access centre entity
  5681.         $entityManager->persist($accessCentre);
  5682.         $entityManager->flush();
  5683.         return $this->json([
  5684.             'message' => 'centre a été modifié avec succée',
  5685.             "status" => 200
  5686.         ]);
  5687.     }
  5688.     /**
  5689.      * @Route("/centresingle/horaire/{id}", name="setCentreHoraireSingle", methods={"PUT"})
  5690.      */
  5691.     public function setCentreSingleHoraire(Centre $centrePublicFunction $publicFunctionRequest $request)
  5692.     {
  5693.         if (!$request->query->get('token')) {
  5694.             return new Response(json_encode([
  5695.                 "message" => "Pas de token n'a été spécifié",
  5696.                 "status" => 401,
  5697.             ]), 401);
  5698.         }
  5699.         $entityManager $this->getDoctrine()->getManager();
  5700.         /** @var Token */
  5701.         $token $this->getDoctrine()
  5702.             ->getRepository(Token::class)
  5703.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $request->query->get('audio')]);
  5704.         if (!$token) {
  5705.             return new Response(json_encode([
  5706.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  5707.                 "status" => 404,
  5708.             ]), 404);
  5709.         }
  5710.         // get token age
  5711.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  5712.         // if the token if older than 7 days
  5713.         if ($dateDiff->7) {
  5714.             $entityManager->remove($token);
  5715.             $entityManager->flush();
  5716.             return $this->json([
  5717.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  5718.                 'path' => 'src/Controller/AudioController.php',
  5719.                 "status" => 401,
  5720.             ], 401);
  5721.         }
  5722.         $entityManager $this->getDoctrine()->getManager();
  5723.         $data json_decode($request->getContent(), true);
  5724.         $centre->setHoraire($data["horaires"]);
  5725.         $entityManager->flush();
  5726.         return $this->json([
  5727.             "id" => $centre->getId(),
  5728.             "horaires" => $data["horaires"]
  5729.         ]);
  5730.     }
  5731.     /**
  5732.      * @Route("/centresingle/horaire-holiday/{id}", name="setCentreHoraireHolidaySingle", methods={"PUT"})
  5733.      */
  5734.     public function setCentreHoraireHolidaySingle(Centre $centrePublicFunction $publicFunctionRequest $request)
  5735.     {
  5736.         if (!$request->query->get('token')) {
  5737.             return new Response(json_encode([
  5738.                 "message" => "Pas de token n'a été spécifié",
  5739.                 "status" => 401,
  5740.             ]), 401);
  5741.         }
  5742.         $entityManager $this->getDoctrine()->getManager();
  5743.         /** @var Token */
  5744.         $token $this->getDoctrine()
  5745.             ->getRepository(Token::class)
  5746.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $request->query->get('audio')]);
  5747.         if (!$token) {
  5748.             return new Response(json_encode([
  5749.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  5750.                 "status" => 404,
  5751.             ]), 404);
  5752.         }
  5753.         // get token age
  5754.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  5755.         // if the token if older than 7 days
  5756.         if ($dateDiff->7) {
  5757.             $entityManager->remove($token);
  5758.             $entityManager->flush();
  5759.             return $this->json([
  5760.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  5761.                 'path' => 'src/Controller/AudioController.php',
  5762.                 "status" => 401,
  5763.             ], 401);
  5764.         }
  5765.         $entityManager $this->getDoctrine()->getManager();
  5766.         $data json_decode($request->getContent(), true);
  5767.         $centre->setHorairesHoliday($data["horaires"]);
  5768.         $entityManager->flush();
  5769.         return $this->json([
  5770.             "id" => $centre->getId(),
  5771.             "horaires" => $data["horaires"]
  5772.         ]);
  5773.     }
  5774.     /**
  5775.      * @Route("/centres/fData/{id}", name="postCentresImageByFormData", methods={"POST"})
  5776.      */
  5777.     public function postCentresImageByFormData(Centre $centreRequest $requestFileUploader $fileUploader): Response
  5778.     {
  5779.         if (!$request->query->get('token')) {
  5780.             return new Response(json_encode([
  5781.                 "message" => "Pas de token n'a été spécifié",
  5782.                 "status" => 401,
  5783.             ]), 401);
  5784.         }
  5785.         $entityManager $this->getDoctrine()->getManager();
  5786.         /** @var Token */
  5787.         $token $this->getDoctrine()
  5788.             ->getRepository(Token::class)
  5789.             ->findOneBy(['token' => $request->query->get('token'), 'id_audio' => $centre->getIdGerant()]);
  5790.         if (!$token) {
  5791.             return new Response(json_encode([
  5792.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  5793.                 "status" => 404,
  5794.             ]), 404);
  5795.         }
  5796.         // get token age
  5797.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  5798.         // if the token if older than 7 days
  5799.         if ($dateDiff->7) {
  5800.             $entityManager $this->getDoctrine()->getManager();
  5801.             $entityManager->remove($token);
  5802.             $entityManager->flush();
  5803.             return $this->json([
  5804.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  5805.                 'path' => 'src/Controller/AudioController.php',
  5806.                 "status" => 401,
  5807.             ], 401);
  5808.         }
  5809.         // Handle updates to existing images
  5810.         if (isset($_FILES["file"])) {
  5811.             foreach ($_FILES["file"]["error"] as $key => $error) {
  5812.                 if ($error == UPLOAD_ERR_OK) {
  5813.                     $file = [
  5814.                         "name" => $_FILES["file"]["name"][$key],
  5815.                         "type" => $_FILES["file"]["type"][$key],
  5816.                         "tmp_name" => $_FILES["file"]["tmp_name"][$key],
  5817.                         "error" => $_FILES["file"]["error"][$key],
  5818.                         "size" => $_FILES["file"]["size"][$key],
  5819.                     ];
  5820.                     // Extract the image ID from the key
  5821.                     $imageId $key// Ensure this matches how you're identifying images
  5822.                     $image $entityManager->getRepository(CenterImage::class)->find($imageId);
  5823.                     if ($image) {
  5824.                         // Delete old file from the filesystem
  5825.                         $oldFilePath "images/centres/" $image->getUrl();
  5826.                         if (file_exists($oldFilePath)) {
  5827.                             unlink($oldFilePath);
  5828.                         }
  5829.                     } else {
  5830.                         // If no existing image, create a new entity
  5831.                         $image = new CenterImage();
  5832.                         $image->setCenter($centre);
  5833.                     }
  5834.                     // Determine file type (image or video) based on MIME type
  5835.                     $fileType mime_content_type($file['tmp_name']);
  5836.                     if (strpos($fileType'image') !== false) {
  5837.                         // File is an image
  5838.                         $image->setType('image');
  5839.                     } elseif (strpos($fileType'video') !== false) {
  5840.                         // File is a video
  5841.                         $image->setType('video');
  5842.                     }
  5843.                     $newfilename $fileUploader->uploadFormData($file"images/centres/");
  5844.                     if ($newfilename) {
  5845.                         $image->setUrl($newfilename);
  5846.                         $entityManager->persist($image);
  5847.                     }
  5848.                 }
  5849.             }
  5850.         }
  5851.         // Handle new image uploads
  5852.         if (isset($_FILES['newFile'])) {
  5853.             foreach ($_FILES['newFile']['error'] as $key => $error) {
  5854.                 if ($error == UPLOAD_ERR_OK) {
  5855.                     $file = [
  5856.                         'name' => $_FILES['newFile']['name'][$key],
  5857.                         'type' => $_FILES['newFile']['type'][$key],
  5858.                         'tmp_name' => $_FILES['newFile']['tmp_name'][$key],
  5859.                         'error' => $_FILES['newFile']['error'][$key],
  5860.                         'size' => $_FILES['newFile']['size'][$key],
  5861.                     ];
  5862.                     $image = new CenterImage();
  5863.                     $image->setCenter($centre);
  5864.                     $fileType mime_content_type($file['tmp_name']);
  5865.                     if (strpos($fileType'image') !== false) {
  5866.                         $image->setType('image');
  5867.                     } elseif (strpos($fileType'video') !== false) {
  5868.                         $image->setType('video');
  5869.                     }
  5870.                     $newfilename $fileUploader->uploadFormData($file"images/centres/");
  5871.                     if ($newfilename) {
  5872.                         $image->setUrl($newfilename);
  5873.                         $entityManager->persist($image);
  5874.                     }
  5875.                 }
  5876.             }
  5877.         }
  5878.         $entityManager->flush(); // Apply changes to the database
  5879.         return $this->json([
  5880.             "imgUrl" => $centre->getImgUrl(),
  5881.         ]);
  5882.     }
  5883.     /**
  5884.      * @Route("/centre/images/{id}", name="getCentresImage", methods={"GET"})
  5885.      */
  5886.     public function getCentresImage(Centre $centerPublicFunction $publicFunction): Response
  5887.     {
  5888.         $images $this->getDoctrine()
  5889.             ->getRepository(CenterImage::class)
  5890.             ->findBy(['center' => $center]);
  5891.         $imageCenter array_map(function ($image) {
  5892.             return [
  5893.                 "id" => $image->getId(),
  5894.                 "url" => $image->getUrl(),
  5895.                 "type" => $image->getType(),
  5896.             ];
  5897.         }, $images);
  5898.         return $this->json([
  5899.             "images" => $imageCenter,
  5900.         ]);
  5901.     }
  5902.     /**
  5903.      * @Route("/center/images/{url}", name="getCentresByImages", methods={"GET"})
  5904.      */
  5905.     public function getCentresByImages(string $urlPublicFunction $publicFunction): Response
  5906.     {
  5907.         return $publicFunction->replyWithFile('images/centres/'$url);
  5908.     }
  5909.     /**
  5910.      * @Route("centre/images/delete/", name="deleteCentresImage", methods={"POST"})
  5911.      */
  5912.     public function deleteCentresImage(Request $request): Response
  5913.     {
  5914.         $imageId $request->request->get("imageId");
  5915.         $imageGalerie $this->getDoctrine()->getRepository(CenterImage::class)
  5916.             ->find($imageId);
  5917.         $defaultImageUrls = ["by-default-1.jpeg""by-default-2.jpeg""by-default-3.jpeg"];
  5918.         if (!in_array($imageGalerie->getUrl(), $defaultImageUrls)) {
  5919.             $filePath $this->getParameter('kernel.project_dir') . "/assets/images/centres/" $imageGalerie->getUrl();
  5920.             if (file_exists($filePath)) {
  5921.                 unlink($filePath);
  5922.             }
  5923.         }
  5924.         $entityManager $this->getDoctrine()->getManager();
  5925.         $entityManager->remove($imageGalerie);
  5926.         $entityManager->flush();
  5927.         return $this->json(["status" => 200]);
  5928.     }
  5929.     /**
  5930.      * @Route("/center-update-description/{id}", name="setCentreDescription", methods={"PUT"})
  5931.      */
  5932.     public function setCentreDescription(Centre $centrePublicFunction $publicFunctionRequest $request)
  5933.     {
  5934.         $data json_decode($request->getContent(), true);
  5935.         if (!$data['token']) {
  5936.             return new Response(json_encode([
  5937.                 "message" => "Pas de token n'a été spécifié",
  5938.                 "status" => 401,
  5939.             ]), 401);
  5940.         }
  5941.         $entityManager $this->getDoctrine()->getManager();
  5942.         /** @var Token */
  5943.         $token $this->getDoctrine()
  5944.             ->getRepository(Token::class)
  5945.             ->findOneBy(['token' => $data['token'], 'id_audio' => $data['audio']]);
  5946.         if (!$token) {
  5947.             return new Response(json_encode([
  5948.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  5949.                 "status" => 404,
  5950.             ]), 404);
  5951.         }
  5952.         // get token age
  5953.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  5954.         // if the token if older than 7 days
  5955.         if ($dateDiff->7) {
  5956.             $entityManager->remove($token);
  5957.             $entityManager->flush();
  5958.             return $this->json([
  5959.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  5960.                 'path' => 'src/Controller/AudioController.php',
  5961.                 "status" => 401,
  5962.             ], 401);
  5963.         }
  5964.         $date1 = new DateTime();
  5965.         $date2 = new DateTime();
  5966.         $entityManager $this->getDoctrine()->getManager();
  5967.         $centre->setDescription($data["description"]);
  5968.         $entityManager->flush();
  5969.         return $this->json([
  5970.             "id" => $centre->getId(),
  5971.             "status" => "200"
  5972.         ]);
  5973.     }
  5974.     /**
  5975.      * @Route("/audioschedule/centre", name="getScheduleCentre", methods={"GET","HEAD"})
  5976.      */
  5977.     public function getScheduleCentre(Request $requestPublicFunction $publicFunction)
  5978.     {
  5979.         $data $request->query->all();
  5980.         //dd($data);
  5981.         if (!$data['token']) {
  5982.             return new Response(json_encode([
  5983.                 "message" => "Pas de token n'a été spécifié",
  5984.                 "status" => 401,
  5985.             ]), 401);
  5986.         }
  5987.         $entityManager $this->getDoctrine()->getManager();
  5988.         /** @var Token */
  5989.         $token $this->getDoctrine()
  5990.             ->getRepository(Token::class)
  5991.             ->findOneBy(['token' => $data['token'], 'id_audio' => $data['audio']]);
  5992.         if (!$token) {
  5993.             return new Response(json_encode([
  5994.                 "message" => "Pas de token trouvé dans la base de données. Veuillez vous reconnecter.",
  5995.                 "status" => 404,
  5996.             ]), 404);
  5997.         }
  5998.         // get token age
  5999.         $dateDiff $token->getCreationDate()->diff(new DateTime());
  6000.         // if the token if older than 7 days
  6001.         if ($dateDiff->7) {
  6002.             $entityManager->remove($token);
  6003.             $entityManager->flush();
  6004.             return $this->json([
  6005.                 'message' => 'Ce token est obselète. Veuillez vous reconnecter.',
  6006.                 'path' => 'src/Controller/AudioController.php',
  6007.                 "status" => 401,
  6008.             ], 401);
  6009.         }
  6010.         $audio $this->getDoctrine()
  6011.             ->getRepository(Audio::class)
  6012.             ->find($data['audio']);
  6013.         $centre $this->getDoctrine()
  6014.             ->getRepository(Centre::class)
  6015.             ->find($data['center']);
  6016.         $date1 = new DateTime();
  6017.         $date2 = new DateTime();
  6018.         return $this->json([
  6019.             "schedule" => [
  6020.                 $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  6021.                 $publicFunction->calculSchedule($audio$date1->add(new DateInterval('P7D')), $centre),
  6022.                 $publicFunction->calculSchedule($audio$date2->add(new DateInterval('P14D')), $centre)
  6023.             ],
  6024.             "status" => "200"
  6025.         ]);
  6026.     }
  6027.     /**
  6028.      * @Route("/villes", name="getVilleCentre", methods={"GET","HEAD"})
  6029.      */
  6030.     public function getVilleCentre(Request $requestPublicFunction $publicFunction)
  6031.     {
  6032.         $data $request->query->all();
  6033.         //dd($data);
  6034.         $villes $this->getDoctrine()
  6035.             ->getRepository(Ville::class)
  6036.             ->findAll();
  6037.         $getVilles array_map(function ($ville) {
  6038.             return [
  6039.                 "id" => $ville->getId(),
  6040.                 "nom" => $ville->getNom(),
  6041.                 "slug" => $ville->getSlug(),
  6042.             ];
  6043.         }, $villes);
  6044.         return $this->json([
  6045.             "villes" => $getVilles,
  6046.             "status" => "200"
  6047.         ]);
  6048.     }
  6049.     /**
  6050.      * @Route("/assets/pdf/{filename}", name="download_pdf", methods={"GET"})
  6051.      */
  6052.     public function downloadPdf(string $filename): Response
  6053.     {
  6054.         $filePath '../assets/pdf/' $filename;
  6055.         if (!file_exists($filePath)) {
  6056.             return new Response('File not found.'Response::HTTP_NOT_FOUND);
  6057.         }
  6058.         return new BinaryFileResponse($filePath);
  6059.     }
  6060.     /**
  6061.      * @Route("/checkphoneclient", name="checkPhoneClient", methods={"GET","HEAD"})
  6062.      */
  6063.     public function checkPhoneClient(Request $requestPublicFunction $publicFunction)
  6064.     {
  6065.         $clientPhoneTest $this->getDoctrine()
  6066.             ->getRepository(Client::class)
  6067.             ->findOneBy(['phone' => $request->query->get('phone')]);
  6068.         if ($clientPhoneTest) {
  6069.             return $this->json([
  6070.                 'message' => 'Ce numéro de téléphone est déjà attribué.',
  6071.                 'path' => 'src/Controller/ClientController.php',
  6072.                 "status" => 401,
  6073.             ], 200);
  6074.         }
  6075.         return $this->json([
  6076.             'message' => 'Le numéro n\'est pas utilisé.',
  6077.             "status" => 200,
  6078.         ]);
  6079.     }
  6080.     /**
  6081.      * @Route("/checkemailclient", name="checkEmailClient", methods={"GET","HEAD"})
  6082.      */
  6083.     public function checkEmailClient(Request $requestPublicFunction $publicFunction)
  6084.     {
  6085.         $clientMailTest $this->getDoctrine()
  6086.             ->getRepository(Client::class)
  6087.             ->findOneBy(['mail' => $request->query->get('mail')]);
  6088.         if ($clientMailTest) {
  6089.             return $this->json([
  6090.                 'message' => 'Ce mail est déjà attribué.',
  6091.                 'path' => 'src/Controller/ClientController.php',
  6092.                 "status" => 401,
  6093.             ], 200);
  6094.         }
  6095.         return $this->json([
  6096.             'message' => 'Le mail n\'est pas utilisé.',
  6097.             "status" => 200,
  6098.         ]);
  6099.     }
  6100.     /**
  6101.      * @Route("/audioprothesiste/{ville}/{codePostal}/{nomDuCentre}/prise-de-rdv/{id}", name="getCentreByDetails", methods={"GET","HEAD"})
  6102.      */
  6103.     public function getCentreByDetails(string $villestring $codePostalstring $nomDuCentreint $idPublicFunction $publicFunctionRequest $request): Response
  6104.     {
  6105.         // Récupération du centre par ville, code postal et nom
  6106.         $centre $this->getDoctrine()->getRepository(Centre::class)->find($id);
  6107.         if (!$centre) {
  6108.             return new Response(json_encode([
  6109.                 'message' => 'Error, no centre found for these details.',
  6110.                 'path' => 'src/Controller/CentreController.php',
  6111.             ]), 404);
  6112.         }
  6113.         /** @var CentrePrestation[]*/
  6114.         $prestations $this->getDoctrine()->getRepository(CentrePrestation::class)
  6115.             ->findBy(array('id_centre' => $centre->getId()));
  6116.         $resultPrestation = new ArrayCollection();
  6117.         foreach ($prestations as $prestation) {
  6118.             $resultPrestation->add([
  6119.                 "id" => $prestation->getIdPrestation()->getId(),
  6120.                 "titre" => $prestation->getIdPrestation()->getLibelle(),
  6121.             ]);
  6122.         }
  6123.         /** @var CentreMutuelle[]*/
  6124.         $mutuelles $this->getDoctrine()->getRepository(CentreMutuelle::class)
  6125.             ->findBy(array('id_centre' => $centre->getId()));
  6126.         $resultMutuelle = new ArrayCollection();
  6127.         foreach ($mutuelles as $mutuelle) {
  6128.             $resultMutuelle->add([
  6129.                 "id" => $mutuelle->getIdMutuelle()->getId(),
  6130.                 "titre" => $mutuelle->getIdMutuelle()->getLibelle(),
  6131.             ]);
  6132.         }
  6133.         /** @var CentreTier[]*/
  6134.         $tiers $this->getDoctrine()->getRepository(CentreTier::class)
  6135.             ->findBy(array('id_centre' => $centre->getId()));
  6136.         $resultTier = new ArrayCollection();
  6137.         foreach ($tiers as $tier) {
  6138.             $resultTier->add([
  6139.                 "id" => $tier->getIdTier()->getId(),
  6140.                 "titre" => $tier->getIdTier()->getLibelle(),
  6141.             ]);
  6142.         }
  6143.         /** @var AudioCentre[] */
  6144.         $liaisons $this->getDoctrine()->getRepository(AudioCentre::class)
  6145.             ->findBy(array('id_centre' => $centre'isConfirmed' => true));
  6146.         $resultAudio = new ArrayCollection();
  6147.         foreach ($liaisons as $liaison) {
  6148.             /** @var Audio */
  6149.             $audio $this->getDoctrine()->getRepository(Audio::class)
  6150.                 ->findOneBy(array('id' => $liaison->getIdAudio()));
  6151.             // Motifs
  6152.             /** @var AudioMotif[] */
  6153.             $motifs $this->getDoctrine()->getRepository(AudioMotif::class)
  6154.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  6155.             // will test whether or not the audio has the necessery motif to be added
  6156.             $resultMotif = new ArrayCollection();
  6157.             foreach ($motifs as $motif) {
  6158.                 // ignore deleted motif
  6159.                 if (!$motif->getIsDeleted() && $motif->getType() !== 2)
  6160.                     $resultMotif->add([
  6161.                         "id" => $motif->getIdMotif()->getId(),
  6162.                         "titre" => $motif->getIdMotif()->getTitre(),
  6163.                         "consigne" => $motif->getConsigne(),
  6164.                         "duration" => $motif->getDuration(),
  6165.                     ]);
  6166.             }
  6167.             // Specialities
  6168.             /** @var AudioSpecialite[] */
  6169.             $specialities $this->getDoctrine()->getRepository(AudioSpecialite::class)
  6170.                 ->findBy(array('id_audio' => $liaison->getIdAudio()));
  6171.             //speciality filter
  6172.             $resultSpeciality = new ArrayCollection();
  6173.             foreach ($specialities as $speciality) {
  6174.                 if ($speciality->getIdSpecialite() !== null) {
  6175.                     $resultSpeciality->add([
  6176.                         "id" => $speciality->getIdSpecialite()->getId(),
  6177.                         "titre" => $speciality->getIdSpecialite()->getLibelle(),
  6178.                     ]);
  6179.                 }
  6180.             }
  6181.             //schedule
  6182.             $date = new DateTime();
  6183.             //add audio in the result 
  6184.             if ($centre->getHoraire() == null || $centre->getHoraire() == []) continue;
  6185.             /** @var Rdv[] */
  6186.             $audioRdvs $this->getDoctrine()->getRepository(Rdv::class)
  6187.                 ->findAllReviewsAudio($audio->getId());
  6188.             $resultAudio->add([
  6189.                 "id" => $audio->getId(),
  6190.                 "civilite" => $audio->getCivilite(),
  6191.                 "name" => $audio->getName(),
  6192.                 "lastname" => $audio->getLastname(),
  6193.                 "birthdate" => $audio->getBirthdate(),
  6194.                 "mail" => $audio->getMail(),
  6195.                 "phone" => $audio->getPhone(),
  6196.                 "adeli" => $audio->getAdeli(),
  6197.                 "pin" => $audio->getPin(),
  6198.                 "description" => $audio->getDescription(),
  6199.                 "imgUrl" => $audio->getImgUrl(),
  6200.                 "averageRating" => $publicFunction->calculateRating($audioRdvs),
  6201.                 "nbrReview" => count($audioRdvs),
  6202.                 "motifs" => $resultMotif->toArray(),
  6203.                 "specialities" => $resultSpeciality->toArray(),
  6204.                 "schedule" => [
  6205.                     $publicFunction->calculSchedule($audio, new \DateTime(), $centre),
  6206.                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P7D')), $centre),
  6207.                     $publicFunction->calculSchedule($audio$date->add(new DateInterval('P14D')), $centre)
  6208.                 ],
  6209.             ]);
  6210.         }
  6211.         /** @var AccessCentre*/
  6212.         $accessCentre $this->getDoctrine()->getRepository(AccessCentre::class)
  6213.             ->findOneBy(array('id_centre' => $centre->getId()));
  6214.         if (!$accessCentre) {
  6215.             $tram = [];
  6216.             $rer = [];
  6217.             $metro = [];
  6218.             $bus = [];
  6219.             $parking = [];
  6220.             $pp = [];
  6221.             $other = [];
  6222.         } else {
  6223.             $metroIDs json_decode($accessCentre->getMetro(), true);
  6224.             $metroNames = array();
  6225.             if ($metroIDs) {
  6226.                 foreach ($metroIDs as $key => $stationID) {
  6227.                     $station $this->getDoctrine()->getRepository(Station::class)->find($stationID);
  6228.                     if ($station) {
  6229.                         $metroNames[$key] = $station->getName();
  6230.                     } else {
  6231.                         $metroNames[$key] = "Station Not Found";
  6232.                     }
  6233.                 }
  6234.             }
  6235.             $tram $accessCentre->getTram();
  6236.             $rer $accessCentre->getRer();
  6237.             $metro $metroNames;
  6238.             $bus $accessCentre->getBus();
  6239.             $parking $accessCentre->getParkingPublic();
  6240.             $pp $accessCentre->getParkingPrivate();
  6241.             $other $accessCentre->getOther();
  6242.         }
  6243.         /** @var Rdv[] */
  6244.         $centreRdvs $this->getDoctrine()->getRepository(Rdv::class)
  6245.             ->findAllReviewsCentre($centre->getId());
  6246.         // Comment
  6247.         /** @var Rdv[] */
  6248.         $rdvs $this->getDoctrine()->getRepository(Rdv::class)
  6249.             ->findBy(array('id_centre' => $centre));
  6250.         $comments = [];
  6251.         foreach ($rdvs as $rdv)
  6252.             if ($rdv->getComment() && $rdv->getReview() && $rdv->getIdClient())
  6253.                 array_push($comments, [
  6254.                     "id" => $rdv->getIdClient()->getId(),
  6255.                     "name" => $rdv->getIdClient()->getName() . " " $rdv->getIdClient()->getLastname()[0] . ".",
  6256.                     "comment" => $rdv->getComment(),
  6257.                     "isMale" => $rdv->getIdClient()->getCivilite() == "Monsieur",
  6258.                     "review" => $rdv->getReview(),
  6259.                 ]);
  6260.         $audioCentre $this->getDoctrine()->getRepository(AudioCentre::class)
  6261.             ->findOneBy(['id_centre' => $centre->getId()]);
  6262.         $audio $this->getDoctrine()->getRepository(Audio::class)
  6263.             ->findOneBy(['id' => $audioCentre->getIdAudio()]);
  6264.         //$doctor = $audio->serialize();
  6265.         return new Response(json_encode([
  6266.             "id" => $centre->getId(),
  6267.             "audio_id" => $centre->getIdGerant()->getId(),
  6268.             "name" => $centre->getName(),
  6269.             "imgUrl" => $centre->getImgUrl(),
  6270.             "isRdvDomicile" => $centre->getIsRdvDomicile(),
  6271.             "address" => $centre->getAddress(),
  6272.             "numero" => $centre->getNumero(),
  6273.             "voie" => $centre->getVoie(),
  6274.             "rue" => $centre->getRue(),
  6275.             "description" => $centre->getDescription(),
  6276.             "postale" => $centre->getPostale(),
  6277.             "city" => $centre->getCity(),
  6278.             "finess" => $centre->getFiness(),
  6279.             "siret" => $centre->getSiret(),
  6280.             "website" => $centre->getWebsite(),
  6281.             "phone" => $centre->getPhone(),
  6282.             "isHandicap" => $centre->getIsHandicap(),
  6283.             "longitude" => $centre->getLongitude(),
  6284.             "latitude" => $centre->getLatitude(),
  6285.             "averageRating" => $publicFunction->calculateRating($centreRdvs),
  6286.             "nbrReview" => count($centreRdvs),
  6287.             "tram" => $tram,
  6288.             "rer" => $rer,
  6289.             "metro" => $metro,
  6290.             "bus" => $bus,
  6291.             "parking" => $parking,
  6292.             "parkingPrivate" => $pp,
  6293.             "other" => $other,
  6294.             "comments" => $comments,
  6295.             "mutuelles" => $resultMutuelle->toArray(),
  6296.             "prestations" => $resultPrestation->toArray(),
  6297.             "tiers" => $resultTier->toArray(),
  6298.             "audio" => $resultAudio->toArray(),
  6299.             "schedule" => $centre->getHoraire(),
  6300.             //"doctor" => $doctor,
  6301.             "status" => 200,
  6302.         ]));
  6303.     }
  6304.     /**
  6305.      * @Route("/centres/generate-url-rdv", name="generateUrlRdvForAllCentres", methods={"POST"})
  6306.      */
  6307.     public function generateUrlRdvForAllCentres(): Response
  6308.     {
  6309.         $entityManager $this->getDoctrine()->getManager();
  6310.         $repository $this->getDoctrine()->getRepository(Centre::class);
  6311.         // Récupération de tous les centres
  6312.         $centres $repository->findAll();
  6313.         if (empty($centres)) {
  6314.             return new Response(json_encode([
  6315.                 'message' => 'No centres found in the database.',
  6316.             ]), 404, ['Content-Type' => 'application/json']);
  6317.         }
  6318.         $baseClient $_ENV['BASE_client'] ?? 'https://default-client-url.com';
  6319.         $updatedCentres = [];
  6320.         foreach ($centres as $centre) {
  6321.             // Récupération des informations nécessaires
  6322.             $id $centre->getId();
  6323.             $name $centre->getName();
  6324.             $city $centre->getCity();
  6325.             $postal $centre->getPostale();
  6326.             // Transformation en URL-friendly
  6327.             $nameSlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($name)));
  6328.             $citySlug strtolower(preg_replace('/[^a-zA-Z0-9]+/''-'trim($city)));
  6329.             // Construction de l'URL
  6330.             $urlRdv "{$baseClient}audioprothesiste/{$citySlug}/{$postal}/{$nameSlug}/prise-de-rdvaudioprothesiste-rapide/{$id}";
  6331.             // Mise à jour si l'URL est différente ou inexistante
  6332.             if (!$centre->getUrlRdv() || $centre->getUrlRdv() !== $urlRdv) {
  6333.                 $centre->setUrlRdv($urlRdv);
  6334.                 $entityManager->persist($centre);
  6335.                 $updatedCentres[] = $centre->getId(); // Ajoute l'ID des centres mis à jour
  6336.             }
  6337.         }
  6338.         // Sauvegarde des changements
  6339.         $entityManager->flush();
  6340.         // Retourne une réponse avec les centres mis à jour
  6341.         return new Response(json_encode([
  6342.             'message' => count($updatedCentres) . ' centres updated.',
  6343.             'updatedCentres' => $updatedCentres,
  6344.         ]), 200, ['Content-Type' => 'application/json']);
  6345.     }
  6346.     /**
  6347.      * @Route("/getlogin", name="getAssetsImage", methods={"GET"})
  6348.      */
  6349.     public function getAssetsImage(PublicFunction $publicFunction): Response
  6350.     {
  6351.         return $publicFunction->replyWithFile('images/'"login.png");
  6352.     }
  6353.     /**
  6354.      * @Route("/getloginImg", name="getAssetsImages", methods={"GET"})
  6355.      */
  6356.     public function getAssetsImages(PublicFunction $publicFunction): Response
  6357.     {
  6358.         return $publicFunction->replyWithFile('images/'"Logoblanc.png");
  6359.     }
  6360.     /**
  6361.      * @Route("/send-password-email/{audio}", name="send-password-email-audio")
  6362.      */
  6363.     public function sendPassworEmail(Request $requestAudio $audioPublicFunction $publicFunction)
  6364.     {
  6365.         $randomPassword substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 08);
  6366.         $encodedPassword password_hash($randomPasswordPASSWORD_BCRYPT);
  6367.         $audio->setPassword($encodedPassword);
  6368.         $entityManager $this->getDoctrine()->getManager();
  6369.         $entityManager->persist($audio);
  6370.         $entityManager->flush();
  6371.         // send email notif to audio
  6372.         $params = [
  6373.             "nom" => $audio->getName(),
  6374.             "url" => $_ENV['BASE_logiciel'],
  6375.             "password" => $randomPassword,
  6376.             "email" => $audio->getMail(),
  6377.         ];
  6378.         $publicFunction->sendEmail($params$audio->getMail(), "Audioprothésiste""Bienvenue chez MyAudio, complétez vos informations"201);
  6379.         $referer $request->headers->get('referer');
  6380.         if (!$referer) {
  6381.             return $this->redirectToRoute('easyadmin', [
  6382.                 'controller' => 'CentreCrudController',
  6383.                 'action' => 'index',
  6384.             ]);
  6385.         }
  6386.         $this->addFlash('success'"L'audioprothésiste a bien reçu les mails d'activation et de génération de son compte MyAudio Pro.");
  6387.         return $this->redirect($referer);
  6388.     }
  6389. }