<?php
namespace App\Controller\Registration;
use Knp\Snappy\Pdf;
use App\Entity\User;
use App\Service\SMSSender;
use App\Entity\SettingLevel;
use App\Entity\RegistrationStudent;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Doctrine\Common\Collections\ArrayCollection;
use App\Repository\RegistrationStudentRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use App\Entity\RegistrationStudentPreRegistration;
use App\Repository\SchoolAssessmentByLevelRepository;
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use App\Repository\RegistrationStudentPreRegistrationRepository;
use App\Form\Registration\RegistrationStudentPreRegistrationType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @Route("/registration/student-pre-registration")
*/
class RegistrationStudentPreRegistrationController extends AbstractController
{
/**
* @Route("/index", name="registration_student_pre_registration_index", methods={"GET"})
*/
public function index(Request $request, PaginatorInterface $paginator, RegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $user->getEstablishment();/*
$registration_student_pre_registrations = $paginator->paginate(
$registrationStudentPreRegistrationRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear)
->orderBy('entity.id', 'DESC')
->getQuery(),
$request->query->getInt('page', 1),
1000
); */
$waiting_for_validations = new ArrayCollection();
$waiting_for_registrations = new ArrayCollection();
$waiting_for_test = new ArrayCollection();
if ($establishment->getType() == $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (false == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}else {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
//}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (false == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
//}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}
return $this->render('registration/registration_student_pre_registration/index.html.twig', [
/* 'registration_student_pre_registrations' => $registration_student_pre_registrations, */
'waiting_for_validations' => count($waiting_for_validations),
'waiting_for_test' => count($waiting_for_test),
'waiting_for_registrations' => count($waiting_for_registrations),
'pre_registrations' => count($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], [])),
]);
}
/**
* @Route("/_searh-table", name="registration_student_pre_registration_searh_table", methods={"GET","POST"})
*/
public function _searh_table(Request $request, RegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$establishment = $user->getEstablishment();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$query = $registrationStudentPreRegistrationRepository->createQueryBuilder('entity')
->andWhere('entity.establishment = :establishment')
->setParameter('establishment', $establishment)
->andWhere('entity.schoolYear = :schoolYear')
->setParameter('schoolYear', $schoolYear);
if ($request->get('registrationNumber')) {
$query = $query
->andWhere('entity.registration_number LIKE :registration_number')
->setParameter('registration_number', '%'.$request->get('registrationNumber').'%');
}
if ($request->get('code')) {
$query = $query
->andWhere('entity.code LIKE :code')
->setParameter('code', '%'.$request->get('code').'%');
}
if ($request->get('lastName')) {
$query = $query
->andWhere('entity.last_name LIKE :last_name')
->setParameter('last_name', '%'.$request->get('lastName').'%');
}
if ($request->get('firstName')) {
$query = $query
->andWhere('entity.first_name LIKE :first_name')
->setParameter('first_name', '%'.$request->get('firstName').'%');
}
$query = $query
->orderBy('entity.last_name', 'ASC')
->getQuery();
$registration_student_pre_registrations = $query
->setMaxResults(100)
->getResult();
return $this->renderForm('registration/registration_student_pre_registration/_searh_table.html.twig', [
'registration_student_pre_registrations' => $registration_student_pre_registrations,
]);
}
/**
* @Route("/waiting-for-validation", name="registration_student_pre_registration_waiting_for_validation", methods={"GET"})
*/
public function waiting_for_validation(RegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$waiting_for_validations = new ArrayCollection();
$waiting_for_registrations = new ArrayCollection();
$waiting_for_test = new ArrayCollection();
if ($establishment->getType() == $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (false == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}else {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
//}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (false == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
//}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}
return $this->render('registration/registration_student_pre_registration/wfv.html.twig', [
'registration_student_pre_registrations' => $waiting_for_validations,
'waiting_for_validations' => count($waiting_for_validations),
'waiting_for_test' => count($waiting_for_test),
'waiting_for_registrations' => count($waiting_for_registrations),
'pre_registrations' => count($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], [])),
]);
}
/**
* @Route("/waiting-for-test", name="registration_student_pre_registration_waiting_for_test", methods={"GET"})
*/
public function waiting_for_test(RegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$waiting_for_validations = new ArrayCollection();
$waiting_for_registrations = new ArrayCollection();
$waiting_for_test = new ArrayCollection();
if ($establishment->getType() == $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (false == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}else {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
//}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (false == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
//}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}
return $this->render('registration/registration_student_pre_registration/wft.html.twig', [
'registration_student_pre_registrations' => $waiting_for_test,
'waiting_for_validations' => count($waiting_for_validations),
'waiting_for_test' => count($waiting_for_test),
'waiting_for_registrations' => count($waiting_for_registrations),
'pre_registrations' => count($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], [])),
]);
}
/**
* @Route("/waiting-for-registrations", name="registration_student_pre_registration_waiting_for_registrations", methods={"GET"})
*/
public function waiting_for_registrations(RegistrationStudentPreRegistrationRepository $registrationStudentPreRegistrationRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$establishment = $this->getUser()->getEstablishment();
$waiting_for_validations = new ArrayCollection();
$waiting_for_registrations = new ArrayCollection();
$waiting_for_test = new ArrayCollection();
if ($establishment->getType() == $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (false == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectEntryTest()) {
if (true == $registration_student_pre_registration->getIsEntryTestDone()) {
if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}else {
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
$waiting_for_validations->add($registration_student_pre_registration);
//}
}
}else {
$waiting_for_validations->add($registration_student_pre_registration);
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null == $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (false == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
$waiting_for_test->add($registration_student_pre_registration);
}
}
}
}
foreach ($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], []) as $key => $registration_student_pre_registration) {
if (null != $registration_student_pre_registration->getStudent()) {
if (true == $registration_student_pre_registration->getIsSubjectToxicologicalTest()) {
if (true == $registration_student_pre_registration->getIsToxicologicalTestPerformed()) {
//if (true == $registration_student_pre_registration->getIsEntryTestPerformed()) {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
//}
}
}else {
if (count($registration_student_pre_registration->getRegistrationStudentRegistrations()) <= 0) {
$waiting_for_registrations->add($registration_student_pre_registration);
}
}
}
}
}
return $this->render('registration/registration_student_pre_registration/wfr.html.twig', [
'registration_student_pre_registrations' => $waiting_for_registrations,
'waiting_for_validations' => count($waiting_for_validations),
'waiting_for_test' => count($waiting_for_test),
'waiting_for_registrations' => count($waiting_for_registrations),
'pre_registrations' => count($registrationStudentPreRegistrationRepository->findBy(['establishment' => $establishment, 'schoolYear' => $schoolYear], [])),
]);
}
/**
* @Route("/{id}/edit", name="registration_student_pre_registration_edit", methods={"GET","POST"})
*/
public function edit(Request $request, RegistrationStudentPreRegistration $registrationStudentPreRegistration): Response
{
$establishment = $this->getUser()->getEstablishment();
$template = 'registration/registration_student_pre_registration/primaireEdit.html.twig';
if ($establishment->getType() != $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
$template = 'registration/registration_student_pre_registration/secondaireEdit.html.twig';
}
$entryLevels = new ArrayCollection();
foreach ($establishment->getSettingLevels() as $key => $level) {
if (count($level->getSettingClassrooms()) > 0) {
$entryLevels->add($level);
}
}
$form = $this->createForm(RegistrationStudentPreRegistrationType::class, $registrationStudentPreRegistration)
->remove('agree_parent_engagement')
->remove('agree_internal_rules')
->add('is_entry_test_done', ChoiceType::class,[
'choices' => [
'OUI' => true,
'NON' => false
]
])
->add('entryLevel', EntityType::class, [
'class' => SettingLevel::class,
'choices' => $entryLevels,
'required' => true
])
->add('classJumps', EntityType::class, [
'class' => SettingLevel::class,
'choices' => $entryLevels,
'required' => false,
'multiple' => true,
]);
if ($establishment->getType() != $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
$form = $this->createForm(RegistrationStudentPreRegistrationType::class, $registrationStudentPreRegistration)
->add('lv1', ChoiceType::class,[
'choices' => RegistrationStudent::LV1
])
->add('lv2', ChoiceType::class,[
'choices' => RegistrationStudent::LV2
])
->add('entryLevel', EntityType::class, [
'class' => SettingLevel::class,
'choices' => $entryLevels,
'required' => true
])
->remove('agree_parent_engagement')
->remove('agree_internal_rules')
->remove('is_need_canteen')
->remove('is_need_keep');
}
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$this->getDoctrine()->getManager()->flush();
$this->addFlash('success', "pre-inscription à été édité.");
} catch (\Throwable $th) {
$this->addFlash('warning', "Une erreure est survenue lors de l'édition de pre-inscription.");
$this->addFlash('info', $th->getMessage());
}
return $this->redirectToRoute('registration_student_pre_registration_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm($template, [
'registration_student_pre_registration' => $registrationStudentPreRegistration,
'form' => $form,
]);
}
/**
* @Route("/delete-selection", name="registration_student_pre_registrations_selected_delete", methods={"GET"})
*/
public function deleteSelected(Request $request, RegistrationStudentPreRegistrationRepository $entityRepository): Response
{
$list = $request->get('entities');
$entityManager = $this->getDoctrine()->getManager();
$errors = 0;
$success = 0;
foreach ($list as $key => $id) {
$entity = $entityRepository->findOneBy(['id' => intval($id)], []);
if ($entity != null) {
if (count($entity->getRegistrationStudentRegistrations()) <= 0) {
$entityManager->remove($entity);
$success = $success + 1;
}else{
$errors = $errors + 1;
}
}else{
$errors = $errors + 1;
}
}
try {
$entityManager->flush();
$this->addFlash('success', $success. " Eléments ont été supprimé.");
return $this->json(['code' => 200, 'message' => $success. " Eléments ont été supprimé. ".$errors . "N'ont pas pu être supprimés." ], 200);
} catch (\Throwable $th) {
//$th->getMessage()
$this->addFlash('warning', $th->getMessage());
}
$this->addFlash('warning', "Traitement non effectué, une erreur s'est produite.");
return $this->json(['code' => 500, 'message' => "Traitement non effectué, une erreur s'est produite."], 200);
}
/**
* @Route("/validate/{id}", name="registration_student_pre_registration_validate", methods={"GET"})
*/
public function validate(RegistrationStudentPreRegistration $registrationStudentPreRegistration, RegistrationStudentRepository $registrationStudentRepository, SMSSender $smsSender): Response
{
if(null != $registrationStudentPreRegistration->getStudent()) {
return $this->json(['code' => 500, 'message' => "Echèc: cette pre-inscription est déjà validé."], 200);
}
$entityManager = $this->getDoctrine()->getManager();
$establishment = $this->getUser()->getEstablishment();
$registrationStudent = $registrationStudentRepository->findOneBy(['id' => $registrationStudentPreRegistration->getHoldStudentId()], []);
if (null == $registrationStudent) {
$registrationStudent = new RegistrationStudent();
$nextIndex = count($registrationStudentRepository->findBy([], [])) + 1;
$registrationStudent->setCode(date('Y').'-'.sprintf("%'05s", $nextIndex));
$registrationStudent->setEstablishment($establishment);
}
$registrationStudent->setAccompanyingPersonName($registrationStudentPreRegistration->getAccompanyingPersonName());
$registrationStudent->setAccompanyingPersonPhoneNumber($registrationStudentPreRegistration->getAccompanyingPersonPhoneNumber());
$registrationStudent->setFatherAddress($registrationStudentPreRegistration->getFatherAddress());
$registrationStudent->setFatherEmail($registrationStudentPreRegistration->getFatherEmail());
$registrationStudent->setFatherFirstName($registrationStudentPreRegistration->getFatherFirstName());
$registrationStudent->setFatherLastName($registrationStudentPreRegistration->getFatherLastName());
$registrationStudent->setFatherPhoneNumber($registrationStudentPreRegistration->getFatherPhoneNumber());
$registrationStudent->setIsFatherCallToEmergency($registrationStudentPreRegistration->getIsFatherCallToEmergency());
$registrationStudent->setIsParntalAuthorityFather($registrationStudentPreRegistration->getIsParntalAuthorityFather());
$registrationStudent->setMotherAddress($registrationStudentPreRegistration->getMotherAddress());
$registrationStudent->setMotherEmail($registrationStudentPreRegistration->getMotherEmail());
$registrationStudent->setMotherFirstName($registrationStudentPreRegistration->getMotherFirstName());
$registrationStudent->setMotherLastName($registrationStudentPreRegistration->getMotherLastName());
$registrationStudent->setMotherPhoneNumber($registrationStudentPreRegistration->getMotherPhoneNumber());
$registrationStudent->setIsMotherCallToEmergency($registrationStudentPreRegistration->getIsMotherCallToEmergency());
$registrationStudent->setIsParntalAuthorityMother($registrationStudentPreRegistration->getIsParntalAuthorityMother());
$registrationStudent->setFirstName($registrationStudentPreRegistration->getFirstName());
$registrationStudent->setLastName($registrationStudentPreRegistration->getLastName());
$registrationStudent->setImage($registrationStudentPreRegistration->getImage());
$registrationStudent->setIsAffected($registrationStudentPreRegistration->getIsAffected());
$registrationStudent->setLocation($registrationStudentPreRegistration->getLocation());
if ($establishment->getType() != $establishment::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
$registrationStudent->setLv1($registrationStudentPreRegistration->getLv1());
$registrationStudent->setLv2($registrationStudentPreRegistration->getLv2());
}
$registrationStudent->setNationality($registrationStudentPreRegistration->getNationality());
$registrationStudent->setBirthday($registrationStudentPreRegistration->getBirthday());
$registrationStudent->setBirthLocation($registrationStudentPreRegistration->getBirthLocation());
$registrationStudent->setBirthCertificateNumber($registrationStudentPreRegistration->getBirthCertificateNumber());
$registrationStudent->setRegistrationNumber($registrationStudentPreRegistration->getRegistrationNumber());
$registrationStudent->setLastSchoolAttended($registrationStudentPreRegistration->getLastSchoolAttended());
$registrationStudent->setLastSchoolAttendedType($registrationStudentPreRegistration->getLastSchoolAttendedType());
$registrationStudent->setNotificationWatsappNumber($registrationStudentPreRegistration->getNotificationWatsappNumber());
$registrationStudent->setNotificationPhoneNumber($registrationStudentPreRegistration->getNotificationPhoneNumber());
$registrationStudent->setObservation($registrationStudentPreRegistration->getObservation());
$registrationStudent->setParentStatus($registrationStudentPreRegistration->getParentStatus());
$registrationStudent->setResponsibleOfSchooling($registrationStudentPreRegistration->getResponsibleOfSchooling());
$registrationStudent->setResponsibleOfSchoolingAddress($registrationStudentPreRegistration->getResponsibleOfSchoolingAddress());
$registrationStudent->setResponsibleOfSchoolingFirstName($registrationStudentPreRegistration->getResponsibleOfSchoolingFirstName());
$registrationStudent->setResponsibleOfSchoolingLastName($registrationStudentPreRegistration->getResponsibleOfSchoolingLastName());
$registrationStudent->setResponsibleOfSchoolingLocation($registrationStudentPreRegistration->getResponsibleOfSchoolingLocation());
$registrationStudent->setResponsibleOfSchoolingPhoneNumber($registrationStudentPreRegistration->getResponsibleOfSchoolingPhoneNumber());
$registrationStudent->setResponsibleOfSchoolingPost($registrationStudentPreRegistration->getResponsibleOfSchoolingPost());
$registrationStudent->setGender($registrationStudentPreRegistration->getGender());
if (0 >= $registrationStudent->getId()) {
$entityManager->persist($registrationStudent);
try {
$entityManager->flush();
$registrationStudent->setCode(date('Y').'-'.sprintf("%'05s", $registrationStudent->getId()));
$entityManager->flush();
} catch (\Throwable $th) {
$this->addFlash('info', $th->getMessage());
}
}
$registrationStudentPreRegistration->setStudent($registrationStudent);
try {
$entityManager->flush();
$this->addFlash('success', "Validation effectuée");
return $this->json(['code' => 200, 'message' => "Traitement effectué :)"], 200);
} catch (\Throwable $th) {
//$th->getMessage()
$this->addFlash('warning', $th->getMessage());
}
$this->addFlash('warning', "Validation non effectuée");
return $this->json(['code' => 500, 'message' => "Traitement non effectué"], 200);
}
/**
* @Route("/{id}/print", name="registration_student_pre_registration_print", methods={"GET"})
*/
public function print(Pdf $knpSnappyPdf, RegistrationStudentPreRegistration $registrationStudentPreRegistration)
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$setting = $registrationStudentPreRegistration->getEstablishment();
$template = 'registration/print/prePrimaire.html.twig';
if ($setting->getType() != $setting::ESTABLISHMENT_PRESCOLAIRE_PRIMAIRE_TYPES) {
$template = 'registration/print/preSecondaire.html.twig';
}
$html = $this->renderView($template, [
'registration_student_pre_registration' => $registrationStudentPreRegistration,
'school_year' => $schoolYear,
'setting' => $setting,
]);
$file_name = 'PRE_INSCRIPTION_N_'.$registrationStudentPreRegistration->getCode().".pdf";
return new PdfResponse(
$knpSnappyPdf->getOutputFromHtml($html),
$file_name,
'application/pdf',
'attachment'
);
}
/**
* @Route("/api/get-info", name="api_registration_student_pre_registration_info", methods={"GET"})
*/
public function apiGetInfo(Request $request, RegistrationStudentPreRegistrationRepository $entityRepository, SchoolAssessmentByLevelRepository $schoolAssessmentByLevelRepository): Response
{
/**@var User $user */
$user = $this->getUser();
$schoolYear = $user->getSchoolYear();
$id = intval($request->get('id'));
$entity = $entityRepository->findOneBy(['id' => $id], []);
$schoolAssessmentByLevels = $schoolAssessmentByLevelRepository->createQueryBuilder('entity')
->innerJoin('entity.studentRegistration', 'studentRegistration')
->addSelect('studentRegistration')
->innerJoin('entity.schoolAssessment', 'schoolAssessment')
->addSelect('schoolAssessment')
->innerJoin('entity.nextClassroom', 'nextClassroom')
->addSelect('nextClassroom')
->andWhere('studentRegistration.student = :student')
->setParameter('student', $entity->getStudent())
->andWhere('schoolAssessment.nexSchoolYear = :nexSchoolYear')
->setParameter('nexSchoolYear', $schoolYear)
->getQuery()
->getResult();
if ($entity != null) {
$classrooms = new ArrayCollection();
foreach ($schoolAssessmentByLevels as $key => $schoolAssessmentByLevel) {
if ($schoolAssessmentByLevel->getNextClassroom()->getCapacity() > count($schoolAssessmentByLevel->getNextClassroom()->getRegistereds($schoolYear))) {
$classrooms->add([
'id' => $schoolAssessmentByLevel->getNextClassroom()->getId(),
'label' => $schoolAssessmentByLevel->getNextClassroom()->getLabel()
]);
}
};
if (count($classrooms) <= 0) {
foreach ($entity->getEntryLevel()->getSettingClassrooms() as $key => $classroom) {
if (!$classroom->getIsExcellent()) {
if ($classroom->getSchoolYear() == $schoolYear) {
if ($classroom->getCapacity() > count($classroom->getRegistereds($schoolYear))) {
$classrooms->add([
'id' => $classroom->getId(),
'label' => $classroom->getLabel()
]);
}
}
}
}
}
$is_affected = false;
$is_redoubling = $entity->getIsRedoubling();
if (null != $entity->getStudent()) {
$is_affected = $entity->getStudent()->getIsAffected();
}
return $this->json([
'code' => 200, 'message' => "found :)",
'name' => $entity->getName(),
'registrationNumber' => $entity->getRegistrationNumber(),
'id' => $entity->getCode(),
'birthDate' => $entity->getBirthday()->format('d/m/Y'),
'birthLocation' => $entity->getBirthLocation(),
'phoneNumber' => $entity->getNotificationPhoneNumber(),
'establishment' => $entity->getEstablishment()->getName(),
'classroom' => $entity->getEntryLevel()->getLabel(),
'classrooms' => $classrooms,
'preCode' => $entity->getCode(),
'is_affected' => $is_affected,
'is_redoubling' => $is_redoubling,
'img_src' =>$entity->getImage(),
], 200);
}else{
return $this->json(['code' => 500, 'message' => "not found :)"], 200);
}
}
}