invitation event
This commit is contained in:
@@ -53,7 +53,7 @@ class SortieController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Définir les relations et l'état initial
|
// Définir les relations et l'état initial
|
||||||
$etat = $etatRepository->findOneBy(['libelle' => 'Créée']);
|
$etat = $etatRepository->findOneBy(['libelle' => 'Ouverte']);
|
||||||
if (!$etat) {
|
if (!$etat) {
|
||||||
$this->addFlash('error', 'Erreur interne : état introuvable.');
|
$this->addFlash('error', 'Erreur interne : état introuvable.');
|
||||||
return $this->redirectToRoute('sortie_create');
|
return $this->redirectToRoute('sortie_create');
|
||||||
@@ -83,6 +83,7 @@ class SortieController extends AbstractController
|
|||||||
EntityManagerInterface $entityManager,
|
EntityManagerInterface $entityManager,
|
||||||
TokenStorageInterface $tokenStorage
|
TokenStorageInterface $tokenStorage
|
||||||
): Response {
|
): Response {
|
||||||
|
dump('before sortie');
|
||||||
$sortie = $entityManager->getRepository(Sortie::class)->find($id);
|
$sortie = $entityManager->getRepository(Sortie::class)->find($id);
|
||||||
if (!$sortie) {
|
if (!$sortie) {
|
||||||
$this->addFlash('error', 'Cette sortie n\'existe pas.');
|
$this->addFlash('error', 'Cette sortie n\'existe pas.');
|
||||||
@@ -99,10 +100,13 @@ class SortieController extends AbstractController
|
|||||||
public function inscription(
|
public function inscription(
|
||||||
string $id,
|
string $id,
|
||||||
EntityManagerInterface $entityManager,
|
EntityManagerInterface $entityManager,
|
||||||
TokenStorageInterface $tokenStorage
|
TokenStorageInterface $tokenStorage,
|
||||||
|
ParticipantRepository $participantRepository,
|
||||||
): Response {
|
): Response {
|
||||||
|
dump('before sortie');
|
||||||
$userConnect = $tokenStorage->getToken()?->getUser();
|
$userConnect = $tokenStorage->getToken()?->getUser();
|
||||||
if (!$userConnect) {
|
$participant = $participantRepository->find($userConnect->getIdParticipant());
|
||||||
|
if (!$participant) {
|
||||||
$this->addFlash('error', 'Vous devez être connecté pour vous inscrire.');
|
$this->addFlash('error', 'Vous devez être connecté pour vous inscrire.');
|
||||||
return $this->redirectToRoute('app_login');
|
return $this->redirectToRoute('app_login');
|
||||||
}
|
}
|
||||||
@@ -116,12 +120,13 @@ class SortieController extends AbstractController
|
|||||||
// Conditions supplémentaires pour l'inscription
|
// Conditions supplémentaires pour l'inscription
|
||||||
if ($sortie->getEtat()->getLibelle() !== 'Ouverte') {
|
if ($sortie->getEtat()->getLibelle() !== 'Ouverte') {
|
||||||
$this->addFlash('error', 'Cette sortie n\'est pas ouverte aux inscriptions.');
|
$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.');
|
$this->addFlash('error', 'Vous êtes déjà inscrit à cette sortie.');
|
||||||
} elseif ($sortie->getParticipants()->count() >= $sortie->getNbInscriptionsMax()) {
|
} elseif ($sortie->getParticipants()->count() >= $sortie->getNbInscriptionsMax()) {
|
||||||
$this->addFlash('error', 'Cette sortie est complète.');
|
$this->addFlash('error', 'Cette sortie est complète.');
|
||||||
} else {
|
} else {
|
||||||
$sortie->addParticipant($userConnect);
|
$sortie->addParticipant($participant);
|
||||||
|
dump($sortie->getParticipants()->toArray());
|
||||||
$entityManager->flush();
|
$entityManager->flush();
|
||||||
$this->addFlash('success', 'Votre inscription a été validée.');
|
$this->addFlash('success', 'Votre inscription a été validée.');
|
||||||
}
|
}
|
||||||
@@ -129,6 +134,39 @@ class SortieController extends AbstractController
|
|||||||
return $this->redirectToRoute('sortie_view', ['id' => $id]);
|
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'])]
|
#[Route('/edit/{id}', name: 'edit', methods: ['GET', 'POST'])]
|
||||||
public function edit(
|
public function edit(
|
||||||
string $id,
|
string $id,
|
||||||
@@ -144,6 +182,7 @@ class SortieController extends AbstractController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$userConnect = $tokenStorage->getToken()?->getUser();
|
$userConnect = $tokenStorage->getToken()?->getUser();
|
||||||
|
|
||||||
if ($userConnect->getIdParticipant() !== $sortie->getOrganisateur()->getIdParticipant()) {
|
if ($userConnect->getIdParticipant() !== $sortie->getOrganisateur()->getIdParticipant()) {
|
||||||
$this->addFlash('error', 'Vous ne pouvez pas modifier cette sortie.');
|
$this->addFlash('error', 'Vous ne pouvez pas modifier cette sortie.');
|
||||||
return $this->redirectToRoute('home');
|
return $this->redirectToRoute('home');
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ class EtatFixtures extends Fixture
|
|||||||
public function load(ObjectManager $manager): void
|
public function load(ObjectManager $manager): void
|
||||||
{
|
{
|
||||||
$etats = [
|
$etats = [
|
||||||
'Créée',
|
|
||||||
'Ouverte',
|
'Ouverte',
|
||||||
'Clôturée',
|
'Clôturée',
|
||||||
'En cours',
|
'En cours',
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ class Participant implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
{
|
{
|
||||||
if (!$this->sortiesParticipants->contains($sortiesParticipant)) {
|
if (!$this->sortiesParticipants->contains($sortiesParticipant)) {
|
||||||
$this->sortiesParticipants->add($sortiesParticipant);
|
$this->sortiesParticipants->add($sortiesParticipant);
|
||||||
$sortiesParticipant->addParticipant($this);
|
$sortiesParticipant->addParticipant($this); // Synchronise avec Sortie
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@@ -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); // Synchronisation côté Participant
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -210,7 +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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,18 +65,25 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if app.user and sortie.etat.libelle == 'Ouverte' and not sortie.participants.contains(app.user) %}
|
{% if app.user and app.user.idParticipant != sortie.organisateur.idParticipant %}
|
||||||
<form action="{{ path('sortie_inscription', { id: sortie.idSortie }) }}" method="post" class="mt-6">
|
{% if sortie.participants.contains(app.user) %}
|
||||||
<button type="submit" class="px-6 py-3 bg-green-500 text-white rounded-md shadow hover:bg-green-600">
|
<!-- Bouton pour se désinscrire -->
|
||||||
✅ S'inscrire
|
<form action="{{ path('sortie_desinscription', { id: sortie.idSortie }) }}" method="post" class="mt-6">
|
||||||
</button>
|
<button type="submit" class="px-6 py-3 bg-red-500 text-white rounded-md shadow hover:bg-red-600">
|
||||||
</form>
|
❌ Se désinscrire
|
||||||
{% elseif app.user and sortie.participants.contains(app.user) %}
|
</button>
|
||||||
<div class="mt-6">
|
</form>
|
||||||
<p class="text-green-600 font-bold">✅ Vous êtes déjà inscrit à cette sortie.</p>
|
{% elseif sortie.etat.libelle == 'Ouverte' %}
|
||||||
</div>
|
<!-- 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 %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
{% if app.user and app.user.idParticipant == sortie.organisateur.idParticipant %}
|
{% if app.user and app.user.idParticipant == sortie.organisateur.idParticipant %}
|
||||||
<div class="mt-6 flex justify-end">
|
<div class="mt-6 flex justify-end">
|
||||||
<a href="{{ path('sortie_edit', { id: sortie.idSortie }) }}"
|
<a href="{{ path('sortie_edit', { id: sortie.idSortie }) }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user