first commit

This commit is contained in:
BRAMAS Arthur
2025-10-16 17:09:34 +02:00
parent 02765a025e
commit 00a7a1665b
6 changed files with 129 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Contribution; use App\Entity\Contribution;
use App\Form\ContributionType; use App\Form\ContributionType;
use App\Repository\ContributionRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -14,11 +15,9 @@ use Symfony\Component\Routing\Attribute\Route;
final class ContributionController extends AbstractController final class ContributionController extends AbstractController
{ {
#[Route(name: 'app_contribution_index', methods: ['GET'])] #[Route(name: 'app_contribution_index', methods: ['GET'])]
public function index(EntityManagerInterface $entityManager): Response public function index(ContributionRepository $contributionRepository): Response
{ {
$contributions = $entityManager $contributions = $contributionRepository->findAll();
->getRepository(Contribution::class)
->findAll();
return $this->render('contribution/index.html.twig', [ return $this->render('contribution/index.html.twig', [
'contributions' => $contributions, 'contributions' => $contributions,
@@ -74,7 +73,8 @@ final class ContributionController extends AbstractController
#[Route('/{id}', name: 'app_contribution_delete', methods: ['POST'])] #[Route('/{id}', name: 'app_contribution_delete', methods: ['POST'])]
public function delete(Request $request, Contribution $contribution, EntityManagerInterface $entityManager): Response 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->remove($contribution);
$entityManager->flush(); $entityManager->flush();
} }

View File

@@ -4,6 +4,7 @@ namespace App\Controller;
use App\Entity\Membre; use App\Entity\Membre;
use App\Form\MembreType; use App\Form\MembreType;
use App\Repository\MembreRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -14,11 +15,9 @@ use Symfony\Component\Routing\Attribute\Route;
final class MembreController extends AbstractController final class MembreController extends AbstractController
{ {
#[Route(name: 'app_membre_index', methods: ['GET'])] #[Route(name: 'app_membre_index', methods: ['GET'])]
public function index(EntityManagerInterface $entityManager): Response public function index(MembreRepository $membreRepository): Response
{ {
$membres = $entityManager $membres = $membreRepository->findAll();
->getRepository(Membre::class)
->findAll();
return $this->render('membre/index.html.twig', [ return $this->render('membre/index.html.twig', [
'membres' => $membres, 'membres' => $membres,
@@ -74,7 +73,8 @@ final class MembreController extends AbstractController
#[Route('/{id}', name: 'app_membre_delete', methods: ['POST'])] #[Route('/{id}', name: 'app_membre_delete', methods: ['POST'])]
public function delete(Request $request, Membre $membre, EntityManagerInterface $entityManager): Response 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->remove($membre);
$entityManager->flush(); $entityManager->flush();
} }

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Repository;
use App\Entity\Contribution;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Contribution>
*/
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 dun 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();
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Repository;
use App\Entity\Membre;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Membre>
*/
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 dun 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();
}
}

View File

@@ -0,0 +1,39 @@
<?php
namespace App\Repository;
use App\Entity\Projet;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Projet>
*/
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();
}
}

View File

@@ -11,6 +11,7 @@
<th>Id</th> <th>Id</th>
<th>Nom</th> <th>Nom</th>
<th>Droit</th> <th>Droit</th>
<th>Contributions</th>
<th>actions</th> <th>actions</th>
</tr> </tr>
</thead> </thead>
@@ -20,6 +21,7 @@
<td>{{ membre.id }}</td> <td>{{ membre.id }}</td>
<td>{{ membre.nom }}</td> <td>{{ membre.nom }}</td>
<td>{{ membre.droit }}</td> <td>{{ membre.droit }}</td>
<td>{{ membre.contributions|length }}</td>
<td> <td>
<a href="{{ path('app_membre_show', {'id': membre.id}) }}">show</a> <a href="{{ path('app_membre_show', {'id': membre.id}) }}">show</a>
<a href="{{ path('app_membre_edit', {'id': membre.id}) }}">edit</a> <a href="{{ path('app_membre_edit', {'id': membre.id}) }}">edit</a>