first commit
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
39
src/Repository/ContributionRepository.php
Normal file
39
src/Repository/ContributionRepository.php
Normal 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 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();
|
||||
}
|
||||
}
|
||||
39
src/Repository/MembreRepository.php
Normal file
39
src/Repository/MembreRepository.php
Normal 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 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();
|
||||
}
|
||||
}
|
||||
39
src/Repository/ProjetRepository.php
Normal file
39
src/Repository/ProjetRepository.php
Normal 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();
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@
|
||||
<th>Id</th>
|
||||
<th>Nom</th>
|
||||
<th>Droit</th>
|
||||
<th>Contributions</th>
|
||||
<th>actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -20,6 +21,7 @@
|
||||
<td>{{ membre.id }}</td>
|
||||
<td>{{ membre.nom }}</td>
|
||||
<td>{{ membre.droit }}</td>
|
||||
<td>{{ membre.contributions|length }}</td>
|
||||
<td>
|
||||
<a href="{{ path('app_membre_show', {'id': membre.id}) }}">show</a>
|
||||
<a href="{{ path('app_membre_edit', {'id': membre.id}) }}">edit</a>
|
||||
|
||||
Reference in New Issue
Block a user