Merge branch 'main' into Marvin

# Conflicts:
#	src/Repository/SortieRepository.php
#	templates/sortie/list.html.twig
This commit is contained in:
mepiphana2023
2024-11-26 15:59:51 +01:00
2 changed files with 151 additions and 35 deletions

View File

@@ -17,45 +17,59 @@ class SortieRepository extends ServiceEntityRepository
parent::__construct($registry, Sortie::class); parent::__construct($registry, Sortie::class);
} }
public function findWithFilters($search, $siteId, $startDate, $endDate, $organisateur, $inscrit, $nonInscrit, $passees, $user) public function findWithFilters($search, $siteId, $startDate, $endDate, $organisateur, $inscrit, $nonInscrit, $passees, $userConnect)
{ {
$qb = $this->createQueryBuilder('s'); $qb = $this->createQueryBuilder('s')
->leftJoin('s.etat', 'e')
->addSelect('e')
->leftJoin('s.participants', 'p')
->addSelect('p')
->where('e.libelle != :annulee')
->setParameter('annulee', 'Annulée');
if ($search) { // Filtre par nom
if (!empty($search)) {
$qb->andWhere('s.nom LIKE :search') $qb->andWhere('s.nom LIKE :search')
->setParameter('search', '%' . $search . '%'); ->setParameter('search', '%' . $search . '%');
} }
if ($siteId) { // Filtre par site
if (!empty($siteId)) {
$qb->andWhere('s.site = :siteId') $qb->andWhere('s.site = :siteId')
->setParameter('siteId', $siteId); ->setParameter('siteId', $siteId);
} }
if ($startDate) { // Filtre par date de début
if (!empty($startDate)) {
$qb->andWhere('s.dateHeureDebut >= :startDate') $qb->andWhere('s.dateHeureDebut >= :startDate')
->setParameter('startDate', new \DateTime($startDate)); ->setParameter('startDate', $startDate);
} }
if ($endDate) { // Filtre par date de fin
if (!empty($endDate)) {
$qb->andWhere('s.dateHeureDebut <= :endDate') $qb->andWhere('s.dateHeureDebut <= :endDate')
->setParameter('endDate', new \DateTime($endDate)); ->setParameter('endDate', $endDate);
} }
if ($organisateur) { // Filtre par organisateur
$qb->andWhere('s.organisateur = :user') if ($organisateur && $userConnect) {
->setParameter('user', $user); $qb->andWhere('s.organisateur = :organisateur')
->setParameter('organisateur', $userConnect);
} }
if ($inscrit) { // Filtre par inscription
$qb->andWhere(':user MEMBER OF s.participants') if ($inscrit && $userConnect) {
->setParameter('user', $user); $qb->andWhere(':userConnect MEMBER OF s.participants')
->setParameter('userConnect', $userConnect);
} }
if ($nonInscrit) { // Filtre par non-inscription
$qb->andWhere(':user NOT MEMBER OF s.participants') if ($nonInscrit && $userConnect) {
->setParameter('user', $user); $qb->andWhere(':userConnect NOT MEMBER OF s.participants')
->setParameter('userConnect', $userConnect);
} }
// Filtre par sorties passées
if ($passees) { if ($passees) {
$qb->andWhere('s.dateHeureDebut < :now') $qb->andWhere('s.dateHeureDebut < :now')
->setParameter('now', new \DateTime()); ->setParameter('now', new \DateTime());
@@ -67,6 +81,36 @@ class SortieRepository extends ServiceEntityRepository
return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }
public function findForDashboard()
{
return $this->createQueryBuilder('s')
->orderBy('s.dateLimiteInscription', 'ASC')
->andWhere('s.dateHeureDebut >= :lastMonth')
->setParameter('lastMonth', (new \DateTime())->modify('-1 month'))
->getQuery()
->getResult();
}
public function findUserParticipation($userConnect)
{
return $this->createQueryBuilder('s')
->leftJoin('s.participants', 'p')
->where('p.idParticipant = :user')
->setParameter('user', $userConnect->getIdParticipant())
->getQuery()
->getResult();
}
public function findUserOrganisation($userConnect)
{
return $this->createQueryBuilder('s')
->leftJoin('s.organisateur', 'o')
->where('o.idParticipant = :user')
->setParameter('user', $userConnect->getIdParticipant())
->getQuery()
->getResult();
}
public function findAllSites() public function findAllSites()
{ {
return $this->getEntityManager() return $this->getEntityManager()

View File

@@ -5,16 +5,46 @@
<title>Liste des sorties</title> <title>Liste des sorties</title>
{% block stylesheets %} {% block stylesheets %}
{{ encore_entry_link_tags('app') }} {{ encore_entry_link_tags('app') }}
<style>
.pin-creee {
background-color: #4CAF50;
}
.pin-ouverte {
background-color: #2196F3;
}
.pin-archivee {
background-color: #FF9800;
}
.pin-en-cours {
background-color: #FFC107;
}
.pin-terminee {
background-color: #9E9E9E;
}
.pin-annulee {
background-color: #f44336;
}
.pin-default {
background-color: #E0E0E0;
}
.pin {
display: inline-block;
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 8px;
}
</style>
{% endblock %} {% endblock %}
</head> </head>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
<div class="container mx-auto p-6 bg-gray-50 rounded-lg shadow-lg mt-6"> <div class="container mx-auto p-4 sm:p-6 bg-gray-50 rounded-lg shadow-lg mt-4 sm:mt-6">
<h1 class="text-3xl font-bold text-center text-gray-800 mb-8">🎉 Liste des sorties</h1> <h1 class="text-2xl sm:text-3xl font-bold text-center text-gray-800 mb-6 sm:mb-8">🎉 Liste des sorties</h1>
<form method="GET" action="{{ path('home') }}" class="bg-white rounded-lg shadow-md p-4 mb-6"> <form method="GET" action="{{ path('home') }}" class="bg-white rounded-lg shadow-md p-4 mb-6">
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6"> <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 sm:gap-6">
<div> <div>
<label for="search" class="block text-sm font-medium text-gray-700">🔍 Recherche</label> <label for="search" class="block text-sm font-medium text-gray-700">🔍 Recherche</label>
<input type="text" name="search" id="search" value="{{ app.request.query.get('search', '') }}" <input type="text" name="search" id="search" value="{{ app.request.query.get('search', '') }}"
@@ -47,7 +77,7 @@
</div> </div>
</div> </div>
<div class="mt-4 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"> <div class="mt-4 grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="flex items-center"> <div class="flex items-center">
<input type="checkbox" name="organisateur" id="organisateur" value="1" <input type="checkbox" name="organisateur" id="organisateur" value="1"
{% if app.request.query.get('organisateur') %}checked{% endif %} {% if app.request.query.get('organisateur') %}checked{% endif %}
@@ -84,29 +114,71 @@
</div> </div>
</form> </form>
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-6"> <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-4 sm:gap-6">
<a href="/sortie/creates"> <a href="/sortie/creates" class="hidden sm:block">
<div class="bg-white rounded-lg shadow-md p-4 text-center"> <div class="bg-white rounded-lg shadow-md p-4 text-center">
<img src="/img/add.svg" alt="Créer une sortie" class="w-40 h-40 mx-auto mb-4"> <img src="/img/add.svg" alt="Créer une sortie" class="w-24 h-24 mx-auto mb-4">
<h2 class="text-lg font-semibold">Créer une sortie</h2> <h2 class="text-lg font-semibold">Créer une sortie</h2>
</div> </div>
</a> </a>
{% for sortie in sorties %} {% for sortie in sorties %}
<div class="bg-white rounded-lg shadow-md p-4"> <div class="bg-white rounded-lg shadow-md p-4">
<h2 class="text-lg font-semibold text-gray-800">{{ sortie.nom }}</h2> <div class="flex items-center mb-2">
<p class="mt-2 text-gray-600"> <div class="pin
<strong>Date de début :</strong> {{ sortie.dateHeureDebut|date('d/m/Y H:i') }}<br> {% if sortie.etat.libelle == 'Créée' %}
<strong>Durée :</strong> {{ sortie.duree }} minutes<br> pin-creee
<strong>Inscriptions max :</strong> {{ sortie.nbInscriptionsMax }}<br> {% elseif sortie.etat.libelle == 'Ouverte' %}
<strong>Infos :</strong> {{ sortie.infosSortie }} pin-ouverte
</p> {% elseif sortie.etat.libelle == 'Archivée' %}
<div class="mt-4 flex justify-end"> pin-archivee
<a href="{{ path('sortie_view', { id: sortie.idSortie }) }}" class="text-blue-500 hover:text-blue-700 font-medium">Voir plus</a> {% elseif sortie.etat.libelle == 'En cours' %}
pin-en-cours
{% elseif sortie.etat.libelle == 'Terminée' %}
pin-terminee
{% elseif sortie.etat.libelle == 'Annulée' %}
pin-annulee
{% else %}
pin-default
{% endif %}
"></div>
<h2 class="text-lg font-semibold text-gray-800">{{ sortie.nom }}</h2>
</div> </div>
</div> <a href="{{ path('sortie_view', { id: sortie.idSortie }) }}" class="text-blue-500 hover:text-blue-700 font-medium">
<div class="bg-white rounded-lg shadow-md p-4">
<h2 class="text-lg font-semibold text-gray-800">{{ sortie.nom }}</h2>
<p class="mt-2 text-gray-600">
<strong>Date de début :</strong> {{ sortie.dateHeureDebut|date('d/m/Y H:i') }}<br>
<strong>Durée :</strong> {{ sortie.duree }} minutes<br>
<strong>Inscriptions max :</strong> {{ sortie.nbInscriptionsMax }}<br>
<strong>Infos :</strong> {{ sortie.infosSortie }}
</p>
</div>
</a>
{% else %} {% else %}
<p class="text-gray-600 text-center col-span-6">Aucune sortie ne correspond à vos critères.</p> <p class="text-gray-600 text-center col-span-4">Aucune sortie ne correspond à vos critères.</p>
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% block javascripts %}
{{ encore_entry_script_tags('app') }}
<script>
document.addEventListener('DOMContentLoaded', () => {
const inscritCheckbox = document.getElementById('inscrit');
const nonInscritCheckbox = document.getElementById('non_inscrit');
inscritCheckbox.addEventListener('change', () => {
if (inscritCheckbox.checked) {
nonInscritCheckbox.checked = false;
}
});
nonInscritCheckbox.addEventListener('change', () => {
if (nonInscritCheckbox.checked) {
inscritCheckbox.checked = false;
}
});
});
</script>
{% endblock %}
{% endblock %} {% endblock %}