<?php
namespace App\Controller;
use App\Entity\CvFormation;
use App\Entity\Formation;
use App\Repository\FormationRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\String\Slugger\SluggerInterface;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Validator\Constraints\File;
class FormationController extends AbstractController
{
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @Route("/batiment/{nom<[a-zA-Z0-9\_]*>}", name="batiment")
*/
public function batiment(String $nom, FormationRepository $repo, Request $request, SluggerInterface $slugger, \Swift_Mailer $mailer): Response
{
$cvform = new CvFormation;
#dd($repo->findOneByCode($nom)->getNom());
$form = $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
->add('nom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Nom*'
]
])
->add('prenom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Prénom*'
]
])
->add('mail', EmailType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Adresse mail*'
]
])
->add('telephone', TextType::class, [
'required' => false,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Téléphone'
]
])
->add('cv', FileType::class, [
'label' => false,
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => true,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid PDF document',
])
],
])
/*->add('idFormation', HiddenType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'value' => $repo->findOneByCode($nom)->getNom()
]
])*/
->add('submit', SubmitType::class, [
'label' => 'Envoyer mon cv'
])
->getForm()
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
$cv = $form->get('cv')->getData();
// this condition is needed because the 'brochure' field is not required
// so the PDF file must be processed only when a file is uploaded
if ($cv) {
$originalFilename = pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
// this is needed to safely include the file name as part of the URL
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
// Move the file to the directory where brochures are stored
try {
$cv->move(
$this->getParameter('cvform_repo'),
$newFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
// updates the 'brochureFilename' property to store the PDF file name
// instead of its contents
$cvform->setCvname($newFilename);
}
$cvform->setIdFormation($repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom());
$this->em->persist($cvform);
$this->em->flush();
#dd($cvform);
$postu = $form->getData();
$adresseNom = $form['mail']->getData();
$expNom = $form['nom']->getData().' '.$form['prenom']->getData();
$pdf = '/uploads/cvformation/'.$form['cv']->getData();
$pdfname = $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
// On crée le message
$message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
// On attribue l'expéditeur
->setFrom('cnfpcontact@gmail.com')
// On attribue le destinataire
->setTo('contact@cnfpformations.fr')
// On crée le texte avec la vue
->setBody(
$this->renderView(
'formation/mail.html.twig', compact('postu')
),
'text/html'
)
// Optionally add any attachments
->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
;
$mailer->send($message);
$this->addFlash('success', 'Votre CV a bien été déposé.');
return $this->redirectToRoute('batiment', array('nom' => $repo->findOneByCode($nom)->getcode()));
}
return $this->render('formation/formation.html.twig', [
'formation' => $repo->findOneByCode($nom),
'titre' => $repo->findOneByCode($nom)->getNom(),
'cate' => $repo->findOneByCode($nom)->getCategorie(),
'formPostuler' => $form->createView()
]);
}
/**
* @Route("/comptabilite_gestion/{nom<[a-zA-Z\_]*>}", name="comptabilite_gestion")
*/
public function cg(String $nom, FormationRepository $repo, Request $request, SluggerInterface $slugger, \Swift_Mailer $mailer): Response
{
$cvform = new CvFormation;
$form = $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
->add('nom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Nom*'
]
])
->add('prenom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Prénom*'
]
])
->add('mail', EmailType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Adresse mail*'
]
])
->add('telephone', TextType::class, [
'required' => false,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Téléphone'
]
])
->add('cv', FileType::class, [
'label' => false,
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => true,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid PDF document',
])
],
])
->add('id_formation', HiddenType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
]
])
->add('submit', SubmitType::class, [
'label' => 'Envoyer mon cv'
])
->getForm()
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
$cv = $form->get('cv')->getData();
// this condition is needed because the 'brochure' field is not required
// so the PDF file must be processed only when a file is uploaded
if ($cv) {
$originalFilename = pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
// this is needed to safely include the file name as part of the URL
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
// Move the file to the directory where brochures are stored
try {
$cv->move(
$this->getParameter('cvform_repo'),
$newFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
// updates the 'brochureFilename' property to store the PDF file name
// instead of its contents
$cvform->setCvname($newFilename);
}
$this->em->persist($cvform);
$this->em->flush();
$postu = $form->getData();
$adresseNom = $form['mail']->getData();
$expNom = $form['nom']->getData().' '.$form['prenom']->getData();
$pdf = '/uploads/cvformation/'.$form['cv']->getData();
$pdfname = $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
// On crée le message
$message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
// On attribue l'expéditeur
->setFrom('cnfpcontact@gmail.com')
// On attribue le destinataire
->setTo('contact@cnfpformations.fr')
// On crée le texte avec la vue
->setBody(
$this->renderView(
'formation/mail.html.twig', compact('postu')
),
'text/html'
)
// Optionally add any attachments
->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
;
$mailer->send($message);
$this->addFlash('success', 'Votre CV a bien été déposé.');
return $this->redirectToRoute('comptabilite_gestion', array('nom' => $repo->findOneByCode($nom)->getcode()));
}
return $this->render('formation/formation.html.twig', [
'formation' => $repo->findOneByCode($nom),
'titre' => $repo->findOneByCode($nom)->getNom(),
'cate' => $repo->findOneByCode($nom)->getCategorie(),
'formPostuler' => $form->createView()
]);
}
/**
* @Route("/services/{nom<[a-zA-Z\_]*>}", name="services")
*/
public function services(String $nom, FormationRepository $repo, Request $request, SluggerInterface $slugger, \Swift_Mailer $mailer): Response
{
$cvform = new CvFormation;
$form = $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
->add('nom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Nom*'
]
])
->add('prenom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Prénom*'
]
])
->add('mail', EmailType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Adresse mail*'
]
])
->add('telephone', TextType::class, [
'required' => false,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Téléphone'
]
])
->add('cv', FileType::class, [
'label' => false,
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => true,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid PDF document',
])
],
])
->add('id_formation', HiddenType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
]
])
->add('submit', SubmitType::class, [
'label' => 'Envoyer mon cv'
])
->getForm()
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
$cv = $form->get('cv')->getData();
// this condition is needed because the 'brochure' field is not required
// so the PDF file must be processed only when a file is uploaded
if ($cv) {
$originalFilename = pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
// this is needed to safely include the file name as part of the URL
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
// Move the file to the directory where brochures are stored
try {
$cv->move(
$this->getParameter('cvform_repo'),
$newFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
// updates the 'brochureFilename' property to store the PDF file name
// instead of its contents
$cvform->setCvname($newFilename);
}
$this->em->persist($cvform);
$this->em->flush();
$postu = $form->getData();
$adresseNom = $form['mail']->getData();
$expNom = $form['nom']->getData().' '.$form['prenom']->getData();
$pdf = '/uploads/cvformation/'.$form['cv']->getData();
$pdfname = $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
// On crée le message
$message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
// On attribue l'expéditeur
->setFrom('cnfpcontact@gmail.com')
// On attribue le destinataire
->setTo('contact@cnfpformations.fr')
// On crée le texte avec la vue
->setBody(
$this->renderView(
'formation/mail.html.twig', compact('postu')
),
'text/html'
)
// Optionally add any attachments
->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
;
$mailer->send($message);
$this->addFlash('success', 'Votre CV a bien été déposé.');
return $this->redirectToRoute('services', array('nom' => $repo->findOneByCode($nom)->getcode()));
}
return $this->render('formation/formation.html.twig', [
'formation' => $repo->findOneByCode($nom),
'titre' => $repo->findOneByCode($nom)->getNom(),
'cate' => $repo->findOneByCode($nom)->getCategorie(),
'formPostuler' => $form->createView()
]);
}
/**
* @Route("/diagnostic_immobilier", name="diagnostic_immobilier")
*/
public function diag(): Response
{
return $this->render('formation/diag.html.twig', [
'titre' => "Diagnostic immobilier"
]);
}
/**
* @Route("/diagnostic_immobilier/cursus_complet", name="diagnostic_immobilier_cursus")
*/
public function diag_cursus(FormationRepository $repo, Request $request, SluggerInterface $slugger, \Swift_Mailer $mailer): Response
{
$nom = "diagnostic_immobilier";
$cvform = new CvFormation;
$form = $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
->add('nom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Nom*'
]
])
->add('prenom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Prénom*'
]
])
->add('mail', EmailType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Adresse mail*'
]
])
->add('telephone', TextType::class, [
'required' => false,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Téléphone'
]
])
->add('cv', FileType::class, [
'label' => false,
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => true,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid PDF document',
])
],
])
->add('id_formation', HiddenType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
]
])
->add('submit', SubmitType::class, [
'label' => 'Envoyer mon cv'
])
->getForm()
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
$cv = $form->get('cv')->getData();
// this condition is needed because the 'brochure' field is not required
// so the PDF file must be processed only when a file is uploaded
if ($cv) {
$originalFilename = pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
// this is needed to safely include the file name as part of the URL
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
// Move the file to the directory where brochures are stored
try {
$cv->move(
$this->getParameter('cvform_repo'),
$newFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
// updates the 'brochureFilename' property to store the PDF file name
// instead of its contents
$cvform->setCvname($newFilename);
}
$this->em->persist($cvform);
$this->em->flush();
$postu = $form->getData();
$adresseNom = $form['mail']->getData();
$expNom = $form['nom']->getData().' '.$form['prenom']->getData();
$pdf = '/uploads/cvformation/'.$form['cv']->getData();
$pdfname = $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
// On crée le message
$message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
// On attribue l'expéditeur
->setFrom('cnfpcontact@gmail.com')
// On attribue le destinataire
->setTo('contact@cnfpformations.fr')
// On crée le texte avec la vue
->setBody(
$this->renderView(
'formation/mail.html.twig', compact('postu')
),
'text/html'
)
// Optionally add any attachments
->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
;
$mailer->send($message);
$this->addFlash('success', 'Votre CV a bien été déposé.');
return $this->redirectToRoute('diagnostic_immobilier_cursus');
}
return $this->render('formation/diag_cursus.html.twig', [
'formation' => $repo->findOneByCode("diagnostic_immobilier"),
'titre' => "Diagnostic immobilier - Cursus complet",
'formPostuler' => $form->createView()
]);
}
/**
* @Route("/diagnostic_immobilier/modules", name="diagnostic_immobilier_modules")
*/
public function diag_modules(): Response
{
return $this->render('formation/diag_modules.html.twig', [
'titre' => "Diagnostic immobilier - Modules à la carte"
]);
}
/**
* @Route("/ascensoriste", name="ascensoriste")
*/
public function asc(FormationRepository $repo, Request $request, SluggerInterface $slugger, \Swift_Mailer $mailer): Response
{
$nom = "ascensoriste";
$cvform = new CvFormation;
$form = $this->createFormBuilder($cvform, ['attr' => ['id' => 'postuler-form']])
->add('nom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Nom*'
]
])
->add('prenom', TextType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Prénom*'
]
])
->add('mail', EmailType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Adresse mail*'
]
])
->add('telephone', TextType::class, [
'required' => false,
'label' => false,
'attr' => [
'autofocus' => false,
'placeholder' => 'Téléphone'
]
])
->add('cv', FileType::class, [
'label' => false,
// unmapped means that this field is not associated to any entity property
'mapped' => false,
// make it optional so you don't have to re-upload the PDF file
// every time you edit the Product details
'required' => true,
// unmapped fields can't define their validation using annotations
// in the associated entity, so you can use the PHP constraint classes
'constraints' => [
new File([
'maxSize' => '1024k',
'mimeTypes' => [
'application/pdf',
'application/x-pdf',
],
'mimeTypesMessage' => 'Please upload a valid PDF document',
])
],
])
->add('id_formation', HiddenType::class, [
'required' => true,
'label' => false,
'attr' => [
'autofocus' => false,
'value' => $repo->findOneByCode($nom)->getId().' - '.$repo->findOneByCode($nom)->getNom()
]
])
->add('submit', SubmitType::class, [
'label' => 'Envoyer mon cv'
])
->getForm()
;
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid() && isset($_POST['raison']) && empty($_POST['raison'])) {
$cv = $form->get('cv')->getData();
// this condition is needed because the 'brochure' field is not required
// so the PDF file must be processed only when a file is uploaded
if ($cv) {
$originalFilename = pathinfo($cv->getClientOriginalName(), PATHINFO_FILENAME);
// this is needed to safely include the file name as part of the URL
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$cv->guessExtension();
// Move the file to the directory where brochures are stored
try {
$cv->move(
$this->getParameter('cvform_repo'),
$newFilename
);
} catch (FileException $e) {
// ... handle exception if something happens during file upload
}
// updates the 'brochureFilename' property to store the PDF file name
// instead of its contents
$cvform->setCvname($newFilename);
}
$this->em->persist($cvform);
$this->em->flush();
$postu = $form->getData();
$adresseNom = $form['mail']->getData();
$expNom = $form['nom']->getData().' '.$form['prenom']->getData();
$pdf = '/uploads/cvformation/'.$form['cv']->getData();
$pdfname = $form['nom']->getData().'-'.$form['prenom']->getData().'.pdf';
// On crée le message
$message = (new \Swift_Message('CNFP - Nouvelle postulation - Formation '.$repo->findOneByCode($nom)->getNom()))
// On attribue l'expéditeur
->setFrom('cnfpcontact@gmail.com')
// On attribue le destinataire
->setTo('contact@cnfpformations.fr')
// On crée le texte avec la vue
->setBody(
$this->renderView(
'formation/mail.html.twig', compact('postu')
),
'text/html'
)
// Optionally add any attachments
->attach(\Swift_Attachment::fromPath($pdf)->setFilename($pdfname))
;
$mailer->send($message);
$this->addFlash('success', 'Votre CV a bien été déposé.');
return $this->redirectToRoute('ascensoriste');
}
return $this->render('formation/asc.html.twig', [
'formation' => $repo->findOneByCode($nom),
'titre' => "Ascensoriste",
'formPostuler' => $form->createView()
]);
}
}