Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

afup#1180 plan du site #1528

Merged
merged 3 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
stakovicz marked this conversation as resolved.
Show resolved Hide resolved
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(),
stakovicz marked this conversation as resolved.
Show resolved Hide resolved
]
);
}

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;
}
}