diff --git a/app/Resources/views/site/sitemap.html.twig b/app/Resources/views/site/sitemap.html.twig new file mode 100644 index 000000000..0717248b6 --- /dev/null +++ b/app/Resources/views/site/sitemap.html.twig @@ -0,0 +1,41 @@ +{% extends ':site:base.html.twig' %} + +{% block title %}Plan du site de l'AFUP{% endblock %} + +{% macro list(items) %} + +{% endmacro %} + +{% block content %} +
+
+

Plan du site

+
+ +
+

Association

+ {{ _self.list(association) }} + +

Entreprises adhérentes

+ {{ _self.list(members) }} + +

Actualités

+ {{ _self.list(news) }} +
+
+
+
+{% endblock %} diff --git a/app/config/routing/global.yml b/app/config/routing/global.yml index dedee729b..5afc63e16 100644 --- a/app/config/routing/global.yml +++ b/app/config/routing/global.yml @@ -7,3 +7,9 @@ home: become_sponsor_latest: path: /become-sponsor defaults: {_controller: AppBundle:Lead:becomeSponsorLatest} + +sitemap: + path: /plan-du-site + defaults: { _controller: AppBundle:Sitemap:display } + options: + sitemap: true \ No newline at end of file diff --git a/app/config/services.yml b/app/config/services.yml index 4fe997027..4c4a43b4c 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -110,6 +110,9 @@ services: AppBundle\Controller\LeadController: autowire: true + AppBundle\Controller\SitemapController: + autowire: true + AppBundle\Controller\SpeakerSuggestionController: autowire: true diff --git a/sources/AppBundle/Controller/SitemapController.php b/sources/AppBundle/Controller/SitemapController.php new file mode 100644 index 000000000..765e219ad --- /dev/null +++ b/sources/AppBundle/Controller/SitemapController.php @@ -0,0 +1,101 @@ +urlGenerator = $urlGenerator; + } + + public function displayAction() + { + $branche = new Branche(); + + return $this->render( + ':site:sitemap.html.twig', + [ + 'pages' => $this->buildLeafs($branche, Feuille::ID_FEUILLE_HEADER), + 'association' => $this->buildLeafs($branche, Feuille::ID_FEUILLE_ANTENNES), + 'members' => $this->members(), + 'news' => $this->news(), + ] + ); + } + + private function buildLeafs(Branche $branche, int $id): array + { + $leafs = $branche->feuillesEnfants($id); + + $pages = []; + foreach ($leafs as $leaf) { + if (!$leaf['lien'] || starts_with($leaf['lien'], 'http')) { + continue; + } + $pages[] = [ + 'name' => $leaf['nom'], + 'url' => $leaf['lien'], + ]; + } + + return $pages; + } + + private function members(): array + { + /** + * @var CompanyMemberRepository $companyRepository + */ + $companyRepository = $this->get('ting')->get(CompanyMemberRepository::class); + $displayableCompanies = $companyRepository->findDisplayableCompanies(); + + $members = []; + foreach ($displayableCompanies as $member) { + $url = $this->urlGenerator->generate('company_public_profile', [ + 'id' => $member->getId(), + 'slug' => $member->getSlug(), + ]); + + $members[] = [ + 'name' => $member->getCompanyName(), + 'url' => $url + ]; + } + return $members; + } + + private function news(): array + { + $itemPerPage = 100; + $page = 1; + + $repository = $this->get('ting')->get(ArticleRepository::class); + + $news = []; + do { + $newsList = $repository->findPublishedNews($page++, $itemPerPage, []); + foreach ($newsList as $newsItem) { + $url = $this->urlGenerator->generate('news_display', [ + 'code' => $newsItem->getSlug(), + ]); + + $news[] = [ + 'name' => $newsItem->getTitle(), + 'url' => $url + ]; + } + } while (count($newsList) >= $itemPerPage); + + return $news; + } +}