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,

View File

@@ -202,6 +202,7 @@ class Sortie
{
if (!$this->participants->contains($participant)) {
$this->participants->add($participant);
$participant->addSortiesParticipant($this);
}
return $this;
@@ -210,6 +211,7 @@ class Sortie
public function removeParticipant(Participant $participant): static
{
$this->participants->removeElement($participant);
$participant->removeSortiesParticipant($this);
return $this;
}

View File

@@ -74,6 +74,13 @@
{% elseif app.user and sortie.participants.contains(app.user) %}
<div class="mt-6">
<p class="text-green-600 font-bold">✅ Vous êtes déjà inscrit à cette sortie.</p>
{% if sortie.etat.libelle == 'Ouverte' %}
<form action="{{ path('sortie_unsubscribe', { id: sortie.idSortie }) }}" method="post" class="mt-6">
<button type="submit" class="px-6 py-3 bg-red-500 text-white rounded-md shadow hover:bg-red-600">
❌ Se désister
</button>
</form>
{% endif %}
</div>
{% endif %}
@@ -85,6 +92,14 @@
</a>
</div>
{% endif %}
{# {% if app.user %}#}
{# <div class="mt-6 flex">#}
{# <a href="{{ path('sortie_inscription') }}">#}
{# <button class="px-6 py-3 bg-green-500 text-white rounded-md shadow hover:bg-green-600">M'inscrire</button>#}
{# </a>#}
{# </div>#}
{# {% endif %}#}
</div>
<div class="lg:col-span-5 bg-white rounded-lg shadow p-6">