From 0cc7902f7f367caf1b4608747befd7d4a2427651 Mon Sep 17 00:00:00 2001 From: jannisp Date: Mon, 26 Apr 2021 17:31:24 +0200 Subject: [PATCH] disply all offerings on homepage --- composer.json | 1 + composer.lock | 71 +++++++++++++++++++++++++++++++- src/Controller/AppController.php | 15 ++++--- symfony.lock | 3 ++ templates/app/index.html.twig | 21 +++++++--- templates/app/user.html.twig | 9 ++++ 6 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 templates/app/user.html.twig diff --git a/composer.json b/composer.json index 31511e5..f50b350 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ "symfony/yaml": "5.2.*", "symfonycasts/verify-email-bundle": "^1.4", "twig/extra-bundle": "^2.12|^3.0", + "twig/intl-extra": "^3.3", "twig/twig": "^2.12|^3.0" }, "config": { diff --git a/composer.lock b/composer.lock index 740b4ce..6230179 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c6de01df386cc0add59c4fb1ed211ddf", + "content-hash": "25e9fe3b823da6b1cae7cf742689d667", "packages": [ { "name": "composer/package-versions-deprecated", @@ -7009,6 +7009,75 @@ ], "time": "2021-02-06T21:13:17+00:00" }, + { + "name": "twig/intl-extra", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/intl-extra.git", + "reference": "919e8f945c30bd3efeb6a4d79722cda538116658" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/intl-extra/zipball/919e8f945c30bd3efeb6a4d79722cda538116658", + "reference": "919e8f945c30bd3efeb6a4d79722cda538116658", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "symfony/intl": "^4.3|^5.0", + "twig/twig": "^2.4|^3.0" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4.9|^5.0.9" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "psr-4": { + "Twig\\Extra\\Intl\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + } + ], + "description": "A Twig extension for Intl", + "homepage": "https://twig.symfony.com", + "keywords": [ + "intl", + "twig" + ], + "support": { + "source": "https://github.com/twigphp/intl-extra/tree/v3.3.0" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2021-01-01T14:58:18+00:00" + }, { "name": "twig/twig", "version": "v3.3.0", diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index c495a04..fac385b 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -2,24 +2,27 @@ namespace App\Controller; +use App\Repository\OfferingRepository; + use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Twig\Environment; class AppController extends AbstractController { - #[Route('/homepage', name: 'homepage')] - public function index(): Response + #[Route('/', name: 'homepage')] + public function index(Environment $twig, OfferingRepository $offeringRepository): Response { - return $this->render('app/index.html.twig', [ - 'controller_name' => 'AppController', - ]); + return new Response($twig->render('app/index.html.twig', [ + 'offerings' => $offeringRepository->findAll(), + ])); } #[Route('/user', name: 'user_page')] public function user(): Response { - return $this->render('app/index.html.twig', [ + return $this->render('app/user.html.twig', [ 'user' => $this->getUser(), ]); } diff --git a/symfony.lock b/symfony.lock index 20182e3..4a3072b 100644 --- a/symfony.lock +++ b/symfony.lock @@ -471,6 +471,9 @@ "twig/extra-bundle": { "version": "v3.3.0" }, + "twig/intl-extra": { + "version": "v3.3.0" + }, "twig/twig": { "version": "v3.3.0" } diff --git a/templates/app/index.html.twig b/templates/app/index.html.twig index ff1c2e5..aa0d3fa 100644 --- a/templates/app/index.html.twig +++ b/templates/app/index.html.twig @@ -1,9 +1,18 @@ {% extends 'base.html.twig' %} -{% block title %}User{% endblock %} - {% block body %} -
-

Hello {{ user.username }}!

-

-{% endblock %} + {% if offerings|length > 0 %} + {% for offering in offerings %} + {% if offering.photoFilename %} + + {% endif %} + +

{{ offering.title }}

+ + {{ offering.createdAt|format_datetime('medium', 'short') }} + + {% endfor %} + {% else %} +

There are currently no active listings

+ {% endif %} +{% endblock %} \ No newline at end of file diff --git a/templates/app/user.html.twig b/templates/app/user.html.twig new file mode 100644 index 0000000..ff1c2e5 --- /dev/null +++ b/templates/app/user.html.twig @@ -0,0 +1,9 @@ +{% extends 'base.html.twig' %} + +{% block title %}User{% endblock %} + +{% block body %} +
+

Hello {{ user.username }}!

+

+{% endblock %}