Compare commits
4 Commits
308914a3ed
...
e0d6563583
| Author | SHA1 | Date | |
|---|---|---|---|
| e0d6563583 | |||
| e538b82bf5 | |||
| cd8fe1d509 | |||
| 75afd8af57 |
@@ -46,6 +46,7 @@
|
|||||||
"symfony/yaml": "6.4.*",
|
"symfony/yaml": "6.4.*",
|
||||||
"symfonycorp/platformsh-meta": "^1.0",
|
"symfonycorp/platformsh-meta": "^1.0",
|
||||||
"twig/extra-bundle": "^2.12|^3.0",
|
"twig/extra-bundle": "^2.12|^3.0",
|
||||||
|
"twig/intl-extra": "^3",
|
||||||
"twig/twig": "^2.12|^3.0"
|
"twig/twig": "^2.12|^3.0"
|
||||||
},
|
},
|
||||||
"config": {
|
"config": {
|
||||||
|
|||||||
66
composer.lock
generated
66
composer.lock
generated
@@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "4a519caa6276f3bc3a66cec485313e3b",
|
"content-hash": "8c1a998d0fd531901efdf4231f51010e",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "blackfire/php-sdk",
|
"name": "blackfire/php-sdk",
|
||||||
@@ -7812,6 +7812,70 @@
|
|||||||
],
|
],
|
||||||
"time": "2024-05-11T07:35:57+00:00"
|
"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",
|
"name": "twig/twig",
|
||||||
"version": "v3.10.3",
|
"version": "v3.10.3",
|
||||||
|
|||||||
@@ -3,10 +3,17 @@
|
|||||||
namespace App\Controller\Admin;
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
use App\Entity\Comment;
|
use App\Entity\Comment;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
|
||||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||||
|
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;
|
||||||
|
|
||||||
class CommentCrudController extends AbstractCrudController
|
class CommentCrudController extends AbstractCrudController
|
||||||
{
|
{
|
||||||
@@ -15,14 +22,42 @@ class CommentCrudController extends AbstractCrudController
|
|||||||
return Comment::class;
|
return Comment::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public function configureCrud(Crud $crud): Crud
|
||||||
|
{
|
||||||
|
return $crud
|
||||||
|
->setEntityLabelInSingular('Conference Comment')
|
||||||
|
->setEntityLabelInPlural('Conference Comments')
|
||||||
|
->setSearchFields(['author', 'text', 'email'])
|
||||||
|
->setDefaultSort(['createdAt' => 'DESC'])
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function configureFilters(Filters $filters): Filters
|
||||||
|
{
|
||||||
|
return $filters
|
||||||
|
->add(EntityFilter::new('conference'));
|
||||||
|
}
|
||||||
|
|
||||||
public function configureFields(string $pageName): iterable
|
public function configureFields(string $pageName): iterable
|
||||||
{
|
{
|
||||||
return [
|
yield AssociationField::new('conference');
|
||||||
IdField::new('id'),
|
yield TextField::new('author');
|
||||||
TextField::new('title'),
|
yield EmailField::new('email');
|
||||||
TextEditorField::new('description'),
|
yield TextareaField::new('text')
|
||||||
];
|
->hideOnIndex()
|
||||||
|
;
|
||||||
|
yield TextField::new('photoFilename')
|
||||||
|
->onlyOnIndex()
|
||||||
|
;
|
||||||
|
|
||||||
|
$createdAt = DateTimeField::new('createdAt')->setFormTypeOptions([
|
||||||
|
'years' => range(date('Y'), date('Y') + 5),
|
||||||
|
'widget' => 'single_text',
|
||||||
|
]);
|
||||||
|
if(Crud::PAGE_EDIT === $pageName) {
|
||||||
|
yield $createdAt->setFormTypeOption('disabled', true);
|
||||||
|
} else {
|
||||||
|
yield $createdAt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,22 +2,36 @@
|
|||||||
|
|
||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Conference;
|
||||||
|
use App\Repository\CommentRepository;
|
||||||
|
use App\Repository\ConferenceRepository;
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Attribute\Route;
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use Twig\Environment;
|
||||||
|
|
||||||
class ConferenceController extends AbstractController
|
class ConferenceController extends AbstractController
|
||||||
{
|
{
|
||||||
#[Route('/', name: 'homepage')]
|
#[Route('/', name: 'homepage')]
|
||||||
public function index(): Response
|
public function index(ConferenceRepository $conferenceRepository): Response
|
||||||
{
|
{
|
||||||
return new Response(<<<EOF
|
return $this->render('conference/index.html.twig', [
|
||||||
<html>
|
'conferences' => $conferenceRepository->findAll(),
|
||||||
<body>
|
]);
|
||||||
<img src="/images/under-construction.gif" />
|
}
|
||||||
</body>
|
|
||||||
</html>
|
#[Route('/conference/{id}', name: 'conference')]
|
||||||
EOF
|
public function show(Request $request, Conference $conference, CommentRepository $commentRepository): Response
|
||||||
);
|
{
|
||||||
|
$offset = max(0, $request->query->getInt('offset', 0));
|
||||||
|
$paginator = $commentRepository->getCommentPaginator($conference, $offset);
|
||||||
|
|
||||||
|
return $this->render('conference/show.html.twig', [
|
||||||
|
'conference' => $conference,
|
||||||
|
'comments' => $paginator,
|
||||||
|
'previous' => $offset - CommentRepository::COMMENTS_PER_PAGE,
|
||||||
|
'next' => min(count($paginator), $offset + CommentRepository::COMMENTS_PER_PAGE)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,37 @@
|
|||||||
namespace App\Repository;
|
namespace App\Repository;
|
||||||
|
|
||||||
use App\Entity\Comment;
|
use App\Entity\Comment;
|
||||||
|
use App\Entity\Conference;
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @extends ServiceEntityRepository<Comment>
|
* @extends ServiceEntityRepository<Comment>
|
||||||
*/
|
*/
|
||||||
class CommentRepository extends ServiceEntityRepository
|
class CommentRepository extends ServiceEntityRepository
|
||||||
{
|
{
|
||||||
|
public const COMMENTS_PER_PAGE = 2;
|
||||||
|
|
||||||
public function __construct(ManagerRegistry $registry)
|
public function __construct(ManagerRegistry $registry)
|
||||||
{
|
{
|
||||||
parent::__construct($registry, Comment::class);
|
parent::__construct($registry, Comment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCommentPaginator(Conference $conference, int $offset): Paginator
|
||||||
|
{
|
||||||
|
$query = $this->createQueryBuilder('c')
|
||||||
|
->andWhere('c.conference = :conference')
|
||||||
|
->setParameter('conference', $conference)
|
||||||
|
->orderBy('c.createdAt', 'DESC')
|
||||||
|
->setMaxResults(self::COMMENTS_PER_PAGE)
|
||||||
|
->setFirstResult($offset)
|
||||||
|
->getQuery()
|
||||||
|
;
|
||||||
|
|
||||||
|
return new Paginator($query);
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * @return Comment[] Returns an array of Comment objects
|
// * @return Comment[] Returns an array of Comment objects
|
||||||
// */
|
// */
|
||||||
|
|||||||
@@ -1,20 +1,14 @@
|
|||||||
{% extends 'base.html.twig' %}
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
{% block title %}Hello ConferenceController!{% endblock %}
|
{% block title %}Conference Guestbook{% endblock %}
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<style>
|
<h2>Give your feedback!</h2>
|
||||||
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
|
|
||||||
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<div class="example-wrapper">
|
{% for conference in conferences %}
|
||||||
<h1>Hello {{ controller_name }}! ✅</h1>
|
<h4>{{ conference }}</h4>
|
||||||
|
<p>
|
||||||
This friendly message is coming from:
|
<a href="{{ path('conference', { id: conference.id }) }}">View</a>
|
||||||
<ul>
|
</p>
|
||||||
<li>Your controller at <code>/home/pablo_rodriguez/guestbook/src/Controller/ConferenceController.php</code></li>
|
{% endfor %}
|
||||||
<li>Your template at <code>/home/pablo_rodriguez/guestbook/templates/conference/index.html.twig</code></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
33
templates/conference/show.html.twig
Normal file
33
templates/conference/show.html.twig
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Conference Guestbook - {{ conference }}{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<h2>{{ conference }} Conference<h2>
|
||||||
|
|
||||||
|
{% if comments|length > 0 %}
|
||||||
|
<div>There are {{ comments|length }} comments.</div>
|
||||||
|
|
||||||
|
{% for comment in comments %}
|
||||||
|
{% if comment.photoFilename %}
|
||||||
|
<img src="{{ asset('uploads/photos/' ~ comment.photofilename) }}" style="max-width: 200px"/>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
<h4>{{ comment.author }}</h4>
|
||||||
|
<small>
|
||||||
|
{{ comment.createdAt|format_datetime('medium', 'short') }}
|
||||||
|
</small>
|
||||||
|
|
||||||
|
<p>{{ comment.text }}</p>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if previous >= 0 %}
|
||||||
|
<a href="{{ path('conference', { id: conference.id, offset: previous }) }}">Previous</a>
|
||||||
|
{% endif %}
|
||||||
|
{% if next < comments|length %}
|
||||||
|
<a href="{{ path('conference', { id: conference.id, offset: next }) }}">Next</a>
|
||||||
|
{% endif %}
|
||||||
|
{% else %}
|
||||||
|
<div>No comments have been posted yet for this conference.</div>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user