<?php
namespace App\Controller;
use App\Entity\Volunteers;
use App\Form\VolunteersType;
use App\Repository\SectionTitleRepository;
use App\Service\FileUploader;
use App\Notification\VolunteersNotification;
use Doctrine\ORM\EntityManagerInterface;
// use App\Notification\ConsultationNotification;
use Symfony\Component\HttpFoundation\Request;
use MercurySeries\FlashyBundle\FlashyNotifier;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class VolunteersController extends AbstractController
{
/**
* @Route("/bilimon-inscription", name="app_volunteers_index")
*/
public function index(FlashyNotifier $flashy, VolunteersNotification $notification, Request $request, FileUploader $fileUploader, EntityManagerInterface $entityManager, SectionTitleRepository $titleRepository)
{
$title = $titleRepository->findTitleByTag('registrationPage');
$volunteers = new Volunteers;
$form = $this->createForm(VolunteersType::class, $volunteers);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// /** @var UploadedFile $brochureFile */
$brochureFile = $form->get('passport')->getData();
if ($brochureFile) {
$brochureFileName = $fileUploader->upload($brochureFile);
$volunteers->setBrochureFilename($brochureFileName);
}
$notification->notify($volunteers);
$flashy->success('Votre candidature a bien été envoyée. Nous vous contacterons sous peu');
return $this->redirectToRoute('app_thanks_index');
}
// // tell Doctrine you want to (eventually) save the Product (no queries yet)
// $entityManager->persist($volunteers);
// // actually executes the queries (i.e. the INSERT query)
// $entityManager->flush();
return $this->render('registration/index.html.twig', [
'form' => $form->createView(),
'titles' => $title
]);
}
}