From c553c9c805daba0d07c30e0ff5b153a4a24a020a Mon Sep 17 00:00:00 2001 From: Thomy Loan <loan.thomy@etudiant.univ-lr.fr> Date: Mon, 11 Dec 2023 10:23:58 +0100 Subject: [PATCH] add /artistes --- src/Controller/DefaultController.php | 14 ++++++++++++++ src/Repository/ConcertRepository.php | 11 +++++++++++ templates/default/artistes.html.twig | 15 +++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 templates/default/artistes.html.twig diff --git a/src/Controller/DefaultController.php b/src/Controller/DefaultController.php index d9cee41..a7cd524 100644 --- a/src/Controller/DefaultController.php +++ b/src/Controller/DefaultController.php @@ -5,6 +5,7 @@ namespace App\Controller; use App\Entity\Concert; use App\Entity\Email; use App\Form\NewsletterType; +use App\Repository\ArtisteRepository; use App\Repository\ConcertRepository; use App\Repository\EmailRepository; use Doctrine\ORM\EntityManagerInterface; @@ -12,6 +13,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use function Sodium\add; class DefaultController extends AbstractController { @@ -27,6 +29,18 @@ class DefaultController extends AbstractController } + #[Route('/artistes', name: 'app_artistes')] + public function artists(ArtisteRepository $ar, ConcertRepository $cr): Response + { + $pastConcerts=$cr->findPast(); + $artistes = []; + foreach($pastConcerts as $concert){ + array_push($artistes, $concert->getArtiste()); + } + return $this->render('default/artistes.html.twig', [ + 'artistes'=>$artistes + ]); + } #[Route("/concert/{id}", name: "app_concert")] public function voirConcert(Concert $concert): Response diff --git a/src/Repository/ConcertRepository.php b/src/Repository/ConcertRepository.php index d0a3121..72023ae 100644 --- a/src/Repository/ConcertRepository.php +++ b/src/Repository/ConcertRepository.php @@ -44,6 +44,17 @@ class ConcertRepository extends ServiceEntityRepository return $this->findBy(array(), array('dateConcert' => 'ASC')); } + public function findPast(): array + { + $currentDate = new \DateTime(); + + return $this->createQueryBuilder('c') + ->andWhere('c.dateConcert < :currentDate') + ->setParameter('currentDate', $currentDate) + ->getQuery() + ->getResult(); + } + // /** // * @return Concert[] Returns an array of Concert objects // */ diff --git a/templates/default/artistes.html.twig b/templates/default/artistes.html.twig new file mode 100644 index 0000000..d79c2ab --- /dev/null +++ b/templates/default/artistes.html.twig @@ -0,0 +1,15 @@ +{% extends 'base.html.twig' %} + +{% block body %} + <main class="wrap"> + <header><h2>Ils sont passés à La Sirène !</h2></header> + <ul class="listeEvenements"> + {% for artiste in artistes %} + <li class="evenement"> + <img src="assets/imgGroupes/{{ artiste.photo }}" alt=""> + <h3>{{artiste.nom}}</h3> + </li> + {% endfor %} + </ul> + </main> +{% endblock %} -- GitLab