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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace AppBundle\Controller\Website\Talks;

use AppBundle\Event\Model\Repository\TalkRepository;
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->talkRepository->getEventTalksSummaries() 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->talkRepository->getEventTalksSummaries()),
]);
}
}
32 changes: 32 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\Model\Repository\TalkRepository;
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,15 @@ 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);

return $this->view->render('site/talks/list.html.twig', [
'title' => $title,
'show_hub' => $showHub,
'latest_talks' => $showHub ? $this->talkRepository->getLatestPublishedTalksWithVideo(self::LATEST_TALKS_COUNT) : [],
'summaries_by_year' => $showHub ? EventTalksSummary::groupByYear($this->talkRepository->getEventTalksSummaries()) : [],
'canonical' => $canonical,
'antennes' => $this->antennesRepository->getAllSortedByLabels(),
'algolia_app_id' => $this->algoliaAppId,
Expand Down Expand Up @@ -99,6 +114,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
28 changes: 28 additions & 0 deletions sources/AppBundle/Event/Model/Repository/TalkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,34 @@ public function getEventTalksSummaries(): array
return $summaries;
}

/**
* Les derniers talks publiés qui ont une vidéo, avec leur édition, du créneau terminé le plus récent au plus
* ancien, en une seule requête.
*
* @return list<array{talk: Talk, event: Event}>
*/
public function getLatestPublishedTalksWithVideo(int $limit): array
{
$query = $this->getQuery(
"SELECT talk.session_id, talk.titre, talk.youtube_id, event.id, event.titre, event.path
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 . "
AND talk.youtube_id IS NOT NULL AND talk.youtube_id <> ''
ORDER BY planning.fin DESC, talk.session_id DESC
LIMIT " . max(0, $limit),
);

$latest = [];
/** @var array{talk: Talk, event: Event} $row */
foreach ($query->query($this->getCollection(new Hydrator())) as $row) {
$latest[] = ['talk' => $row['talk'], 'event' => $row['event']];
}

return $latest;
}

/**
* @param array<int> $talkIds
* @return CollectionInterface<Talk>
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 @@ -24,4 +24,21 @@ public function getYear(): int
{
return (int) $this->event->getDateStart()?->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;
}
}
38 changes: 38 additions & 0 deletions templates/site/talks/_events_by_year.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{# Éditions groupées par année : navigation par année puis une section par année, chaque édition liée à sa page.
`heading_level` : niveau des titres d'année (2 par défaut, 3 sous un titre de section). #}
{% set heading_tag = 'h' ~ (heading_level|default(2)) %}
<div class="flex flex-col gap-8">
{% if summaries_by_year|length > 1 %}
<nav aria-label="Années">
<ul class="flex flex-wrap gap-2">
{% for year in summaries_by_year|keys %}
<li>
<a href="#evenements-{{ year }}"
class="inline-flex items-center justify-center rounded-lg bg-afup-100 px-2 py-1 text-sm font-medium text-afup-500 hover:bg-afup-500 hover:text-white">{{ year }}</a>
</li>
{% endfor %}
</ul>
</nav>
{% endif %}

{% for year, summaries in summaries_by_year %}
<section id="evenements-{{ year }}" class="flex flex-col gap-4 scroll-mt-4">
{# Mêmes classes que le composant SectionTitle, qui ne rend qu'un h2 #}
<{{ heading_tag }} class="font-semibold text-base text-afup-800 border-b border-neutre-300 pb-2">{{ year }}</{{ heading_tag }}>
<ul class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{% for summary in summaries %}
<li class="flex flex-col gap-1 rounded-2xl border-2 border-neutre-300 p-4">
<a href="{{ path('talks_event', {path: summary.event.path}) }}"
class="font-titre text-lg leading-snug text-afup-800 hover:underline">{{ summary.event.title }}</a>
<p class="text-sm text-neutre-400">
{{ summary.talkCount }} talk{{ summary.talkCount > 1 ? 's' }}
· {{ summary.videoCount }} vidéo{{ summary.videoCount > 1 ? 's' }}
</p>
</li>
{% endfor %}
</ul>
</section>
{% else %}
<p class="text-neutre-700">Aucun événement pour le moment.</p>
{% endfor %}
</div>
35 changes: 2 additions & 33 deletions templates/site/talks/events.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,9 @@
<a href="{{ path('talks_list') }}" class="text-afup-500 underline hover:no-underline">Vidéos</a>
</p>
<h1 class="font-titre text-afup-800 text-2xl sm:text-4xl">Les événements de l'AFUP et leurs talks</h1>

{% if summaries_by_year|length > 1 %}
<nav aria-label="Années">
<ul class="flex flex-wrap gap-2">
{% for year in summaries_by_year|keys %}
<li>
<a href="#evenements-{{ year }}"
class="inline-flex items-center justify-center rounded-lg bg-afup-100 px-2 py-1 text-sm font-medium text-afup-500 hover:bg-afup-500 hover:text-white">{{ year }}</a>
</li>
{% endfor %}
</ul>
</nav>
{% endif %}
</div>

<div class="container mx-auto px-4 pb-6 sm:px-28 sm:pb-10 flex flex-col gap-8">
{% for year, summaries in summaries_by_year %}
<section id="evenements-{{ year }}" class="flex flex-col gap-4 scroll-mt-4">
<twig:SectionTitle>{{ year }}</twig:SectionTitle>
<ul class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{% for summary in summaries %}
<li class="flex flex-col gap-1 rounded-2xl border-2 border-neutre-300 p-4">
<a href="{{ path('talks_event', {path: summary.event.path}) }}"
class="font-titre text-lg leading-snug text-afup-800 hover:underline">{{ summary.event.title }}</a>
<p class="text-sm text-neutre-400">
{{ summary.talkCount }} talk{{ summary.talkCount > 1 ? 's' }}
· {{ summary.videoCount }} vidéo{{ summary.videoCount > 1 ? 's' }}
</p>
</li>
{% endfor %}
</ul>
</section>
{% else %}
<p class="text-neutre-700">Aucun événement pour le moment.</p>
{% endfor %}
<div class="container mx-auto px-4 pb-6 sm:px-28 sm:pb-10">
{% include 'site/talks/_events_by_year.html.twig' %}
</div>
{% endblock %}
42 changes: 42 additions & 0 deletions templates/site/talks/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

{% block title %}{{ title }}{% endblock %}

{% block description %}Les talks et vidéos des conférences de l'AFUP : Forum PHP, AFUP Day, PHP Tour… Dernières vidéos, toutes les éditions année par année, les speakers et une recherche dans tout l'historique.{% endblock %}

{% block canonical %}
<link rel="canonical" href="{{ canonical }}" />
{% endblock %}
Expand Down Expand Up @@ -37,6 +39,46 @@
évènements, rendez-vous sur <a href="https://event.afup.org" class="text-afup-500 underline hover:no-underline">event.afup.org</a>.
</p>

{% if show_hub %}
<ul class="flex flex-wrap gap-3">
<li><twig:Button variant="secondary" as="a" href="{{ path('talks_events') }}">Tous les événements</twig:Button></li>
<li><twig:Button variant="secondary" as="a" href="{{ path('talks_speakers') }}">Tous les speakers de A à Z</twig:Button></li>
</ul>
{% endif %}
</div>

{# Hub rendu côté serveur : liens HTML vers les talks, les éditions et les speakers, lisibles sans JavaScript. #}
{% if show_hub %}
{% if latest_talks is not empty %}
<section id="dernieres-videos" class="container mx-auto px-4 pb-6 sm:px-28 sm:pb-10 flex flex-col gap-4">
<twig:SectionTitle>Dernières vidéos</twig:SectionTitle>
<ol class="grid grid-cols-1 lg:grid-cols-2 gap-4">
{% for latest in latest_talks %}
<li>
{% embed 'site/talks/_talk_card.html.twig' with {talk: latest.talk} %}
{% block details %}
<p class="text-sm text-neutre-400">
<a href="{{ path('talks_event', {path: latest.event.path}) }}" class="text-afup-500 underline hover:no-underline">{{ latest.event.title }}</a>
</p>
{% endblock %}
{% endembed %}
</li>
{% endfor %}
</ol>
</section>
{% endif %}

<section id="editions" class="container mx-auto px-4 pb-6 sm:px-28 sm:pb-10 flex flex-col gap-4">
<twig:SectionTitle>Les éditions</twig:SectionTitle>
{% include 'site/talks/_events_by_year.html.twig' with {heading_level: 3} %}
</section>
{% endif %}

<div class="container mx-auto px-4 pb-6 sm:px-28 sm:pb-10 flex flex-col gap-4">
{% if show_hub %}
<twig:SectionTitle>Rechercher une conférence</twig:SectionTitle>
{% endif %}

{# instantsearch remplace cet input ; les classes sont posées via cssClasses.input #}
<div id="search-box"></div>
</div>
Expand Down
46 changes: 46 additions & 0 deletions tests/behat/features/PublicSite/Talks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,49 @@ Feature: Site Public - Talks
When I go to "/talks/1-jouons-tous-ensemble-a-un-petit-jeu"
Then the response should contain "href=\"https://apachephptest:80/talks/evenements/forum\""
And the response should not contain "fR%5Bevent.title"

@reloadDbWithTestData
Scenario: Hub des talks rendu côté serveur
When I go to "/talks/"
Then the response status code should be 200
And I should see "Historique des conférences de l'AFUP" in the "h1" element
And the response should contain "<link rel=\"canonical\" href=\"https://apachephptest:80/talks/\" />"
# Les données de test n'ont que 2 talks publiés avec vidéo (le hub en affiche jusqu'à 12) ;
# « Révolutionons PHP » a une vidéo mais une publication à venir.
And the texts of "#dernieres-videos article h3" should be, in this order:
"""
REST ou GraphQL ? Exemples illustrés avec Symfony et API Platform
Jouons tous ensemble à un petit jeu
"""
And the response should contain "href=\"/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform\""
And the response should contain "href=\"/talks/1-jouons-tous-ensemble-a-un-petit-jeu\""
And the texts of "#editions section li a" should be, in this order:
"""
forum
Un évènement du passé
"""
And the response should contain "href=\"/talks/evenements/forum\""
And the response should contain "href=\"/talks/evenements/passed\""
And the response should not contain "href=\"/talks/evenements/afup-day-lyon\""
And the response should contain "href=\"/talks/speakers/\""
And the response should contain "href=\"/talks/evenements/\""
# Conteneurs du moteur Algolia (htdocs/js/talk/list.js), toujours présents sous le hub
And the response should contain "<div id=\"search-box\"></div>"
And the response should contain "<div id=\"hits-container\""
And the response should contain "<div id=\"refinement-event\"></div>"
And the response should contain "<nav id=\"pagination\""

@reloadDbWithTestData
Scenario: Le hub des talks n'est pas affiché sur une recherche
When I go to "/talks/?q=symfony&hPP=7&idx=afup_talks&p=0&is_v=1"
Then the response status code should be 200
And the response should not contain "id=\"dernieres-videos\""
And the response should not contain "id=\"editions\""
And the response should contain "<div id=\"search-box\"></div>"
When I go to "/talks/?fR[event.title][0]=forum&p=1"
Then the response should not contain "id=\"dernieres-videos\""
And I should see "forum les vidéos"
When I go to "/talks/?p=2"
Then the response should not contain "id=\"dernieres-videos\""
When I go to "/talks/?q=&hPP=7&idx=afup_talks&p=0&is_v=1&utm_source=newsletter"
Then the response should contain "id=\"dernieres-videos\""
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,34 @@ public function testGetEventTalksSummariesCountsPublishedTalksAndVideos(): void
);
}

public function testGetLatestPublishedTalksWithVideoSortsBySlotEnd(): void
{
// Le créneau du talk 301 se termine après celui du talk 300, qui a un identifiant plus petit.
$this->insertTalk(301, 3, 'Forum 2018, fin de journée', strtotime('2018-10-25 17:00:00'), youtubeId: 'video301');
$this->insertTalk(110, 1, 'Vidéo, créneau en cours', time() - 600, youtubeId: 'video110', slotEnd: time() + 600);
$this->insertTalk(111, 1, 'Vidéo, non planifié', strtotime('2019-10-24 11:00:00'), youtubeId: 'video111', scheduled: false);
$repository = self::getContainer()->get(TalkRepository::class);
$toRows = static fn(array $latest): array => array_map(static fn(array $row): array => [
$row['talk']->getId(),
$row['talk']->getTitle(),
$row['talk']->getYoutubeId(),
$row['event']->getPath(),
], $latest);

// Exclus : sans vidéo ou vidéo vide (101, 103, 200), clinique (104), publication à venir (107), créneau en
// cours (110), non planifié (111).
self::assertSame(
[
[100, 'Clôture', 'video100', 'forumphp2019'],
[102, 'Salle 2', 'video102', 'forumphp2019'],
[301, 'Forum 2018, fin de journée', 'video301', 'forumphp2018'],
[300, 'Forum 2018', 'video300', 'forumphp2018'],
],
$toRows($repository->getLatestPublishedTalksWithVideo(12)),
);
self::assertSame([100, 102], array_column($toRows($repository->getLatestPublishedTalksWithVideo(2)), 0));
}

private function getEvent(string $path): Event
{
$event = self::getContainer()->get(EventRepository::class)->getByPath($path);
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/AppBundle/Event/Talk/EventTalksSummaryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace AppBundle\Tests\Event\Talk;

use AppBundle\Event\Model\Event;
use AppBundle\Event\Talk\EventTalksSummary;
use PHPUnit\Framework\TestCase;

final class EventTalksSummaryTest extends TestCase
{
public function testGroupByYearKeepsTheGivenOrder(): void
{
$forum2025 = self::summary('forumphp2025', '2025-10-09');
$day2025 = self::summary('afupday2025', '2025-05-16');
$forum2024 = self::summary('forumphp2024', '2024-10-10');

self::assertSame(
[2025 => [$forum2025, $day2025], 2024 => [$forum2024]],
EventTalksSummary::groupByYear([$forum2025, $day2025, $forum2024]),
);
self::assertSame([], EventTalksSummary::groupByYear([]));
}

private static function summary(string $path, string $dateStart): EventTalksSummary
{
return new EventTalksSummary(new Event()->setPath($path)->setDateStart(new \DateTime($dateStart)), 1, 0);
}
}
Loading