<?php
namespace App\Controller\MobileApp;
use DateTimeImmutable;
use App\Entity\SettingFee;
use App\Service\SMSSender;
use App\Entity\SchoolWorkingTime;
use App\Service\NotificationService;
use App\Repository\SchoolYearRepository;
use App\Repository\CanteenMenuRepository;
use App\Entity\RegistrationStudentContact;
use App\Repository\SchoolMatterRepository;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\MobileParentAppAccountActivity;
use App\Repository\SchoolReportCardRepository;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\RegistrationStudentRegistration;
use App\Repository\SchoolYearPeriodeRepository;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Common\Collections\ArrayCollection;
use App\Repository\CommunicationMessageRepository;
use App\Repository\SchoolStudentAverageRepository;
use App\Repository\MobileParentAppAccountRepository;
use App\Repository\RegistrationStudentRegistrationRepository;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use App\Repository\SchoolTeacherCallSheetLineRepository;
use App\Repository\SchoolWorkingTimeHourLessonRepository;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @Route("/online/api/v1/parent")
*/
class ParentAppController extends AbstractController
{
private $headers = [
'Content-Type' => 'application/json',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'POST'
];
private $authToken = '834f9d5c4639af2de6afc0e24adf556933fca38e168be527c766f81a4fd3e91e';
/**
* @Route("/auth", name="online_api_v1_parent_auth")
*/
public function auth(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, NotificationService $notificationService): Response
{
$entityManager = $this->getDoctrine()->getManager();
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$content = $request->getContent();
$contentJson = json_decode($content, true);
$username = $contentJson['username'];
$password = $contentJson['password'];
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['username' => $username], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Account not found", 'request' => $contentJson];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable", 'request' => $contentJson];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (md5($password) != $mobileParentAppAccount->getPassword()) {
$data = ['code' => 403, 'msg' => "invalid credential", 'request' => $request->request];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
$deviceToken = $request->headers->get('X-Device-Token');
$mobileParentAppAccount->setDeviceToken($deviceToken);
$mobileParentAppAccount->setLastAuthTime(time());
$mobileParentAppAccount->setToken(md5($this->randomPassword()).$mobileParentAppAccount->getId());
$userData = [
'token' => $mobileParentAppAccount->getToken(),
'_token_expire_at' => (time() + 604800),
'_time' => time(),
'last_name' => $mobileParentAppAccount->getLastName(),
'first_name' => $mobileParentAppAccount->getFirstName(),
'phone_number' => $mobileParentAppAccount->getPhoneNumber(),
'device_token' => $deviceToken,
];
$notificationResponse = $notificationService->sendNotification($deviceToken, 'Bienvenue!', 'Bienvenue sur Central Parent');
try {
$entityManager->flush();
} catch (\Throwable $th) {
$data = ['code' => 500, 'msg' => $th->getMessage()];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 500, $this->headers);
return $response;
}
$data = ['code' => 200, 'msg' => "Access Granted", 'user' => $userData, 'notificationResponse' => $notificationResponse];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/logout", name="online_api_v1_parent_logout")
*/
public function logout(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository): Response
{
$token = $request->headers->get('token');
$entityManager = $this->getDoctrine()->getManager();
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
$mobileParentAppAccount->setToken(md5('-1'));
try {
$entityManager->flush();
} catch (\Throwable $th) {}
$data = ['code' => 200, 'msg' => "logout", 'token' => '-1'];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/me", name="online_api_v1_parent_me")
* Ajouter le 12/05/2025
* Par oumiche10@gmail.com
* pour envoyer recupérer le device token
*/
public function me(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, NotificationService $notificationService): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
$deviceToken = $request->headers->get('X-Device-Token');
$notificationResponse = $notificationService->sendNotification($mobileParentAppAccount->getDeviceToken(), 'Bienvenue!', 'Bienvenue sur Central Parent');
$entityManager = $this->getDoctrine()->getManager();
try {
$deviceToken = $request->headers->get('X-Device-Token');
$mobileParentAppAccount->setDeviceToken($deviceToken);
$entityManager->flush();
} catch (\Throwable $th) {
$data = ['code' => 500, 'msg' => $th->getMessage()];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 500, $this->headers);
return $response;
}
$me = [
'id' => $mobileParentAppAccount->getId(),
'username' => $mobileParentAppAccount->getUsername(),
'firstName' => $mobileParentAppAccount->getFirstName(),
'lastName' => $mobileParentAppAccount->getLastName(),
'phoneNumber' => $mobileParentAppAccount->getPhoneNumber(),
'isEnabled' => $mobileParentAppAccount->getIsEnabled(),
'lastAuthTime' => $mobileParentAppAccount->getLastAuthTime(),
'token' => $mobileParentAppAccount->getToken(),
'deviceToken' => $deviceToken,
];
$data = ['code' => 200, 'msg' => "success", 'me' => $me, 'notificationResponse' => $notificationResponse];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/abonnements", name="online_api_v1_parent_abonnements")
* modifier pour afficher les 3 dernières années scolaires
* par oumiche10@gmail.com
* le 12/05/2025
*/
public function abonnements(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, SchoolYearRepository $schoolYearRepository, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
{
$schoolYear = $schoolYearRepository->findOneBy(['is_ongoing' => 1, 'is_archived' => 0], []);
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
$registrationStudents = $mobileParentAppAccount->getRegistrationStudents();
$abonnements = new ArrayCollection();
//foreach ($registrationStudents as $key => $registrationStudent) {
$registrationStudentRegistrations = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->innerJoin('entity.student', 'student')
->addSelect('student')
->join('student.mobileParentAppAccounts', 'mobileParentAppAccount')
->addSelect('mobileParentAppAccount')
->andWhere('mobileParentAppAccount.id = :idParentAppAccount')
->setParameter('idParentAppAccount', $mobileParentAppAccount->getId())
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult();
foreach ($registrationStudentRegistrations as $key => $registrationStudentRegistration) {
//if ($registrationStudentRegistration->hasMobileApp()) {
$abonnements->add([
'id' => $registrationStudentRegistration->getId(),
'code' => $registrationStudentRegistration->getStudent()->getCode(),
'registrationNumber' => $registrationStudentRegistration->getStudent()->getRegistrationNumber() != "AUCUN" ? $registrationStudentRegistration->getStudent()->getRegistrationNumber() : $registrationStudentRegistration->getStudent()->getCode(),
'name' => $registrationStudentRegistration->getName(),
'image' => 'images/students/'.$registrationStudentRegistration->getImage(),
'establishmentId' => $registrationStudentRegistration->getEstablishment()->getId(),
'establishmentName' => $registrationStudentRegistration->getEstablishment()->getName(),
'establishmentType' => $registrationStudentRegistration->getEstablishment()->getType(),
'classroom' => $registrationStudentRegistration->getClassroom()->getLabel().' - '.$registrationStudentRegistration->getSchoolYear()->getCode(),
]);
//}
}
//}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Accueil");
$mobileParentAppAccountActivity->setDescription("Accueil");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'abonnements' => $abonnements];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/abonnement/{id}/establishment", name="online_api_v1_parent_abonnement_establishment")
*/
public function abonnement_establishment(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
$data = [
'code' => 200,
'msg' => "success",
'establishment' => [
'code' => $registrationStudentRegistration->getEstablishment()->getCode(),
'name' => $registrationStudentRegistration->getEstablishment()->getName(),
'type' => $registrationStudentRegistration->getEstablishment()->getType(),
'address' => $registrationStudentRegistration->getEstablishment()->getAddress(),
'phoneNumber' => $registrationStudentRegistration->getEstablishment()->getPhoneNumber(),
'email' => $registrationStudentRegistration->getEstablishment()->getEmail(),
'website' => $registrationStudentRegistration->getEstablishment()->getWebsite(),
'image' => 'images/establishments/'.$registrationStudentRegistration->getEstablishment()->getImage(),
],
];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/forget-password", name="online_api_v1_parent_forget_password")
*/
public function forget_password(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$entityManager = $this->getDoctrine()->getManager();
$content = $request->getContent();
$contentJson = json_decode($content, true);
$username = $contentJson['username'];
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['username' => $username], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 404, 'msg' => "Not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
$plainPass = strtoupper($this->randomPassword());
$mobileParentAppAccount->setPassword(md5($plainPass));
$mobileParentAppAccount->setToken(md5('-1'));
try {
$entityManager->flush();
return $this->json(['code' => 200, 'message' => "Mot de passe réinitialisé :)", 'newPass' => $plainPass], 200);
} catch (\Throwable $th) {
$data = ['code' => 500, 'msg' => "Server error"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 500, $this->headers);
return $response;
}
$data = ['code' => 200, 'msg' => "success"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-payments/{id}", name="online_api_v1_parent_student_payments")
*/
public function student_payments(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, SchoolYearRepository $schoolYearRepository, RegistrationStudentRegistration $registrationStudentRegistration): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Elève introuvable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
$studentPayments = new ArrayCollection();
foreach ($registrationStudentRegistration->getAccountingStudentRegistrationPayments() as $key => $accountingStudentRegistrationPayment) {
$studentPayments->add([
'id' => $accountingStudentRegistrationPayment->getId(),
'code' => $accountingStudentRegistrationPayment->getCode(),
'createDate' => $accountingStudentRegistrationPayment->getCreateAt()->format('d/m/Y'),
'amount' => $accountingStudentRegistrationPayment->getAmount(),
]);
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Finances");
$mobileParentAppAccountActivity->setDescription("Paiement");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'studentPayments' => $studentPayments];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-fees/{id}", name="online_api_v1_parent_student_fees")
*/
public function student_fees(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, SchoolYearRepository $schoolYearRepository, RegistrationStudentRegistration $registrationStudentRegistration): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Elève introuvable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
$studentFees = new ArrayCollection();
foreach ($registrationStudentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
$studentFeeSheduls = new ArrayCollection();
foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
$studentFeeSheduls->add([
'id' => $accountingStudentRegistrationFeeShedul->getId(),
'amount' => $accountingStudentRegistrationFeeShedul->getAmount(),
'amountPaid' => $accountingStudentRegistrationFeeShedul->getAmountPaid(),
'amountCancel' => $accountingStudentRegistrationFeeShedul->getAmountCancel(),
'amountRest' => $accountingStudentRegistrationFeeShedul->getAmountRest(),
'dateDue' => $accountingStudentRegistrationFeeShedul->getDateDue()->format('d/m/Y'),
]);
}
$studentFees->add([
'id' => $accountingStudentRegistrationFee->getId(),
'code' => $accountingStudentRegistrationFee->getCode(),
'label' => $accountingStudentRegistrationFee->getLabel(),
'amount' => $accountingStudentRegistrationFee->getAmount(),
'amountPaid' => $accountingStudentRegistrationFee->getAmountPaid(),
'amountCancel' => $accountingStudentRegistrationFee->getAmountCancel(),
'amountRest' => $accountingStudentRegistrationFee->getAmountRest(),
'amountDueToDay' => $accountingStudentRegistrationFee->getAmountDueAt(new DateTimeImmutable()),
'studentFeeSheduls' => $studentFeeSheduls,
]);
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Finances");
$mobileParentAppAccountActivity->setDescription("Frais");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'studentFees' => $studentFees];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-balance/{id}", name="online_api_v1_parent_student_balance")
*/
public function student_balance(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, SchoolYearRepository $schoolYearRepository, RegistrationStudentRegistration $registrationStudentRegistration): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
$studentBalance = [
'id' => $registrationStudentRegistration->getId(),
'amount' => $registrationStudentRegistration->getGleAmount(),
'amountPaid' => $registrationStudentRegistration->getAmountPaid(),
'amountCancel' => $registrationStudentRegistration->getAmountCancel(),
'amountRest' => $registrationStudentRegistration->getAmountRest(),
'amountDueToDay' => $registrationStudentRegistration->getAmountDueAt(new DateTimeImmutable()),
];
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Finances");
$mobileParentAppAccountActivity->setDescription("Solde");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'studentBalance' => $studentBalance];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-averages/{id}", name="online_api_v1_parent_student_averages")
*/
public function student_averages(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, SchoolYearPeriodeRepository $schoolYearPeriodeRepository, SchoolMatterRepository $schoolMatterRepository, SchoolStudentAverageRepository $schoolStudentAverageRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- authentification et authorisation---- */
$schoolYearPeriodes = $schoolYearPeriodeRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $registrationStudentRegistration->getSchoolYear()], ['begin_at' => 'ASC']);
$schoolMatters = $schoolMatterRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'level' => $registrationStudentRegistration->getClassroom()->getLevel()], ['label' => 'ASC']);
$studentAverages = new ArrayCollection();
foreach ($schoolYearPeriodes as $key => $schoolYearPeriode) {
$matters = new ArrayCollection();
foreach ($schoolMatters as $key => $schoolMatter) {
if (!$schoolMatter->getIsTestMatter()) {
$averages = new ArrayCollection();
foreach ($schoolStudentAverageRepository->findBy(['registrationStudentRegistration' => $registrationStudentRegistration, 'matter' => $schoolMatter, 'schoolYearPeriode' => $schoolYearPeriode], []) as $key => $schoolStudentAverage) {
if ($schoolStudentAverage->getSchoolAverage()->getIsValidated()) {
if (null != $schoolStudentAverage->getSubMatter()) {
$averages->add([
'label' => $schoolStudentAverage->getSchoolAverage()->getLabel(). ' - ' .$schoolStudentAverage->getSubMatter()->getLabel(),
'notedOn' => $schoolStudentAverage->getNoteOn(),
'note' => $schoolStudentAverage->getNote() < 999 ? $schoolStudentAverage->getNote() : 'NC',
'createDate' => $schoolStudentAverage->getCreatedAt()->format('d/m/Y'),
]);
}else {
$averages->add([
'label' => $schoolStudentAverage->getSchoolAverage()->getLabel(),
'notedOn' => $schoolStudentAverage->getNoteOn(),
'note' => $schoolStudentAverage->getNote() < 999 ? $schoolStudentAverage->getNote() : 'NC',
'createDate' => $schoolStudentAverage->getCreatedAt()->format('d/m/Y'),
]);
}
}
}
if (count($averages) > 0) {
$matters->add([
'label' => $schoolMatter->getLabel(),
'averages' => $averages
]);
}
}
}
if (count($matters) > 0) {
$studentAverages->add([
'label' => $schoolYearPeriode->getLabel(),
'matters' => $matters
]);
}
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Centre d'étude");
$mobileParentAppAccountActivity->setDescription("Notes");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'studentAverages' => $studentAverages];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-timesheets/{id}", name="online_api_v1_parent_student_timesheets")
*/
public function student_timesheet(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, SchoolWorkingTimeHourLessonRepository $schoolWorkingTimeHourLessonRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- authentification et authorisation---- */
$studentWorkingTimes = new ArrayCollection();
for ($i = 0; $i < 6; $i++) {
$timeHours = new ArrayCollection();
$schoolWorkingTimeHourLessons = $schoolWorkingTimeHourLessonRepository->createQueryBuilder('entity')
->innerJoin('entity.settingTimeTable', 'settingTimeTable')
->addSelect('settingTimeTable')
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $registrationStudentRegistration->getSchoolYear())
->andWhere('entity.settingClassroom = :settingClassroom')
->setParameter('settingClassroom', $registrationStudentRegistration->getClassroom())
->andWhere('entity.day = :day')
->setParameter('day', SchoolWorkingTime::COURS_DAYS[$i])
->orderBy('settingTimeTable.label', 'ASC')
->getQuery()
->getResult();
foreach ($schoolWorkingTimeHourLessons as $key => $schoolWorkingTimeHourLesson) {
if (null != $schoolWorkingTimeHourLesson->getSchoolMatter()) {
$timeHours->add(
[
'matter' => $schoolWorkingTimeHourLesson->getSchoolMatter()->getLabel(),
'timeTable' => $schoolWorkingTimeHourLesson->getSettingTimeTable()->getLabel(),
'room' => $schoolWorkingTimeHourLesson->getSettingRoom() ? $schoolWorkingTimeHourLesson->getSettingRoom()->getLabel() : 'NON DEFINI',
'teacher' => $schoolWorkingTimeHourLesson->getSchoolTeacher() ? $schoolWorkingTimeHourLesson->getSchoolTeacher()->getName() : 'NON DEFINI',
]
);
}
}
$studentWorkingTimes->add(
[
'day' => SchoolWorkingTime::COURS_DAYS[$i],
'timeHours' => $timeHours,
]
);
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Centre d'étude");
$mobileParentAppAccountActivity->setDescription("Emploi du temps");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'studentWorkingTimes' => $studentWorkingTimes];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-absences/{id}", name="online_api_v1_parent_student_absences")
*/
public function student_absences(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, SchoolTeacherCallSheetLineRepository $schoolTeacherCallSheetLineRepository, SchoolYearPeriodeRepository $schoolYearPeriodeRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- authentification et authorisation---- */
$schoolYearPeriodes = $schoolYearPeriodeRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $registrationStudentRegistration->getSchoolYear()], ['begin_at' => 'ASC']);
$periodAbsences = new ArrayCollection();
foreach ($schoolYearPeriodes as $key => $schoolYearPeriode) {
$absences = new ArrayCollection();
$_schoolTeacherCallSheetLines = $schoolTeacherCallSheetLineRepository->createQueryBuilder('entity')
->andWhere('entity.registrationStudentRegistration = :registrationStudentRegistration')
->setParameter('registrationStudentRegistration', $registrationStudentRegistration)
->innerJoin('entity.schoolTeacherCallSheet', 'schoolTeacherCallSheet')
->addSelect('schoolTeacherCallSheet')
->andWhere('schoolTeacherCallSheet.create_date BETWEEN :dateStart AND :dateEnd')
->setParameter('dateStart', $schoolYearPeriode->getBeginAt())
->setParameter('dateEnd', $schoolYearPeriode->getEndAt())
->andWhere('entity.is_presente = :is_presente')
->setParameter('is_presente', 0)
->andWhere('entity.is_absent = :is_absent')
->setParameter('is_absent', 1)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult();
foreach ($_schoolTeacherCallSheetLines as $key => $_schoolTeacherCallSheetLine) {
if ($_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getIsValidated()) {
$absences->add([
'createDate' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getCreateDate()->format('d/m/Y'),
'matter' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getSchoolMatter()->getLabel(),
'teacher' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getSchoolTeacher()->getName(),
'timeTable' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getSettingTimeTable()->getLabel(),
'day' => $_schoolTeacherCallSheetLine->getSchoolTeacherCallSheet()->getDay(),
]);
}
}
$periodAbsences->add([
'schoolYearPeriode' => $schoolYearPeriode->getLabel(),
'absences' => $absences
]);
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Centre d'étude");
$mobileParentAppAccountActivity->setDescription("Absences");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'periodAbsences' => $periodAbsences];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-report-cards/{id}", name="online_api_v1_parent_student_report_cards")
*/
public function student_report_cards(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, SchoolReportCardRepository $schoolReportCardRepository, SchoolYearPeriodeRepository $schoolYearPeriodeRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- authentification et authorisation---- */
$schoolYearPeriodes = new ArrayCollection();
foreach ($schoolYearPeriodeRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment(), 'schoolYear' => $registrationStudentRegistration->getSchoolYear()], ['begin_at' => 'ASC']) as $key => $schoolYearPeriode) {
$studentReportCards = new ArrayCollection();
foreach ($schoolReportCardRepository->findBy(['studentRegistration' => $registrationStudentRegistration, 'schoolYearPeriode' => $schoolYearPeriode], []) as $key => $schoolReportCard) {
if ($schoolReportCard->getIsValidated()) {
$studentAverageReportCards = new ArrayCollection();
foreach ($schoolReportCard->getSchoolAverageReportCards() as $key => $schoolAverageReportCard) {
$studentAverageReportCards->add([
'matter' => $schoolAverageReportCard->getMatter()->getLabel(),
'average' => $schoolAverageReportCard->getAverage() < 999 ? $schoolAverageReportCard->getAverage() : 'NC',
'rank' => $schoolAverageReportCard->getAverage() < 999 ? $schoolAverageReportCard->getRank() : 'NC',
'notedOn' => $schoolAverageReportCard->getNoteOn(),
'coefficient' => $schoolAverageReportCard->getCoefficient(),
'coefficientXAverage' => $schoolAverageReportCard->getCoefficientXAverage(),
]);
}
$studentReportCards->add([
'label' => $schoolReportCard->getLabel(),
'studentAverageReportCards' => $studentAverageReportCards,
'rank' => $schoolReportCard->getIsUnclassified() ? 'NC' : $schoolReportCard->getRank(),
'average' => $schoolReportCard->getIsUnclassified() ? 'NC' : round($schoolReportCard->getReportCardAverage(), 2, PHP_ROUND_HALF_DOWN),
'effective' => count($schoolReportCard->getClassroom()->getRegistereds($schoolReportCard->getSchoolYear())),
]);
}
}
if (count($studentReportCards) > 0) {
$schoolYearPeriodes->add([
'label' => $schoolYearPeriode->getLabel(),
'studentReportCards' => $studentReportCards
]);
}
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Centre d'étude");
$mobileParentAppAccountActivity->setDescription("Bulletins");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'schoolYearPeriodes' => $schoolYearPeriodes];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-information/{id}", name="online_api_v1_parent_student_information")
*/
public function student_information(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- authentification et authorisation---- */
$student = [
'registrationNumber' => $registrationStudentRegistration->getStudent()->getRegistrationNumber() != "AUCUN" ? $registrationStudentRegistration->getStudent()->getRegistrationNumber() : $registrationStudentRegistration->getStudent()->getCode(),
'lastName' => $registrationStudentRegistration->getStudent()->getLastName(),
'firstName' => $registrationStudentRegistration->getStudent()->getFirstName(),
'birthday' => $registrationStudentRegistration->getStudent()->getBirthday()->format('d/m/Y'),
'birthLocation' => $registrationStudentRegistration->getStudent()->getBirthLocation(),
'birthCertificateNumber' => $registrationStudentRegistration->getStudent()->getBirthCertificateNumber(),
'lv2' => $registrationStudentRegistration->getStudent()->getLv2(),
'gender' => $registrationStudentRegistration->getStudent()->getGender(),
'nationality' => $registrationStudentRegistration->getStudent()->getNationality(),
'fatherName' => $registrationStudentRegistration->getStudent()->getFatherLastName(). ' ' .$registrationStudentRegistration->getStudent()->getFatherFirstName(),
'motherName' => $registrationStudentRegistration->getStudent()->getMotherLastName(). ' ' .$registrationStudentRegistration->getStudent()->getMotherFirstName(),
'notificationPhoneNumber' => $registrationStudentRegistration->getStudent()->getNotificationPhoneNumber(),
'classroom' => $registrationStudentRegistration->getClassroom()->getLabel(),
'affected' => $registrationStudentRegistration->getStudent()->getIsAffected() ? 'Affecté' : 'Non Affecté',
'redoubling' => $registrationStudentRegistration->getIsRedoubling() ? 'Doublant' : 'Non Doublant',
];
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Autres");
$mobileParentAppAccountActivity->setDescription("Données personnelles");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'student' => $student];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* @Route("/student-informations/{id}", name="online_api_v1_parent_student_informations")
*/
public function student_informations(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, CommunicationMessageRepository $communicationMessageRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- authentification et authorisation---- */
$studentCommunicationMessages = $communicationMessageRepository->createQueryBuilder('entity')
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $registrationStudentRegistration->getSchoolYear())
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $registrationStudentRegistration->getEstablishment())
->orderBy('entity.id', 'ASC')
->getQuery()
->getResult();
$communicationMessages = new ArrayCollection();
//dd($studentCommunicationMessages);
foreach ($studentCommunicationMessages as $key => $studentCommunicationMessage) {
if (in_array($registrationStudentRegistration->getStudent()->getNotificationPhoneNumber(), $studentCommunicationMessage->getContacts())) {
$communicationMessages->add([
'id' => $studentCommunicationMessage->getId(),
'createDate' => $studentCommunicationMessage->getCreatedAt()->format('d/m/Y'),
'content' => $studentCommunicationMessage->getContent(),
]);
}
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Autres");
$mobileParentAppAccountActivity->setDescription("Informations");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'communicationMessages' => $communicationMessages];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* Cette fonction permet d'afficher le menu de la cantine
* 10/05/2025 by oumiche10@gmail.com
* @Route("/student-cantine/{id}", name="online_api_v1_parent_student_cantine")
*/
public function student_cantine(Request $request, CanteenMenuRepository $canteenMenuRepository, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, CommunicationMessageRepository $communicationMessageRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- fin authentification et authorisation---- */
$canteenMenus = new ArrayCollection();
if($registrationStudentRegistration->hasCanteenFee()){
foreach ($canteenMenuRepository->findBy(['establishment' => $registrationStudentRegistration->getEstablishment()]) as $key => $canteenMenu) {
if ($canteenMenu->getDateStart()->format('Y-m-d') <= date('Y-m-d') && $canteenMenu->getDateEnd()->format('Y-m-d') >= date('Y-m-d')) {
foreach ($canteenMenu->getCanteenMenuItems() as $key => $canteenMenuItem) {
$canteenMenus->add([
'horaire' => $canteenMenuItem->getCanteenTime() ? $canteenMenuItem->getCanteenTime()->getName() : '',
'lun' => $canteenMenuItem->getDay1Dish() ? $canteenMenuItem->getDay1Dish()->getName() : '',
'mar' => $canteenMenuItem->getDay2Dish() ? $canteenMenuItem->getDay2Dish()->getName() : '',
'mer' => $canteenMenuItem->getDay3Dish() ? $canteenMenuItem->getDay3Dish()->getName() : '',
'jeu' => $canteenMenuItem->getDay4Dish() ? $canteenMenuItem->getDay4Dish()->getName() : '',
'ven' => $canteenMenuItem->getDay5Dish() ? $canteenMenuItem->getDay5Dish()->getName() : '',
'sam' => $canteenMenuItem->getDay6Dish() ? $canteenMenuItem->getDay6Dish()->getName() : '',
'dim' => $canteenMenuItem->getDay7Dish() ? $canteenMenuItem->getDay7Dish()->getName() : '',
]);
}
}
}
}else {
$data = ['code' => 200, 'msg' => "Merci de vous abonner à la cantine", 'canteenMenus' => $canteenMenus];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
if (count($canteenMenus) <= 0) {
$data = ['code' => 200, 'msg' => "Aucun menu disponible, veuillez contacter l'administration", 'canteenMenus' => $canteenMenus];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Autres");
$mobileParentAppAccountActivity->setDescription("Menu cantine");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "Menu de la semaine", 'canteenMenus' => $canteenMenus];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* Cette fonction permet d'afficher les information concernant le transport
* 10/05/2025 by oumiche10@gmail.com
* @Route("/student-transport/{id}", name="online_api_v1_parent_student_transport")
*/
public function student_transport(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, CommunicationMessageRepository $communicationMessageRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- fin authentification et authorisation---- */
$transportCheckpoints = new ArrayCollection();
if($registrationStudentRegistration->hasTransportFee()){
foreach ($registrationStudentRegistration->getRegistrationTransportCheckpoints() as $key => $transportCheckpoint) {
$transportCheckpoints->add([
'heurepassageMatin' => $transportCheckpoint->getMorningSchedule(),
'heurepassageSoir' => $transportCheckpoint->getEveningSchedule(),
'zone' => $transportCheckpoint->getTransportZone() ? $transportCheckpoint->getTransportZone()->getName() : '',
'pointArret' => $transportCheckpoint->getTransportZoneCheckPoint() ? $transportCheckpoint->getTransportZoneCheckPoint()->getName() : '',
'immCar' => $transportCheckpoint->getTransportVehicle() ? $transportCheckpoint->getTransportVehicle()->getRegistrationNumber() : '',
'couleurCar' => $transportCheckpoint->getTransportVehicle() ? $transportCheckpoint->getTransportVehicle()->getColor() : '',
]);
}
}else {
$data = ['code' => 200, 'msg' => "Merci de vous abonner au transport", 'transportCheckpoints' => $transportCheckpoints];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
if (count($transportCheckpoints) <= 0) {
$data = ['code' => 200, 'msg' => "Aucun checkpoint disponible, veuillez contacter l'administration", 'transportCheckpoints' => $transportCheckpoints];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Autres");
$mobileParentAppAccountActivity->setDescription("Menu cantine");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "Vos checkpoints", 'transportCheckpoints' => $transportCheckpoints];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* Cette fonction permet d'envoyer le formulaire de contact
* 10/05/2025 by oumiche10@gmail.com
* @Route("/student-contact/{id}", name="online_api_v1_parent_student_contact")
*/
public function student_contact(Request $request, ValidatorInterface $validator, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration, CommunicationMessageRepository $communicationMessageRepository): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
/* authentification et authorisation*/
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Student not found"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
/* ---- fin authentification et authorisation---- */
$data = json_decode($request->getContent(), true);
$contact = new RegistrationStudentContact();
$contact->setRegistrationStudentRegistration($registrationStudentRegistration);
$contact->setEstablishment($registrationStudentRegistration->getEstablishment());
$contact->setName($data['name'] ?? '');
$contact->setSubject($data['subject'] ?? '');
$contact->setPhone($data['phone'] ?? $registrationStudentRegistration->getStudent()->getNotificationPhoneNumber());
$contact->setMessage($data['message'] ?? '');
$errors = $validator->validate($contact);
if (count($errors) > 0) {
$errorMessages = [];
foreach ($errors as $error) {
$errorMessages[$error->getPropertyPath()] = $error->getMessage();
}
$data = ['code' => 500, 'msg' => "Echec les information renseigné ne sont pas valide!"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 500, $this->headers);
}
$entityManager = $this->getDoctrine()->getManager();
// Ici vous pourriez envoyer un email ou sauvegarder en base
$entityManager->persist($contact);
try {
$entityManager->flush();
} catch (\Throwable $th) {
$data = ['code' => 500, 'msg' => $th->getMessage()];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 500, $this->headers);
}
$data = ['code' => 200, 'msg' => "Votre message a bien été envoyé. Merci!"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
/**
* Cette fonction permet d'afficher les frais dus pour un élève
* 14/05/2025 by oumiche10@gmail.com
* @Route("/student-fees/dues/{id}", name="online_api_v1_parent_student_fees_dues")
*/
public function student_fees_dues(Request $request, MobileParentAppAccountRepository $mobileParentAppAccountRepository, RegistrationStudentRegistration $registrationStudentRegistration): Response
{
$token = $request->headers->get('token');
$encoders = [new JsonEncoder()];
$normalizer = [new ObjectNormalizer()];
$serializer = new Serializer($normalizer, $encoders);
$mobileParentAppAccount = $mobileParentAppAccountRepository->findOneBy(['token' => $token], []);
if (null == $mobileParentAppAccount) {
$data = ['code' => 403, 'msg' => "Access denied"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getIsEnabled()) {
$data = ['code' => 403, 'msg' => "Account desable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->isTokenValid()) {
$data = ['code' => 403, 'msg' => "Token Invalid", 'time' => time(), 'exp' => ($mobileParentAppAccount->getLastAuthTime())];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 403, $this->headers);
return $response;
}
if (!$mobileParentAppAccount->getRegistrationStudents()->contains($registrationStudentRegistration->getStudent())) {
$data = ['code' => 404, 'msg' => "Elève introuvable"];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 404, $this->headers);
return $response;
}
$registrationStudent = $registrationStudentRegistration->getStudent();
$studentFees = new ArrayCollection();
foreach ($registrationStudent->getRegistrationStudentRegistrations() as $key => $studentRegistration) {
//if($studentRegistration->getSchoolYear()->getId() != $registrationStudentRegistration->getSchoolYear()->getId()){
foreach ($studentRegistration->getAccountingStudentRegistrationFees() as $key => $accountingStudentRegistrationFee) {
$studentFeeSheduls = new ArrayCollection();
foreach ($accountingStudentRegistrationFee->getAccountingStudentRegistrationFeeSheduls() as $key => $accountingStudentRegistrationFeeShedul) {
$studentFeeSheduls->add([
'id' => $accountingStudentRegistrationFeeShedul->getId(),
'amount' => $accountingStudentRegistrationFeeShedul->getAmount(),
'amountPaid' => $accountingStudentRegistrationFeeShedul->getAmountPaid(),
'amountCancel' => $accountingStudentRegistrationFeeShedul->getAmountCancel(),
'amountRest' => $accountingStudentRegistrationFeeShedul->getAmountRest(),
'dateDue' => $accountingStudentRegistrationFeeShedul->getDateDue()->format('d/m/Y'),
]);
}
$studentFees->add([
'id' => $accountingStudentRegistrationFee->getId(),
'schoolYear' => $studentRegistration->getSchoolYear()->getCode(),
'code' => $accountingStudentRegistrationFee->getCode(),
'label' => $accountingStudentRegistrationFee->getLabel(),
'amount' => $accountingStudentRegistrationFee->getAmount(),
'amountPaid' => $accountingStudentRegistrationFee->getAmountPaid(),
'amountCancel' => $accountingStudentRegistrationFee->getAmountCancel(),
'amountRest' => $accountingStudentRegistrationFee->getAmountRest(),
'amountDueToDay' => $accountingStudentRegistrationFee->getAmountDueAt(new DateTimeImmutable()),
'studentFeeSheduls' => $studentFeeSheduls,
]);
}
//}
}
//workflow
$entityManager = $this->getDoctrine()->getManager();
$mobileParentAppAccountActivity = new MobileParentAppAccountActivity();
$mobileParentAppAccountActivity->setCreateAt(new DateTimeImmutable());
$mobileParentAppAccountActivity->setMobileParentAppAccount($mobileParentAppAccount);
$mobileParentAppAccountActivity->setType("Finances");
$mobileParentAppAccountActivity->setDescription("Frais");
$entityManager->persist($mobileParentAppAccountActivity);
try {
$entityManager->flush();
} catch (\Throwable $th) {
//throw $th;
}
$data = ['code' => 200, 'msg' => "success", 'studentFeesDues' => $studentFees];
$jsonContent = $serializer->serialize($data, 'json');
$response = new Response($jsonContent, 200, $this->headers);
return $response;
}
private function randomPassword($length = 4) {
$alphabet = "0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 4; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
}