src/Controller/InterventionController.php line 81

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use DateTime;
  4. use Mpdf\Mpdf;
  5. use DateInterval;
  6. use DateTimeZone;
  7. use App\Library\GraphUser;
  8. use App\Service\Securizer;
  9. use App\Entity\Intervention;
  10. use App\Entity\LigneDeContrat;
  11. use App\Repository\StatusRepository;
  12. use App\Repository\ActionsRepository;
  13. use App\Repository\ClientsRepository;
  14. use App\Repository\ContactsRepository;
  15. use App\Repository\ContratsRepository;
  16. use Doctrine\ORM\EntityManagerInterface;
  17. use App\Repository\InterventionRepository;
  18. use App\Repository\LigneDeContratRepository;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use App\Repository\TypeInterventionRepository;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Serializer\SerializerInterface;
  23. use Symfony\Component\Validator\Validator\ValidatorInterface;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\Security\Core\Authorization\AccessDecisionManagerInterface;
  27. require_once realpath(__DIR__ '/../../vendor/autoload.php');
  28. class InterventionController extends AbstractController
  29. {
  30.     /**
  31.      * @IsGranted("ROLE_USER")
  32.      */
  33.     public function index($yearAccessDecisionManagerInterface $accessDecisionManagerInterventionRepository $repoInterventionContratsRepository $repoContratLigneDeContratRepository $repoLigneContrat): Response
  34.     {
  35.         //retourne liste des interventions par année
  36.         $securizer = new Securizer($accessDecisionManager);
  37.         $interventions $repoIntervention->findInterventions($this->getUser(), $securizer$repoContrat$repoLigneContrat);
  38.         $res = [];
  39.         foreach ($interventions as $key => $value) {
  40.             $date date('Y'$value->getDateInterventionTimestamp());
  41.             if ($date === $year)
  42.                 $res[] = $value;
  43.         }
  44.         return $this->json($res200, [], ['groups' => 'affichageIntervention']);
  45.     }
  46.     /**
  47.      * @IsGranted("ROLE_USER")
  48.      */
  49.     public function voir($idInterventionRepository $repoInterventionContratsRepository $repoContratAccessDecisionManagerInterface $accessDecisionManagerLigneDeContratRepository $repoLigneContrat): Response
  50.     {
  51.         //voir une intervention
  52.         $securizer = new Securizer($accessDecisionManager);
  53.         $interventions $repoIntervention->findInterventions($this->getUser(), $securizer$repoContrat$repoLigneContrat);
  54.         //verifi que l'intervention que l'on cherche fait bien partie de la liste de ceux qu'il est possible d'afficher
  55.         if (in_array($repoIntervention->find($id), $interventions)) {
  56.             $intervention $repoIntervention->find($id);
  57.         } else {
  58.             return $this->json([
  59.                 'status' => 400,
  60.                 'message' => "Vous ne pouvez pas consulter cette intervention"
  61.             ], 400);
  62.         }
  63.         return $this->json($intervention200, [], ['groups' => 'affichageIntervention']);
  64.     }
  65.     /**
  66.      * @IsGranted("ROLE_TECH")
  67.      */
  68.     public function getByLigne($idInterventionRepository $repoInterventionContratsRepository $repoContratContactsRepository $repoContactAccessDecisionManagerInterface $accessDecisionManagerLigneDeContratRepository $repoLigneContrat): Response
  69.     {
  70.         //voir une intervention
  71.         $securizer = new Securizer($accessDecisionManager);
  72.         if (!$securizer->isGranted($this->getUser(), "ROLE_TECH")) {
  73.             $ligneContrat $repoLigneContrat->find($id);
  74.             $contact $repoContact->findOneBy(['mail' => $this->getUser()->getUserIdentifier()]);
  75.             if ($ligneContrat->getIdContrat()->getIdClient() !== $contact->getIdClient()) {
  76.                 return $this->json([
  77.                     'status' => 400,
  78.                     'message' => "Vous ne pouvez pas consulter cette intervention"
  79.                 ], 400);
  80.             }
  81.         }
  82.         $interventions $repoIntervention->findBy(['idLigneContrat' => $id]);
  83.         return $this->json($interventions200, [], ['groups' => 'affichageInterventionLigne']);
  84.     }
  85.     /**
  86.      * @IsGranted("ROLE_CLIENT")
  87.      */
  88.     public function getResumeClient(ClientsRepository $repoClientContratsRepository $repoContratAccessDecisionManagerInterface $accessDecisionManager): Response
  89.     {
  90.         $securizer = new Securizer($accessDecisionManager);
  91.         $clients $repoClient->findClientTous($this->getUser(), $securizer);
  92.         $client $clients[0];
  93.         $contrats $repoContrat->getContratsActifBy($client->getId());
  94.         $data = [
  95.             'Preventive' => ['Cloture' => 0'En Cours' => 0'Programmer' => 0],
  96.             'Curative' => ['Cloture' => 0'En Cours' => 0'Programmer' => 0],
  97.             'Télémaintenance' => ['rest' => 0'spent' => 0],
  98.             'nextInterventions' => [],
  99.         ];
  100.         $today = new DateTime();
  101.         foreach ($contrats as $contrat) {
  102.             foreach ($contrat->getLigneDeContrats() as $ligne) {
  103.                 if ($ligne->getIdTypeIntervention()->gettype() === "Télémaintenance") {
  104.                     $data["Télémaintenance"]['spent'] += $ligne->getQuantiteConsome();
  105.                     $data["Télémaintenance"]['rest'] += ($ligne->getQuantitePrevus() - $ligne->getQuantiteConsome());
  106.                 } else {
  107.                     foreach ($ligne->getInterventions() as $interv) {
  108.                         if (isset($data[$ligne->getIdTypeIntervention()->gettype()][$interv->getIdStatus()->getStatus()])) $data[$ligne->getIdTypeIntervention()->gettype()][$interv->getIdStatus()->getStatus()] += 1;
  109.                         if ($interv->getDateInterventionTimestamp() > $today->getTimestamp())
  110.                             array_push($data['nextInterventions'], ['date' => $interv->getDateInterventionTimestamp(), 'tech' => $interv->getTechPrevus()]);
  111.                     }
  112.                 }
  113.             }
  114.         }
  115.         return $this->json($data200, [], ['groups' => 'affichageIntervention']);
  116.     }
  117.     /**
  118.      * @IsGranted("ROLE_TECH")
  119.      */
  120.     public function creer(Request $requestStatusRepository $repoStatusValidatorInterface $validatorSerializerInterface $serializerEntityManagerInterface $managerClientsRepository $repoClientSecurizer $securizer): Response
  121.     {
  122.         //creer une nouvelle intervention, seul les role tech ou superieur peuvent acceder a cette page
  123.         $clients $repoClient->findClientActif($this->getUser(), $securizer);
  124.         $jsonRecu $request->getContent();
  125.         try {
  126.             //transforme le json reçu en entity
  127.             $intervention $serializer->deserialize($jsonRecuIntervention::class, 'json');
  128.             if (in_array($intervention->getIdLigneContrat()->getIdContrat()->getIdClient(), $clients)) {
  129.                 $date = new DateTime();
  130.                 $intervention->setCreateur($this->getUser())
  131.                     ->setDateCreation($date)
  132.                     ->setIdStatus($repoStatus->findOneBy(['status' => 'Programmer']));
  133.                 $ligneContrat $intervention->getIdLigneContrat();
  134.                 $ligneContrat->setQuantiteConsome($intervention->getIdLigneContrat()->getQuantiteConsome() + 1);
  135.                 //validation des données reçus
  136.                 //liste les erreur de validation deffini dans les entitées
  137.                 $errors $validator->validate($intervention);
  138.                 if (count($errors) > 0) {
  139.                     return $this->json($errors400);
  140.                 }
  141.                 // check if create event in json
  142.                 $jsonRecu json_decode($jsonRecu);
  143.                 $graphUser = new GraphUser();
  144.                 // recuperer graph id du technicien
  145.                 $techReferent $intervention->getTechPrevus();
  146.                 $users $graphUser->getUsers();
  147.                 $idUserGraph null;
  148.                 foreach ($users as $key => $value) {
  149.                     if ($value->getMail() === $techReferent->getMail()) {
  150.                         $idUserGraph $value->getId();
  151.                         break;
  152.                     }
  153.                 }
  154.                 if (isset($idUserGraph)) {
  155.                     $dateStart $jsonRecu->dateIntervention " " . ($jsonRecu->momentOfTheDay->value == "morning" "08:30:00" "14:00:00");
  156.                     $dateFin $jsonRecu->dateIntervention " " . ($jsonRecu->momentOfTheDay->value == "morning" "12:30:00" "18:00:00");
  157.                     $client $ligneContrat->getIdContrat()->getIdClient();
  158.                     // call create event function
  159.                     $eventId $graphUser->addEventUserDefaultCalendar($idUserGraph$dateStart$dateFin$jsonRecu->titre$jsonRecu->description$client->getAdresse() . ", " $client->getVille() . " " $client->getCodePostal(), 1.0);
  160.                     // recuperer event id
  161.                     $eventId $eventId->getBody()['id'];
  162.                     // save id in $intervention
  163.                     $intervention->setCalendarEventId($eventId);
  164.                 }
  165.                 $manager->persist($intervention);
  166.                 $manager->flush();
  167.             } else {
  168.                 return $this->json([
  169.                     'status' => 400,
  170.                     'message' => "Vous ne pouvez pas lier d'intervention à ce contact"
  171.                 ], 400);
  172.             }
  173.         } catch (\throwable $e) {
  174.             return $this->json([
  175.                 'status' => 400,
  176.                 'message' => $e->getMessage()
  177.             ], 400);
  178.         }
  179.         return $this->json($intervention201, [], ['groups' => 'affichageIntervention']);
  180.     }
  181.     /**
  182.      * @IsGranted("ROLE_TECH")
  183.      */
  184.     public function modif($idRequest $requestInterventionRepository $repoInterventionContactsRepository $repoContactsValidatorInterface $validatorSerializerInterface $serializerEntityManagerInterface $manager): Response
  185.     {
  186.         //modifi une intervention existant, seul les role tech ou superieur peuvent acceder a cette url
  187.         $intervention $repoIntervention->find($id);
  188.         $clientsDepart $intervention->getIdLigneContrat()->getIdContrat()->getIdClient();
  189.         if ($intervention == null) {
  190.             return $this->json([
  191.                 'status' => 400,
  192.                 'message' => "l'intervention à modifier n'existe pas"
  193.             ], 400);
  194.         }
  195.         $jsonRecu $request->getContent();
  196.         try {
  197.             $eventId $intervention->getCalendarEventId();
  198.             if (isset(json_decode($jsonRecu)->techPrevus) && json_decode($jsonRecu)->techPrevus !== $intervention->getTechPrevus()->getId() && isset($eventId)) {
  199.                 $prevTech $intervention->getTechPrevus();
  200.                 $newTech $repoContacts->find(json_decode($jsonRecu)->techPrevus);
  201.                 if (!isset($newTech) || !in_array("ROLE_TECH"$newTech->getRoles())) {
  202.                     return $this->json([
  203.                         'status' => 400,
  204.                         'message' => "le nouveau technicien n'est pas valide"
  205.                     ], 400);
  206.                 }
  207.                 $graphUser = new GraphUser();
  208.                 $users $graphUser->getUsers();
  209.                 $idPrevTech null;
  210.                 $idNewTech null;
  211.                 foreach ($users as $key => $value) {
  212.                     if ($value->getMail() === $prevTech->getMail()) {
  213.                         $idPrevTech $value->getId();
  214.                     } else if ($value->getMail() === $newTech->getMail()) {
  215.                         $idNewTech $value->getId();
  216.                     }
  217.                 }
  218.                 if (!isset($idPrevTech) || !isset($idNewTech))
  219.                     return $this->json([
  220.                         'status' => 400,
  221.                         'message' => "Il y a une erreur de synchronisation du calendrier"
  222.                     ], 400);
  223.                 // Prev event
  224.                 try {
  225.                     $prevEvent $graphUser->getCalendarEvent($idPrevTech$eventId);
  226.                     $subject $prevEvent->getBody()["subject"];
  227.                     $description $prevEvent->getBody()["bodyPreview"];
  228.                     $location $prevEvent->getBody()["location"]["displayName"];
  229.                     $time $prevEvent->getBody()["reminderMinutesBeforeStart"] / 60;
  230.                     $dateStart = new DateTime($prevEvent->getBody()["start"]["dateTime"], new DateTimeZone("Europe/Paris"));
  231.                     $dateStart->add(new DateInterval("PT1H"));
  232.                     $dateStart $dateStart->format('Y-m-d H:i:s');
  233.                     $dateFin = new DateTime($prevEvent->getBody()["end"]["dateTime"], new DateTimeZone("Europe/Paris"));
  234.                     $dateFin->add(new DateInterval("PT1H"));
  235.                     $dateFin $dateFin->format('Y-m-d H:i:s');
  236.                     // Suprimmer event
  237.                     $graphUser->deleteEventCalendar($idPrevTech$eventId);
  238.                 } catch (\throwable $e) {
  239.                     $dateStart $intervention->getDateIntervention()->format('Y-m-d') . " 08:30:00";
  240.                     $dateFin $intervention->getDateIntervention()->format('Y-m-d') . " 12:30:00";
  241.                     $client $intervention->getIdLigneContrat()->getIdContrat()->getIdClient();
  242.                     $subject $intervention->getTitre();
  243.                     $description $intervention->getDescription();
  244.                     $location $client->getAdresse() . ", " $client->getVille() . " " $client->getCodePostal();
  245.                     $time 1.0;
  246.                 }
  247.                 // call create event function
  248.                 $eventId $graphUser->addEventUserDefaultCalendar($idNewTech$dateStart$dateFin$subject$description$location$time);
  249.                 // recuperer event id
  250.                 $eventId $eventId->getBody()['id'];
  251.                 // save id in $intervention
  252.                 $intervention->setCalendarEventId($eventId);
  253.             }
  254.             //transforme le json reçu en entity
  255.             $serializer->deserialize($jsonRecuIntervention::class, 'json', ['object_to_populate' => $intervention]);
  256.             if ($intervention->getIdLigneContrat()->getIdContrat()->getIdClient() == $clientsDepart) {
  257.                 $errors $validator->validate($intervention);
  258.                 if (count($errors) > 0) {
  259.                     return $this->json($errors400);
  260.                 }
  261.                 $manager->persist($intervention);
  262.                 if ($intervention->getIdStatus()->getStatus() == 'Cloture') {
  263.                     //recupère la ligne de contrat de l'intervention et mettre a jour qteConsome / qtePrevus
  264.                     $ligneContrat $intervention->getIdLigneContrat();
  265.                     $actions $intervention->getActions();
  266.                     $dureeTotale 0;
  267.                     foreach ($actions as $action) {
  268.                         $dureeTotale $dureeTotale $action->getDuree();
  269.                     }
  270.                     $quantiteConsome $ligneContrat->getQuantiteConsome() + $dureeTotale;
  271.                     $ligneContrat $ligneContrat->setQuantiteConsome($quantiteConsome);
  272.                     $manager->persist($ligneContrat);
  273.                 }
  274.                 $manager->flush();
  275.             } else {
  276.                 return $this->json([
  277.                     'status' => 400,
  278.                     'message' => "Vous ne pouvez pas modifier le client d'une intervention"
  279.                 ], 400);
  280.             }
  281.         } catch (\throwable $e) {
  282.             return $this->json([
  283.                 'status' => 400,
  284.                 'message' => $e->getMessage()
  285.             ], 400);
  286.         }
  287.         return $this->json($intervention201, [], ['groups' => 'affichageIntervention']);
  288.     }
  289.     /**
  290.      * @IsGranted("ROLE_TECH")
  291.      */
  292.     public function delete($idInterventionRepository $repoIntervention): Response
  293.     {
  294.         //Permets de supprimer une intervention
  295.         $intervention $repoIntervention->find($id);
  296.         if ($intervention == null) {
  297.             return $this->json([
  298.                 'status' => 400,
  299.                 'message' => "l'intervention à supprimer n'existe pas"
  300.             ], 400);
  301.         }
  302.         if ($intervention->getIdStatus()->getStatus() != "Programmer") {
  303.             return $this->json([
  304.                 'status' => 400,
  305.                 'message' => "l'intervention ne peut pas être supprimé car il a pas un état 'Programmer'"
  306.             ], 400);
  307.         }
  308.         $ligneContrat $intervention->getIdLigneContrat();
  309.         $ligneContrat->setQuantiteConsome($ligneContrat->getQuantiteConsome() - 1);
  310.         //Remove calendrier id si exist
  311.         $eventId $intervention->getCalendarEventId();
  312.         if (isset($eventId)) {
  313.             $graphUser = new GraphUser();
  314.             $techReferent $intervention->getTechPrevus();
  315.             $users $graphUser->getUsers();
  316.             $idUserGraph null;
  317.             foreach ($users as $key => $value) {
  318.                 if ($value->getMail() === $techReferent->getMail()) {
  319.                     $idUserGraph $value->getId();
  320.                     break;
  321.                 }
  322.             }
  323.             if (isset($idUserGraph)) {
  324.                 try {
  325.                     $graphUser->deleteEventCalendar($idUserGraph$eventId);
  326.                 } catch (\Throwable $th) {
  327.                 }
  328.             }
  329.         }
  330.         $repoIntervention->remove($intervention);
  331.         return $this->json(true200, [], ['groups' => 'affichageIntervention']);
  332.     }
  333.     /**
  334.      * @IsGranted("ROLE_TECH")
  335.      */
  336.     public function types(TypeInterventionRepository $repoTypeIntervention): Response
  337.     {
  338.         $interventionsType $repoTypeIntervention->findAllInterventionsTypes();
  339.         return $this->json($interventionsType200, [], ['groups' => 'affichageContrat']);
  340.     }
  341.     /**
  342.      * @IsGranted("ROLE_TECH")
  343.      */
  344.     public function exportRapport(int $idInterventionRepository $repoInterventionActionsRepository $repoActionsContratsRepository $repoContrats)
  345.     {
  346.         $filename 'rapport_intervention.pdf';
  347.         $intervention $repoIntervention->find($id);
  348.         $preActions $repoActions->findBy(["intervention" => $intervention->getId()]);
  349.         $actions = [];
  350.         foreach ($preActions as $value) {
  351.             $actions[] = $value;
  352.             if ($value->getTicket() !== null) {
  353.                 $actionsTicktes $repoActions->findBy(["ticket" => $value->getTicket()->getId()]);
  354.                 foreach ($actionsTicktes as $v) {
  355.                     if ($v->getIntervention() === null)
  356.                         $actions[] = $v;
  357.                 }
  358.             }
  359.         }
  360.         $contrat $repoContrats->find($intervention->getIdLigneContrat()->getIdContrat());
  361.         $acts = [];
  362.         foreach ($actions as $key => $action) {
  363.             array_push($acts, ["date" => $action->getDateAction()->format('d/m/Y'), "message" => $action->getMessage(), "class" => ($key "border" "")]);
  364.         }
  365.         try {
  366.             $mpdf = new Mpdf();
  367.             $html $this->renderView('export/rapportIntervention.html.twig', [
  368.                 'dateIntervention' => $intervention->getDateIntervention()->format("d/m/Y"),
  369.                 'intervenant' => $intervention->getTechPrevus()->getNom() . " " $intervention->getTechPrevus()->getPrenom(),
  370.                 'nomClient' => $contrat->getIdClient()->getNom(),
  371.                 'adressClient' => $contrat->getIdClient()->getAdresse(),
  372.                 'villeClient' => $contrat->getIdClient()->getCodePostal() . " " $contrat->getIdClient()->getVille(),
  373.                 'titre' => $intervention->getTitre(),
  374.                 'description' => $intervention->getDescription(),
  375.                 'actions' => $acts,
  376.                 'route' => $_SERVER["DOCUMENT_ROOT"] . '/ExtranetV2/public'
  377.             ]);
  378.             $mpdf->setFooter('{PAGENO}');
  379.             $mpdf->WriteHTML("");
  380.             $mpdf->WriteHTML($html);
  381.             $path $_SERVER["DOCUMENT_ROOT"] . ($_ENV['APP_ENV'] == "dev" '../documents/' '/ExtranetV2/documents/') . $filename;
  382.             $mpdf->Output($path'F');
  383.             // header('Access-Control-Allow-Origin: ' . "http://localhost:8001");
  384.             header('Access-Control-Allow-Origin: ' "https://extranet.cco-info.fr/");
  385.             header('Access-Control-Allow-Credentials: true');
  386.             header('Access-Control-Allow-Methods: POST');
  387.             header('Access-Control-Allow-Headers: Content-Type');
  388.             header('Content-Description: File Transfer');
  389.             header('Content-Type: application/pdf');
  390.             header('Content-Disposition: attachment; filename="rapport_intervention.pdf"');
  391.             header('Expires: 0');
  392.             header('Cache-Control: must-revalidate');
  393.             header('Pragma: public');
  394.             header('Content-Length: ' filesize($path));
  395.             return readfile($path);
  396.         } catch (\throwable $e) {
  397.             return $this->json([
  398.                 'status' => 400,
  399.                 'message' => $e->getMessage()
  400.             ], 400);
  401.         }
  402.     }
  403.     /**
  404.      * @IsGranted("ROLE_COMMERCIAL")
  405.      */
  406.     public function stats(Request $requestInterventionRepository $repoIntervention): Response
  407.     {
  408.         $jsonRecu json_decode($request->getContent());
  409.         $startDate = (new DateTime())->setTimestamp($jsonRecu->startDate 1000);
  410.         $endDate = (new DateTime())->setTimestamp($jsonRecu->endDate 1000);
  411.         $interventions $repoIntervention->findByDate($startDate$endDate);
  412.         $monthsData = [];
  413.         /** @var Intervention $intervention */
  414.         foreach ($interventions as $key => $intervention) {
  415.             if ($intervention->getIdLigneContrat()->getIdTypeIntervention()->getType() !== "Télémaintenance") {
  416.                 $i $intervention->getDateIntervention()->format('Y-m');
  417.                 if (!isset($monthsData[$i])) $monthsData[$i] = ["month" => (int) $intervention->getDateIntervention()->format('m'), "total" => 0"curative" => 0"preventive" => 0];
  418.                 $monthsData[$i]["total"]++;
  419.                 if ($intervention->getIdLigneContrat()->getIdTypeIntervention()->getType() == "Preventive") {
  420.                     $monthsData[$i]["preventive"]++;
  421.                 } else if ($intervention->getIdLigneContrat()->getIdTypeIntervention()->getType() == "Curative") {
  422.                     $monthsData[$i]["curative"]++;
  423.                 }
  424.             }
  425.         }
  426.         return $this->json($monthsData200);
  427.     }
  428.     /**
  429.      * @IsGranted("ROLE_COMMERCIAL")
  430.      */
  431.     public function statsTelemaintenance(Request $requestLigneDeContratRepository $repoLigneContratTypeInterventionRepository $repoType): Response
  432.     {
  433.         $jsonRecu json_decode($request->getContent());
  434.         if ($jsonRecu->getBy !== "activeContrats") {
  435.             $startDate = (new DateTime())->setTimestamp($jsonRecu->startDate 1000);
  436.             $endDate = (new DateTime())->setTimestamp($jsonRecu->endDate 1000);
  437.             $lignesTelemaintenanceContrat $repoLigneContrat->findTelemeaintenanceByDate($startDate$endDate$repoType);
  438.         } else {
  439.             $lignesTelemaintenanceContrat $repoLigneContrat->findTelemeaintenanceContratsActifs($repoType);
  440.         }
  441.         $telemaintenanceData = [];
  442.         /** @var LigneDeContrat $ligne */
  443.         foreach ($lignesTelemaintenanceContrat as $key => $ligne) {
  444.             $client = (string) $ligne->getIdContrat()->getIdClient()->getNom();
  445.             if (!isset($telemaintenanceData[$client])) $telemaintenanceData[$client] = ['sold' => 0'spent' => 0];
  446.             $telemaintenanceData[$client]["sold"] += $ligne->getQuantitePrevus();
  447.             $telemaintenanceData[$client]["spent"] += $ligne->getQuantiteConsome();
  448.         }
  449.         return $this->json($telemaintenanceData200);
  450.     }
  451.     /**
  452.      * @IsGranted("ROLE_TECH")
  453.      */
  454.     public function syncEvenementsOutlook(InterventionRepository $repoInterventionEntityManagerInterface $manager)
  455.     {
  456.         $graphUser = new GraphUser();
  457.         $interventionsPorgrammes $repoIntervention->findInterventionsProgrammes();
  458.         $users $graphUser->getUsers();
  459.         $idUserGraph null;
  460.         /** @var Intervention $intervention */
  461.         for ($i 0$i count($interventionsPorgrammes); $i++) {
  462.             $intervention $interventionsPorgrammes[$i];
  463.             if ($intervention->getCalendarEventId() == null) {
  464.                 $this->delete($intervention->getId(), $repoIntervention);
  465.                 continue;
  466.             }
  467.             $idUserGraph null;
  468.             foreach ($users as $key => $value) {
  469.                 if ($value->getMail() === $intervention->getTechPrevus()->getMail()) {
  470.                     $idUserGraph $value->getId();
  471.                     break;
  472.                 }
  473.             }
  474.             if (isset($idUserGraph)) {
  475.                 try {
  476.                     $event $graphUser->getCalendarEvent($idUserGraph$intervention->getCalendarEventId());
  477.                 } catch (\Throwable $e) {
  478.                     if ($e->getCode() == 404) {
  479.                         $this->delete($intervention->getId(), $repoIntervention);
  480.                     }
  481.                     continue;
  482.                 }
  483.                 $date = new DateTime($event->getBody()['start']['dateTime']);
  484.                 if ($date->format('Y-m-d') != $intervention->getDateIntervention()->format('Y-m-d'))
  485.                     $intervention->setDateIntervention($date);
  486.                 $manager->persist($intervention);
  487.             }
  488.         }
  489.         $manager->flush();
  490.         return $this->json(true200);
  491.     }
  492. }