diff --git a/src/Controller/ProjectController.php b/src/Controller/ProjectController.php index 91bf17d..9cda60b 100644 --- a/src/Controller/ProjectController.php +++ b/src/Controller/ProjectController.php @@ -22,7 +22,7 @@ class ProjectController extends AbstractController #[Route('/', name: 'app_project')] public function index(EntityManagerInterface $entityManager): Response { - $projects = $entityManager->getRepository(Project::class)->findAll(); + $projects = $entityManager->getRepository(Project::class)->findAllOrderedByActivity(); return $this->render('project/index.html.twig', [ 'projects' => $projects, diff --git a/src/Repository/ProjectRepository.php b/src/Repository/ProjectRepository.php index 0865b50..cbdd125 100644 --- a/src/Repository/ProjectRepository.php +++ b/src/Repository/ProjectRepository.php @@ -3,6 +3,7 @@ namespace App\Repository; use App\Entity\Project; +use App\Entity\Task; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -16,20 +17,17 @@ class ProjectRepository extends ServiceEntityRepository parent::__construct($registry, Project::class); } - // /** - // * @return Project[] Returns an array of Project objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('p') - // ->andWhere('p.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('p.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } + /** + * @return Project[] Returns an array of Project objects + */ + public function findAllOrderedByActivity(): array + { + return $this->createQueryBuilder('p') + ->orderBy('p.createdAt', 'DESC') + ->getQuery() + ->getResult() + ; + } // public function findOneBySomeField($value): ?Project // {