conflict resolved

This commit is contained in:
Olivier PARPAILLON
2024-11-26 15:58:14 +01:00
5 changed files with 214 additions and 43 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Controller;
use App\Entity\Etat;
use App\Entity\Sortie;
use App\Form\SortieType;
use App\Repository\EtatRepository;
@@ -235,4 +236,35 @@ class SortieController extends AbstractController
'profile' => $userConnect,
]);
}
#[Route('/cancel/{id}', name: 'cancel', methods: ['POST'])]
public function cancel(
string $id,
Request $request,
EntityManagerInterface $entityManager,
TokenStorageInterface $tokenStorage
): Response {
$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 d\'annuler cette sortie.');
return $this->redirectToRoute('home');
}
$motif = $request->request->get('motif');
if (!$motif) {
$this->addFlash('error', 'Le motif d\'annulation est obligatoire.');
return $this->redirectToRoute('sortie_view', ['id' => $id]);
}
$sortie->setMotifAnnul($motif);
$sortie->setEtat($entityManager->getRepository(Etat::class)->findOneBy(['libelle' => 'Annulée']));
$entityManager->flush();
$this->addFlash('success', 'La sortie a été annulée avec succès.');
return $this->redirectToRoute('home');
}
}

View File

@@ -29,7 +29,6 @@ class Sortie
private ?int $duree = null;
#[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
#[Assert\GreaterThan("today")]
private ?\DateTimeInterface $dateLimiteInscription = null;
#[ORM\Column(nullable: true)]

View File

@@ -17,45 +17,59 @@ class SortieRepository extends ServiceEntityRepository
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')
->setParameter('search', '%' . $search . '%');
}
if ($siteId) {
// Filtre par site
if (!empty($siteId)) {
$qb->andWhere('s.site = :siteId')
->setParameter('siteId', $siteId);
}
if ($startDate) {
// Filtre par date de début
if (!empty($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')
->setParameter('endDate', new \DateTime($endDate));
->setParameter('endDate', $endDate);
}
if ($organisateur) {
$qb->andWhere('s.organisateur = :user')
->setParameter('user', $user);
// Filtre par organisateur
if ($organisateur && $userConnect) {
$qb->andWhere('s.organisateur = :organisateur')
->setParameter('organisateur', $userConnect);
}
if ($inscrit) {
$qb->andWhere(':user MEMBER OF s.participants')
->setParameter('user', $user);
// Filtre par inscription
if ($inscrit && $userConnect) {
$qb->andWhere(':userConnect MEMBER OF s.participants')
->setParameter('userConnect', $userConnect);
}
if ($nonInscrit) {
$qb->andWhere(':user NOT MEMBER OF s.participants')
->setParameter('user', $user);
// Filtre par non-inscription
if ($nonInscrit && $userConnect) {
$qb->andWhere(':userConnect NOT MEMBER OF s.participants')
->setParameter('userConnect', $userConnect);
}
// Filtre par sorties passées
if ($passees) {
$qb->andWhere('s.dateHeureDebut < :now')
->setParameter('now', new \DateTime());
@@ -67,6 +81,7 @@ class SortieRepository extends ServiceEntityRepository
return $qb->getQuery()->getResult();
}
public function findForDashboard()
{
return $this->createQueryBuilder('s')