|  | @@ -30,6 +30,16 @@ final class ParticipationController extends AbstractController
 | 
	
		
			
				|  |  |              $this->addFlash('danger', 'Participation inexistante !');
 | 
	
		
			
				|  |  |              return $this->redirectToRoute('app_main');
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $redirectPath = 'app_main';
 | 
	
		
			
				|  |  | +        $user = $this->getUser();
 | 
	
		
			
				|  |  | +        if ($user && $user->getEmail() == $participation->getParticipantEmail()) {
 | 
	
		
			
				|  |  | +            // L'utilisateur qui annule est connecté, la page de redirection est sa liste de parties
 | 
	
		
			
				|  |  | +            $redirectPath = 'app_profile_participations';
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // @todo: prendre en charge l'annulation en une fois de réservations de groupe
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          $form = $this->createFormBuilder(FormType::class)->getForm();
 | 
	
		
			
				|  |  |          $form->handleRequest($request);
 | 
	
		
			
				|  |  |          if ($form->isSubmitted() && $form->isValid()) {
 | 
	
	
		
			
				|  | @@ -40,12 +50,13 @@ final class ParticipationController extends AbstractController
 | 
	
		
			
				|  |  |              $manager->remove($participation);
 | 
	
		
			
				|  |  |              $manager->flush();
 | 
	
		
			
				|  |  |              $this->addFlash('info', 'Votre participation à '.$game.' du '.$gameDateStr.' a bien été annulée.');
 | 
	
		
			
				|  |  | -            return $this->redirectToRoute('app_main');
 | 
	
		
			
				|  |  | +            return $this->redirectToRoute($redirectPath);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return $this->render('participation/cancel.html.twig' , [
 | 
	
		
			
				|  |  |              'form' => $form,
 | 
	
		
			
				|  |  |              'participation' => $participation,
 | 
	
		
			
				|  |  | +            'redirectPath' => $redirectPath,
 | 
	
		
			
				|  |  |          ]);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -88,6 +99,14 @@ final class ParticipationController extends AbstractController
 | 
	
		
			
				|  |  |          // Traitement des entrées du formulaire
 | 
	
		
			
				|  |  |          $form->handleRequest($request);
 | 
	
		
			
				|  |  |          if ($form->isSubmitted() && $form->isValid()) {
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            // Récupérer le tableau des accompagnant.e envoyé
 | 
	
		
			
				|  |  | +            $partyMore = $request->request->all('party_more');
 | 
	
		
			
				|  |  | +            // Garder uniquement les noms non vides
 | 
	
		
			
				|  |  | +            $partyMore = array_filter($partyMore, fn($name) => trim($name) !== '');
 | 
	
		
			
				|  |  | +            // Réindexer pour avoir un tableau propre (0, 1, 2, ...)
 | 
	
		
			
				|  |  | +            $partyMore = array_values($partyMore);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              // On contrôle qu'il y a encore de la place, sinon -> erreur
 | 
	
		
			
				|  |  |              if ($party->getSeatsLeft() < 1) {
 | 
	
		
			
				|  |  |                  if ($party->getSeatsLeft() > 0) {
 | 
	
	
		
			
				|  | @@ -98,8 +117,6 @@ final class ParticipationController extends AbstractController
 | 
	
		
			
				|  |  |              } else {
 | 
	
		
			
				|  |  |                  $reservationsCounter = 1;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                // @todo: réservation multiples
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |                  // On enregistre dans la base
 | 
	
		
			
				|  |  |                  $manager->persist($participation);
 | 
	
		
			
				|  |  |                  $manager->flush();
 | 
	
	
		
			
				|  | @@ -116,6 +133,29 @@ final class ParticipationController extends AbstractController
 | 
	
		
			
				|  |  |                          'participation' => $participation,
 | 
	
		
			
				|  |  |                      ]);
 | 
	
		
			
				|  |  |                  $mailer->send($email);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                // On traite les accompagnant.e.s
 | 
	
		
			
				|  |  | +                foreach ($partyMore as $companion) {
 | 
	
		
			
				|  |  | +                    $newParticipation = new Participation;
 | 
	
		
			
				|  |  | +                    $newParticipation->setParty($participation->getParty());
 | 
	
		
			
				|  |  | +                    $newParticipation->setParticipantName($companion);
 | 
	
		
			
				|  |  | +                    $newParticipation->setParticipantEmail($participation->getParticipantEmail());
 | 
	
		
			
				|  |  | +                    $newParticipation->setParticipantPhone($participation->getParticipantPhone());
 | 
	
		
			
				|  |  | +                    $manager->persist($newParticipation);
 | 
	
		
			
				|  |  | +                    $manager->flush();                   
 | 
	
		
			
				|  |  | +                    $email = (new TemplatedEmail())
 | 
	
		
			
				|  |  | +                        ->from(new Address($_ENV['CONTACT_EMAIL'], $_ENV['CONTACT_NAME']))
 | 
	
		
			
				|  |  | +                        ->to((string) $participation->getParticipantEmail())
 | 
	
		
			
				|  |  | +                        ->subject('Votre réservation pour '.$party->getGame()->getName())
 | 
	
		
			
				|  |  | +                        ->htmlTemplate('participation/booking.email.html.twig')
 | 
	
		
			
				|  |  | +                        ->textTemplate('participation/booking.email.txt.twig')
 | 
	
		
			
				|  |  | +                        ->context([
 | 
	
		
			
				|  |  | +                            'participation' => $newParticipation,
 | 
	
		
			
				|  |  | +                        ]);
 | 
	
		
			
				|  |  | +                    $mailer->send($email);
 | 
	
		
			
				|  |  | +                    $reservationsCounter++;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                  // On informe
 | 
	
		
			
				|  |  |                  if ($reservationsCounter > 1) {
 | 
	
		
			
				|  |  |                      $this->addFlash('success', $reservationsCounter.' réservations enregistrées.');
 |