src/Controller/MobileApp/ParentAppController.php line 808

Open in your IDE?
  1. <?php
  2. namespace App\Controller\MobileApp;
  3. use DateTimeImmutable;
  4. use App\Entity\SettingFee;
  5. use App\Service\SMSSender;
  6. use App\Entity\SchoolWorkingTime;
  7. use App\Service\NotificationService;
  8. use App\Repository\SchoolYearRepository;
  9. use App\Repository\CanteenMenuRepository;
  10. use App\Entity\RegistrationStudentContact;
  11. use App\Repository\SchoolMatterRepository;
  12. use Symfony\Component\HttpClient\HttpClient;
  13. use Symfony\Component\Serializer\Serializer;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use App\Entity\MobileParentAppAccountActivity;
  16. use App\Repository\SchoolReportCardRepository;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use App\Entity\RegistrationStudentRegistration;
  19. use App\Repository\SchoolYearPeriodeRepository;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Doctrine\Common\Collections\ArrayCollection;
  22. use App\Repository\CommunicationMessageRepository;
  23. use App\Repository\SchoolStudentAverageRepository;
  24. use App\Repository\MobileParentAppAccountRepository;
  25. use App\Repository\RegistrationStudentRegistrationRepository;
  26. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  27. use App\Repository\SchoolTeacherCallSheetLineRepository;
  28. use App\Repository\SchoolWorkingTimeHourLessonRepository;
  29. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  30. use Symfony\Component\Validator\Validator\ValidatorInterface;
  31. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  32. /**
  33.  * @Route("/online/api/v1/parent")
  34. */
  35. class ParentAppController extends AbstractController
  36. {
  37.     private $headers = [
  38.         'Content-Type' => 'application/json',
  39.         'Access-Control-Allow-Origin' => '*',
  40.         'Access-Control-Allow-Methods' => 'POST'
  41.     ];
  42.     private $authToken '834f9d5c4639af2de6afc0e24adf556933fca38e168be527c766f81a4fd3e91e';
  43.     /**
  44.      * @Route("/auth", name="online_api_v1_parent_auth")
  45.     */
  46.     public function auth(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryNotificationService $notificationService): Response
  47.     {
  48.         $entityManager $this->getDoctrine()->getManager();
  49.         $encoders = [new JsonEncoder()];
  50.         $normalizer = [new ObjectNormalizer()];
  51.         $serializer = new Serializer($normalizer$encoders);
  52.         $content $request->getContent();
  53.         $contentJson json_decode($contenttrue);
  54.         $username $contentJson['username'];
  55.         $password $contentJson['password'];
  56.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['username' => $username], []);
  57.         if (null == $mobileParentAppAccount) {
  58.             $data = ['code' => 403'msg' => "Account not found"'request' => $contentJson];
  59.             $jsonContent $serializer->serialize($data'json');
  60.             $response = new Response($jsonContent403$this->headers);
  61.             return $response;
  62.         }
  63.         if (!$mobileParentAppAccount->getIsEnabled()) {
  64.             $data = ['code' => 403'msg' => "Account desable"'request' => $contentJson];
  65.             $jsonContent $serializer->serialize($data'json');
  66.             $response = new Response($jsonContent403$this->headers);
  67.             return $response;
  68.         }
  69.         if (md5($password) != $mobileParentAppAccount->getPassword()) {
  70.             $data = ['code' => 403'msg' => "invalid credential"'request' => $request->request];
  71.             $jsonContent $serializer->serialize($data'json');
  72.             $response = new Response($jsonContent403$this->headers);
  73.             return $response;
  74.         }
  75.         $deviceToken $request->headers->get('X-Device-Token');
  76.         $mobileParentAppAccount->setDeviceToken($deviceToken);
  77.         $mobileParentAppAccount->setLastAuthTime(time());
  78.         $mobileParentAppAccount->setToken(md5($this->randomPassword()).$mobileParentAppAccount->getId());
  79.         $userData = [
  80.             'token' => $mobileParentAppAccount->getToken(),
  81.             '_token_expire_at' => (time() + 604800),
  82.             '_time' => time(),
  83.             'last_name' => $mobileParentAppAccount->getLastName(),
  84.             'first_name' => $mobileParentAppAccount->getFirstName(),
  85.             'phone_number' => $mobileParentAppAccount->getPhoneNumber(),
  86.             'device_token' => $deviceToken,
  87.         ];
  88.         $notificationResponse $notificationService->sendNotification($deviceToken'Bienvenue!''Bienvenue sur Central Parent');
  89.         try {
  90.             $entityManager->flush();
  91.         } catch (\Throwable $th) {
  92.             $data = ['code' => 500'msg' => $th->getMessage()];
  93.             $jsonContent $serializer->serialize($data'json');
  94.             $response = new Response($jsonContent500$this->headers);
  95.             
  96.             return $response;
  97.         }
  98.         $data = ['code' => 200'msg' => "Access Granted"'user' => $userData'notificationResponse' => $notificationResponse];
  99.         $jsonContent $serializer->serialize($data'json');
  100.         $response = new Response($jsonContent200$this->headers);
  101.         
  102.         return $response;
  103.     }
  104.     /**
  105.      * @Route("/logout", name="online_api_v1_parent_logout")
  106.     */
  107.     public function logout(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepository): Response
  108.     {
  109.         $token $request->headers->get('token');
  110.         $entityManager $this->getDoctrine()->getManager();
  111.         $encoders = [new JsonEncoder()];
  112.         $normalizer = [new ObjectNormalizer()];
  113.         $serializer = new Serializer($normalizer$encoders);
  114.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  115.         if (null == $mobileParentAppAccount) {
  116.             $data = ['code' => 403'msg' => "Access denied"];
  117.             $jsonContent $serializer->serialize($data'json');
  118.             $response = new Response($jsonContent403$this->headers);
  119.             return $response;
  120.         }
  121.         $mobileParentAppAccount->setToken(md5('-1'));
  122.         try {
  123.             $entityManager->flush();
  124.         } catch (\Throwable $th) {}
  125.         $data = ['code' => 200'msg' => "logout"'token' => '-1'];
  126.         $jsonContent $serializer->serialize($data'json');
  127.         $response = new Response($jsonContent200$this->headers);
  128.         
  129.         return $response;
  130.     }
  131.     /**
  132.      * @Route("/me", name="online_api_v1_parent_me")
  133.      * Ajouter le 12/05/2025
  134.      * Par oumiche10@gmail.com
  135.      * pour envoyer recupérer le device token
  136.     */
  137.     public function me(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryNotificationService $notificationService): Response
  138.     {
  139.         $token $request->headers->get('token');
  140.         $encoders = [new JsonEncoder()];
  141.         $normalizer = [new ObjectNormalizer()];
  142.         $serializer = new Serializer($normalizer$encoders);
  143.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  144.         if (null == $mobileParentAppAccount) {
  145.             $data = ['code' => 403'msg' => "Access denied"];
  146.             $jsonContent $serializer->serialize($data'json');
  147.             $response = new Response($jsonContent403$this->headers);
  148.             return $response;
  149.         }
  150.         if (!$mobileParentAppAccount->getIsEnabled()) {
  151.             $data = ['code' => 403'msg' => "Account desable"];
  152.             $jsonContent $serializer->serialize($data'json');
  153.             $response = new Response($jsonContent403$this->headers);
  154.             return $response;
  155.         }
  156.         if (!$mobileParentAppAccount->isTokenValid()) {
  157.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  158.             $jsonContent $serializer->serialize($data'json');
  159.             $response = new Response($jsonContent403$this->headers);
  160.             return $response;
  161.         }
  162.         $deviceToken $request->headers->get('X-Device-Token');
  163.         $notificationResponse $notificationService->sendNotification($mobileParentAppAccount->getDeviceToken(), 'Bienvenue!''Bienvenue sur Central Parent');
  164.         $entityManager $this->getDoctrine()->getManager();
  165.         try {
  166.             $deviceToken $request->headers->get('X-Device-Token');
  167.             $mobileParentAppAccount->setDeviceToken($deviceToken);
  168.             $entityManager->flush();
  169.         } catch (\Throwable $th) {
  170.             $data = ['code' => 500'msg' => $th->getMessage()];
  171.             $jsonContent $serializer->serialize($data'json');
  172.             $response = new Response($jsonContent500$this->headers);
  173.             
  174.             return $response;
  175.         }
  176.         $me = [
  177.             'id' => $mobileParentAppAccount->getId(),
  178.             'username' => $mobileParentAppAccount->getUsername(),
  179.             'firstName' => $mobileParentAppAccount->getFirstName(),
  180.             'lastName' => $mobileParentAppAccount->getLastName(),
  181.             'phoneNumber' => $mobileParentAppAccount->getPhoneNumber(),
  182.             'isEnabled' => $mobileParentAppAccount->getIsEnabled(),
  183.             'lastAuthTime' => $mobileParentAppAccount->getLastAuthTime(),
  184.             'token' => $mobileParentAppAccount->getToken(),
  185.             'deviceToken' => $deviceToken,
  186.             
  187.         ];
  188.         $data = ['code' => 200'msg' => "success"'me' => $me'notificationResponse' => $notificationResponse];
  189.         $jsonContent $serializer->serialize($data'json');
  190.         $response = new Response($jsonContent200$this->headers);
  191.         
  192.         return $response;
  193.     }
  194.     /**
  195.      * @Route("/abonnements", name="online_api_v1_parent_abonnements")
  196.      * modifier pour afficher les 3 dernières années scolaires
  197.      * par oumiche10@gmail.com
  198.      * le 12/05/2025
  199.     */
  200.     public function abonnements(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositorySchoolYearRepository $schoolYearRepositoryRegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
  201.     {
  202.         $schoolYear $schoolYearRepository->findOneBy(['is_ongoing' => 1'is_archived' => 0], []);
  203.         $token $request->headers->get('token');
  204.         $encoders = [new JsonEncoder()];
  205.         $normalizer = [new ObjectNormalizer()];
  206.         $serializer = new Serializer($normalizer$encoders);
  207.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  208.         if (null == $mobileParentAppAccount) {
  209.             $data = ['code' => 403'msg' => "Access denied"];
  210.             $jsonContent $serializer->serialize($data'json');
  211.             $response = new Response($jsonContent403$this->headers);
  212.             return $response;
  213.         }
  214.         if (!$mobileParentAppAccount->getIsEnabled()) {
  215.             $data = ['code' => 403'msg' => "Account desable"];
  216.             $jsonContent $serializer->serialize($data'json');
  217.             $response = new Response($jsonContent403$this->headers);
  218.             return $response;
  219.         }
  220.         if (!$mobileParentAppAccount->isTokenValid()) {
  221.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  222.             $jsonContent $serializer->serialize($data'json');
  223.             $response = new Response($jsonContent403$this->headers);
  224.             return $response;
  225.         }
  226.         $registrationStudents $mobileParentAppAccount->getRegistrationStudents();
  227.         $abonnements = new ArrayCollection();
  228.         //foreach ($registrationStudents as $key => $registrationStudent) {
  229.             $registrationStudentRegistrations $registrationStudentRegistrationRepository->createQueryBuilder('entity')
  230.                 ->innerJoin('entity.student''student')
  231.                 ->addSelect('student')
  232.                 ->join('student.mobileParentAppAccounts''mobileParentAppAccount')
  233.                 ->addSelect('mobileParentAppAccount')
  234.                 ->andWhere('mobileParentAppAccount.id = :idParentAppAccount')
  235.                 ->setParameter('idParentAppAccount'$mobileParentAppAccount->getId())
  236.                 ->andWhere('entity.schoolYear = :schoolYear')
  237.                 ->setParameter('schoolYear'$schoolYear)
  238.                 ->orderBy('entity.id''DESC')
  239.                 ->getQuery()
  240.                 ->getResult();
  241.             foreach ($registrationStudentRegistrations as $key => $registrationStudentRegistration) {
  242.                 //if ($registrationStudentRegistration->hasMobileApp()) {
  243.                     $abonnements->add([
  244.                         'id' => $registrationStudentRegistration->getId(),
  245.                         'code' => $registrationStudentRegistration->getStudent()->getCode(),
  246.                         'registrationNumber' => $registrationStudentRegistration->getStudent()->getRegistrationNumber() != "AUCUN" $registrationStudentRegistration->getStudent()->getRegistrationNumber() : $registrationStudentRegistration->getStudent()->getCode(),
  247.                         'name' => $registrationStudentRegistration->getName(),
  248.                         'image' => 'images/students/'.$registrationStudentRegistration->getImage(),
  249.                         'establishmentId' => $registrationStudentRegistration->getEstablishment()->getId(),
  250.                         'establishmentName' => $registrationStudentRegistration->getEstablishment()->getName(),
  251.                         'establishmentType' => $registrationStudentRegistration->getEstablishment()->getType(),
  252.                         'classroom' => $registrationStudentRegistration->getClassroom()->getLabel().' - '.$registrationStudentRegistration->getSchoolYear()->getCode(),
  253.                     ]);
  254.                 //}
  255.             }
  256.         //}
  257.         //workflow
  258.         $entityManager $this->getDoctrine()->getManager();
  259.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  260.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  261.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  262.         $mobileParentAppAccountActivity->setType("Accueil");
  263.         $mobileParentAppAccountActivity->setDescription("Accueil");
  264.         $entityManager->persist($mobileParentAppAccountActivity);
  265.         try {
  266.             $entityManager->flush();
  267.         } catch (\Throwable $th) {
  268.             //throw $th;
  269.         }
  270.         $data = ['code' => 200'msg' => "success"'abonnements' => $abonnements];
  271.         $jsonContent $serializer->serialize($data'json');
  272.         $response = new Response($jsonContent200$this->headers);
  273.         
  274.         return $response;
  275.     }
  276.     /**
  277.      * @Route("/abonnement/{id}/establishment", name="online_api_v1_parent_abonnement_establishment")
  278.     */
  279.     public function abonnement_establishment(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistration): Response
  280.     {
  281.         $token $request->headers->get('token');
  282.         $encoders = [new JsonEncoder()];
  283.         $normalizer = [new ObjectNormalizer()];
  284.         $serializer = new Serializer($normalizer$encoders);
  285.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  286.         if (null == $mobileParentAppAccount) {
  287.             $data = ['code' => 403'msg' => "Access denied"];
  288.             $jsonContent $serializer->serialize($data'json');
  289.             $response = new Response($jsonContent403$this->headers);
  290.             return $response;
  291.         }
  292.         if (!$mobileParentAppAccount->getIsEnabled()) {
  293.             $data = ['code' => 403'msg' => "Account desable"];
  294.             $jsonContent $serializer->serialize($data'json');
  295.             $response = new Response($jsonContent403$this->headers);
  296.             return $response;
  297.         }
  298.         if (!$mobileParentAppAccount->isTokenValid()) {
  299.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  300.             $jsonContent $serializer->serialize($data'json');
  301.             $response = new Response($jsonContent403$this->headers);
  302.             return $response;
  303.         }
  304.         $data = [
  305.             'code' => 200,
  306.             'msg' => "success",
  307.             'establishment' => [
  308.                 'code' => $registrationStudentRegistration->getEstablishment()->getCode(),
  309.                 'name' => $registrationStudentRegistration->getEstablishment()->getName(),
  310.                 'type' => $registrationStudentRegistration->getEstablishment()->getType(),
  311.                 'address' => $registrationStudentRegistration->getEstablishment()->getAddress(),
  312.                 'phoneNumber' => $registrationStudentRegistration->getEstablishment()->getPhoneNumber(),
  313.                 'email' => $registrationStudentRegistration->getEstablishment()->getEmail(),
  314.                 'website' => $registrationStudentRegistration->getEstablishment()->getWebsite(),
  315.                 'image' => 'images/establishments/'.$registrationStudentRegistration->getEstablishment()->getImage(),
  316.             ],
  317.         ];
  318.         $jsonContent $serializer->serialize($data'json');
  319.         $response = new Response($jsonContent200$this->headers);
  320.         
  321.         return $response;
  322.     }
  323.     /**
  324.      * @Route("/forget-password", name="online_api_v1_parent_forget_password")
  325.     */
  326.     public function forget_password(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepository): Response
  327.     {
  328.         $token $request->headers->get('token');
  329.         $encoders = [new JsonEncoder()];
  330.         $normalizer = [new ObjectNormalizer()];
  331.         $serializer = new Serializer($normalizer$encoders);
  332.         $entityManager $this->getDoctrine()->getManager();
  333.         $content $request->getContent();
  334.         $contentJson json_decode($contenttrue);
  335.         $username $contentJson['username'];
  336.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['username' => $username], []);
  337.         if (null == $mobileParentAppAccount) {
  338.             $data = ['code' => 404'msg' => "Not found"];
  339.             $jsonContent $serializer->serialize($data'json');
  340.             $response = new Response($jsonContent404$this->headers);
  341.             return $response;
  342.         }
  343.         if (!$mobileParentAppAccount->getIsEnabled()) {
  344.             $data = ['code' => 403'msg' => "Account desable"];
  345.             $jsonContent $serializer->serialize($data'json');
  346.             $response = new Response($jsonContent403$this->headers);
  347.             return $response;
  348.         }
  349.         $plainPass strtoupper($this->randomPassword());
  350.         $mobileParentAppAccount->setPassword(md5($plainPass));
  351.         $mobileParentAppAccount->setToken(md5('-1'));
  352.         try {
  353.             $entityManager->flush();
  354.             return $this->json(['code' => 200'message' => "Mot de passe réinitialisé :)"'newPass' => $plainPass], 200);
  355.         } catch (\Throwable $th) {
  356.             $data = ['code' => 500'msg' => "Server error"];
  357.             $jsonContent $serializer->serialize($data'json');
  358.             $response = new Response($jsonContent500$this->headers);
  359.             return $response;
  360.         }
  361.         $data = ['code' => 200'msg' => "success"];
  362.         $jsonContent $serializer->serialize($data'json');
  363.         $response = new Response($jsonContent200$this->headers);
  364.         
  365.         return $response;
  366.     }
  367.     /**
  368.      * @Route("/student-payments/{id}", name="online_api_v1_parent_student_payments")
  369.     */
  370.     public function student_payments(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositorySchoolYearRepository $schoolYearRepositoryRegistrationStudentRegistration $registrationStudentRegistration): Response
  371.     {
  372.         $token $request->headers->get('token');
  373.         $encoders = [new JsonEncoder()];
  374.         $normalizer = [new ObjectNormalizer()];
  375.         $serializer = new Serializer($normalizer$encoders);
  376.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  377.         if (null == $mobileParentAppAccount) {
  378.             $data = ['code' => 403'msg' => "Access denied"];
  379.             $jsonContent $serializer->serialize($data'json');
  380.             $response = new Response($jsonContent403$this->headers);
  381.             return $response;
  382.         }
  383.         if (!$mobileParentAppAccount->getIsEnabled()) {
  384.             $data = ['code' => 403'msg' => "Account desable"];
  385.             $jsonContent $serializer->serialize($data'json');
  386.             $response = new Response($jsonContent403$this->headers);
  387.             return $response;
  388.         }
  389.         if (!$mobileParentAppAccount->isTokenValid()) {
  390.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  391.             $jsonContent $serializer->serialize($data'json');
  392.             $response = new Response($jsonContent403$this->headers);
  393.             return $response;
  394.         }
  395.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  396.             $data = ['code' => 404'msg' => "Elève introuvable"];
  397.             $jsonContent $serializer->serialize($data'json');
  398.             $response = new Response($jsonContent404$this->headers);
  399.             return $response;
  400.         }
  401.         $studentPayments = new ArrayCollection();
  402.         foreach ($registrationStudentRegistration->getAccountingStudentRegistrationPayments() as $key => $accountingStudentRegistrationPayment) {
  403.             $studentPayments->add([
  404.                 'id' => $accountingStudentRegistrationPayment->getId(),
  405.                 'code' => $accountingStudentRegistrationPayment->getCode(),
  406.                 'createDate' => $accountingStudentRegistrationPayment->getCreateAt()->format('d/m/Y'),
  407.                 'amount' => $accountingStudentRegistrationPayment->getAmount(),
  408.             ]);
  409.         }
  410.         //workflow
  411.         $entityManager $this->getDoctrine()->getManager();
  412.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  413.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  414.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  415.         $mobileParentAppAccountActivity->setType("Finances");
  416.         $mobileParentAppAccountActivity->setDescription("Paiement");
  417.         $entityManager->persist($mobileParentAppAccountActivity);
  418.         try {
  419.             $entityManager->flush();
  420.         } catch (\Throwable $th) {
  421.             //throw $th;
  422.         }
  423.         $data = ['code' => 200'msg' => "success"'studentPayments' => $studentPayments];
  424.         $jsonContent $serializer->serialize($data'json');
  425.         $response = new Response($jsonContent200$this->headers);
  426.         
  427.         return $response;
  428.     }
  429.     /**
  430.      * @Route("/student-fees/{id}", name="online_api_v1_parent_student_fees")
  431.     */
  432.     public function student_fees(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositorySchoolYearRepository $schoolYearRepositoryRegistrationStudentRegistration $registrationStudentRegistration): Response
  433.     {
  434.         $token $request->headers->get('token');
  435.         $encoders = [new JsonEncoder()];
  436.         $normalizer = [new ObjectNormalizer()];
  437.         $serializer = new Serializer($normalizer$encoders);
  438.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  439.         if (null == $mobileParentAppAccount) {
  440.             $data = ['code' => 403'msg' => "Access denied"];
  441.             $jsonContent $serializer->serialize($data'json');
  442.             $response = new Response($jsonContent403$this->headers);
  443.             return $response;
  444.         }
  445.         if (!$mobileParentAppAccount->getIsEnabled()) {
  446.             $data = ['code' => 403'msg' => "Account desable"];
  447.             $jsonContent $serializer->serialize($data'json');
  448.             $response = new Response($jsonContent403$this->headers);
  449.             return $response;
  450.         }
  451.         if (!$mobileParentAppAccount->isTokenValid()) {
  452.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  453.             $jsonContent $serializer->serialize($data'json');
  454.             $response = new Response($jsonContent403$this->headers);
  455.             return $response;
  456.         }
  457.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  458.             $data = ['code' => 404'msg' => "Elève introuvable"];
  459.             $jsonContent $serializer->serialize($data'json');
  460.             $response = new Response($jsonContent404$this->headers);
  461.             return $response;
  462.         }
  463.         $studentFees = new ArrayCollection();
  464.         
  465.         foreach ($registrationStudentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
  466.             $studentFeeSheduls = new ArrayCollection();
  467.             foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
  468.                 $studentFeeSheduls->add([
  469.                     'id' => $accountingStudentRegistrationFeeShedul->getId(),
  470.                     'amount' => $accountingStudentRegistrationFeeShedul->getAmount(),
  471.                     'amountPaid' => $accountingStudentRegistrationFeeShedul->getAmountPaid(),
  472.                     'amountCancel' => $accountingStudentRegistrationFeeShedul->getAmountCancel(),
  473.                     'amountRest' => $accountingStudentRegistrationFeeShedul->getAmountRest(),
  474.                     'dateDue' => $accountingStudentRegistrationFeeShedul->getDateDue()->format('d/m/Y'),
  475.                 ]);
  476.             }
  477.             $studentFees->add([
  478.                 'id' => $accountingStudentRegistrationFee->getId(),
  479.                 'code' => $accountingStudentRegistrationFee->getCode(),
  480.                 'label' => $accountingStudentRegistrationFee->getLabel(),
  481.                 'amount' => $accountingStudentRegistrationFee->getAmount(),
  482.                 'amountPaid' => $accountingStudentRegistrationFee->getAmountPaid(),
  483.                 'amountCancel' => $accountingStudentRegistrationFee->getAmountCancel(),
  484.                 'amountRest' => $accountingStudentRegistrationFee->getAmountRest(),
  485.                 'amountDueToDay' => $accountingStudentRegistrationFee->getAmountDueAt(new DateTimeImmutable()),
  486.                 'studentFeeSheduls' => $studentFeeSheduls,
  487.             ]);
  488.         }
  489.         //workflow
  490.         $entityManager $this->getDoctrine()->getManager();
  491.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  492.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  493.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  494.         $mobileParentAppAccountActivity->setType("Finances");
  495.         $mobileParentAppAccountActivity->setDescription("Frais");
  496.         $entityManager->persist($mobileParentAppAccountActivity);
  497.         try {
  498.             $entityManager->flush();
  499.         } catch (\Throwable $th) {
  500.             //throw $th;
  501.         }
  502.         $data = ['code' => 200'msg' => "success"'studentFees' => $studentFees];
  503.         $jsonContent $serializer->serialize($data'json');
  504.         $response = new Response($jsonContent200$this->headers);
  505.         
  506.         return $response;
  507.     }
  508.     /**
  509.      * @Route("/student-balance/{id}", name="online_api_v1_parent_student_balance")
  510.     */
  511.     public function student_balance(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositorySchoolYearRepository $schoolYearRepositoryRegistrationStudentRegistration $registrationStudentRegistration): Response
  512.     {
  513.         $token $request->headers->get('token');
  514.         $encoders = [new JsonEncoder()];
  515.         $normalizer = [new ObjectNormalizer()];
  516.         $serializer = new Serializer($normalizer$encoders);
  517.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  518.         if (null == $mobileParentAppAccount) {
  519.             $data = ['code' => 403'msg' => "Access denied"];
  520.             $jsonContent $serializer->serialize($data'json');
  521.             $response = new Response($jsonContent403$this->headers);
  522.             return $response;
  523.         }
  524.         if (!$mobileParentAppAccount->getIsEnabled()) {
  525.             $data = ['code' => 403'msg' => "Account desable"];
  526.             $jsonContent $serializer->serialize($data'json');
  527.             $response = new Response($jsonContent403$this->headers);
  528.             return $response;
  529.         }
  530.         if (!$mobileParentAppAccount->isTokenValid()) {
  531.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  532.             $jsonContent $serializer->serialize($data'json');
  533.             $response = new Response($jsonContent403$this->headers);
  534.             return $response;
  535.         }
  536.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  537.             $data = ['code' => 404'msg' => "Student not found"];
  538.             $jsonContent $serializer->serialize($data'json');
  539.             $response = new Response($jsonContent404$this->headers);
  540.             return $response;
  541.         }
  542.         $studentBalance = [
  543.             'id' => $registrationStudentRegistration->getId(),
  544.             'amount' => $registrationStudentRegistration->getGleAmount(),
  545.             'amountPaid' => $registrationStudentRegistration->getAmountPaid(),
  546.             'amountCancel' => $registrationStudentRegistration->getAmountCancel(),
  547.             'amountRest' => $registrationStudentRegistration->getAmountRest(),
  548.             'amountDueToDay' => $registrationStudentRegistration->getAmountDueAt(new DateTimeImmutable()),
  549.         ];
  550.         //workflow
  551.         $entityManager $this->getDoctrine()->getManager();
  552.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  553.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  554.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  555.         $mobileParentAppAccountActivity->setType("Finances");
  556.         $mobileParentAppAccountActivity->setDescription("Solde");
  557.         $entityManager->persist($mobileParentAppAccountActivity);
  558.         try {
  559.             $entityManager->flush();
  560.         } catch (\Throwable $th) {
  561.             //throw $th;
  562.         }
  563.         
  564.         $data = ['code' => 200'msg' => "success"'studentBalance' => $studentBalance];
  565.         $jsonContent $serializer->serialize($data'json');
  566.         $response = new Response($jsonContent200$this->headers);
  567.         
  568.         return $response;
  569.     }
  570.     /**
  571.      * @Route("/student-averages/{id}", name="online_api_v1_parent_student_averages")
  572.     */
  573.     public function student_averages(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationSchoolYearPeriodeRepository $schoolYearPeriodeRepositorySchoolMatterRepository $schoolMatterRepositorySchoolStudentAverageRepository $schoolStudentAverageRepository): Response
  574.     {
  575.         $token $request->headers->get('token');
  576.         $encoders = [new JsonEncoder()];
  577.         $normalizer = [new ObjectNormalizer()];
  578.         $serializer = new Serializer($normalizer$encoders);
  579.         /* authentification et authorisation*/
  580.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  581.         if (null == $mobileParentAppAccount) {
  582.             $data = ['code' => 403'msg' => "Access denied"];
  583.             $jsonContent $serializer->serialize($data'json');
  584.             $response = new Response($jsonContent403$this->headers);
  585.             return $response;
  586.         }
  587.         if (!$mobileParentAppAccount->getIsEnabled()) {
  588.             $data = ['code' => 403'msg' => "Account desable"];
  589.             $jsonContent $serializer->serialize($data'json');
  590.             $response = new Response($jsonContent403$this->headers);
  591.             return $response;
  592.         }
  593.         if (!$mobileParentAppAccount->isTokenValid()) {
  594.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  595.             $jsonContent $serializer->serialize($data'json');
  596.             $response = new Response($jsonContent403$this->headers);
  597.             return $response;
  598.         }
  599.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  600.             $data = ['code' => 404'msg' => "Student not found"];
  601.             $jsonContent $serializer->serialize($data'json');
  602.             $response = new Response($jsonContent404$this->headers);
  603.             return $response;
  604.         }
  605.         /* ---- authentification et authorisation---- */
  606.         $schoolYearPeriodes $schoolYearPeriodeRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $registrationStudentRegistration->getSchoolYear()], ['begin_at' => 'ASC']);
  607.         $schoolMatters $schoolMatterRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'level' => $registrationStudentRegistration->getClassroom()->getLevel()], ['label' => 'ASC']);
  608.         $studentAverages = new ArrayCollection();
  609.         foreach ($schoolYearPeriodes as $key => $schoolYearPeriode) {
  610.             $matters = new ArrayCollection();
  611.             foreach ($schoolMatters as $key => $schoolMatter) {
  612.                 if (!$schoolMatter->getIsTestMatter()) {
  613.                     $averages = new ArrayCollection();
  614.                     foreach ($schoolStudentAverageRepository->findBy(['registrationStudentRegistration' => $registrationStudentRegistration'matter' => $schoolMatter'schoolYearPeriode' => $schoolYearPeriode], []) as $key => $schoolStudentAverage) {
  615.                         if ($schoolStudentAverage->getSchoolAverage()->getIsValidated()) {
  616.                             if (null != $schoolStudentAverage->getSubMatter()) {
  617.                                 $averages->add([
  618.                                     'label' => $schoolStudentAverage->getSchoolAverage()->getLabel(). ' - ' .$schoolStudentAverage->getSubMatter()->getLabel(),
  619.                                     'notedOn' => $schoolStudentAverage->getNoteOn(),
  620.                                     'note' => $schoolStudentAverage->getNote() < 999 $schoolStudentAverage->getNote() : 'NC',
  621.                                     'createDate' => $schoolStudentAverage->getCreatedAt()->format('d/m/Y'),
  622.                                 ]);
  623.                             }else {
  624.                                 $averages->add([
  625.                                     'label' => $schoolStudentAverage->getSchoolAverage()->getLabel(),
  626.                                     'notedOn' => $schoolStudentAverage->getNoteOn(),
  627.                                     'note' => $schoolStudentAverage->getNote() < 999 $schoolStudentAverage->getNote() : 'NC',
  628.                                     'createDate' => $schoolStudentAverage->getCreatedAt()->format('d/m/Y'),
  629.                                 ]);
  630.                             }
  631.                         }
  632.                     }
  633.                     if (count($averages) > 0) {
  634.                         $matters->add([
  635.                             'label' => $schoolMatter->getLabel(),
  636.                             'averages' => $averages
  637.                         ]);
  638.                     }
  639.                     
  640.                 }
  641.             }
  642.             
  643.             if (count($matters) > 0) {
  644.                 $studentAverages->add([
  645.                     'label' => $schoolYearPeriode->getLabel(),
  646.                     'matters' => $matters
  647.                 ]);
  648.             }
  649.         }
  650.         //workflow
  651.         $entityManager $this->getDoctrine()->getManager();
  652.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  653.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  654.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  655.         $mobileParentAppAccountActivity->setType("Centre d'étude");
  656.         $mobileParentAppAccountActivity->setDescription("Notes");
  657.         $entityManager->persist($mobileParentAppAccountActivity);
  658.         try {
  659.             $entityManager->flush();
  660.         } catch (\Throwable $th) {
  661.             //throw $th;
  662.         }
  663.         $data = ['code' => 200'msg' => "success"'studentAverages' => $studentAverages];
  664.         $jsonContent $serializer->serialize($data'json');
  665.         $response = new Response($jsonContent200$this->headers);
  666.         
  667.         return $response;
  668.     }
  669.     /**
  670.      * @Route("/student-timesheets/{id}", name="online_api_v1_parent_student_timesheets")
  671.     */
  672.     public function student_timesheet(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationSchoolWorkingTimeHourLessonRepository $schoolWorkingTimeHourLessonRepository): Response
  673.     {
  674.         $token $request->headers->get('token');
  675.         $encoders = [new JsonEncoder()];
  676.         $normalizer = [new ObjectNormalizer()];
  677.         $serializer = new Serializer($normalizer$encoders);
  678.         /* authentification et authorisation*/
  679.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  680.         if (null == $mobileParentAppAccount) {
  681.             $data = ['code' => 403'msg' => "Access denied"];
  682.             $jsonContent $serializer->serialize($data'json');
  683.             $response = new Response($jsonContent403$this->headers);
  684.             return $response;
  685.         }
  686.         if (!$mobileParentAppAccount->getIsEnabled()) {
  687.             $data = ['code' => 403'msg' => "Account desable"];
  688.             $jsonContent $serializer->serialize($data'json');
  689.             $response = new Response($jsonContent403$this->headers);
  690.             return $response;
  691.         }
  692.         if (!$mobileParentAppAccount->isTokenValid()) {
  693.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  694.             $jsonContent $serializer->serialize($data'json');
  695.             $response = new Response($jsonContent403$this->headers);
  696.             return $response;
  697.         }
  698.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  699.             $data = ['code' => 404'msg' => "Student not found"];
  700.             $jsonContent $serializer->serialize($data'json');
  701.             $response = new Response($jsonContent404$this->headers);
  702.             return $response;
  703.         }
  704.         /* ---- authentification et authorisation---- */
  705.         $studentWorkingTimes = new ArrayCollection();
  706.         for ($i 0$i 6$i++) {
  707.             $timeHours = new ArrayCollection(); 
  708.             $schoolWorkingTimeHourLessons $schoolWorkingTimeHourLessonRepository->createQueryBuilder('entity')
  709.             ->innerJoin('entity.settingTimeTable''settingTimeTable')
  710.             ->addSelect('settingTimeTable')
  711.             ->andWhere('entity.schoolYear = :schoolYear')
  712.             ->setParameter('schoolYear'$registrationStudentRegistration->getSchoolYear())
  713.             ->andWhere('entity.settingClassroom = :settingClassroom')
  714.             ->setParameter('settingClassroom'$registrationStudentRegistration->getClassroom())
  715.             ->andWhere('entity.day = :day')
  716.             ->setParameter('day'SchoolWorkingTime::COURS_DAYS[$i])
  717.             ->orderBy('settingTimeTable.label''ASC')
  718.             ->getQuery()
  719.             ->getResult();
  720.             foreach ($schoolWorkingTimeHourLessons as $key => $schoolWorkingTimeHourLesson) {
  721.                 if (null != $schoolWorkingTimeHourLesson->getSchoolMatter()) {
  722.                     $timeHours->add(
  723.                         [
  724.                             'matter' => $schoolWorkingTimeHourLesson->getSchoolMatter()->getLabel(),
  725.                             'timeTable' => $schoolWorkingTimeHourLesson->getSettingTimeTable()->getLabel(),
  726.                             'room' => $schoolWorkingTimeHourLesson->getSettingRoom() ? $schoolWorkingTimeHourLesson->getSettingRoom()->getLabel() : 'NON DEFINI',
  727.                             'teacher' => $schoolWorkingTimeHourLesson->getSchoolTeacher() ? $schoolWorkingTimeHourLesson->getSchoolTeacher()->getName() : 'NON DEFINI',
  728.                         ]
  729.                     );
  730.                 }
  731.             }
  732.             $studentWorkingTimes->add(
  733.                 [
  734.                     'day' => SchoolWorkingTime::COURS_DAYS[$i],
  735.                     'timeHours' => $timeHours,
  736.                 ]
  737.             );
  738.         }
  739.         //workflow
  740.         $entityManager $this->getDoctrine()->getManager();
  741.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  742.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  743.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  744.         $mobileParentAppAccountActivity->setType("Centre d'étude");
  745.         $mobileParentAppAccountActivity->setDescription("Emploi du temps");
  746.         $entityManager->persist($mobileParentAppAccountActivity);
  747.         try {
  748.             $entityManager->flush();
  749.         } catch (\Throwable $th) {
  750.             //throw $th;
  751.         }
  752.         $data = ['code' => 200'msg' => "success"'studentWorkingTimes' => $studentWorkingTimes];
  753.         $jsonContent $serializer->serialize($data'json');
  754.         $response = new Response($jsonContent200$this->headers);
  755.         
  756.         return $response;
  757.     }
  758.     /**
  759.      * @Route("/student-absences/{id}", name="online_api_v1_parent_student_absences")
  760.     */
  761.     public function student_absences(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationSchoolTeacherCallSheetLineRepository $schoolTeacherCallSheetLineRepositorySchoolYearPeriodeRepository $schoolYearPeriodeRepository): Response
  762.     {
  763.         $token $request->headers->get('token');
  764.         $encoders = [new JsonEncoder()];
  765.         $normalizer = [new ObjectNormalizer()];
  766.         $serializer = new Serializer($normalizer$encoders);
  767.         /* authentification et authorisation*/
  768.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  769.         if (null == $mobileParentAppAccount) {
  770.             $data = ['code' => 403'msg' => "Access denied"];
  771.             $jsonContent $serializer->serialize($data'json');
  772.             $response = new Response($jsonContent403$this->headers);
  773.             return $response;
  774.         }
  775.         if (!$mobileParentAppAccount->getIsEnabled()) {
  776.             $data = ['code' => 403'msg' => "Account desable"];
  777.             $jsonContent $serializer->serialize($data'json');
  778.             $response = new Response($jsonContent403$this->headers);
  779.             return $response;
  780.         }
  781.         if (!$mobileParentAppAccount->isTokenValid()) {
  782.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  783.             $jsonContent $serializer->serialize($data'json');
  784.             $response = new Response($jsonContent403$this->headers);
  785.             return $response;
  786.         }
  787.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  788.             $data = ['code' => 404'msg' => "Student not found"];
  789.             $jsonContent $serializer->serialize($data'json');
  790.             $response = new Response($jsonContent404$this->headers);
  791.             return $response;
  792.         }
  793.         /* ---- authentification et authorisation---- */
  794.         $schoolYearPeriodes $schoolYearPeriodeRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $registrationStudentRegistration->getSchoolYear()], ['begin_at' => 'ASC']);
  795.         $periodAbsences = new ArrayCollection();
  796.         foreach ($schoolYearPeriodes as $key => $schoolYearPeriode) {
  797.             $absences = new ArrayCollection();
  798.             $_schoolTeacherCallSheetLines $schoolTeacherCallSheetLineRepository->createQueryBuilder('entity')
  799.             ->andWhere('entity.registrationStudentRegistration = :registrationStudentRegistration')
  800.             ->setParameter('registrationStudentRegistration'$registrationStudentRegistration)
  801.             ->innerJoin('entity.schoolTeacherCallSheet''schoolTeacherCallSheet')
  802.             ->addSelect('schoolTeacherCallSheet')
  803.             ->andWhere('schoolTeacherCallSheet.create_date BETWEEN :dateStart AND :dateEnd')
  804.             ->setParameter('dateStart'$schoolYearPeriode->getBeginAt())
  805.             ->setParameter('dateEnd'$schoolYearPeriode->getEndAt())
  806.             ->andWhere('entity.is_presente = :is_presente')
  807.             ->setParameter('is_presente'0)
  808.             ->andWhere('entity.is_absent = :is_absent')
  809.             ->setParameter('is_absent'1)
  810.             ->orderBy('entity.id''DESC')
  811.             ->getQuery()
  812.             ->getResult();
  813.             foreach ($_schoolTeacherCallSheetLines as $key => $_schoolTeacherCallSheetLine) {
  814.                 if ($_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getIsValidated()) {
  815.                     $absences->add([
  816.                         'createDate' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getCreateDate()->format('d/m/Y'),
  817.                         'matter' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getSchoolMatter()->getLabel(),
  818.                         'teacher' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getSchoolTeacher()->getName(),
  819.                         'timeTable' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getSettingTimeTable()->getLabel(),
  820.                         'day' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getDay(),
  821.                     ]);
  822.                 }
  823.             }
  824.             $periodAbsences->add([
  825.                 'schoolYearPeriode' => $schoolYearPeriode->getLabel(),
  826.                 'absences' => $absences
  827.             ]);
  828.         }
  829.         //workflow
  830.         $entityManager $this->getDoctrine()->getManager();
  831.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  832.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  833.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  834.         $mobileParentAppAccountActivity->setType("Centre d'étude");
  835.         $mobileParentAppAccountActivity->setDescription("Absences");
  836.         $entityManager->persist($mobileParentAppAccountActivity);
  837.         try {
  838.             $entityManager->flush();
  839.         } catch (\Throwable $th) {
  840.             //throw $th;
  841.         }
  842.         $data = ['code' => 200'msg' => "success"'periodAbsences' => $periodAbsences];
  843.         $jsonContent $serializer->serialize($data'json');
  844.         $response = new Response($jsonContent200$this->headers);
  845.         
  846.         return $response;
  847.     }
  848.     /**
  849.      * @Route("/student-report-cards/{id}", name="online_api_v1_parent_student_report_cards")
  850.     */
  851.     public function student_report_cards(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationSchoolReportCardRepository $schoolReportCardRepositorySchoolYearPeriodeRepository $schoolYearPeriodeRepository): Response
  852.     {
  853.         $token $request->headers->get('token');
  854.         $encoders = [new JsonEncoder()];
  855.         $normalizer = [new ObjectNormalizer()];
  856.         $serializer = new Serializer($normalizer$encoders);
  857.         /* authentification et authorisation*/
  858.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  859.         if (null == $mobileParentAppAccount) {
  860.             $data = ['code' => 403'msg' => "Access denied"];
  861.             $jsonContent $serializer->serialize($data'json');
  862.             $response = new Response($jsonContent403$this->headers);
  863.             return $response;
  864.         }
  865.         if (!$mobileParentAppAccount->getIsEnabled()) {
  866.             $data = ['code' => 403'msg' => "Account desable"];
  867.             $jsonContent $serializer->serialize($data'json');
  868.             $response = new Response($jsonContent403$this->headers);
  869.             return $response;
  870.         }
  871.         if (!$mobileParentAppAccount->isTokenValid()) {
  872.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  873.             $jsonContent $serializer->serialize($data'json');
  874.             $response = new Response($jsonContent403$this->headers);
  875.             return $response;
  876.         }
  877.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  878.             $data = ['code' => 404'msg' => "Student not found"];
  879.             $jsonContent $serializer->serialize($data'json');
  880.             $response = new Response($jsonContent404$this->headers);
  881.             return $response;
  882.         }
  883.         /* ---- authentification et authorisation---- */
  884.         $schoolYearPeriodes = new ArrayCollection();
  885.         foreach ($schoolYearPeriodeRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $registrationStudentRegistration->getSchoolYear()], ['begin_at' => 'ASC']) as $key => $schoolYearPeriode) {
  886.             $studentReportCards = new ArrayCollection();
  887.             foreach ($schoolReportCardRepository->findBy(['studentRegistration' => $registrationStudentRegistration'schoolYearPeriode' => $schoolYearPeriode], []) as $key => $schoolReportCard) {
  888.                 if ($schoolReportCard->getIsValidated()) {
  889.                     $studentAverageReportCards = new ArrayCollection();
  890.                     foreach ($schoolReportCard->getSchoolAverageReportCards() as $key => $schoolAverageReportCard) {
  891.                         $studentAverageReportCards->add([
  892.                             'matter' => $schoolAverageReportCard->getMatter()->getLabel(),
  893.                             'average' => $schoolAverageReportCard->getAverage() < 999 $schoolAverageReportCard->getAverage() : 'NC',
  894.                             'rank' => $schoolAverageReportCard->getAverage() < 999 $schoolAverageReportCard->getRank() : 'NC',
  895.                             'notedOn' => $schoolAverageReportCard->getNoteOn(),
  896.                             'coefficient' => $schoolAverageReportCard->getCoefficient(),
  897.                             'coefficientXAverage' => $schoolAverageReportCard->getCoefficientXAverage(),
  898.                         ]);
  899.                     }
  900.                     $studentReportCards->add([
  901.                         'label' => $schoolReportCard->getLabel(),
  902.                         'studentAverageReportCards' => $studentAverageReportCards,
  903.                         'rank' => $schoolReportCard->getIsUnclassified() ? 'NC' $schoolReportCard->getRank(),
  904.                         'average' => $schoolReportCard->getIsUnclassified() ? 'NC' round($schoolReportCard->getReportCardAverage(), 2PHP_ROUND_HALF_DOWN),
  905.                         'effective' => count($schoolReportCard->getClassroom()->getRegistereds($schoolReportCard->getSchoolYear())),
  906.                     ]);
  907.                 }
  908.             }
  909.             if (count($studentReportCards) > 0) {
  910.                 $schoolYearPeriodes->add([
  911.                     'label' => $schoolYearPeriode->getLabel(),
  912.                     'studentReportCards' => $studentReportCards
  913.                 ]);
  914.             }
  915.         }
  916.         //workflow
  917.         $entityManager $this->getDoctrine()->getManager();
  918.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  919.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  920.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  921.         $mobileParentAppAccountActivity->setType("Centre d'étude");
  922.         $mobileParentAppAccountActivity->setDescription("Bulletins");
  923.         $entityManager->persist($mobileParentAppAccountActivity);
  924.         try {
  925.             $entityManager->flush();
  926.         } catch (\Throwable $th) {
  927.             //throw $th;
  928.         }
  929.         $data = ['code' => 200'msg' => "success"'schoolYearPeriodes' => $schoolYearPeriodes];
  930.         $jsonContent $serializer->serialize($data'json');
  931.         $response = new Response($jsonContent200$this->headers);
  932.         
  933.         return $response;
  934.     }
  935.     /**
  936.      * @Route("/student-information/{id}", name="online_api_v1_parent_student_information")
  937.     */
  938.     public function student_information(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistration): Response
  939.     {
  940.         $token $request->headers->get('token');
  941.         $encoders = [new JsonEncoder()];
  942.         $normalizer = [new ObjectNormalizer()];
  943.         $serializer = new Serializer($normalizer$encoders);
  944.         /* authentification et authorisation*/
  945.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  946.         if (null == $mobileParentAppAccount) {
  947.             $data = ['code' => 403'msg' => "Access denied"];
  948.             $jsonContent $serializer->serialize($data'json');
  949.             $response = new Response($jsonContent403$this->headers);
  950.             return $response;
  951.         }
  952.         if (!$mobileParentAppAccount->getIsEnabled()) {
  953.             $data = ['code' => 403'msg' => "Account desable"];
  954.             $jsonContent $serializer->serialize($data'json');
  955.             $response = new Response($jsonContent403$this->headers);
  956.             return $response;
  957.         }
  958.         if (!$mobileParentAppAccount->isTokenValid()) {
  959.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  960.             $jsonContent $serializer->serialize($data'json');
  961.             $response = new Response($jsonContent403$this->headers);
  962.             return $response;
  963.         }
  964.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  965.             $data = ['code' => 404'msg' => "Student not found"];
  966.             $jsonContent $serializer->serialize($data'json');
  967.             $response = new Response($jsonContent404$this->headers);
  968.             return $response;
  969.         }
  970.         /* ---- authentification et authorisation---- */
  971.         
  972.         $student = [
  973.             'registrationNumber' => $registrationStudentRegistration->getStudent()->getRegistrationNumber() != "AUCUN" $registrationStudentRegistration->getStudent()->getRegistrationNumber() : $registrationStudentRegistration->getStudent()->getCode(),
  974.             'lastName' => $registrationStudentRegistration->getStudent()->getLastName(),
  975.             'firstName' => $registrationStudentRegistration->getStudent()->getFirstName(),
  976.             'birthday' => $registrationStudentRegistration->getStudent()->getBirthday()->format('d/m/Y'),
  977.             'birthLocation' => $registrationStudentRegistration->getStudent()->getBirthLocation(),
  978.             'birthCertificateNumber' => $registrationStudentRegistration->getStudent()->getBirthCertificateNumber(),
  979.             'lv2' => $registrationStudentRegistration->getStudent()->getLv2(),
  980.             'gender' => $registrationStudentRegistration->getStudent()->getGender(),
  981.             'nationality' => $registrationStudentRegistration->getStudent()->getNationality(),
  982.             'fatherName' => $registrationStudentRegistration->getStudent()->getFatherLastName(). ' ' .$registrationStudentRegistration->getStudent()->getFatherFirstName(),
  983.             'motherName' => $registrationStudentRegistration->getStudent()->getMotherLastName(). ' ' .$registrationStudentRegistration->getStudent()->getMotherFirstName(),
  984.             'notificationPhoneNumber' => $registrationStudentRegistration->getStudent()->getNotificationPhoneNumber(),
  985.             'classroom' => $registrationStudentRegistration->getClassroom()->getLabel(),
  986.             'affected' => $registrationStudentRegistration->getStudent()->getIsAffected() ? 'Affecté' 'Non Affecté',
  987.             'redoubling' => $registrationStudentRegistration->getIsRedoubling() ? 'Doublant' 'Non Doublant',
  988.         ];
  989.         //workflow
  990.         $entityManager $this->getDoctrine()->getManager();
  991.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  992.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  993.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  994.         $mobileParentAppAccountActivity->setType("Autres");
  995.         $mobileParentAppAccountActivity->setDescription("Données personnelles");
  996.         $entityManager->persist($mobileParentAppAccountActivity);
  997.         try {
  998.             $entityManager->flush();
  999.         } catch (\Throwable $th) {
  1000.             //throw $th;
  1001.         }
  1002.         $data = ['code' => 200'msg' => "success"'student' => $student];
  1003.         $jsonContent $serializer->serialize($data'json');
  1004.         $response = new Response($jsonContent200$this->headers);
  1005.         
  1006.         return $response;
  1007.     }
  1008.     /**
  1009.      * @Route("/student-informations/{id}", name="online_api_v1_parent_student_informations")
  1010.     */
  1011.     public function student_informations(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationCommunicationMessageRepository $communicationMessageRepository): Response
  1012.     {
  1013.         $token $request->headers->get('token');
  1014.         $encoders = [new JsonEncoder()];
  1015.         $normalizer = [new ObjectNormalizer()];
  1016.         $serializer = new Serializer($normalizer$encoders);
  1017.         /* authentification et authorisation*/
  1018.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  1019.         if (null == $mobileParentAppAccount) {
  1020.             $data = ['code' => 403'msg' => "Access denied"];
  1021.             $jsonContent $serializer->serialize($data'json');
  1022.             $response = new Response($jsonContent403$this->headers);
  1023.             return $response;
  1024.         }
  1025.         if (!$mobileParentAppAccount->getIsEnabled()) {
  1026.             $data = ['code' => 403'msg' => "Account desable"];
  1027.             $jsonContent $serializer->serialize($data'json');
  1028.             $response = new Response($jsonContent403$this->headers);
  1029.             return $response;
  1030.         }
  1031.         if (!$mobileParentAppAccount->isTokenValid()) {
  1032.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  1033.             $jsonContent $serializer->serialize($data'json');
  1034.             $response = new Response($jsonContent403$this->headers);
  1035.             return $response;
  1036.         }
  1037.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  1038.             $data = ['code' => 404'msg' => "Student not found"];
  1039.             $jsonContent $serializer->serialize($data'json');
  1040.             $response = new Response($jsonContent404$this->headers);
  1041.             return $response;
  1042.         }
  1043.         /* ---- authentification et authorisation---- */
  1044.         $studentCommunicationMessages $communicationMessageRepository->createQueryBuilder('entity')
  1045.         ->andWhere('entity.schoolYear = :schoolYear')
  1046.         ->setParameter('schoolYear'$registrationStudentRegistration->getSchoolYear())
  1047.         ->andWhere('entity.establishment = :establishment')
  1048.         ->setParameter('establishment'$registrationStudentRegistration->getEstablishment())
  1049.         ->orderBy('entity.id''ASC')
  1050.         ->getQuery()
  1051.         ->getResult();
  1052.         $communicationMessages = new ArrayCollection();
  1053.         //dd($studentCommunicationMessages);
  1054.         foreach ($studentCommunicationMessages as $key => $studentCommunicationMessage) {
  1055.             if (in_array($registrationStudentRegistration->getStudent()->getNotificationPhoneNumber(), $studentCommunicationMessage->getContacts())) {
  1056.                 $communicationMessages->add([
  1057.                     'id' => $studentCommunicationMessage->getId(),
  1058.                     'createDate' => $studentCommunicationMessage->getCreatedAt()->format('d/m/Y'),
  1059.                     'content' => $studentCommunicationMessage->getContent(),
  1060.                 ]);
  1061.             }
  1062.         }
  1063.         //workflow
  1064.         $entityManager $this->getDoctrine()->getManager();
  1065.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  1066.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  1067.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  1068.         $mobileParentAppAccountActivity->setType("Autres");
  1069.         $mobileParentAppAccountActivity->setDescription("Informations");
  1070.         $entityManager->persist($mobileParentAppAccountActivity);
  1071.         try {
  1072.             $entityManager->flush();
  1073.         } catch (\Throwable $th) {
  1074.             //throw $th;
  1075.         }
  1076.         $data = ['code' => 200'msg' => "success"'communicationMessages' => $communicationMessages];
  1077.         $jsonContent $serializer->serialize($data'json');
  1078.         $response = new Response($jsonContent200$this->headers);
  1079.         
  1080.         return $response;
  1081.     }
  1082.     /**
  1083.      * Cette fonction permet d'afficher le menu de la cantine
  1084.      * 10/05/2025 by oumiche10@gmail.com
  1085.      * @Route("/student-cantine/{id}", name="online_api_v1_parent_student_cantine")
  1086.     */
  1087.     public function student_cantine(Request $requestCanteenMenuRepository $canteenMenuRepositoryMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationCommunicationMessageRepository $communicationMessageRepository): Response
  1088.     {
  1089.         $token $request->headers->get('token');
  1090.         $encoders = [new JsonEncoder()];
  1091.         $normalizer = [new ObjectNormalizer()];
  1092.         $serializer = new Serializer($normalizer$encoders);
  1093.         /* authentification et authorisation*/
  1094.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  1095.         if (null == $mobileParentAppAccount) {
  1096.             $data = ['code' => 403'msg' => "Access denied"];
  1097.             $jsonContent $serializer->serialize($data'json');
  1098.             $response = new Response($jsonContent403$this->headers);
  1099.             return $response;
  1100.         }
  1101.         if (!$mobileParentAppAccount->getIsEnabled()) {
  1102.             $data = ['code' => 403'msg' => "Account desable"];
  1103.             $jsonContent $serializer->serialize($data'json');
  1104.             $response = new Response($jsonContent403$this->headers);
  1105.             return $response;
  1106.         }
  1107.         if (!$mobileParentAppAccount->isTokenValid()) {
  1108.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  1109.             $jsonContent $serializer->serialize($data'json');
  1110.             $response = new Response($jsonContent403$this->headers);
  1111.             return $response;
  1112.         }
  1113.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  1114.             $data = ['code' => 404'msg' => "Student not found"];
  1115.             $jsonContent $serializer->serialize($data'json');
  1116.             $response = new Response($jsonContent404$this->headers);
  1117.             return $response;
  1118.         }
  1119.         /* ---- fin authentification et authorisation---- */
  1120.         $canteenMenus = new ArrayCollection();
  1121.         if($registrationStudentRegistration->hasCanteenFee()){
  1122.             foreach ($canteenMenuRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment()]) as $key => $canteenMenu) {
  1123.                 if ($canteenMenu->getDateStart()->format('Y-m-d') <= date('Y-m-d') && $canteenMenu->getDateEnd()->format('Y-m-d') >= date('Y-m-d')) {
  1124.                     foreach ($canteenMenu->getCanteenMenuItems() as $key => $canteenMenuItem) {
  1125.                         $canteenMenus->add([
  1126.                             'horaire' => $canteenMenuItem->getCanteenTime() ? $canteenMenuItem->getCanteenTime()->getName() : '',
  1127.                             'lun' => $canteenMenuItem->getDay1Dish() ? $canteenMenuItem->getDay1Dish()->getName() : '',
  1128.                             'mar' => $canteenMenuItem->getDay2Dish() ? $canteenMenuItem->getDay2Dish()->getName() : '',
  1129.                             'mer' => $canteenMenuItem->getDay3Dish() ? $canteenMenuItem->getDay3Dish()->getName() : '',
  1130.                             'jeu' => $canteenMenuItem->getDay4Dish() ? $canteenMenuItem->getDay4Dish()->getName() : '',
  1131.                             'ven' => $canteenMenuItem->getDay5Dish() ? $canteenMenuItem->getDay5Dish()->getName() : '',
  1132.                             'sam' => $canteenMenuItem->getDay6Dish() ? $canteenMenuItem->getDay6Dish()->getName() : '',
  1133.                             'dim' => $canteenMenuItem->getDay7Dish() ? $canteenMenuItem->getDay7Dish()->getName() : '',
  1134.                         ]);
  1135.                     }
  1136.                     
  1137.                 }
  1138.             }
  1139.         }else {
  1140.             $data = ['code' => 200'msg' => "Merci de vous abonner à la cantine"'canteenMenus' => $canteenMenus];
  1141.             $jsonContent $serializer->serialize($data'json');
  1142.             $response = new Response($jsonContent200$this->headers);
  1143.             
  1144.             return $response;
  1145.         }
  1146.         if (count($canteenMenus) <= 0) {
  1147.             $data = ['code' => 200'msg' => "Aucun menu disponible, veuillez contacter l'administration"'canteenMenus' => $canteenMenus];
  1148.             $jsonContent $serializer->serialize($data'json');
  1149.             $response = new Response($jsonContent200$this->headers);
  1150.         }
  1151.         //workflow
  1152.         $entityManager $this->getDoctrine()->getManager();
  1153.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  1154.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  1155.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  1156.         $mobileParentAppAccountActivity->setType("Autres");
  1157.         $mobileParentAppAccountActivity->setDescription("Menu cantine");
  1158.         $entityManager->persist($mobileParentAppAccountActivity);
  1159.         try {
  1160.             $entityManager->flush();
  1161.         } catch (\Throwable $th) {
  1162.             //throw $th;
  1163.         }
  1164.         $data = ['code' => 200'msg' => "Menu de la semaine"'canteenMenus' => $canteenMenus];
  1165.         $jsonContent $serializer->serialize($data'json');
  1166.         $response = new Response($jsonContent200$this->headers);
  1167.         
  1168.         return $response;
  1169.     }
  1170.     /**
  1171.      * Cette fonction permet d'afficher les information concernant le transport
  1172.      * 10/05/2025 by oumiche10@gmail.com
  1173.      * @Route("/student-transport/{id}", name="online_api_v1_parent_student_transport")
  1174.     */
  1175.     public function student_transport(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationCommunicationMessageRepository $communicationMessageRepository): Response
  1176.     {
  1177.         $token $request->headers->get('token');
  1178.         $encoders = [new JsonEncoder()];
  1179.         $normalizer = [new ObjectNormalizer()];
  1180.         $serializer = new Serializer($normalizer$encoders);
  1181.         /* authentification et authorisation*/
  1182.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  1183.         if (null == $mobileParentAppAccount) {
  1184.             $data = ['code' => 403'msg' => "Access denied"];
  1185.             $jsonContent $serializer->serialize($data'json');
  1186.             $response = new Response($jsonContent403$this->headers);
  1187.             return $response;
  1188.         }
  1189.         if (!$mobileParentAppAccount->getIsEnabled()) {
  1190.             $data = ['code' => 403'msg' => "Account desable"];
  1191.             $jsonContent $serializer->serialize($data'json');
  1192.             $response = new Response($jsonContent403$this->headers);
  1193.             return $response;
  1194.         }
  1195.         if (!$mobileParentAppAccount->isTokenValid()) {
  1196.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  1197.             $jsonContent $serializer->serialize($data'json');
  1198.             $response = new Response($jsonContent403$this->headers);
  1199.             return $response;
  1200.         }
  1201.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  1202.             $data = ['code' => 404'msg' => "Student not found"];
  1203.             $jsonContent $serializer->serialize($data'json');
  1204.             $response = new Response($jsonContent404$this->headers);
  1205.             return $response;
  1206.         }
  1207.         /* ---- fin authentification et authorisation---- */
  1208.         $transportCheckpoints = new ArrayCollection();
  1209.         if($registrationStudentRegistration->hasTransportFee()){
  1210.             foreach ($registrationStudentRegistration->getRegistrationTransportCheckpoints() as $key => $transportCheckpoint) {
  1211.                 $transportCheckpoints->add([
  1212.                     'heurepassageMatin' => $transportCheckpoint->getMorningSchedule(),
  1213.                     'heurepassageSoir' => $transportCheckpoint->getEveningSchedule(),
  1214.                     'zone' => $transportCheckpoint->getTransportZone() ? $transportCheckpoint->getTransportZone()->getName() : '',
  1215.                     'pointArret' => $transportCheckpoint->getTransportZoneCheckPoint() ? $transportCheckpoint->getTransportZoneCheckPoint()->getName() : '',
  1216.                     'immCar' => $transportCheckpoint->getTransportVehicle() ? $transportCheckpoint->getTransportVehicle()->getRegistrationNumber() : '',
  1217.                     'couleurCar' => $transportCheckpoint->getTransportVehicle() ? $transportCheckpoint->getTransportVehicle()->getColor() : '',
  1218.                     
  1219.                 ]);
  1220.             }
  1221.         }else {
  1222.             $data = ['code' => 200'msg' => "Merci de vous abonner au transport"'transportCheckpoints' => $transportCheckpoints];
  1223.             $jsonContent $serializer->serialize($data'json');
  1224.             $response = new Response($jsonContent200$this->headers);
  1225.             
  1226.             return $response;
  1227.         }
  1228.         if (count($transportCheckpoints) <= 0) {
  1229.             $data = ['code' => 200'msg' => "Aucun checkpoint disponible, veuillez contacter l'administration"'transportCheckpoints' => $transportCheckpoints];
  1230.             $jsonContent $serializer->serialize($data'json');
  1231.             $response = new Response($jsonContent200$this->headers);
  1232.         }
  1233.         //workflow
  1234.         $entityManager $this->getDoctrine()->getManager();
  1235.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  1236.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  1237.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  1238.         $mobileParentAppAccountActivity->setType("Autres");
  1239.         $mobileParentAppAccountActivity->setDescription("Menu cantine");
  1240.         $entityManager->persist($mobileParentAppAccountActivity);
  1241.         try {
  1242.             $entityManager->flush();
  1243.         } catch (\Throwable $th) {
  1244.             //throw $th;
  1245.         }
  1246.         $data = ['code' => 200'msg' => "Vos checkpoints"'transportCheckpoints' => $transportCheckpoints];
  1247.         $jsonContent $serializer->serialize($data'json');
  1248.         $response = new Response($jsonContent200$this->headers);
  1249.         
  1250.         return $response;
  1251.     }
  1252.     /**
  1253.      * Cette fonction permet d'envoyer le formulaire de contact
  1254.      * 10/05/2025 by oumiche10@gmail.com
  1255.      * @Route("/student-contact/{id}", name="online_api_v1_parent_student_contact")
  1256.     */
  1257.     public function student_contact(Request $requestValidatorInterface $validatorMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistrationCommunicationMessageRepository $communicationMessageRepository): Response
  1258.     {
  1259.         $token $request->headers->get('token');
  1260.         $encoders = [new JsonEncoder()];
  1261.         $normalizer = [new ObjectNormalizer()];
  1262.         $serializer = new Serializer($normalizer$encoders);
  1263.         /* authentification et authorisation*/
  1264.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  1265.         if (null == $mobileParentAppAccount) {
  1266.             $data = ['code' => 403'msg' => "Access denied"];
  1267.             $jsonContent $serializer->serialize($data'json');
  1268.             $response = new Response($jsonContent403$this->headers);
  1269.             return $response;
  1270.         }
  1271.         if (!$mobileParentAppAccount->getIsEnabled()) {
  1272.             $data = ['code' => 403'msg' => "Account desable"];
  1273.             $jsonContent $serializer->serialize($data'json');
  1274.             $response = new Response($jsonContent403$this->headers);
  1275.             return $response;
  1276.         }
  1277.         if (!$mobileParentAppAccount->isTokenValid()) {
  1278.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  1279.             $jsonContent $serializer->serialize($data'json');
  1280.             $response = new Response($jsonContent403$this->headers);
  1281.             return $response;
  1282.         }
  1283.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  1284.             $data = ['code' => 404'msg' => "Student not found"];
  1285.             $jsonContent $serializer->serialize($data'json');
  1286.             $response = new Response($jsonContent404$this->headers);
  1287.             return $response;
  1288.         }
  1289.         /* ---- fin authentification et authorisation---- */
  1290.         $data json_decode($request->getContent(), true);
  1291.         
  1292.         $contact = new RegistrationStudentContact();
  1293.         $contact->setRegistrationStudentRegistration($registrationStudentRegistration);
  1294.         $contact->setEstablishment($registrationStudentRegistration->getEstablishment());
  1295.         $contact->setName($data['name'] ?? '');
  1296.         $contact->setSubject($data['subject'] ?? '');
  1297.         $contact->setPhone($data['phone'] ?? $registrationStudentRegistration->getStudent()->getNotificationPhoneNumber());
  1298.         $contact->setMessage($data['message'] ?? '');
  1299.         $errors $validator->validate($contact);
  1300.         
  1301.         if (count($errors) > 0) {
  1302.             $errorMessages = [];
  1303.             foreach ($errors as $error) {
  1304.                 $errorMessages[$error->getPropertyPath()] = $error->getMessage();
  1305.             }
  1306.             $data = ['code' => 500'msg' => "Echec les information renseigné ne sont pas valide!"];
  1307.             $jsonContent $serializer->serialize($data'json');
  1308.             $response = new Response($jsonContent500$this->headers);
  1309.         }
  1310.         $entityManager $this->getDoctrine()->getManager();
  1311.         // Ici vous pourriez envoyer un email ou sauvegarder en base
  1312.         $entityManager->persist($contact);
  1313.         try {
  1314.             $entityManager->flush(); 
  1315.         } catch (\Throwable $th) {
  1316.             $data = ['code' => 500'msg' => $th->getMessage()];
  1317.             $jsonContent $serializer->serialize($data'json');
  1318.             $response = new Response($jsonContent500$this->headers);
  1319.         }
  1320.         $data = ['code' => 200'msg' => "Votre message a bien été envoyé. Merci!"];
  1321.         $jsonContent $serializer->serialize($data'json');
  1322.         $response = new Response($jsonContent200$this->headers);
  1323.         
  1324.         return $response;
  1325.     }
  1326.     /**
  1327.      * Cette fonction permet d'afficher les frais dus pour un élève
  1328.      * 14/05/2025 by oumiche10@gmail.com
  1329.      * @Route("/student-fees/dues/{id}", name="online_api_v1_parent_student_fees_dues")
  1330.     */
  1331.     public function student_fees_dues(Request $requestMobileParentAppAccountRepository $mobileParentAppAccountRepositoryRegistrationStudentRegistration $registrationStudentRegistration): Response
  1332.     {
  1333.         $token $request->headers->get('token');
  1334.         $encoders = [new JsonEncoder()];
  1335.         $normalizer = [new ObjectNormalizer()];
  1336.         $serializer = new Serializer($normalizer$encoders);
  1337.         $mobileParentAppAccount $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
  1338.         if (null == $mobileParentAppAccount) {
  1339.             $data = ['code' => 403'msg' => "Access denied"];
  1340.             $jsonContent $serializer->serialize($data'json');
  1341.             $response = new Response($jsonContent403$this->headers);
  1342.             return $response;
  1343.         }
  1344.         if (!$mobileParentAppAccount->getIsEnabled()) {
  1345.             $data = ['code' => 403'msg' => "Account desable"];
  1346.             $jsonContent $serializer->serialize($data'json');
  1347.             $response = new Response($jsonContent403$this->headers);
  1348.             return $response;
  1349.         }
  1350.         if (!$mobileParentAppAccount->isTokenValid()) {
  1351.             $data = ['code' => 403'msg' => "Token Invalid"'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
  1352.             $jsonContent $serializer->serialize($data'json');
  1353.             $response = new Response($jsonContent403$this->headers);
  1354.             return $response;
  1355.         }
  1356.         if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
  1357.             $data = ['code' => 404'msg' => "Elève introuvable"];
  1358.             $jsonContent $serializer->serialize($data'json');
  1359.             $response = new Response($jsonContent404$this->headers);
  1360.             return $response;
  1361.         }
  1362.         $registrationStudent $registrationStudentRegistration->getStudent(); 
  1363.         $studentFees = new ArrayCollection();
  1364.         foreach ($registrationStudent->getRegistrationStudentRegistrations() as $key => $studentRegistration) {
  1365.             //if($studentRegistration->getSchoolYear()->getId() != $registrationStudentRegistration->getSchoolYear()->getId()){
  1366.                 foreach ($studentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
  1367.                     $studentFeeSheduls = new ArrayCollection();
  1368.                     foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
  1369.                         $studentFeeSheduls->add([
  1370.                             'id' => $accountingStudentRegistrationFeeShedul->getId(),
  1371.                             'amount' => $accountingStudentRegistrationFeeShedul->getAmount(),
  1372.                             'amountPaid' => $accountingStudentRegistrationFeeShedul->getAmountPaid(),
  1373.                             'amountCancel' => $accountingStudentRegistrationFeeShedul->getAmountCancel(),
  1374.                             'amountRest' => $accountingStudentRegistrationFeeShedul->getAmountRest(),
  1375.                             'dateDue' => $accountingStudentRegistrationFeeShedul->getDateDue()->format('d/m/Y'),
  1376.                         ]);
  1377.                     }
  1378.         
  1379.                     $studentFees->add([
  1380.                         'id' => $accountingStudentRegistrationFee->getId(),
  1381.                         'schoolYear' => $studentRegistration->getSchoolYear()->getCode(),
  1382.                         'code' => $accountingStudentRegistrationFee->getCode(),
  1383.                         'label' => $accountingStudentRegistrationFee->getLabel(),
  1384.                         'amount' => $accountingStudentRegistrationFee->getAmount(),
  1385.                         'amountPaid' => $accountingStudentRegistrationFee->getAmountPaid(),
  1386.                         'amountCancel' => $accountingStudentRegistrationFee->getAmountCancel(),
  1387.                         'amountRest' => $accountingStudentRegistrationFee->getAmountRest(),
  1388.                         'amountDueToDay' => $accountingStudentRegistrationFee->getAmountDueAt(new DateTimeImmutable()),
  1389.                         'studentFeeSheduls' => $studentFeeSheduls,
  1390.                     ]);
  1391.                 }
  1392.             //}
  1393.         }
  1394.         //workflow
  1395.         $entityManager $this->getDoctrine()->getManager();
  1396.         $mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
  1397.         $mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
  1398.         $mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
  1399.         $mobileParentAppAccountActivity->setType("Finances");
  1400.         $mobileParentAppAccountActivity->setDescription("Frais");
  1401.         $entityManager->persist($mobileParentAppAccountActivity);
  1402.         try {
  1403.             $entityManager->flush();
  1404.         } catch (\Throwable $th) {
  1405.             //throw $th;
  1406.         }
  1407.         $data = ['code' => 200'msg' => "success"'studentFeesDues' => $studentFees];
  1408.         $jsonContent $serializer->serialize($data'json');
  1409.         $response = new Response($jsonContent200$this->headers);
  1410.         
  1411.         return $response;
  1412.     }
  1413.     private function randomPassword($length 4) {
  1414.         $alphabet "0123456789";
  1415.         $pass = array(); //remember to declare $pass as an array
  1416.         $alphaLength strlen($alphabet) - 1//put the length -1 in cache
  1417.         for ($i 0$i 4$i++) {
  1418.             $n rand(0$alphaLength);
  1419.             $pass[] = $alphabet[$n];
  1420.         }
  1421.         return implode($pass); //turn the array into a string
  1422.     }
  1423. }