sortie etat done

This commit is contained in:
Olivier PARPAILLON
2024-11-28 09:44:27 +01:00
parent 6a429984d1
commit 5d3b63b343
2 changed files with 86 additions and 7 deletions

View File

@@ -110,7 +110,7 @@ class SortieController extends AbstractController
$entityManager->flush(); $entityManager->flush();
$this->addFlash('success', 'La sortie a été créée avec succès.'); $this->addFlash('success', 'La sortie a été créée avec succès.');
return $this->redirectToRoute('home'); return $this->redirectToRoute('sortie_view', ['id'=> $sortie->getIdSortie()]);
} }
return $this->render('sortie/create.html.twig', [ return $this->render('sortie/create.html.twig', [
@@ -136,6 +136,14 @@ class SortieController extends AbstractController
return $this->redirectToRoute('home'); return $this->redirectToRoute('home');
} }
// Changer l'état si date de début commencé.
if($sortie->getDateLimiteInscription() < new DateTime()){
$sortie->setEtat($entityManager->getRepository(Etat::class)->findOneBy(['libelle' => 'Clôturée']));
}
if ($sortie->getDateHeureDebut() <= (new DateTime())) {
$sortie->setEtat($entityManager->getRepository(Etat::class)->findOneBy(['libelle' => 'En cours']));
}
return $this->render('sortie/view.html.twig', [ return $this->render('sortie/view.html.twig', [
'sortie' => $sortie, 'sortie' => $sortie,
'profile' => $tokenStorage->getToken()?->getUser(), 'profile' => $tokenStorage->getToken()?->getUser(),
@@ -280,4 +288,22 @@ class SortieController extends AbstractController
return $this->redirectToRoute('home'); return $this->redirectToRoute('home');
} }
#[Route('/confirm/{id}', name: 'confirm', methods: ['POST'])]
public function confirm(string $id, EntityManagerInterface $entityManager, TokenStorageInterface $tokenStorage)
{
$user = $tokenStorage->getToken()?->getUser();
$sortie = $entityManager->getRepository(Sortie::class)->find($id);
if (!$sortie || $sortie->getOrganisateur()->getIdParticipant() !== $user->getIdParticipant()) {
$this->addFlash('error', 'Vous n\'avez pas l\'autorisation de démarrer les inscriptions pour cette sortie.');
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
$sortie->setEtat($entityManager->getRepository(Etat::class)->findOneBy(['libelle' => 'Ouverte']));
$entityManager->flush();
$this->addFlash('success', 'Les inscriptions sont ouvertes pour cette sortie');
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
} }

View File

@@ -11,6 +11,9 @@
#delete-modal { #delete-modal {
z-index: 1050; z-index: 1050;
} }
#confirm-modal {
z-index: 1050;
}
</style> </style>
{% endblock %} {% endblock %}
</head> </head>
@@ -93,18 +96,32 @@
</div> </div>
{% endif %} {% endif %}
{% if app.user and app.user.idParticipant == sortie.organisateur.idParticipant and sortie.etat.libelle == 'Créée' %} {% if app.user and app.user.idParticipant == sortie.organisateur.idParticipant %}
<div class="mt-6 flex justify-end space-x-4"> <div class="mt-6 flex justify-end space-x-4">
{% if sortie.etat.libelle == 'Créée' or sortie.etat.libelle == 'Ouverte'%}
<button <button
type="button" type="button"
id="open-delete-modal" id="open-delete-modal"
class="px-6 py-3 bg-red-500 text-white rounded-md shadow hover:bg-red-600"> class="px-6 py-3 bg-red-500 text-white rounded-md shadow hover:bg-red-600">
❌ Annuler la sortie ❌ Annuler la sortie
</button> </button>
<a href="{{ path('sortie_edit', { id: sortie.idSortie }) }}" {% endif %}
class="px-6 py-3 bg-yellow-500 text-white rounded-md shadow hover:bg-yellow-600"> {% if sortie.etat.libelle == 'Créée' %}
✏️ Modifier la sortie <a href="{{ path('sortie_edit', { id: sortie.idSortie }) }}"
</a> class="px-6 py-3 bg-yellow-500 text-white rounded-md shadow hover:bg-yellow-600">
✏️ Modifier la sortie
</a>
{# <a href="{{ path('sortie_open', { id: sortie.idSortie }) }}"#}
{# class="px-6 py-3 bg-yellow-500 text-white rounded-md shadow hover:bg-yellow-600">#}
{# 🚀 Démarrer les inscriptions#}
{# </a>#}
<button
type="button"
id="open-confirm-modal"
class="px-6 py-3 bg-green-500 text-white rounded-md shadow hover:bg-green-600">
🚀 Démarrer les inscriptions
</button>
{% endif %}
</div> </div>
{% endif %} {% endif %}
@@ -161,6 +178,31 @@
</div> </div>
</div> </div>
{# Modale pour ouvrir les inscriptions d'une sortie#}
<div id="confirm-modal" class="fixed inset-0 flex items-center justify-center bg-gray-800 bg-opacity-50 hidden">
<div class="bg-white p-6 rounded-lg shadow-lg w-full max-w-lg">
<h2 class="text-xl font-bold mb-4">Ouvrir les inscriptions</h2>
<form action="{{ path('sortie_confirm', {id: sortie.idSortie}) }}" method="post">
<div class="mb-4">
<p class="text-base">La modification de cette sortie ne sera pu possible une fois les inscriptions ouverte</p>
</div>
<div class="flex justify-end space-x-4">
<button
type="button"
id="cancel-confirm-modal"
class="px-4 py-2 bg-gray-500 text-white rounded-md hover:bg-gray-600">
Annuler
</button>
<button
type="submit"
class="px-4 py-2 bg-green-500 text-white rounded-md hover:bg-green-600">
Démarrer les inscriptions
</button>
</div>
</form>
</div>
</div>
<div class="flex justify-center mt-8"> <div class="flex justify-center mt-8">
<a href="{{ path('home') }}" class="px-6 py-3 bg-blue-500 text-white rounded-md shadow hover:bg-blue-600"> <a href="{{ path('home') }}" class="px-6 py-3 bg-blue-500 text-white rounded-md shadow hover:bg-blue-600">
🔙 Retour à l'accueil 🔙 Retour à l'accueil
@@ -191,16 +233,27 @@
.openPopup(); .openPopup();
const openModalButton = document.getElementById('open-delete-modal'); const openModalButton = document.getElementById('open-delete-modal');
const openModalConfirm = document.getElementById('open-confirm-modal');
const cancelModalButton = document.getElementById('cancel-modal'); const cancelModalButton = document.getElementById('cancel-modal');
const cancelModalConfirm = document.getElementById('cancel-confirm-modal')
const deleteModal = document.getElementById('delete-modal'); const deleteModal = document.getElementById('delete-modal');
const confirmModal = document.getElementById('confirm-modal');
openModalButton?.addEventListener('click', () => { openModalButton?.addEventListener('click', () => {
deleteModal.classList.remove('hidden'); deleteModal.classList.remove('hidden');
}); });
cancelModalButton?.addEventListener('click', () => { cancelModalButton?.addEventListener('click', () => {
deleteModal.classList.add('hidden'); deleteModal.classList.add('hidden');
}); });
openModalConfirm?.addEventListener('click', () => {
confirmModal.classList.remove('hidden');
})
cancelModalConfirm?.addEventListener('click', () => {
confirmModal.classList.add('hidden')
})
}); });
</script> </script>
{% endblock %} {% endblock %}