From cd8fe1d509347ea52eaa657be9d6f3d153db9461 Mon Sep 17 00:00:00 2001 From: Pablo Rodriguez Date: Sun, 28 Jul 2024 00:09:47 -0400 Subject: [PATCH] Build user interface prototype --- composer.json | 1 + composer.lock | 66 ++++++++++++++++++++++++- src/Controller/ConferenceController.php | 26 ++++++---- templates/conference/index.html.twig | 22 +++------ templates/conference/show.html.twig | 24 +++++++++ 5 files changed, 115 insertions(+), 24 deletions(-) create mode 100644 templates/conference/show.html.twig diff --git a/composer.json b/composer.json index 6f2a5f4..e145451 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "symfony/yaml": "6.4.*", "symfonycorp/platformsh-meta": "^1.0", "twig/extra-bundle": "^2.12|^3.0", + "twig/intl-extra": "^3", "twig/twig": "^2.12|^3.0" }, "config": { diff --git a/composer.lock b/composer.lock index dd09624..c9d137f 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": "4a519caa6276f3bc3a66cec485313e3b", + "content-hash": "8c1a998d0fd531901efdf4231f51010e", "packages": [ { "name": "blackfire/php-sdk", @@ -7812,6 +7812,70 @@ ], "time": "2024-05-11T07:35:57+00:00" }, + { + "name": "twig/intl-extra", + "version": "v3.10.0", + "source": { + "type": "git", + "url": "https://github.com/twigphp/intl-extra.git", + "reference": "693f6beb8ca91fc6323e01b3addf983812f65c93" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twigphp/intl-extra/zipball/693f6beb8ca91fc6323e01b3addf983812f65c93", + "reference": "693f6beb8ca91fc6323e01b3addf983812f65c93", + "shasum": "" + }, + "require": { + "php": ">=7.2.5", + "symfony/intl": "^5.4|^6.4|^7.0", + "twig/twig": "^3.10" + }, + "require-dev": { + "symfony/phpunit-bridge": "^6.4|^7.0" + }, + "type": "library", + "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.10.0" + }, + "funding": [ + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/twig/twig", + "type": "tidelift" + } + ], + "time": "2024-05-11T07:35:57+00:00" + }, { "name": "twig/twig", "version": "v3.10.3", diff --git a/src/Controller/ConferenceController.php b/src/Controller/ConferenceController.php index 262396e..d18d3ac 100644 --- a/src/Controller/ConferenceController.php +++ b/src/Controller/ConferenceController.php @@ -2,22 +2,30 @@ namespace App\Controller; +use App\Entity\Conference; +use App\Repository\CommentRepository; +use App\Repository\ConferenceRepository; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Attribute\Route; +use Twig\Environment; class ConferenceController extends AbstractController { #[Route('/', name: 'homepage')] - public function index(): Response + public function index(Environment $twig, ConferenceRepository $conferenceRepository): Response { - return new Response(<< - - - - - EOF - ); + return new Response($twig->render('conference/index.html.twig', [ + 'conferences' => $conferenceRepository->findAll(), + ])); + } + + #[Route('/conference/{id}', name: 'conference')] + public function show(Environment $twig, Conference $conference, CommentRepository $commentRepository): Response + { + return new Response($twig->render('conference/show.html.twig', [ + 'conference' => $conference, + 'comments' => $commentRepository->findBy(['conference' => $conference], ['createdAt' => 'DESC']), + ])); } } diff --git a/templates/conference/index.html.twig b/templates/conference/index.html.twig index e5c46d7..57db8a9 100644 --- a/templates/conference/index.html.twig +++ b/templates/conference/index.html.twig @@ -1,20 +1,14 @@ {% extends 'base.html.twig' %} -{% block title %}Hello ConferenceController!{% endblock %} +{% block title %}Conference Guestbook{% endblock %} {% block body %} - +

Give your feedback!

-
-

Hello {{ controller_name }}! ✅

- - This friendly message is coming from: -
    -
  • Your controller at /home/pablo_rodriguez/guestbook/src/Controller/ConferenceController.php
  • -
  • Your template at /home/pablo_rodriguez/guestbook/templates/conference/index.html.twig
  • -
-
+ {% for conference in conferences %} +

{{ conference }}

+

+ View +

+ {% endfor %} {% endblock %} diff --git a/templates/conference/show.html.twig b/templates/conference/show.html.twig new file mode 100644 index 0000000..043de7b --- /dev/null +++ b/templates/conference/show.html.twig @@ -0,0 +1,24 @@ +{% extends 'base.html.twig' %} + +{% block title %}Conference Guestbook - {{ conference }}{% endblock %} + +{% block body %} +

{{ conference }} Conference

+ + {% if comments|length > 0 %} + {% for comment in comments %} + {% if comment.photoFilename %} + + {% endif %} + +

{{ comment.author }}

+ + {{ comment.createdAt|format_datetime('medium', 'short') }} + + +

{{ comment.text }}

+ {% endfor %} + {% else %} +
No comments have been posted yet for this conference.
+ {% endif %} +{% endblock %}