inscription and unscribe done
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user