Skip to content

Commit

Permalink
afup#1180 plan du site
Browse files Browse the repository at this point in the history
  • Loading branch information
stakovicz committed Aug 24, 2024
1 parent 0214c82 commit e161ea6
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
41 changes: 41 additions & 0 deletions app/Resources/views/site/sitemap.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends ':site:base.html.twig' %}

{% block title %}Plan du site de l'AFUP{% endblock %}

{% macro list(items) %}
<ul>
{% for item in items %}
<li><a href="{{ item.url }}">{{ item.name }}</a></li>
{% endfor %}
</ul>
{% endmacro %}

{% block content %}
<div class="mw1400p center" id="container">
<div class="line" id="main">
<h1>Plan du site</h1>
<div class="row">
<div class="col-md-6">
{{ _self.list(pages) }}

<h2><a href="{{ path('become_member') }}">Adhérer</a></h2>
<ul>
<li><a href="{{ path('legacy_inscription') }}">Adhérer en tant que particulier</a></li>
<li><a href="{{ path('company_membership') }}">Adhérer en tant qu'entreprise</a></li>
<li><a href="{{ path('admin_login') }}">Se connecter</a></li>
</ul>
</div>
<div class="col-md-6">
<h2>Association</h2>
{{ _self.list(association) }}

<h2><a href="{{ path('company_public_profile_list') }}">Entreprises adhérentes</a></h2>
{{ _self.list(members) }}

<h2><a href="{{ path('news_list') }}">Actualités</a></h2>
{{ _self.list(news) }}
</div>
</div>
</div>
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions app/config/routing/global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ services:
AppBundle\Controller\LeadController:
autowire: true

AppBundle\Controller\SitemapController:
autowire: true

AppBundle\Controller\SpeakerSuggestionController:
autowire: true

Expand Down
101 changes: 101 additions & 0 deletions sources/AppBundle/Controller/SitemapController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

namespace AppBundle\Controller;

use Afup\Site\Corporate\Branche;
use Afup\Site\Corporate\Feuille;
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
use AppBundle\Site\Model\Repository\ArticleRepository;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class SitemapController extends SiteBaseController
{
/** @var UrlGeneratorInterface */
private $urlGenerator;

public function __construct(UrlGeneratorInterface $urlGenerator)
{
$this->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;
}
}

0 comments on commit e161ea6

Please sign in to comment.