<?php
namespace App\Controller;
use App\Entity\Tutoring\Course;
use App\Entity\Tutoring\Level;
use App\Entity\Tutoring\Rowscourse;
use App\Entity\Tutoring\Student;
use App\Form\Tutoring\CoursesType;
use App\Form\Tutoring\StudentType;
use App\Repository\Tutoring\CourseRepository;
use App\Repository\Tutoring\LevelRepository;
use App\Repository\Tutoring\RowscourseRepository;
use App\Repository\Tutoring\StudentRepository;
use App\Repository\Tutoring\SubjectRepository;
use App\Service\SchoolyearService;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Ensepar\Html2pdfBundle\Factory\Html2pdfFactory;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Yaml\Yaml;
#[Route('/soutien-scolaire', name: 'hs_public_tutoring_')]
class TutoringController extends AbstractController
{
Public function __construct(){}
#[Route(path: '/', name: 'index', options: ['expose' => true])]
public function indexAction(SubjectRepository $subjectRepository)
{
$subjects=$subjectRepository->findAll();
return $this->render('tutoring/index.html.twig', ['subjects'=>$subjects, 'current'=>'tutoring']);
}
#[Route(path: '/preinscription', name: 'preregistration', options: ['expose' => true])]
public function preRegistrationAction(StudentRepository $studentRepository, Request $request)
{
$item = new Student();
$form_soutient = $this->createForm(StudentType::class, $item);
$form_soutient->handleRequest($request);
if ($form_soutient->isSubmitted() && $form_soutient->isValid()) {
$studentRepository->save($item, true);
/* if (!empty($item->getEmail())) {
$message = (new \Swift_Message($this->getParm('0101_institute_name') . ' : Fiche d\'inscription '))
->setFrom($this->getParm('0104_institute_email'), $this->getParm('0101_institute_name'))
->setTo($item->getEmail())
->setBody(
$this->renderView(
'Emails/registration.html.twig',
array('item' => $item, 'infos' => $infos)
),
'text/html'
);
$mailer->send($message);
}*/
return $this->redirectToRoute('hs_public_tutoring_registration', ['slug' => $item->getSlug()]);
}
return $this->render('tutoring/preregistration.html.twig', ['form_soutien'=>$form_soutient->createView(), 'current'=>'tutoring']);
}
#[Route(path: '/inscription/{slug}', name: 'registration', options: ['expose' => true])]
public function registrationAction($slug, StudentRepository $studentRepository, Request $request)
{
$student = $studentRepository->findOneBySlug($slug);
if (empty($student)) {
$this->addFlash('warning', 'Veuillez vous inscrire s\'il vous plaît');
return $this->redirectToRoute('hs_public_tutoring_preregistration');
}
if (!$student->getRowscourses()->isEmpty()) {
$this->addFlash('info','Vous êtes déjà inscrit');
return $this->redirectToRoute('hs_public_tutoring_registration_fiche', ['slug' => $student->getSlug()]);
}
$form = $this->createForm(CoursesType::class);
$form->handleRequest($request);
return $this->render(
'tutoring/inscription.html.twig',
array(
'form' => $form->createView(),
'item' => $student,
'current' => 'tutoring'
)
);
}
#[Route(path: '/inscription_save/{slug}', name: 'registration_save', options: ['expose' => true])]
public function registrationSave($slug,
SchoolyearService $schoolyearService,
LevelRepository $levelRepository,
StudentRepository $studentRepository,
CourseRepository $courseRepository,
RowscourseRepository $rowscourseRepository,
Request $request
)
{
$levelid = $request->request->get('levelid');
$coursesid = $request->request->get('courses');
/** @var Level $level */
$level = $levelRepository->find($levelid);
/** @var Student $student*/
$student = $studentRepository->findOneBySlug($slug);
$student->setLevel($level);
$student->setFirstName($request->request->get('firstName'));
$student->setLastName($request->request->get('lastName'));
$student->setPhone($request->request->get('phone'));
$student->setParentPhone($request->request->get('parentPhone'));
$student->setParentJob($request->request->get('parentJob'));
$student->setEstabl($request->request->get('establ'));
$student->setAdress($request->request->get('adress'));
$student->getRowscourses()->clear();
$ids = explode("|", $coursesid);
if (!empty($ids)) {
foreach ($ids as $id) {
/** @var Course $item */
$item = $courseRepository->find($id);
if (!empty($item)) {
$row = new Rowscourse();
$row->setStudent($student);
$row->setCourse($item);
$row->setPrice($item->getPrice());
$row->setStartAt($schoolyearService->getCurrent()->getStartAt());
$row->setEndAt($schoolyearService->getCurrent()->getEndAt());
$student->addRowscourse($row);
$rowscourseRepository->save($row, true);
}
}
}
$this->addFlash('success', 'Votre demande a été envoyée avec succès, On vous contactera sous peu');
return $this->redirectToRoute('hs_public_tutoring_registration_fiche', ['slug' => $student->getSlug()]);
}
#[Route(path: '/fiche/{slug}', name: 'registration_fiche', options: ['expose' => true])]
public function registrationFiche($slug, StudentRepository $studentRepository)
{
/** @var Student $student*/
$student = $studentRepository->findOneBySlug($slug);
return $this->render(
'tutoring/fiche.html.twig',
array(
'item' => $student,
'current' => 'tutoring'
)
);
}
#[Route(path: '/edit/{slug}', name: 'registration_edit', options: ['expose' => true])]
public function registrationEdit($slug, StudentRepository $studentRepository, Request $request)
{
/** @var Student $student */
$student = $studentRepository->findOneBySlug($slug);
if (empty($student)) {
$this->addFlash('warning', 'Veuillez vous inscrire s\'il vous plaît');
return $this->redirectToRoute('hs_public_tutoring_preinscription');
}
if ($student->isPublished()) {
return $this->redirectToRoute('hs_public_tutoring_registration_edit', ['slug' => $student->getSlug()]);
}
$form = $this->createForm(CoursesType::class);
$form->handleRequest($request);
return $this->render(
'tutoring/inscription.html.twig',
array(
'form' => $form->createView(),
'item' => $student,
'current' => 'tutoring'
)
);
}
#[Route(path: '/fiche-pdf/{slug}', name: 'registration_fiche_pdf', options: ['expose' => true])]
public function registrationFichePDF($slug, StudentRepository $studentRepository, Html2pdfFactory $html2pdfFactory)
{
/** @var Student $student*/
$student = $studentRepository->findOneBySlug($slug);
$html = $this->renderView(
'tutoring/fiche_pdf.html.twig',
array(
'item' => $student,
)
);
$html2pdf = $html2pdfFactory->create();
$html2pdf->pdf->SetDisplayMode('real');
$html2pdf->pdf->SetTitle('Fiche d\'inscription - Cours de soutien FOCUS');
$html2pdf->writeHTML($html);
return new Response($html2pdf->Output('FOCUS_fiche_inscription_' . $student->getFirstName() . '_' . $student->getLastName() . '.pdf'), 200, array('Content-Type' => 'application/pdf'));
}
/*
* * ***** * * *
* * * * * * * *
* ***** * ***** *
* * * * * * * * *
* * * ** * * * *
*
*/
#[Route(
path: '/ajax/select/level/{cycle}',
name: 'ajax_select_niveau_by_cycle',
options: ['expose' => true],
defaults: ['cycle' => 'all']),
]
public function selectNiveauByCycle($cycle, LevelRepository $levelRepository)
{
if ($cycle == 'all') return new Response('false');
$niveaux = $levelRepository->findGroupByNiveau($cycle);
$rep = $this->renderView(
'tutoring/select_list_ajax_niveau.html.twig',
['items' => $niveaux]
);
return new Response($rep);
}
#[Route(
path: '/ajax/select/level/{cycle}/{niveau}',
name: 'ajax_select_niveau_by_niveau',
options: ['expose' => true],
defaults: ['cycle' => 'all', 'niveau' => 'all']),
]
public function selectNiveauByNiveau($cycle, $niveau, LevelRepository $levelRepository)
{
if ($cycle == 'all' || $niveau == 'all') return new Response('false');
$niveaux = $levelRepository->findBy(['cycle' => $cycle, 'name' => $niveau, 'published' => true]);
$rep = $this->renderView(
'tutoring/select_list_ajax_branch.html.twig',
['items' => $niveaux]
);
return new Response($rep);
}
#[Route(
path: '/ajax/select/courses/{level}',
name: 'ajax_select_courses_by_level',
options: ['expose' => true],
defaults: ['cycle' => 'all', 'niveau' => 'all']),
]
public function selectCourses($level, SchoolyearService $schoolyearService, CourseRepository $courseRepository, LevelRepository $levelRepository)
{
if ($level == 'all') return new Response('false');
$level1 = $levelRepository->find($level);
if (empty($level1)) return new Response('false');
$courses = $courseRepository->findByLevel($level1, $schoolyearService->getCurrent());
$rep = $this->renderView(
'tutoring/select_list_ajax_courses.html.twig',
['items' => $courses]
);
return new Response($rep);
}
}