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.');
|
$this->addFlash('error', 'Cette sortie est complète.');
|
||||||
} else {
|
} else {
|
||||||
$sortie->addParticipant($userConnect);
|
$sortie->addParticipant($userConnect);
|
||||||
|
$entityManager->persist($sortie);
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
$this->addFlash('success', 'Votre inscription a été validée.');
|
$this->addFlash('success', 'Votre inscription a été validée.');
|
||||||
}
|
}
|
||||||
@@ -129,6 +130,33 @@ class SortieController extends AbstractController
|
|||||||
return $this->redirectToRoute('sortie_view', ['id' => $id]);
|
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'])]
|
#[Route('/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
|
||||||
public function edit(
|
public function edit(
|
||||||
string $id,
|
string $id,
|
||||||
|
|||||||
@@ -202,6 +202,7 @@ class Sortie
|
|||||||
{
|
{
|
||||||
if (!$this->participants->contains($participant)) {
|
if (!$this->participants->contains($participant)) {
|
||||||
$this->participants->add($participant);
|
$this->participants->add($participant);
|
||||||
|
$participant->addSortiesParticipant($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -210,6 +211,7 @@ class Sortie
|
|||||||
public function removeParticipant(Participant $participant): static
|
public function removeParticipant(Participant $participant): static
|
||||||
{
|
{
|
||||||
$this->participants->removeElement($participant);
|
$this->participants->removeElement($participant);
|
||||||
|
$participant->removeSortiesParticipant($this);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,13 @@
|
|||||||
{% elseif app.user and sortie.participants.contains(app.user) %}
|
{% elseif app.user and sortie.participants.contains(app.user) %}
|
||||||
<div class="mt-6">
|
<div class="mt-6">
|
||||||
<p class="text-green-600 font-bold">✅ Vous êtes déjà inscrit à cette sortie.</p>
|
<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>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
@@ -85,6 +92,14 @@
|
|||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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>
|
||||||
|
|
||||||
<div class="lg:col-span-5 bg-white rounded-lg shadow p-6">
|
<div class="lg:col-span-5 bg-white rounded-lg shadow p-6">
|
||||||
|
|||||||
Reference in New Issue
Block a user