From e2efb267f5f4d290471bdd2c042d79f401bcd81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 29 Nov 2023 20:52:12 +0100 Subject: [PATCH] Improve layout of the history page --- .../Controller/NewsItemHistoryController.php | 21 +++--- .../Repository/NewsItemRepository.php | 8 ++- .../NewsItem/news_items_history.html.twig | 66 +++++++------------ .../Resources/views/NewsItem/show.html.twig | 29 ++++---- 4 files changed, 58 insertions(+), 66 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php b/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php index ff7adf818..1b000665b 100644 --- a/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php +++ b/src/Bundle/ChillMainBundle/Controller/NewsItemHistoryController.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; +use Chill\MainBundle\Entity\NewsItem; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Repository\NewsItemRepository; use Chill\MainBundle\Templating\Listing\FilterOrderHelper; @@ -19,6 +20,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Twig\Environment; class NewsItemHistoryController extends AbstractController { @@ -26,42 +28,41 @@ class NewsItemHistoryController extends AbstractController private readonly NewsItemRepository $newsItemRepository, private readonly PaginatorFactory $paginatorFactory, private readonly FilterOrderHelperFactoryInterface $filterOrderHelperFactory, + private readonly Environment $environment, ) {} /** * @Route("/{_locale}/news-items/history", name="chill_main_news_items_history") */ - public function listAction(Request $request): Response + public function list(): Response { - $filter = $this->buildFilterOrder(false); + $filter = $this->buildFilterOrder(); $total = $this->newsItemRepository->countAllFilteredBySearchTerm($filter->getQueryString()); $newsItems = $this->newsItemRepository->findAllFilteredBySearchTerm($filter->getQueryString()); $pagination = $this->paginatorFactory->create($total); - return $this->render('@ChillMain/NewsItem/news_items_history.html.twig', [ + return new Response($this->environment->render('@ChillMain/NewsItem/news_items_history.html.twig', [ 'entities' => $newsItems, 'paginator' => $pagination, 'filter_order' => $filter, - ]); + ])); } /** * @Route("/{_locale}/news-items/{id}", name="chill_main_single_news_item") */ - public function showSingleItem(int $id, Request $request): Response + public function showSingleItem(NewsItem $newsItem, Request $request): Response { - $newsItem = $this->newsItemRepository->findOneBy(['id' => $id]); - - return $this->render( + return new Response($this->environment->render( '@ChillMain/NewsItem/show.html.twig', [ 'entity' => $newsItem, ] - ); + )); } - private function buildFilterOrder($includeFilterByUser = true, $includeMissionType = false): FilterOrderHelper + private function buildFilterOrder(): FilterOrderHelper { $filterBuilder = $this->filterOrderHelperFactory ->create(self::class) diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index 6787e78bd..f8a155c68 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -57,11 +57,14 @@ class NewsItemRepository implements ObjectRepository return NewsItem::class; } - public function buildBaseQuery( + private function buildBaseQuery( string $pattern = null ): QueryBuilder { $qb = $this->createQueryBuilder('n'); + $qb->where('n.startDate <= :now'); + $qb->setParameter('now', $this->clock->now()); + if (null !== $pattern && '' !== $pattern) { $qb->andWhere($qb->expr()->like('LOWER(UNACCENT(n.title))', 'LOWER(UNACCENT(:pattern))')) ->orWhere($qb->expr()->like('LOWER(UNACCENT(n.content))', 'LOWER(UNACCENT(:pattern))')) @@ -74,7 +77,8 @@ class NewsItemRepository implements ObjectRepository public function findAllFilteredBySearchTerm(string $pattern = null) { $qb = $this->buildBaseQuery($pattern); - $qb->addOrderBy('n.startDate', 'DESC') + $qb + ->addOrderBy('n.startDate', 'DESC') ->addOrderBy('n.id', 'DESC'); return $qb->getQuery()->getResult(); diff --git a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/news_items_history.html.twig b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/news_items_history.html.twig index e462c3302..e6e5f862c 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/news_items_history.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/news_items_history.html.twig @@ -21,54 +21,38 @@ {% for entity in entities %}
-
- -
-

- {{ entity.title }} -

-
- {% if entity.startDate %} - {{ entity.startDate|format_date('long') }} - {% endif %} - {% if entity.endDate %} - - {{ entity.endDate|format_date('long') }} - {% endif %} -
-
-
-
-
-{#
#} - {{ entity.content|u.truncate(350, '…', false)|chill_markdown_to_html }} -{# {% if entity.content|length > 350 %}#} -{# {{ 'news.read_more'|trans }}#} -{# {% endif %}#} -{#
#} -
-
    -
  • - -
  • -
-
-
-
+
+

+ {{ entity.title }} +

+
+
+

+ {% if entity.startDate %} + {{ entity.startDate|format_date('long') }} + {% endif %} + {% if entity.endDate %} + - {{ entity.endDate|format_date('long') }} + {% endif %} +

+
+
+
+ {{ entity.content|u.truncate(350, '… [' ~ ('news.read_more'|trans) ~ '](' ~ chill_path_add_return_path('chill_main_single_news_item', { 'id': entity.id } ) ~ ')', false)|chill_markdown_to_html }}
+
+
    +
  • + +
  • +
+
{% endfor %}
{{ chill_pagination(paginator) }} - - {% endif %}
{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/show.html.twig index b86408183..764a2cc6f 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/NewsItem/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/show.html.twig @@ -3,19 +3,22 @@ {% block title 'news.show_details'|trans %} {% block content %} -

{{ entity.title }}

+
+

{{ entity.title }}

-
-
-
- {{ entity.startDate|format_date('long') }} - {% if entity.endDate is not null %} - - {{ entity.endDate|format_date('long') }} - {% endif %} -
-
-
- {{ entity.content|chill_markdown_to_html }} -
+
+ {{ entity.startDate|format_date('long') }} + {% if entity.endDate is not null %} + - {{ entity.endDate|format_date('long') }} + {% endif %} +
+
+ {{ entity.content|chill_markdown_to_html }} +
+
{% endblock %}