Skip to content
Open
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
2 changes: 1 addition & 1 deletion db/seeds/Feuilles.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function run(): void
[
'id' => 44,
'id_parent' => Feuille::ID_FEUILLE_HEADER,
'nom' => 'Vidéos',
'nom' => 'Talks',
'lien' => '/talks/',
'alt' => '',
'position' => 5,
Expand Down
130 changes: 94 additions & 36 deletions htdocs/js/talk/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var icon = function (path, extraClass) {
var ICONS = {
rss: '<path fill="currentColor" d="M5 17a2 2 0 1 1 0 4a2 2 0 0 1 0-4M4 10a1 1 0 0 0 0 2a8 8 0 0 1 8 8a1 1 0 1 0 2 0A10 10 0 0 0 4 10m0-7a1 1 0 1 0 0 2a15 15 0 0 1 15 15a1 1 0 1 0 2 0A17 17 0 0 0 4 3"/>',
slides: '<path fill="currentColor" d="M20 3a1 1 0 1 1 0 2v9a3 3 0 0 1-3 3h-3.5l2.3 3.4a1 1 0 1 1-1.6 1.2L12 18.3l-2.2 3.3a1 1 0 1 1-1.6-1.2l2.3-3.4H7a3 3 0 0 1-3-3V5a1 1 0 0 1 0-2zM6 5v9a1 1 0 0 0 1 1h10a1 1 0 0 0 1-1V5z"/>',
comments: '<path fill="currentColor" d="M12 2c5.5 0 10 3.8 10 8.5S17.5 19 12 19c-.9 0-1.8-.1-2.6-.3l-4 2.2A1 1 0 0 1 4 20v-3.2C2.7 15.2 2 13 2 10.5C2 5.8 6.5 2 12 2"/>',
angleLeft: '<path fill="currentColor" d="M15.5 4.5a1 1 0 0 1 0 1.4L9.4 12l6.1 6.1a1 1 0 1 1-1.4 1.4l-6.8-6.8a1 1 0 0 1 0-1.4l6.8-6.8a1 1 0 0 1 1.4 0"/>',
angleRight: '<path fill="currentColor" d="M8.5 4.5a1 1 0 0 0 0 1.4l6.1 6.1l-6.1 6.1a1 1 0 1 0 1.4 1.4l6.8-6.8a1 1 0 0 0 0-1.4L9.9 4.5a1 1 0 0 0-1.4 0"/>',
angleDoubleLeft: '<path fill="currentColor" d="M12.7 4.5a1 1 0 0 1 0 1.4L6.6 12l6.1 6.1a1 1 0 1 1-1.4 1.4l-6.8-6.8a1 1 0 0 1 0-1.4l6.8-6.8a1 1 0 0 1 1.4 0m7 0a1 1 0 0 1 0 1.4L13.6 12l6.1 6.1a1 1 0 1 1-1.4 1.4l-6.8-6.8a1 1 0 0 1 0-1.4l6.8-6.8a1 1 0 0 1 1.4 0"/>',
Expand Down Expand Up @@ -87,6 +86,63 @@ search.addWidget(
})
);

var escapeHtml = function (value) {
return String(value)
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
};

var LINK_CLASS = 'text-afup-500 hover:underline';
var RESOURCE_CLASS = 'inline-flex items-center gap-1.5 rounded-lg bg-afup-100 px-2 py-1 text-xs font-medium text-afup-500 hover:bg-afup-500 hover:text-white';

/* Même rendu que la carte Twig templates/site/talks/_talk_card.html.twig : modifier les deux ensemble.
Les liens vers les pages speaker et événement n'existent que si l'index les fournit (slug, path) ;
sinon le nom reste en texte. */
var talkCard = function (data) {
var url = '/talks/' + encodeURIComponent(data.url_key);
var thumbnail = typeof data.video_id !== 'undefined'
? 'https://img.youtube.com/vi/' + encodeURIComponent(data.video_id) + '/hqdefault.jpg'
: '/images/no_video.jpg';

var speakers = (data.speakers || []).map(function (speaker) {
return speaker.slug
? '<a href="/talks/speakers/' + encodeURIComponent(speaker.slug) + '" class="' + LINK_CLASS + '">' + escapeHtml(speaker.label) + '</a>'
: escapeHtml(speaker.label);
}).join(' et ');
var event = data.event && data.event.title
? (data.event.path
? '<a href="/talks/evenements/' + encodeURIComponent(data.event.path) + '" class="' + LINK_CLASS + '">' + escapeHtml(data.event.title) + '</a>'
: escapeHtml(data.event.title))
: '';
var meta = [speakers, event].filter(function (part) { return part !== ''; }).join(' · ');

var resource = function (href, svg, label) {
return '<li><a href="' + escapeHtml(href) + '" target="_blank" rel="noopener" class="' + RESOURCE_CLASS + '">'
+ icon(svg, 'size-3.5') + label + '</a></li>';
};
var resources = '';
if (typeof data.blog_post_url !== 'undefined') {
resources += resource(data.blog_post_url, ICONS.rss, 'Article de blog');
}
if (typeof data.slides_url !== 'undefined') {
resources += resource(data.slides_url, ICONS.slides, 'Slides');
}

return ''
+ '<article class="flex flex-col sm:flex-row gap-4 rounded-2xl border-2 border-neutre-300 p-4">'
+ '<a href="' + url + '" class="shrink-0 w-full sm:w-44" tabindex="-1" aria-hidden="true">'
+ '<img src="' + thumbnail + '" alt="" loading="lazy" class="w-full aspect-video rounded-xl object-cover bg-neutre-200" />'
+ '</a>'
+ '<div class="flex flex-col gap-2 grow min-w-0">'
+ '<h3 class="font-titre text-lg leading-snug text-afup-800"><a href="' + url + '" class="hover:underline">' + escapeHtml(data.title) + '</a></h3>'
+ (meta ? '<p class="text-sm text-neutre-400">' + meta + '</p>' : '')
+ (resources ? '<ul class="flex flex-wrap items-center gap-2 mt-auto">' + resources + '</ul>' : '')
+ '</div>'
+ '</article>';
};

search.addWidget(
instantsearch.widgets.hits({
hitsPerPage: 7,
Expand All @@ -97,41 +153,7 @@ search.addWidget(
},
templates: {
empty: 'Aucune conférence ne correspond à ces critères.',
item: function (data) {
var url = '/talks/' + data.url_key;
var thumbnail = typeof data.video_id !== 'undefined'
? 'https://img.youtube.com/vi/' + data.video_id + '/hqdefault.jpg'
: '/images/no_video.jpg';

var links = '';
var link = function (href, svg, label, rel) {
return '<a href="' + href + '" target="_blank" rel="' + (rel || 'noopener') + '"'
+ ' class="inline-flex items-center gap-1.5 rounded-lg bg-afup-100 px-2 py-1 text-xs font-medium text-afup-500 hover:bg-afup-500 hover:text-white">'
+ icon(svg, 'size-3.5') + label + '</a>';
};

if (typeof data.blog_post_url !== 'undefined') {
links += link(data.blog_post_url, ICONS.rss, 'Article de blog');
}
if (typeof data.slides_url !== 'undefined') {
links += link(data.slides_url, ICONS.slides, 'Slides');
}
if (typeof data.joindin_url !== 'undefined') {
links += link(data.joindin_url, ICONS.comments, 'Fiche joind.in', 'noopener nofollow');
}

return ''
+ '<article class="flex flex-col sm:flex-row gap-4 rounded-2xl border-2 border-neutre-300 p-4">'
+ '<a href="' + url + '" class="shrink-0 w-full sm:w-44">'
+ '<img src="' + thumbnail + '" alt="" loading="lazy" class="w-full aspect-video rounded-xl object-cover bg-neutre-200" />'
+ '</a>'
+ '<div class="flex flex-col gap-2 grow">'
+ '<a href="' + url + '" class="font-titre text-lg leading-snug text-afup-800 hover:underline">' + data.title + '</a>'
+ '<p class="font-sans text-sm text-neutre-400">' + data.speakers_label + ' · ' + data.event.title + '</p>'
+ (links ? '<div class="flex flex-wrap items-center gap-2 mt-auto">' + links + '</div>' : '')
+ '</div>'
+ '</article>';
}
item: talkCard
}
})
);
Expand Down Expand Up @@ -260,6 +282,42 @@ search.addWidget(
})
);

/* Une recherche est active dès qu'il y a un texte, un filtre ou une page autre que la première. */
var isSearchActive = function (state) {
var hasRefinement = function (refinements) {
return Object.keys(refinements || {}).some(function (attribute) {
var values = refinements[attribute];
return Array.isArray(values) ? values.length > 0 : Object.keys(values || {}).length > 0;
});
};

return (state.query || '') !== ''
|| (state.page || 0) > 0
|| hasRefinement(state.facetsRefinements)
|| hasRefinement(state.disjunctiveFacetsRefinements)
|| hasRefinement(state.hierarchicalFacetsRefinements)
|| hasRefinement(state.numericRefinements)
|| (state.tagRefinements || []).length > 0;
};

/* Sans recherche active, la liste des dernières vidéos rendue côté serveur reste affichée ;
sinon les résultats Algolia la remplacent. Sans liste serveur (page ouverte sur une URL de recherche),
les résultats restent affichés. */
var latestTalks = document.getElementById('dernieres-videos');
var section = document.getElementById('talks');
var sectionTitle = document.getElementById('talks-title');

search.on('render', function () {
var showResults = !latestTalks || isSearchActive(search.helper.state);

document.getElementById('hits-container').hidden = !showResults;
document.getElementById('pagination').hidden = !showResults;
if (latestTalks) {
latestTalks.hidden = showResults;
sectionTitle.textContent = showResults ? section.dataset.searchTitle : section.dataset.latestTitle;
}
});

/* instantsearch 1.x n'émet pas aria-current sur la page courante. */
search.on('render', function () {
document.querySelectorAll('#pagination .ais-pagination--item__page').forEach(function (item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AppBundle\Controller\Website\Talks;

use AppBundle\Event\Talk\PublishedTalkRepository;
use AppBundle\Event\Talk\EventTalksSummary;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -18,14 +19,8 @@ public function __construct(

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->publishedTalkRepository->getEventSummaries() as $summary) {
$summariesByYear[$summary->getYear()][] = $summary;
}

return $this->view->render('site/talks/events.html.twig', [
'summaries_by_year' => $summariesByYear,
'summaries_by_year' => EventTalksSummary::groupByYear($this->publishedTalkRepository->getEventSummaries()),
]);
}
}
45 changes: 45 additions & 0 deletions sources/AppBundle/Controller/Website/Talks/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use AppBundle\Antennes\AntenneRepository;
use AppBundle\Event\Talk\PublishedTalkRepository;
use AppBundle\Event\Talk\EventTalksSummary;
use AppBundle\Event\Speaker\SpeakerProfileResolver;
use AppBundle\Twig\ViewRenderer;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -17,6 +18,13 @@

final class ListAction extends AbstractController
{
public const int LATEST_TALKS_COUNT = 12;

/**
* Paramètres de l'état de recherche qu'instantsearch (urlSync) écrit dans l'URL : requête et filtres.
*/
private const array SEARCH_PARAMETERS = ['q', 'fR', 'dFR', 'hFR', 'nR', 'tR', 'fE'];

public function __construct(
private readonly ViewRenderer $view,
#[Autowire(env: 'ALGOLIA_APP_ID')]
Expand Down Expand Up @@ -51,8 +59,28 @@ public function __invoke(Request $request): Response
], UrlGeneratorInterface::ABSOLUTE_URL);
}

// Le hub (dernières vidéos, éditions, speakers) ne s'affiche que hors recherche : sur une URL de recherche,
// il repousserait les résultats sous la ligne de flottaison, et ces URLs ne sont pas destinées à être indexées.
$showHub = !$this->isSearch($request);
$latestTalks = $showHub ? $this->publishedTalkRepository->getLatestTalksWithVideo(self::LATEST_TALKS_COUNT) : [];

// Slug de la page de chaque speaker, par ID de ligne speaker, pour lier les speakers des cartes.
$speakerSlugs = [];
foreach ($latestTalks as $latest) {
foreach ($latest['speakers'] as $speaker) {
$identity = $this->speakerProfileResolver->getIdentityByPersonneId($speaker->personneId);
if (null !== $identity) {
$speakerSlugs[$speaker->id] = $identity->slug;
}
}
}

return $this->view->render('site/talks/list.html.twig', [
'title' => $title,
'show_hub' => $showHub,
'latest_talks' => $latestTalks,
'speaker_slugs' => $speakerSlugs,
'summaries_by_year' => $showHub ? EventTalksSummary::groupByYear($this->publishedTalkRepository->getEventSummaries()) : [],
'canonical' => $canonical,
'antennes' => $this->antennesRepository->getAllSortedByLabels(),
'algolia_app_id' => $this->algoliaAppId,
Expand Down Expand Up @@ -99,6 +127,23 @@ private function redirectEventFacet(Request $request): ?RedirectResponse
return null;
}

/**
* L'URL porte un état de recherche : une requête, un filtre ou une page de résultats autre que la première.
*/
private function isSearch(Request $request): bool
{
$query = $request->query->all();
foreach (self::SEARCH_PARAMETERS as $parameter) {
if (!in_array($query[$parameter] ?? null, [null, '', []], true)) {
return true;
}
}

$page = $query['p'] ?? 0;

return is_numeric($page) && (int) $page > 0;
}

/**
* La valeur de la facette quand la requête n'a aucun autre paramètre que `fR[$facet][0]`.
*/
Expand Down
17 changes: 17 additions & 0 deletions sources/AppBundle/Event/Talk/EventTalksSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@ public function getYear(): int
{
return (int) $this->event->dateStart?->format('Y');
}

/**
* Les éditions regroupées par année, dans l'ordre donné : des éditions triées de la plus récente à la plus
* ancienne donnent des années dans le même ordre.
*
* @param list<self> $summaries
* @return array<int, non-empty-list<self>>
*/
public static function groupByYear(array $summaries): array
{
$summariesByYear = [];
foreach ($summaries as $summary) {
$summariesByYear[$summary->getYear()][] = $summary;
}

return $summariesByYear;
}
}
50 changes: 48 additions & 2 deletions sources/AppBundle/Event/Talk/PublishedTalkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use AppBundle\Event\Model\Talk;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use Webmozart\Assert\Assert;

/**
Expand All @@ -30,7 +31,7 @@
AND (talk.date_publication < NOW() OR talk.date_publication IS NULL)';

/** Colonnes lues par self::talk() et self::event(). */
private const string TALK_AND_EVENT_COLUMNS = 'talk.session_id, talk.titre, talk.youtube_id,
private const string TALK_AND_EVENT_COLUMNS = 'talk.session_id, talk.titre, talk.youtube_id, talk.slides_url, talk.blog_post_url,
event.id AS event_id, event.titre AS event_titre, event.path AS event_path, event.date_debut AS event_date_debut, event.date_fin AS event_date_fin';

public function __construct(private Connection $connection) {}
Expand Down Expand Up @@ -74,7 +75,7 @@ public function getSpeakerAppearances(): array
public function getEventTalks(int $eventId): array
{
$rows = $this->connection->fetchAllAssociative(
'SELECT talk.session_id, talk.titre, talk.youtube_id, planning.debut,
'SELECT talk.session_id, talk.titre, talk.youtube_id, talk.slides_url, talk.blog_post_url, planning.debut,
speaker.conferencier_id, speaker.prenom, speaker.nom, speaker.personne_id
FROM afup_sessions talk'
. self::PLANNING_JOIN . '
Expand Down Expand Up @@ -129,6 +130,49 @@ public function getEventSummaries(): array
), $rows);
}

/**
* Les derniers talks publiés qui ont une vidéo, avec leur édition et leurs speakers, du créneau terminé le plus
* récent au plus ancien, en une seule requête.
*
* @return list<array{talk: PublishedTalk, event: PublishedEvent, speakers: list<PublishedSpeaker>}>
*/
public function getLatestTalksWithVideo(int $limit): array
{
// La limite porte sur les talks : elle s'applique avant la jointure des speakers, qui multiplie les lignes.
$rows = $this->connection->fetchAllAssociative(
'SELECT ' . self::TALK_AND_EVENT_COLUMNS . ',
speaker.conferencier_id, speaker.prenom, speaker.nom, speaker.personne_id
FROM (
SELECT talk.session_id, planning.fin AS slot_end
FROM afup_sessions talk'
. self::PLANNING_JOIN . '
WHERE ' . self::CONDITIONS . "
AND talk.youtube_id IS NOT NULL AND talk.youtube_id <> ''
ORDER BY planning.fin DESC, talk.session_id DESC
LIMIT :limit
) latest
INNER JOIN afup_sessions talk ON talk.session_id = latest.session_id
INNER JOIN afup_forum event ON event.id = talk.id_forum
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
ORDER BY latest.slot_end DESC, talk.session_id DESC, speaker.conferencier_id ASC",
['limit' => max(0, $limit)],
['limit' => ParameterType::INTEGER],
);

/** @var array<int, array{talk: PublishedTalk, event: PublishedEvent, speakers: list<PublishedSpeaker>}> $latest */
$latest = [];
foreach ($rows as $row) {
$talkId = self::toInt($row['session_id']);
$latest[$talkId] ??= ['talk' => self::talk($row), 'event' => self::event($row), 'speakers' => []];
if (null !== $row['conferencier_id']) {
$latest[$talkId]['speakers'][] = self::speaker($row);
}
}

return array_values($latest);
}

/**
* Les talks publiés de ces lignes speaker, avec leur événement, du plus récent au plus ancien.
*
Expand Down Expand Up @@ -175,6 +219,8 @@ private static function talk(array $row): PublishedTalk
self::toInt($row['session_id']),
self::toString($row['titre']),
self::nullableString($row['youtube_id']),
self::nullableString($row['slides_url'] ?? null),
self::nullableString($row['blog_post_url'] ?? null),
);
}

Expand Down
7 changes: 6 additions & 1 deletion sources/AppBundle/Indexation/Talks/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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;

class Runner
{
Expand All @@ -22,8 +24,11 @@ public function __construct(
private readonly TalkRepository $talkRepository,
private readonly EventRepository $eventRepository,
private readonly SpeakerRepository $speakerRepository,
SpeakerProfileResolver $speakerProfileResolver,
) {
$this->transformer = new Transformer();
$this->transformer = new Transformer(
static fn(Speaker $speaker): ?string => $speakerProfileResolver->getIdentityForSpeaker($speaker)?->slug,
);
}

public function run(): void
Expand Down
Loading
Loading