<?php
namespace App\Controller\Registration;
use App\Entity\User;
use App\Entity\SettingClassroom;
use Symfony\Component\HttpFoundation\Request;
use App\Repository\SettingClassroomRepository;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\RegistrationStudentRepository;
use App\Repository\RegistrationStudentRegistrationRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @Route("/student/dashboard")
*/
class StudentDashboardController extends AbstractController
{
/**
* @Route("/index", name="student_dashboard_index")
*/
public function index(SettingClassroomRepository $settingClassroomRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$setting_classrooms =
$settingClassroomRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult();
return $this->render('registration/student_dashboard/index.html.twig', [
'setting_classrooms' => $setting_classrooms,
'school_year' => $schoolYear
]);
}
/**
* @Route("/api/get-count", name="api_student_dashboard_get_count", methods={"GET"})
*/
public function apiGetCount(SettingClassroomRepository $settingClassroomRepository, RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository){
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$countClassroom = count($settingClassroomRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult());
$countRegisteredWithoutBirthCertificate = count($registrationStudentRegistrationRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.birth_certificate_number is null')
//->setParameter('birth_certificate_number', 1)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult());
$countRegistered = count($registrationStudentRegistrationRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult());
return $this->json([
'code' => 200,
'message' => "found :)",
'countClassroom' => $countClassroom,
'countRegistered' => number_format($countRegistered,0,',', ' '),
'countRegisteredWithoutBirthCertificate' => number_format($countRegisteredWithoutBirthCertificate,0,',', ' '),
],
200);
}
/**
* @Route("/classroom/{id}/registered", name="student_dashboard_registereds_by_classroom", methods={"GET"})
*/
public function classroomRegistereds(SettingClassroom $settingClassroom): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$registereds = $settingClassroom->getRegistereds($schoolYear);
return $this->render('registration/student_dashboard/registeredsByClassroom.html.twig', [
'setting_classroom' => $settingClassroom,
'registereds' => $registereds,
'school_year' => $schoolYear
]);
}
/**
* @Route("/api/set-birth-certificate_number", name="api_student_birth_certificate_number", methods={"GET"})
*/
public function api_edit_name(Request $request, RegistrationStudentRepository $registrationStudentRepository){
$entityManager = $this->getDoctrine()->getManager();
if (strlen($request->get('birthCertificateNumber')) <= 3) {
return $this->json(['code' => 500, 'message' => "N° extrait invalide"], 200);
}
$registrationStudentRegistration = $registrationStudentRepository->findOneBy(['id' => $request->get('id')]);
if (null != $registrationStudentRegistration) {
$registrationStudentRegistration->setBirthCertificateNumber($request->get('birthCertificateNumber'));
}
try {
$entityManager->flush();
return $this->json(['code' => 200, 'message' => "N° extrait modifié."], 200);
} catch (\Throwable $th) {
//$th->getMessage()
//return $this->json(['code' => 500, 'message' => $th->getMessage()], 200);
}
return $this->json(['code' => 500, 'message' => "Une erreur s'est produite lors de la modification du N° extrait."], 200);
}
/**
* @Route("/registereds-without-birth-certificate", name="student_dashboard_registereds_without_birth_certificate", methods={"GET"})
*/
public function registeredsWithoutBirthCertificate(RegistrationStudentRegistrationRepository $registrationStudentRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$registereds = $registrationStudentRegistrationRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->innerJoin('entity.student', 'student')
->addSelect('student')
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->andWhere('student.birth_certificate_number is null')
//->setParameter('birth_certificate_number', 1)
->orderBy('entity.id', 'DESC')
->getQuery()
->getResult();
return $this->render('registration/student_dashboard/registeredsWithoutBirthCertificate.html.twig', [
'registereds' => $registereds,
'school_year' => $schoolYear
]);
}
}