From d10ef764bc0df0e4049b101c3c9964baeaf1dcfc Mon Sep 17 00:00:00 2001 From: Jannis Portmann Date: Sun, 9 May 2021 11:20:45 +0200 Subject: [PATCH] change homepage route --- src/Controller/Admin/DashboardController.php | 2 +- src/Controller/AppController.php | 6 +++ src/Controller/OfferController.php | 5 ++- templates/app/index.html.twig | 45 +++++++------------- templates/app/offer.html.twig | 39 ++++++++++------- templates/base.html.twig | 2 +- templates/offer/index.html.twig | 45 +++++++++++++------- 7 files changed, 80 insertions(+), 64 deletions(-) diff --git a/src/Controller/Admin/DashboardController.php b/src/Controller/Admin/DashboardController.php index b6c661a..df0148e 100644 --- a/src/Controller/Admin/DashboardController.php +++ b/src/Controller/Admin/DashboardController.php @@ -29,7 +29,7 @@ class DashboardController extends AbstractDashboardController public function configureMenuItems(): iterable { - yield MenuItem::linktoRoute('Back to the website', 'fas fa-arrow-left', 'homepage'); + yield MenuItem::linktoRoute('Back to the website', 'fas fa-arrow-left', 'offers'); yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home'); yield MenuItem::linkToCrud('User', 'fas fa-user', User::class); yield MenuItem::linkToCrud('Offering', 'fas fa-seedling', Offering::class); diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 4b85e62..5db6515 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -19,4 +19,10 @@ class AppController extends AbstractController { $this->entityManager = $entityManager; } + + #[Route('/', name: 'homepage')] + public function index(Environment $twig, OfferingRepository $offerRepository): Response + { + return new Response($twig->render('app/index.html.twig')); + } } diff --git a/src/Controller/OfferController.php b/src/Controller/OfferController.php index 1286092..fec0c56 100644 --- a/src/Controller/OfferController.php +++ b/src/Controller/OfferController.php @@ -25,7 +25,7 @@ class OfferController extends AbstractController $this->entityManager = $entityManager; } - #[Route('/', name: 'homepage')] + #[Route('/offers', name: 'offers')] public function index(Environment $twig, OfferingRepository $offerRepository): Response { return new Response($twig->render('app/index.html.twig', [ @@ -62,7 +62,7 @@ class OfferController extends AbstractController $this->entityManager->flush(); $this->addFlash("success", "Successfully added the new offer!"); - return $this->redirectToRoute('homepage'); + return $this->redirectToRoute('offers'); } return $this->render('app/new_offer.html.twig', [ @@ -75,6 +75,7 @@ class OfferController extends AbstractController public function show_offer(Offering $offer, WishRepository $wishRepository): Response { return $this->render('app/offer.html.twig', [ + 'user' => $this->getUser(), 'offer' => $offer, 'wishes' => $wishRepository->findByUser($offer->getByUser()), ]); diff --git a/templates/app/index.html.twig b/templates/app/index.html.twig index c773dc0..49343bb 100644 --- a/templates/app/index.html.twig +++ b/templates/app/index.html.twig @@ -1,35 +1,20 @@ {% extends 'base.html.twig' %} +{% block title %}Hello OfferController!{% endblock %} + {% block body %} + - {% for message in app.flashes('success') %} - - {% endfor %} +
+

Hello! ✅

-

Offers

- {% if offers|length > 0 %} - - {% else %} - - {% endif %} -{% endblock %} \ No newline at end of file + This friendly message is coming from: + +
+{% endblock %} diff --git a/templates/app/offer.html.twig b/templates/app/offer.html.twig index b6afcd0..5de1df1 100644 --- a/templates/app/offer.html.twig +++ b/templates/app/offer.html.twig @@ -1,6 +1,10 @@ {% extends 'base.html.twig' %} {% block body %} + {% if offer.byUser == user %} + + {% endif %} +

{{ offer.title }}

@@ -11,24 +15,29 @@

Description

{{ offer.description }}

From

-

{{ offer.byUser }} in {{ offer.zipCode }}

+

{% if offer.byUser == user %}Me{% else %}{{ offer.byUser }}{% endif %} in {{ offer.zipCode }}

-

Wishes

-

{{ offer.byUser }} would like some of the following in return:

-
- {% if wishes == [] %} - - {% endblock %} \ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index ba75956..ecfac9f 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -40,7 +40,7 @@