|
|
|
|
@@ -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');
|
|
|
|
|
|