diff --git a/src/Controller/ContributionController.php b/src/Controller/ContributionController.php index b60a400..c32620b 100644 --- a/src/Controller/ContributionController.php +++ b/src/Controller/ContributionController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Entity\Contribution; use App\Form\ContributionType; +use App\Repository\ContributionRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -14,11 +15,9 @@ use Symfony\Component\Routing\Attribute\Route; final class ContributionController extends AbstractController { #[Route(name: 'app_contribution_index', methods: ['GET'])] - public function index(EntityManagerInterface $entityManager): Response + public function index(ContributionRepository $contributionRepository): Response { - $contributions = $entityManager - ->getRepository(Contribution::class) - ->findAll(); + $contributions = $contributionRepository->findAll(); return $this->render('contribution/index.html.twig', [ 'contributions' => $contributions, @@ -74,7 +73,8 @@ final class ContributionController extends AbstractController #[Route('/{id}', name: 'app_contribution_delete', methods: ['POST'])] public function delete(Request $request, Contribution $contribution, EntityManagerInterface $entityManager): Response { - if ($this->isCsrfTokenValid('delete'.$contribution->getId(), $request->getPayload()->getString('_token'))) { + // ⚠ Correction CSRF + if ($this->isCsrfTokenValid('delete'.$contribution->getId(), $request->request->get('_token'))) { $entityManager->remove($contribution); $entityManager->flush(); } diff --git a/src/Controller/MembreController.php b/src/Controller/MembreController.php index c16957c..719859e 100644 --- a/src/Controller/MembreController.php +++ b/src/Controller/MembreController.php @@ -4,6 +4,7 @@ namespace App\Controller; use App\Entity\Membre; use App\Form\MembreType; +use App\Repository\MembreRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; @@ -14,11 +15,9 @@ use Symfony\Component\Routing\Attribute\Route; final class MembreController extends AbstractController { #[Route(name: 'app_membre_index', methods: ['GET'])] - public function index(EntityManagerInterface $entityManager): Response + public function index(MembreRepository $membreRepository): Response { - $membres = $entityManager - ->getRepository(Membre::class) - ->findAll(); + $membres = $membreRepository->findAll(); return $this->render('membre/index.html.twig', [ 'membres' => $membres, @@ -74,7 +73,8 @@ final class MembreController extends AbstractController #[Route('/{id}', name: 'app_membre_delete', methods: ['POST'])] public function delete(Request $request, Membre $membre, EntityManagerInterface $entityManager): Response { - if ($this->isCsrfTokenValid('delete'.$membre->getId(), $request->getPayload()->getString('_token'))) { + // ⚠ Correction : use $request->request->get('_token') instead of $request->getPayload() + if ($this->isCsrfTokenValid('delete'.$membre->getId(), $request->request->get('_token'))) { $entityManager->remove($membre); $entityManager->flush(); } diff --git a/src/Repository/ContributionRepository.php b/src/Repository/ContributionRepository.php new file mode 100644 index 0000000..979e8fb --- /dev/null +++ b/src/Repository/ContributionRepository.php @@ -0,0 +1,39 @@ + + */ +class ContributionRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Contribution::class); + } + + // 🔹 Exemple : trouver une contribution par son titre + public function findByTitle(string $title): ?Contribution + { + return $this->createQueryBuilder('c') + ->andWhere('c.title = :title') + ->setParameter('title', $title) + ->getQuery() + ->getOneOrNullResult(); + } + + // 🔹 Exemple : récupérer toutes les contributions d’un membre spécifique + public function findByMembre(int $membreId): array + { + return $this->createQueryBuilder('c') + ->andWhere('c.membre = :id') + ->setParameter('id', $membreId) + ->orderBy('c.date', 'DESC') + ->getQuery() + ->getResult(); + } +} diff --git a/src/Repository/MembreRepository.php b/src/Repository/MembreRepository.php new file mode 100644 index 0000000..8b13537 --- /dev/null +++ b/src/Repository/MembreRepository.php @@ -0,0 +1,39 @@ + + */ +class MembreRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Membre::class); + } + + // 🔹 Exemple : trouver un membre par son login (id) + public function findByLogin(string $login): ?Membre + { + return $this->createQueryBuilder('m') + ->andWhere('m.id = :login') + ->setParameter('login', $login) + ->getQuery() + ->getOneOrNullResult(); + } + + // 🔹 Exemple : récupérer tous les membres d’un rôle spécifique + public function findByDroit(string $role): array + { + return $this->createQueryBuilder('m') + ->andWhere('m.droit = :role') + ->setParameter('role', $role) + ->orderBy('m.nom', 'ASC') + ->getQuery() + ->getResult(); + } +} diff --git a/src/Repository/ProjetRepository.php b/src/Repository/ProjetRepository.php new file mode 100644 index 0000000..bfd9504 --- /dev/null +++ b/src/Repository/ProjetRepository.php @@ -0,0 +1,39 @@ + + */ +class ProjetRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Projet::class); + } + + // 🔹 Exemple : trouver un projet par son nom + public function findByName(string $name): ?Projet + { + return $this->createQueryBuilder('p') + ->andWhere('p.name = :name') + ->setParameter('name', $name) + ->getQuery() + ->getOneOrNullResult(); + } + + // 🔹 Exemple : récupérer tous les projets actifs + public function findActiveProjects(): array + { + return $this->createQueryBuilder('p') + ->andWhere('p.isActive = :active') + ->setParameter('active', true) + ->orderBy('p.createdAt', 'DESC') + ->getQuery() + ->getResult(); + } +} diff --git a/templates/membre/index.html.twig b/templates/membre/index.html.twig index 4ab18d7..6266a76 100644 --- a/templates/membre/index.html.twig +++ b/templates/membre/index.html.twig @@ -11,6 +11,7 @@ Id Nom Droit + Contributions actions @@ -20,6 +21,7 @@ {{ membre.id }} {{ membre.nom }} {{ membre.droit }} + {{ membre.contributions|length }} show edit