invitation event

This commit is contained in:
mepiphana2023
2024-11-25 14:50:14 +01:00
parent 7efa22978e
commit 0a6cd2b958
5 changed files with 64 additions and 18 deletions

View File

@@ -53,7 +53,7 @@ class SortieController extends AbstractController
}
// Définir les relations et l'état initial
$etat = $etatRepository->findOneBy(['libelle' => 'Créée']);
$etat = $etatRepository->findOneBy(['libelle' => 'Ouverte']);
if (!$etat) {
$this->addFlash('error', 'Erreur interne : état introuvable.');
return $this->redirectToRoute('sortie_create');
@@ -83,6 +83,7 @@ class SortieController extends AbstractController
EntityManagerInterface $entityManager,
TokenStorageInterface $tokenStorage
): Response {
dump('before sortie');
$sortie = $entityManager->getRepository(Sortie::class)->find($id);
if (!$sortie) {
$this->addFlash('error', 'Cette sortie n\'existe pas.');
@@ -99,10 +100,13 @@ class SortieController extends AbstractController
public function inscription(
string $id,
EntityManagerInterface $entityManager,
TokenStorageInterface $tokenStorage
TokenStorageInterface $tokenStorage,
ParticipantRepository $participantRepository,
): Response {
dump('before sortie');
$userConnect = $tokenStorage->getToken()?->getUser();
if (!$userConnect) {
$participant = $participantRepository->find($userConnect->getIdParticipant());
if (!$participant) {
$this->addFlash('error', 'Vous devez être connecté pour vous inscrire.');
return $this->redirectToRoute('app_login');
}
@@ -116,12 +120,13 @@ class SortieController extends AbstractController
// Conditions supplémentaires pour l'inscription
if ($sortie->getEtat()->getLibelle() !== 'Ouverte') {
$this->addFlash('error', 'Cette sortie n\'est pas ouverte aux inscriptions.');
} elseif ($sortie->getParticipants()->contains($userConnect)) {
} elseif ($sortie->getParticipants()->contains($participant)) {
$this->addFlash('error', 'Vous êtes déjà inscrit à cette sortie.');
} elseif ($sortie->getParticipants()->count() >= $sortie->getNbInscriptionsMax()) {
$this->addFlash('error', 'Cette sortie est complète.');
} else {
$sortie->addParticipant($userConnect);
$sortie->addParticipant($participant);
dump($sortie->getParticipants()->toArray());
$entityManager->flush();
$this->addFlash('success', 'Votre inscription a été validée.');
}
@@ -129,6 +134,39 @@ class SortieController extends AbstractController
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
#[Route('/desinscription/{id}', name: 'desinscription', methods: ['POST'])]
public function desinscription(
string $id,
EntityManagerInterface $entityManager,
TokenStorageInterface $tokenStorage,
ParticipantRepository $participantRepository,
): Response {
$userConnect = $tokenStorage->getToken()?->getUser();
$participant = $participantRepository->find($userConnect->getIdParticipant());
if (!$participant) {
$this->addFlash('error', 'Vous devez être connecté pour vous désinscrire.');
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($participant)) {
$sortie->removeParticipant($participant);
dump($sortie->getParticipants()->toArray());
$entityManager->flush();
$this->addFlash('success', 'Vous avez été désinscrit de la sortie.');
} else {
$this->addFlash('error', 'Vous n\'êtes pas inscrit à cette sortie.');
}
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
#[Route('/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
public function edit(
string $id,
@@ -144,6 +182,7 @@ class SortieController extends AbstractController
}
$userConnect = $tokenStorage->getToken()?->getUser();
if ($userConnect->getIdParticipant() !== $sortie->getOrganisateur()->getIdParticipant()) {
$this->addFlash('error', 'Vous ne pouvez pas modifier cette sortie.');
return $this->redirectToRoute('home');

View File

@@ -12,7 +12,6 @@ class EtatFixtures extends Fixture
public function load(ObjectManager $manager): void
{
$etats = [
'Créée',
'Ouverte',
'Clôturée',
'En cours',

View File

@@ -298,7 +298,7 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
{
if (!$this->sortiesParticipants->contains($sortiesParticipant)) {
$this->sortiesParticipants->add($sortiesParticipant);
$sortiesParticipant->addParticipant($this);
$sortiesParticipant->addParticipant($this); // Synchronise avec Sortie
}
return $this;

View File

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

View File

@@ -65,18 +65,25 @@
{% endif %}
</div>
{% if app.user and sortie.etat.libelle == 'Ouverte' and not sortie.participants.contains(app.user) %}
<form action="{{ path('sortie_inscription', { id: sortie.idSortie }) }}" method="post" class="mt-6">
<button type="submit" class="px-6 py-3 bg-green-500 text-white rounded-md shadow hover:bg-green-600">
✅ S'inscrire
</button>
</form>
{% 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>
</div>
{% if app.user and app.user.idParticipant != sortie.organisateur.idParticipant %}
{% if sortie.participants.contains(app.user) %}
<!-- Bouton pour se désinscrire -->
<form action="{{ path('sortie_desinscription', { 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ésinscrire
</button>
</form>
{% elseif sortie.etat.libelle == 'Ouverte' %}
<!-- Bouton pour s'inscrire -->
<form action="{{ path('sortie_inscription', { id: sortie.idSortie }) }}" method="post" class="mt-6">
<button type="submit" class="px-6 py-3 bg-green-500 text-white rounded-md shadow hover:bg-green-600">
✅ S'inscrire
</button>
</form>
{% endif %}
{% endif %}
{% if app.user and app.user.idParticipant == sortie.organisateur.idParticipant %}
<div class="mt-6 flex justify-end">
<a href="{{ path('sortie_edit', { id: sortie.idSortie }) }}"