Skip to content

Commit

Permalink
Merge pull request afup#1528 from stakovicz/feat-1180-plan-du-site
Browse files Browse the repository at this point in the history
afup#1180 plan du site
  • Loading branch information
agallou authored Sep 1, 2024
2 parents 647160c + 96c97d6 commit 6fabcd6
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/Resources/views/site/sitemap.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% 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 à l'AFUP</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>

<h2><a href="{{ path('talks_list') }}">Historique des conférences</a></h2>
{{ _self.list(talks) }}
</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:HtmlSitemap: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\HtmlSitemapController:
autowire: true

AppBundle\Controller\SpeakerSuggestionController:
autowire: true

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

namespace AppBundle\Controller;

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

class HtmlSitemapController 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(),
'talks' => $this->talks(),
]
);
}

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

private function talks(): array
{
$repository = $this->get('ting')->get(TalkRepository::class);

$talks = [];
$talkList = $repository->getAllPastTalks((new \DateTime())->setTime(29,59,59));

/** @var Talk $talk */
foreach ($talkList as $talk) {
$url = $this->urlGenerator->generate(
'talks_show',
['id' => $talk->getId(), 'slug' => $talk->getSlug()]
);

$talks[] = [
'name' => $talk->getTitle(),
'url' => $url
];
}

return $talks;
}
}

0 comments on commit 6fabcd6

Please sign in to comment.