inscription and unscribe done

This commit is contained in:
Olivier PARPAILLON
2024-11-25 14:56:08 +01:00
parent b98dfd38c8
commit f852b0682a
3 changed files with 45 additions and 0 deletions

View File

@@ -122,6 +122,7 @@ class SortieController extends AbstractController
$this->addFlash('error', 'Cette sortie est complète.');
} else {
$sortie->addParticipant($userConnect);
$entityManager->persist($sortie);
$entityManager->flush();
$this->addFlash('success', 'Votre inscription a été validée.');
}
@@ -129,6 +130,33 @@ class SortieController extends AbstractController
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
#[Route('/unsubscribe/{id}', name: 'unsubscribe', methods: ['POST'])]
public function unsubscribe(string $id, EntityManagerInterface $entityManager, TokenStorageInterface $tokenStorage)
{
$userConnect = $tokenStorage->getToken()?->getUser();
if (!$userConnect) {
$this->addFlash('error', 'Vous devez être connecté pour vous inscrire.');
return $this->redirectToRoute('app_login');
}
$sortie = $entityManager->getRepository(Sortie::class)->find($id);
if (!$sortie) {
$this->addFlash('error', 'Cette sortie n\'existe pas.');
return $this->redirectToRoute('home');
}
if (!$sortie->getParticipants()->contains($userConnect)) {
$this->addFlash('error', 'Vous devez être inscrit pour vous désinscrire d\'une sortie.');
} else {
$sortie->removeParticipant($userConnect);
$entityManager->persist($sortie);
$entityManager->flush();
$this->addFlash('success', 'Vous ne participez pu à cette sortie.');
}
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
#[Route('/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
public function edit(
string $id,