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
14 changes: 13 additions & 1 deletion config/routing/talks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ talks_list:
section: talks
changefreq: monthly

# Avant talks_show (dont l'id est numérique) : /{id}-{slug} ne doit jamais capturer une page speaker.
# Avant talks_show (dont l'id est numérique) : /{id}-{slug} ne doit jamais capturer une page speaker ou événement.
talks_speakers:
path: /speakers/
defaults: { _controller: AppBundle\Controller\Website\Talks\SpeakerListAction }
Expand All @@ -19,6 +19,18 @@ talks_speaker:
path: /speakers/{slug}
defaults: { _controller: AppBundle\Controller\Website\Talks\SpeakerShowAction }

talks_events:
path: /evenements/
defaults: { _controller: AppBundle\Controller\Website\Talks\EventListAction }
options:
sitemap:
section: talks
changefreq: monthly

talks_event:
path: /evenements/{path}
defaults: { _controller: AppBundle\Controller\Website\Talks\EventShowAction }

talks_show:
path: /{id}-{slug}
defaults: { _controller: AppBundle\Controller\Website\Talks\ShowAction }
Expand Down
31 changes: 31 additions & 0 deletions sources/AppBundle/Controller/Website/Talks/EventListAction.php
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\Model\Repository\TalkRepository;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class EventListAction extends AbstractController
{
public function __construct(
private readonly ViewRenderer $view,
private readonly TalkRepository $talkRepository,
) {}

public function __invoke(): Response
{
// Les éditions sont déjà triées de la plus récente à la plus ancienne : les années aussi.
$summariesByYear = [];
foreach ($this->talkRepository->getEventTalksSummaries() as $summary) {
$summariesByYear[$summary->getYear()][] = $summary;
}

return $this->view->render('site/talks/events.html.twig', [
'summaries_by_year' => $summariesByYear,
]);
}
}
52 changes: 52 additions & 0 deletions sources/AppBundle/Controller/Website/Talks/EventShowAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Website\Talks;

use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Event\Talk\EventTalksJsonLd;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;

final class EventShowAction extends AbstractController
{
public function __construct(
private readonly ViewRenderer $view,
private readonly EventRepository $eventRepository,
private readonly TalkRepository $talkRepository,
private readonly SpeakerProfileResolver $speakerProfileResolver,
private readonly EventTalksJsonLd $eventTalksJsonLd,
) {}

public function __invoke(string $path): Response
{
$event = $this->eventRepository->getByPath($path);
$eventTalks = null !== $event ? $this->talkRepository->getPublishedByEventWithSpeakers($event) : [];

if (null === $event || $eventTalks === []) {
throw $this->createNotFoundException();
}

// Slug de la page de chaque speaker, par ID de ligne speaker : un seul index, chargé une fois pour tous.
$speakerSlugs = [];
foreach ($eventTalks as $eventTalk) {
foreach ($eventTalk->speakers as $speaker) {
$identity = $this->speakerProfileResolver->getIdentityForSpeaker($speaker);
if (null !== $identity && null !== $speaker->getId()) {
$speakerSlugs[$speaker->getId()] = $identity->slug;
}
}
}

return $this->view->render('site/talks/event.html.twig', [
'event' => $event,
'event_talks' => $eventTalks,
'speaker_slugs' => $speakerSlugs,
'item_list' => $this->eventTalksJsonLd->getData($event, $eventTalks),
]);
}
}
49 changes: 42 additions & 7 deletions sources/AppBundle/Controller/Website/Talks/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AppBundle\Controller\Website\Talks;

use AppBundle\Antennes\AntenneRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -24,13 +25,14 @@ public function __construct(
private readonly string $algoliaFrontendApikey,
private readonly AntenneRepository $antennesRepository,
private readonly SpeakerProfileResolver $speakerProfileResolver,
private readonly TalkRepository $talkRepository,
) {}

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

$title = 'Historique des conférences de l\'AFUP';
Expand Down Expand Up @@ -64,10 +66,8 @@ public function __invoke(Request $request): Response
*/
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]]]) {
$label = $this->getSingleFacet($request, 'speakers.label');
if (null === $label) {
return null;
}

Expand All @@ -78,4 +78,39 @@ private function redirectSpeakerFacet(Request $request): ?RedirectResponse

return $this->redirectToRoute('talks_speaker', ['slug' => $identity->slug], Response::HTTP_MOVED_PERMANENTLY);
}

/**
* L'ancienne URL d'une édition, `/talks/?fR[event.title][0]=…` sans aucun autre paramètre,
* redirige vers sa page si elle a des talks publiés. Une facette combinée à d'autres filtres reste une recherche.
*/
private function redirectEventFacet(Request $request): ?RedirectResponse
{
$title = $this->getSingleFacet($request, 'event.title');
if (null === $title) {
return null;
}

foreach ($this->talkRepository->getEventTalksSummaries() as $summary) {
if ($summary->event->getTitle() === $title) {
return $this->redirectToRoute('talks_event', ['path' => $summary->event->getPath()], Response::HTTP_MOVED_PERMANENTLY);
}
}

return null;
}

/**
* La valeur de la facette quand la requête n'a aucun autre paramètre que `fR[$facet][0]`.
*/
private function getSingleFacet(Request $request, string $facet): ?string
{
$values = $request->query->all('fR')[$facet] ?? null;
$value = is_array($values) ? $values[0] ?? null : null;

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

return $value;
}
}
18 changes: 4 additions & 14 deletions sources/AppBundle/Event/Model/Repository/SpeakerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,13 @@
class SpeakerRepository extends Repository implements MetadataInitializer
{
/**
* Jointures et conditions d'un talk publié, vu depuis ses speakers : planifié, ni clinique ni
* présentation des speakers (l'équivalent SQL de Talk::isDisplayedOnHistory(), le filtre de la
* page du talk), avec un créneau terminé et une date de publication vide ou passée.
* Jointures d'un talk publié, vu depuis ses speakers ; les conditions sont TalkRepository::PUBLISHED_TALK_CONDITIONS.
*/
private const string PUBLISHED_SPEAKER_TALKS_JOINS = '
FROM afup_conferenciers speaker
INNER JOIN afup_conferenciers_sessions cs ON cs.conferencier_id = speaker.conferencier_id
INNER JOIN afup_sessions talk ON talk.session_id = cs.session_id
INNER JOIN (
SELECT id_session, MIN(debut) AS debut, MIN(fin) AS fin FROM afup_forum_planning GROUP BY id_session
) planning ON planning.id_session = talk.session_id';

private const string PUBLISHED_SPEAKER_TALKS_CONDITIONS = '
talk.plannifie = 1
AND talk.genre NOT IN (' . Talk::TYPE_CLINIC . ', ' . Talk::TYPE_SPEAKER_INTRODUCTIONS . ')
AND planning.fin <= UNIX_TIMESTAMP()
AND (talk.date_publication < NOW() OR talk.date_publication IS NULL)';
' . TalkRepository::PUBLISHED_TALK_PLANNING_JOIN;

/**
* @return CollectionInterface<Speaker>&iterable<Speaker>
Expand Down Expand Up @@ -353,7 +343,7 @@ public function getPublishedTalkAppearances(): array
speaker.prenom AS firstname, speaker.nom AS lastname, talk.session_id AS talk_id, planning.debut AS starts_at'
. self::PUBLISHED_SPEAKER_TALKS_JOINS
. ' INNER JOIN afup_speaker_person person ON person.id = speaker.person_id'
. ' WHERE ' . self::PUBLISHED_SPEAKER_TALKS_CONDITIONS,
. ' WHERE ' . TalkRepository::PUBLISHED_TALK_CONDITIONS,
);

$appearances = [];
Expand Down Expand Up @@ -403,7 +393,7 @@ public function getPublishedSpeakerTalks(array $speakerIds): array
. ' INNER JOIN afup_forum event ON event.id = talk.id_forum
LEFT JOIN afup_user_github github ON github.id = speaker.user_github
WHERE speaker.conferencier_id IN (:' . implode(', :', array_keys($params)) . ')
AND ' . self::PUBLISHED_SPEAKER_TALKS_CONDITIONS
AND ' . TalkRepository::PUBLISHED_TALK_CONDITIONS
. ' ORDER BY planning.debut DESC, talk.session_id DESC, speaker.conferencier_id DESC',
)->setParams($params);

Expand Down
90 changes: 90 additions & 0 deletions sources/AppBundle/Event/Model/Repository/TalkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;
use AppBundle\Event\Model\TalkAggregate;
use AppBundle\Event\Talk\EventTalk;
use AppBundle\Event\Talk\EventTalksSummary;
use AppBundle\Ting\JoinHydrator;
use Aura\SqlQuery\Common\SelectInterface;
use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean;
use CCMBenchmark\Ting\Query\QueryException;
use CCMBenchmark\Ting\Repository\CollectionInterface;
use CCMBenchmark\Ting\Repository\Hydrator;
use CCMBenchmark\Ting\Repository\HydratorArray;
use CCMBenchmark\Ting\Repository\HydratorSingleObject;
use CCMBenchmark\Ting\Repository\Metadata;
Expand All @@ -27,6 +30,25 @@
*/
class TalkRepository extends Repository implements MetadataInitializer
{
/**
* Le créneau d'un talk (le premier, s'il en a plusieurs), sous l'alias `planning`, pour une requête dont
* le talk a l'alias `talk`. Jointure interne : un talk sans créneau n'est pas publié.
*/
public const string PUBLISHED_TALK_PLANNING_JOIN = 'INNER JOIN (
SELECT id_session, MIN(debut) AS debut, MIN(fin) AS fin, MIN(id_salle) AS id_salle FROM afup_forum_planning GROUP BY id_session
) planning ON planning.id_session = talk.session_id';

/**
* Conditions d'un talk publié, à combiner avec PUBLISHED_TALK_PLANNING_JOIN : planifié, ni clinique ni
* présentation des speakers (l'équivalent SQL de Talk::isDisplayedOnHistory(), le filtre de la page du
* talk), avec un créneau terminé et une date de publication vide ou passée.
*/
public const string PUBLISHED_TALK_CONDITIONS = '
talk.plannifie = 1
AND talk.genre NOT IN (' . Talk::TYPE_CLINIC . ', ' . Talk::TYPE_SPEAKER_INTRODUCTIONS . ')
AND planning.fin <= UNIX_TIMESTAMP()
AND (talk.date_publication < NOW() OR talk.date_publication IS NULL)';

public function getNumberOfTalksByEvent(Event|int $event, ?\DateTime $since = null)
{
return $this->getNumberOfTalksByEventAndLanguage($event, null, $since);
Expand Down Expand Up @@ -394,6 +416,74 @@ public function getAllPastTalks(\DateTime $dateTime)
return $query->query($this->getCollection(new HydratorSingleObject()));
}

/**
* Les talks publiés d'une édition dans l'ordre du planning (créneau, salle), avec leurs speakers.
*
* Requête dédiée plutôt que getByEventWithSpeakers() : celle-ci trie d'abord par `position`, garde les
* talks sans créneau ou pas encore terminés, les cliniques et les présentations des speakers, et ne lit
* pas l'ID YouTube.
*
* @return list<EventTalk>
*/
public function getPublishedByEventWithSpeakers(Event $event): array
{
$hydrator = new JoinHydrator();
$hydrator->aggregateOn('talk', 'speaker', 'getId');

$query = $this->getPreparedQuery(
'SELECT talk.session_id, talk.id_forum, talk.titre, talk.genre, talk.plannifie, talk.youtube_id, talk.language_code,
speaker.conferencier_id, speaker.id_forum, speaker.nom, speaker.prenom, speaker.user_github, speaker.person_id,
planning.debut AS starts_at
FROM afup_sessions talk
' . self::PUBLISHED_TALK_PLANNING_JOIN . '
LEFT JOIN afup_conferenciers_sessions cs ON cs.session_id = talk.session_id
LEFT JOIN afup_conferenciers speaker ON speaker.conferencier_id = cs.conferencier_id
WHERE talk.id_forum = :eventId AND ' . self::PUBLISHED_TALK_CONDITIONS . '
ORDER BY planning.debut ASC, planning.id_salle ASC, talk.session_id ASC, speaker.conferencier_id ASC',
)->setParams(['eventId' => $event->getId()]);

$eventTalks = [];
/** @var array{talk: Talk, 0: object{starts_at: int|string}, '.aggregation': array{speaker: array<Speaker|null>}} $row */
foreach ($query->query($this->getCollection($hydrator)) as $row) {
$eventTalks[] = new EventTalk(
$row['talk'],
new \DateTimeImmutable('@' . $row[0]->starts_at)->setTimezone(new \DateTimeZone(date_default_timezone_get())),
array_values(array_filter($row['.aggregation']['speaker'])),
);
}

return $eventTalks;
}

/**
* Les éditions qui ont au moins un talk publié, de la plus récente à la plus ancienne, avec le nombre de
* talks publiés et de vidéos, en une seule requête agrégée.
*
* @return list<EventTalksSummary>
*/
public function getEventTalksSummaries(): array
{
$query = $this->getQuery(
"SELECT event.id, event.titre, event.path, event.date_debut, event.date_fin, event.place_name,
COUNT(talk.session_id) AS talk_count,
SUM(talk.youtube_id IS NOT NULL AND talk.youtube_id <> '') AS video_count
FROM afup_sessions talk
" . self::PUBLISHED_TALK_PLANNING_JOIN . '
INNER JOIN afup_forum event ON event.id = talk.id_forum
WHERE ' . self::PUBLISHED_TALK_CONDITIONS . '
GROUP BY event.id
ORDER BY event.date_debut DESC, event.id DESC',
);

$summaries = [];
/** @var array{event: Event, 0: object{talk_count: int|string, video_count: int|string|null}} $row */
foreach ($query->query($this->getCollection(new Hydrator())) as $row) {
$summaries[] = new EventTalksSummary($row['event'], (int) $row[0]->talk_count, (int) $row[0]->video_count);
}

return $summaries;
}

/**
* @param array<int> $talkIds
* @return CollectionInterface<Talk>
Expand Down
23 changes: 23 additions & 0 deletions sources/AppBundle/Event/Talk/EventTalk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Talk;

use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;

/**
* Un talk publié d'une édition, avec son créneau et ses speakers (les lignes speaker de cette édition).
*/
final readonly class EventTalk
{
/**
* @param list<Speaker> $speakers
*/
public function __construct(
public Talk $talk,
public \DateTimeImmutable $startsAt,
public array $speakers,
) {}
}
Loading
Loading