src/Controller/MobileApp/ParentAppController.php line 1613

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