Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions assets/icons/mdi/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions config/routing/talks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ talks_list:
section: talks
changefreq: monthly

# Avant talks_show (dont l'id est numérique) : /{id}-{slug} ne doit jamais capturer une page speaker.
talks_speakers:
path: /speakers/
defaults: { _controller: AppBundle\Controller\Website\Talks\SpeakerListAction }
options:
sitemap:
section: talks
changefreq: monthly

talks_speaker:
path: /speakers/{slug}
defaults: { _controller: AppBundle\Controller\Website\Talks\SpeakerShowAction }

talks_show:
path: /{id}-{slug}
defaults: { _controller: AppBundle\Controller\Website\Talks\ShowAction }
requirements: { id: '\d+' }

talks_joindin:
path: /{id}-{slug}/joindin
Expand Down
29 changes: 29 additions & 0 deletions sources/AppBundle/Controller/Website/Talks/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace AppBundle\Controller\Website\Talks;

use AppBundle\Antennes\AntenneRepository;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
Expand All @@ -21,10 +23,16 @@ public function __construct(
#[Autowire(env: 'ALGOLIA_FRONTEND_API_KEY')]
private readonly string $algoliaFrontendApikey,
private readonly AntenneRepository $antennesRepository,
private readonly SpeakerProfileResolver $speakerProfileResolver,
) {}

public function __invoke(Request $request): Response
{
$speakerRedirect = $this->redirectSpeakerFacet($request);
if (null !== $speakerRedirect) {
return $speakerRedirect;
}

$title = 'Historique des conférences de l\'AFUP';
$canonical = $this->generateUrl('talks_list', referenceType: UrlGeneratorInterface::ABSOLUTE_URL);
if (isset($request->query->all('fR')['speakers.label'][0])) {
Expand All @@ -49,4 +57,25 @@ public function __invoke(Request $request): Response
'algolia_api_key' => $this->algoliaFrontendApikey,
]);
}

/**
* L'ancienne URL d'un speaker, `/talks/?fR[speakers.label][0]=…` sans aucun autre paramètre,
* redirige vers sa page. Une facette combinée à d'autres filtres reste une recherche.
*/
private function redirectSpeakerFacet(Request $request): ?RedirectResponse
{
$labels = $request->query->all('fR')['speakers.label'] ?? null;
$label = is_array($labels) ? $labels[0] ?? null : null;

if (!is_string($label) || $request->query->all() !== ['fR' => ['speakers.label' => [$label]]]) {
return null;
}

$identity = $this->speakerProfileResolver->getIdentityByLabel($label);
if (null === $identity) {
return null;
}

return $this->redirectToRoute('talks_speaker', ['slug' => $identity->slug], Response::HTTP_MOVED_PERMANENTLY);
}
}
13 changes: 13 additions & 0 deletions sources/AppBundle/Controller/Website/Talks/ShowAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Joindin\JoindinComments;
use AppBundle\Subtitles\Parser;
use AppBundle\Twig\ViewRenderer;
Expand All @@ -23,6 +25,7 @@ public function __construct(
private readonly SpeakerRepository $speakerRepository,
private readonly PlanningRepository $planningRepository,
private readonly EventRepository $eventRepository,
private readonly SpeakerProfileResolver $speakerProfileResolver,
) {}

public function __invoke(int $id, string $slug): Response
Expand All @@ -34,6 +37,15 @@ public function __invoke(int $id, string $slug): Response
}

$speakers = $this->speakerRepository->getSpeakersByTalk($talk);
// Slug de la page de chaque speaker, par ID de ligne speaker : un seul index, chargé une fois pour tous.
$speakerSlugs = [];
/** @var Speaker $speaker */
foreach ($speakers as $speaker) {
$identity = $this->speakerProfileResolver->getIdentityForSpeaker($speaker);
if (null !== $identity && null !== $speaker->getId()) {
$speakerSlugs[$speaker->getId()] = $identity->slug;
}
}
$planning = $this->planningRepository->getByTalk($talk);
if ($planning === null) {
throw $this->createNotFoundException();
Expand All @@ -48,6 +60,7 @@ public function __invoke(int $id, string $slug): Response
'talk' => $talk,
'event' => $event,
'speakers' => $speakers,
'speaker_slugs' => $speakerSlugs,
'comments' => $comments,
'transcript' => $parsedContent,
]);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Website\Talks;

use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class SpeakerListAction extends AbstractController
{
public function __construct(
private readonly ViewRenderer $view,
private readonly SpeakerProfileResolver $speakerProfileResolver,
) {}

public function __invoke(): Response
{
// Les identités sont déjà triées par nom puis prénom : les groupes sortent dans l'ordre alphabétique.
$speakersByInitial = [];
foreach ($this->speakerProfileResolver->getIdentities() as $identity) {
$speakersByInitial[$identity->getInitial()][] = $identity;
}

return $this->view->render('site/talks/speakers.html.twig', [
'speakers_by_initial' => $speakersByInitial,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Website\Talks;

use AppBundle\CFP\PhotoStorage;
use AppBundle\Event\Speaker\PersonJsonLd;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class SpeakerShowAction extends AbstractController
{
public function __construct(
private readonly ViewRenderer $view,
private readonly SpeakerProfileResolver $speakerProfileResolver,
private readonly PhotoStorage $photoStorage,
private readonly PersonJsonLd $personJsonLd,
) {}

public function __invoke(Request $request, string $slug): Response
{
$profile = $this->speakerProfileResolver->getProfileBySlug($slug);

if (null === $profile) {
throw $this->createNotFoundException();
}

$photoUrl = null !== $profile->photoSpeaker ? $this->photoStorage->getUrl($profile->photoSpeaker) : null;

return $this->view->render('site/talks/speaker.html.twig', [
'profile' => $profile,
'photo_url' => $photoUrl,
'person' => $this->personJsonLd->getData(
$profile,
$this->generateUrl('talks_speaker', ['slug' => $profile->identity->slug], UrlGeneratorInterface::ABSOLUTE_URL),
null !== $photoUrl ? $request->getSchemeAndHttpHost() . $photoUrl : null,
),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SpeakerRepository extends Repository implements MetadataInitializer
public function getSpeakersByTalk(Talk $talk)
{
$query = $this->getPreparedQuery('SELECT c.conferencier_id, c.id_forum, c.genre, c.nom, c.prenom, c.email,c.societe,
c.biographie, c.twitter, c.user_github, c.photo, c.bluesky, c.mastodon, c.linkedin
c.biographie, c.twitter, c.user_github, c.person_id, c.photo, c.bluesky, c.mastodon, c.linkedin
FROM afup_conferenciers c
LEFT JOIN afup_conferenciers_sessions cs ON cs.conferencier_id = c.conferencier_id
WHERE cs.session_id = :talkId
Expand Down
45 changes: 45 additions & 0 deletions sources/AppBundle/Event/Speaker/PersonJsonLd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Speaker;

/**
* Données structurées schema.org Person de la page d'un speaker.
*
* @see https://schema.org/Person
*/
final readonly class PersonJsonLd
{
/**
* Options d'encodage à utiliser pour insérer le JSON dans un <script> :
* JSON_HEX_TAG encode < et >, si bien qu'un texte contenant « </script> » ne peut pas fermer la balise.
*/
public const int JSON_FLAGS = JSON_HEX_TAG | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_INVALID_UTF8_SUBSTITUTE;

/**
* @param string $url l'URL absolue de la page du speaker
* @param string|null $imageUrl l'URL absolue de sa photo
*
* @return array<string, string|list<string>>
*/
public function getData(SpeakerProfile $profile, string $url, ?string $imageUrl): array
{
$data = [
'@context' => 'https://schema.org',
'@type' => 'Person',
'name' => $profile->identity->getName(),
'url' => $url,
];

if (null !== $imageUrl) {
$data['image'] = $imageUrl;
}

if ($profile->socialLinks !== []) {
$data['sameAs'] = array_values($profile->socialLinks);
}

return $data;
}
}
11 changes: 11 additions & 0 deletions sources/AppBundle/Event/Speaker/SpeakerIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ public function getLabel(): string
return self::cleanSpaces($this->firstname . ' ' . mb_strtoupper($this->lastname));
}

/**
* La lettre de l'index A–Z : initiale du nom (du prénom à défaut), sans accent, en majuscule ;
* « # » si ce n'est pas une lettre. Cohérente avec le tri de SpeakerProfileResolver::getIdentities().
*/
public function getInitial(): string
{
$initial = strtoupper(substr(SpeakerProfileResolver::normalizeLabel($this->lastname . ' ' . $this->firstname), 0, 1));

return ctype_upper($initial) ? $initial : '#';
}

private static function cleanSpaces(string $value): string
{
return trim((string) preg_replace('/\s+/u', ' ', $value));
Expand Down
22 changes: 12 additions & 10 deletions sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
use AppBundle\Controller\Website\News\ListAction;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Site\Entity\Repository\FeuilleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
use Presta\SitemapBundle\Event\SitemapPopulateEvent;
Expand All @@ -29,7 +28,7 @@ class SitemapXmlSubscriber implements EventSubscriberInterface
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly TalkRepository $talkRepository,
private readonly SpeakerRepository $speakerRepository,
private readonly SpeakerProfileResolver $speakerProfileResolver,
private readonly EventRepository $eventRepository,
private readonly ArticleRepository $articleRepository,
private readonly CompanyMemberRepository $companyMemberRepository,
Expand All @@ -46,7 +45,7 @@ public static function getSubscribedEvents(): array
public function populate(SitemapPopulateEvent $event): void
{
$this->registerTalksUrls($event->getUrlContainer());
$this->registerSpeakersTalksUrls($event->getUrlContainer());
$this->registerSpeakersUrls($event->getUrlContainer());
$this->registerEventsTalksUrls($event->getUrlContainer());
$this->registerNewsUrls($event->getUrlContainer());
$this->registerMembers($event->getUrlContainer());
Expand Down Expand Up @@ -87,17 +86,20 @@ public function registerTalksUrls(UrlContainerInterface $urls): void
}
}

public function registerSpeakersTalksUrls(UrlContainerInterface $urls): void
/**
* La page de chaque speaker ayant au moins un talk publié ; l'index des speakers
* est déclaré par l'option sitemap de sa route.
*/
public function registerSpeakersUrls(UrlContainerInterface $urls): void
{
/** @var Speaker[] $speakers */
$speakers = $this->speakerRepository->getAll();
foreach ($speakers as $speaker) {
foreach ($this->speakerProfileResolver->getIdentities() as $identity) {
$url = new UrlConcrete(
$this->urlGenerator->generate(
'talks_list',
['fR' => ['speakers.label' => [$speaker->getLabel()]]],
'talks_speaker',
['slug' => $identity->slug],
UrlGeneratorInterface::ABSOLUTE_URL,
),
$identity->latestTalkAt,
);
$urls->addUrl($url, 'talks');
}
Expand Down
6 changes: 4 additions & 2 deletions templates/site/talks/show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,10 @@
{% endif %}
</div>
<p class="text-neutre-700">{{ speaker.biography }}</p>
<a href="{{ url('talks_list', {"fR": { "speakers.label" : [ speaker.label ]}}) }}"
class="text-sm text-afup-500 underline hover:no-underline">Voir tous ses talks</a>
{% if speaker_slugs[speaker.id] is defined %}
<a href="{{ path('talks_speaker', {slug: speaker_slugs[speaker.id]}) }}"
class="text-sm text-afup-500 underline hover:no-underline">Voir tous ses talks</a>
{% endif %}
</div>
</div>
{% endfor %}
Expand Down
Loading
Loading