src/Controller/TutoringController.php line 38

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Tutoring\Course;
  4. use App\Entity\Tutoring\Level;
  5. use App\Entity\Tutoring\Rowscourse;
  6. use App\Entity\Tutoring\Student;
  7. use App\Form\Tutoring\CoursesType;
  8. use App\Form\Tutoring\StudentType;
  9. use App\Repository\Tutoring\CourseRepository;
  10. use App\Repository\Tutoring\LevelRepository;
  11. use App\Repository\Tutoring\RowscourseRepository;
  12. use App\Repository\Tutoring\StudentRepository;
  13. use App\Repository\Tutoring\SubjectRepository;
  14. use App\Service\SchoolyearService;
  15. use DateTime;
  16. use Doctrine\Common\Collections\ArrayCollection;
  17. use Ensepar\Html2pdfBundle\Factory\Html2pdfFactory;
  18. use Exception;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\JsonResponse;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. use Symfony\Component\Yaml\Yaml;
  25. #[Route('/soutien-scolaire'name'hs_public_tutoring_')]
  26. class TutoringController extends AbstractController
  27. {
  28.     Public function __construct(){}
  29.     #[Route(path'/'name'index'options: ['expose' => true])]
  30.     public function indexAction(SubjectRepository $subjectRepository)
  31.     {
  32.         $subjects=$subjectRepository->findAll();
  33.         return $this->render('tutoring/index.html.twig', ['subjects'=>$subjects'current'=>'tutoring']);
  34.     }
  35.     #[Route(path'/preinscription'name'preregistration'options: ['expose' => true])]
  36.     public function preRegistrationAction(StudentRepository $studentRepositoryRequest $request)
  37.     {
  38.         $item = new Student();
  39.         $form_soutient $this->createForm(StudentType::class, $item);
  40.         $form_soutient->handleRequest($request);
  41.         if ($form_soutient->isSubmitted() && $form_soutient->isValid()) {
  42.             $studentRepository->save($itemtrue);
  43.             /*            if (!empty($item->getEmail())) {
  44.                             $message = (new \Swift_Message($this->getParm('0101_institute_name') . ' : Fiche d\'inscription '))
  45.                                 ->setFrom($this->getParm('0104_institute_email'), $this->getParm('0101_institute_name'))
  46.                                 ->setTo($item->getEmail())
  47.                                 ->setBody(
  48.                                     $this->renderView(
  49.                                         'Emails/registration.html.twig',
  50.                                         array('item' => $item, 'infos' => $infos)
  51.                                     ),
  52.                                     'text/html'
  53.                                 );
  54.                             $mailer->send($message);
  55.                         }*/
  56.             return $this->redirectToRoute('hs_public_tutoring_registration', ['slug' => $item->getSlug()]);
  57.         }
  58.         return $this->render('tutoring/preregistration.html.twig', ['form_soutien'=>$form_soutient->createView(), 'current'=>'tutoring']);
  59.     }
  60.     #[Route(path'/inscription/{slug}'name'registration'options: ['expose' => true])]
  61.     public function registrationAction($slugStudentRepository $studentRepositoryRequest $request)
  62.     {
  63.         $student $studentRepository->findOneBySlug($slug);
  64.         if (empty($student)) {
  65.             $this->addFlash('warning''Veuillez vous inscrire s\'il vous plaît');
  66.             return $this->redirectToRoute('hs_public_tutoring_preregistration');
  67.         }
  68.         if (!$student->getRowscourses()->isEmpty()) {
  69.             $this->addFlash('info','Vous êtes déjà inscrit');
  70.             return $this->redirectToRoute('hs_public_tutoring_registration_fiche', ['slug' => $student->getSlug()]);
  71.         }
  72.         $form $this->createForm(CoursesType::class);
  73.         $form->handleRequest($request);
  74.         return $this->render(
  75.             'tutoring/inscription.html.twig',
  76.             array(
  77.                 'form' => $form->createView(),
  78.                 'item' => $student,
  79.                 'current' => 'tutoring'
  80.             )
  81.         );
  82.     }
  83.     #[Route(path'/inscription_save/{slug}'name'registration_save'options: ['expose' => true])]
  84.     public function registrationSave($slug,
  85.                                            SchoolyearService $schoolyearService,
  86.                                            LevelRepository $levelRepository,
  87.                                            StudentRepository $studentRepository,
  88.                                            CourseRepository $courseRepository,
  89.                                            RowscourseRepository $rowscourseRepository,
  90.                                            Request $request
  91.     )
  92.     {
  93.         $levelid $request->request->get('levelid');
  94.         $coursesid $request->request->get('courses');
  95.         /** @var Level $level */
  96.         $level $levelRepository->find($levelid);
  97.         /** @var Student $student*/
  98.         $student $studentRepository->findOneBySlug($slug);
  99.         $student->setLevel($level);
  100.         $student->setFirstName($request->request->get('firstName'));
  101.         $student->setLastName($request->request->get('lastName'));
  102.         $student->setPhone($request->request->get('phone'));
  103.         $student->setParentPhone($request->request->get('parentPhone'));
  104.         $student->setParentJob($request->request->get('parentJob'));
  105.         $student->setEstabl($request->request->get('establ'));
  106.         $student->setAdress($request->request->get('adress'));
  107.         $student->getRowscourses()->clear();
  108.         $ids explode("|"$coursesid);
  109.         if (!empty($ids)) {
  110.             foreach ($ids as $id) {
  111.                 /** @var Course $item */
  112.                 $item $courseRepository->find($id);
  113.                 if (!empty($item)) {
  114.                     $row = new Rowscourse();
  115.                     $row->setStudent($student);
  116.                     $row->setCourse($item);
  117.                     $row->setPrice($item->getPrice());
  118.                     $row->setStartAt($schoolyearService->getCurrent()->getStartAt());
  119.                     $row->setEndAt($schoolyearService->getCurrent()->getEndAt());
  120.                     $student->addRowscourse($row);
  121.                     $rowscourseRepository->save($rowtrue);
  122.                 }
  123.             }
  124.         }
  125.         $this->addFlash('success''Votre demande a été envoyée avec succès, On vous contactera sous peu');
  126.         return $this->redirectToRoute('hs_public_tutoring_registration_fiche', ['slug' => $student->getSlug()]);
  127.     }
  128.     #[Route(path'/fiche/{slug}'name'registration_fiche'options: ['expose' => true])]
  129.     public function registrationFiche($slugStudentRepository $studentRepository)
  130.     {
  131.         /** @var Student $student*/
  132.         $student $studentRepository->findOneBySlug($slug);
  133.         return $this->render(
  134.             'tutoring/fiche.html.twig',
  135.             array(
  136.                 'item' => $student,
  137.                 'current' => 'tutoring'
  138.             )
  139.         );
  140.     }
  141.     #[Route(path'/edit/{slug}'name'registration_edit'options: ['expose' => true])]
  142.     public function registrationEdit($slugStudentRepository $studentRepositoryRequest $request)
  143.     {
  144.         /** @var Student $student */
  145.         $student $studentRepository->findOneBySlug($slug);
  146.         if (empty($student)) {
  147.             $this->addFlash('warning''Veuillez vous inscrire s\'il vous plaît');
  148.             return $this->redirectToRoute('hs_public_tutoring_preinscription');
  149.         }
  150.         if ($student->isPublished()) {
  151.             return $this->redirectToRoute('hs_public_tutoring_registration_edit', ['slug' => $student->getSlug()]);
  152.         }
  153.         $form $this->createForm(CoursesType::class);
  154.         $form->handleRequest($request);
  155.         return $this->render(
  156.             'tutoring/inscription.html.twig',
  157.             array(
  158.                 'form' => $form->createView(),
  159.                 'item' => $student,
  160.                 'current' => 'tutoring'
  161.             )
  162.         );
  163.     }
  164.     #[Route(path'/fiche-pdf/{slug}'name'registration_fiche_pdf'options: ['expose' => true])]
  165.     public function registrationFichePDF($slugStudentRepository $studentRepositoryHtml2pdfFactory $html2pdfFactory)
  166.     {
  167.         /** @var Student $student*/
  168.         $student $studentRepository->findOneBySlug($slug);
  169.         $html $this->renderView(
  170.             'tutoring/fiche_pdf.html.twig',
  171.             array(
  172.                 'item' => $student,
  173.             )
  174.         );
  175.         $html2pdf $html2pdfFactory->create();
  176.         $html2pdf->pdf->SetDisplayMode('real');
  177.         $html2pdf->pdf->SetTitle('Fiche d\'inscription - Cours de soutien FOCUS');
  178.         $html2pdf->writeHTML($html);
  179.         return new Response($html2pdf->Output('FOCUS_fiche_inscription_' $student->getFirstName() . '_' $student->getLastName() . '.pdf'), 200, array('Content-Type' => 'application/pdf'));
  180.     }
  181.     /*
  182.      *      *      *****    *       *       *
  183.      *     * *       *     * *        *   *
  184.      *    *****      *    *****         *
  185.      *   *     *  *  *   *     *      *   *
  186.      *  *       *  **   *       *   *       *
  187.      *
  188.      */
  189.     #[Route(
  190.         path'/ajax/select/level/{cycle}',
  191.         name'ajax_select_niveau_by_cycle',
  192.         options: ['expose' => true],
  193.         defaults: ['cycle' => 'all']),
  194.     ]
  195.     public function selectNiveauByCycle($cycleLevelRepository $levelRepository)
  196.     {
  197.         if ($cycle == 'all') return new Response('false');
  198.         $niveaux $levelRepository->findGroupByNiveau($cycle);
  199.         $rep $this->renderView(
  200.             'tutoring/select_list_ajax_niveau.html.twig',
  201.             ['items' => $niveaux]
  202.         );
  203.         return new Response($rep);
  204.     }
  205.     #[Route(
  206.         path'/ajax/select/level/{cycle}/{niveau}',
  207.         name'ajax_select_niveau_by_niveau',
  208.         options: ['expose' => true],
  209.         defaults: ['cycle' => 'all''niveau' => 'all']),
  210.     ]
  211.     public function selectNiveauByNiveau($cycle$niveauLevelRepository $levelRepository)
  212.     {
  213.         if ($cycle == 'all' || $niveau == 'all') return new Response('false');
  214.         $niveaux $levelRepository->findBy(['cycle' => $cycle'name' => $niveau'published' => true]);
  215.         $rep $this->renderView(
  216.             'tutoring/select_list_ajax_branch.html.twig',
  217.             ['items' => $niveaux]
  218.         );
  219.         return new Response($rep);
  220.     }
  221.     #[Route(
  222.         path'/ajax/select/courses/{level}',
  223.         name'ajax_select_courses_by_level',
  224.         options: ['expose' => true],
  225.         defaults: ['cycle' => 'all''niveau' => 'all']),
  226.     ]
  227.     public function selectCourses($levelSchoolyearService $schoolyearServiceCourseRepository $courseRepositoryLevelRepository $levelRepository)
  228.     {
  229.         if ($level == 'all') return new Response('false');
  230.         $level1 $levelRepository->find($level);
  231.         if (empty($level1)) return new Response('false');
  232.         $courses $courseRepository->findByLevel($level1$schoolyearService->getCurrent());
  233.         $rep $this->renderView(
  234.             'tutoring/select_list_ajax_courses.html.twig',
  235.             ['items' => $courses]
  236.         );
  237.         return new Response($rep);
  238.     }
  239. }