diff --git a/src/Bundle/ChillMainBundle/Controller/UserNewsItemsController.php b/src/Bundle/ChillMainBundle/Controller/UserNewsItemsController.php new file mode 100644 index 000000000..08074f346 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Controller/UserNewsItemsController.php @@ -0,0 +1,57 @@ +buildFilterOrder(false); + $total = $this->newsItemRepository->countAllFilteredByUser($filter->getQueryString()); + $newsItems = $this->newsItemRepository->findAllFilteredByUser($filter->getQueryString()); + + $pagination = $this->paginatorFactory->create($total); + + return $this->render('@ChillMain/NewsItem/news_items_history.html.twig', [ + 'entities' => $newsItems, + 'paginator' => $pagination, + 'filter_order' => $filter, + ]); + } + + private function buildFilterOrder($includeFilterByUser = true, $includeMissionType = false): FilterOrderHelper + { + $filterBuilder = $this->filterOrderHelperFactory + ->create(self::class) + ->addSearchBox(); + + return $filterBuilder->build(); + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php index be5190873..b9b0f8727 100644 --- a/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NewsItemRepository.php @@ -57,17 +57,46 @@ class NewsItemRepository implements ObjectRepository return NewsItem::class; } + public function buildBaseQuery( + string $pattern = null + ): QueryBuilder { + $qb = $this->createQueryBuilder('n'); + + 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))')) + ->setParameter('pattern', '%'.$pattern.'%'); + } + + return $qb; + } + + public function findAllFilteredByUser(string $pattern = null) + { + $qb = $this->buildBaseQuery($pattern); + $qb->addOrderBy('n.startDate', 'DESC') + ->addOrderBy('n.id', 'DESC'); + + return $qb->getQuery()->getResult(); + } + public function findWithDateFilter() { - dump($this->buildQueryWithDateFilter() - ->getQuery() - ->getResult()); - return $this->buildQueryWithDateFilter() ->getQuery() ->getResult(); } + public function countAllFilteredByUser(string $pattern = null) + { + $qb = $this->buildBaseQuery($pattern); + + return $qb + ->select('COUNT(n)') + ->getQuery() + ->getSingleScalarResult(); + } + public function countWithDateFilter() { return $this->buildQueryWithDateFilter() 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 new file mode 100644 index 000000000..fe5c70828 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Resources/views/NewsItem/news_items_history.html.twig @@ -0,0 +1,71 @@ +{% extends "@ChillMain/layout.html.twig" %} + +{% block title %} + {{ 'news_history.title'|trans }} +{% endblock title %} + +{% block content %} +
+

{{ 'news_history.title'|trans }}

+ + {{ filter_order|chill_render_filter_order_helper }} + + {% if entities|length == 0 %} +

+ {{ "news_history.no_data"|trans }} +

+ {% else %} + +
+ + {% for entity in entities %} + +
+
+ +
+

+ {{ entity.title }} +

+
+ {% if entity.startDate %} + {{ entity.startDate|format_date('long') }} + {% endif %} + {% if entity.endDate %} + - {{ entity.endDate|format_date('long') }} + {% endif %} +
+
+
+
+
+ {% apply markdown_to_html %} + {{ entity.content }} + {% endapply %} +
+{#
#} +{#
    #} +{#
  • #} +{# #} +{#
  • #} +{#
#} +{#
#} +
+
+
+
+ {% endfor %} +
+ + {{ chill_pagination(paginator) }} + + + {% endif %} +
+{% endblock %} diff --git a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php index 37c47e1bd..88007a074 100644 --- a/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php +++ b/src/Bundle/ChillMainBundle/Routing/MenuBuilder/SectionMenuBuilder.php @@ -58,6 +58,14 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface 'order' => 20, ]); } + + $menu->addChild($this->translator->trans('news_history.menu'), [ + 'route' => 'chill_main_news_items_history', + ]) + ->setExtras([ + 'icons' => ['newspaper-o'], + 'order' => 5, + ]); } public static function getMenuIds(): array diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index cd220de37..98933f614 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -688,3 +688,8 @@ dashboard: noDate: Pas de date de fin startDate: Date de début endDate: Date de fin + +news_history: + title: Historique des actualités + menu: Actualités + no_data: Aucune actualité