diff --git a/config/routing/talks.yml b/config/routing/talks.yml index 0d4633546..a0504db40 100644 --- a/config/routing/talks.yml +++ b/config/routing/talks.yml @@ -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 } @@ -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 } diff --git a/sources/AppBundle/Controller/Website/Talks/EventListAction.php b/sources/AppBundle/Controller/Website/Talks/EventListAction.php new file mode 100644 index 000000000..7e8a1d473 --- /dev/null +++ b/sources/AppBundle/Controller/Website/Talks/EventListAction.php @@ -0,0 +1,31 @@ +talkRepository->getEventTalksSummaries() as $summary) { + $summariesByYear[$summary->getYear()][] = $summary; + } + + return $this->view->render('site/talks/events.html.twig', [ + 'summaries_by_year' => $summariesByYear, + ]); + } +} diff --git a/sources/AppBundle/Controller/Website/Talks/EventShowAction.php b/sources/AppBundle/Controller/Website/Talks/EventShowAction.php new file mode 100644 index 000000000..48841026c --- /dev/null +++ b/sources/AppBundle/Controller/Website/Talks/EventShowAction.php @@ -0,0 +1,52 @@ +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), + ]); + } +} diff --git a/sources/AppBundle/Controller/Website/Talks/ListAction.php b/sources/AppBundle/Controller/Website/Talks/ListAction.php index d1488378a..834440d45 100644 --- a/sources/AppBundle/Controller/Website/Talks/ListAction.php +++ b/sources/AppBundle/Controller/Website/Talks/ListAction.php @@ -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; @@ -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'; @@ -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; } @@ -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; + } } diff --git a/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php b/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php index ea5d8deac..c950cb6d4 100644 --- a/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php +++ b/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php @@ -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&iterable @@ -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 = []; @@ -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); diff --git a/sources/AppBundle/Event/Model/Repository/TalkRepository.php b/sources/AppBundle/Event/Model/Repository/TalkRepository.php index 8ca7ebb12..7ffef433c 100644 --- a/sources/AppBundle/Event/Model/Repository/TalkRepository.php +++ b/sources/AppBundle/Event/Model/Repository/TalkRepository.php @@ -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; @@ -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); @@ -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 + */ + 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}} $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 + */ + 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 $talkIds * @return CollectionInterface diff --git a/sources/AppBundle/Event/Talk/EventTalk.php b/sources/AppBundle/Event/Talk/EventTalk.php new file mode 100644 index 000000000..34397b55e --- /dev/null +++ b/sources/AppBundle/Event/Talk/EventTalk.php @@ -0,0 +1,23 @@ + $speakers + */ + public function __construct( + public Talk $talk, + public \DateTimeImmutable $startsAt, + public array $speakers, + ) {} +} diff --git a/sources/AppBundle/Event/Talk/EventTalksJsonLd.php b/sources/AppBundle/Event/Talk/EventTalksJsonLd.php new file mode 100644 index 000000000..d6b611648 --- /dev/null +++ b/sources/AppBundle/Event/Talk/EventTalksJsonLd.php @@ -0,0 +1,50 @@ + $eventTalks + * + * @return array + */ + public function getData(Event $event, array $eventTalks): array + { + $items = []; + foreach ($eventTalks as $index => $eventTalk) { + $items[] = [ + '@type' => 'ListItem', + 'position' => $index + 1, + 'url' => $this->urlGenerator->generate( + 'talks_show', + ['id' => $eventTalk->talk->getId(), 'slug' => $eventTalk->talk->getSlug()], + UrlGeneratorInterface::ABSOLUTE_URL, + ), + 'name' => $eventTalk->talk->getTitle(), + ]; + } + + return [ + '@context' => 'https://schema.org', + '@type' => 'ItemList', + 'name' => $event->getTitle() . ' : les talks et vidéos', + 'url' => $this->urlGenerator->generate('talks_event', ['path' => $event->getPath()], UrlGeneratorInterface::ABSOLUTE_URL), + 'numberOfItems' => count($items), + 'itemListElement' => $items, + ]; + } +} diff --git a/sources/AppBundle/Event/Talk/EventTalksSummary.php b/sources/AppBundle/Event/Talk/EventTalksSummary.php new file mode 100644 index 000000000..ed2be07d3 --- /dev/null +++ b/sources/AppBundle/Event/Talk/EventTalksSummary.php @@ -0,0 +1,27 @@ +event->getDateStart()?->format('Y'); + } +} diff --git a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php index 50fc30188..9cb7b1ab9 100644 --- a/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php +++ b/sources/AppBundle/Subscriber/SitemapXmlSubscriber.php @@ -8,8 +8,6 @@ use AppBundle\Association\Model\CompanyMember; use AppBundle\Association\Model\Repository\CompanyMemberRepository; use AppBundle\Controller\Website\News\ListAction; -use AppBundle\Event\Model\Event; -use AppBundle\Event\Model\Repository\EventRepository; use AppBundle\Event\Model\Repository\TalkRepository; use AppBundle\Event\Model\Talk; use AppBundle\Event\Speaker\SpeakerProfileResolver; @@ -29,7 +27,6 @@ public function __construct( private readonly UrlGeneratorInterface $urlGenerator, private readonly TalkRepository $talkRepository, private readonly SpeakerProfileResolver $speakerProfileResolver, - private readonly EventRepository $eventRepository, private readonly ArticleRepository $articleRepository, private readonly CompanyMemberRepository $companyMemberRepository, private readonly FeuilleRepository $feuilleRepository, @@ -105,20 +102,21 @@ public function registerSpeakersUrls(UrlContainerInterface $urls): void } } + /** + * La page de chaque édition ayant au moins un talk publié ; l'index des éditions + * est déclaré par l'option sitemap de sa route. + */ public function registerEventsTalksUrls(UrlContainerInterface $urls): void { - /** @var Event[] $events */ - $events = $this->eventRepository->getAll(); - foreach ($events as $event) { + foreach ($this->talkRepository->getEventTalksSummaries() as $summary) { $url = new UrlConcrete( $this->urlGenerator->generate( - 'talks_list', - ['fR' => ['event.title' => [$event->getTitle()]]], + 'talks_event', + ['path' => $summary->event->getPath()], UrlGeneratorInterface::ABSOLUTE_URL, ), - $event->getDateEnd(), - UrlConcrete::CHANGEFREQ_DAILY, - 1, + $summary->event->getDateEnd(), + UrlConcrete::CHANGEFREQ_MONTHLY, ); $urls->addUrl($url, 'talks'); } diff --git a/templates/site/talks/_talk_card.html.twig b/templates/site/talks/_talk_card.html.twig new file mode 100644 index 000000000..3eebf3bea --- /dev/null +++ b/templates/site/talks/_talk_card.html.twig @@ -0,0 +1,14 @@ +{# Carte d'un talk : vignette (ou image par défaut), titre en lien, puis le bloc « details » de l'appelant. #} +{% set talk_url = path('talks_show', {id: talk.id, slug: talk.slug}) %} + diff --git a/templates/site/talks/event.html.twig b/templates/site/talks/event.html.twig new file mode 100644 index 000000000..0f579119d --- /dev/null +++ b/templates/site/talks/event.html.twig @@ -0,0 +1,68 @@ +{% extends 'layouts/site.html.twig' %} + +{% set talk_count = event_talks|length %} +{% set video_count = event_talks|filter(event_talk => event_talk.talk.hasYoutubeId)|length %} +{% set event_dates %} + {%- if event.dateStart|date('Y-m-d') == event.dateEnd|date('Y-m-d') -%} + le {{ event.dateStart|format_date('long') }} + {%- elseif event.dateStart|date('Y-m') == event.dateEnd|date('Y-m') -%} + du {{ event.dateStart|date('j') }} au {{ event.dateEnd|format_date('long') }} + {%- else -%} + du {{ event.dateStart|format_date('long') }} au {{ event.dateEnd|format_date('long') }} + {%- endif -%} +{% endset %} + +{% block title %}{{ event.title }} : les talks et vidéos – AFUP{% endblock %} + +{% block description %}{{ event.title }}, {{ event_dates }}{% if event.placeName %} à {{ event.placeName }}{% endif %} : {{ talk_count }} talk{{ talk_count > 1 ? 's' }}{% if video_count %} dont {{ video_count }} en vidéo{% endif %}, avec leurs speakers.{% endblock %} + +{% block metas %} + {{ parent() }} + +{% endblock %} + +{% block content %} +
+

+ Événements +

+

{{ event.title }} : les talks et vidéos

+

+ {{ event.title }} s'est déroulé {{ event_dates }}{% if event.placeName %} à {{ event.placeName }}{% endif %}. + Retrouvez {{ talk_count > 1 ? 'les ' ~ talk_count ~ ' talks' : 'le talk' }} de cette édition{% if video_count %}, dont {{ video_count }} en vidéo{% endif %}, dans l'ordre du programme. +

+

+ Voir la page de l'édition sur event.afup.org +

+
+ +
+ {{ talk_count > 1 ? 'Les talks' : 'Le talk' }} + +
    + {% for event_talk in event_talks %} +
  1. + {% embed 'site/talks/_talk_card.html.twig' with {talk: event_talk.talk} %} + {% block details %} + {% if event_talk.speakers|length %} +

    + {% for speaker in event_talk.speakers -%} + {%- if speaker_slugs[speaker.id] is defined -%} + {{ speaker.label }} + {%- else -%} + {{ speaker.label }} + {%- endif -%} + {{- not loop.last ? ', ' -}} + {%- endfor %} +

    + {% endif %} +

    + +

    + {% endblock %} + {% endembed %} +
  2. + {% endfor %} +
+
+{% endblock %} diff --git a/templates/site/talks/events.html.twig b/templates/site/talks/events.html.twig new file mode 100644 index 000000000..1e4f5c581 --- /dev/null +++ b/templates/site/talks/events.html.twig @@ -0,0 +1,49 @@ +{% extends 'layouts/site.html.twig' %} + +{% block title %}Événements et conférences : talks et vidéos – AFUP{% endblock %} + +{% block description %}Toutes les éditions des conférences de l'AFUP, année par année : Forum PHP, AFUP Day, PHP Tour… Retrouvez les talks et vidéos de chaque événement.{% endblock %} + +{% block content %} +
+

+ Vidéos +

+

Les événements de l'AFUP et leurs talks

+ + {% if summaries_by_year|length > 1 %} + + {% endif %} +
+ +
+ {% for year, summaries in summaries_by_year %} +
+ {{ year }} +
    + {% for summary in summaries %} +
  • + {{ summary.event.title }} +

    + {{ summary.talkCount }} talk{{ summary.talkCount > 1 ? 's' }} + · {{ summary.videoCount }} vidéo{{ summary.videoCount > 1 ? 's' }} +

    +
  • + {% endfor %} +
+
+ {% else %} +

Aucun événement pour le moment.

+ {% endfor %} +
+{% endblock %} diff --git a/templates/site/talks/show.html.twig b/templates/site/talks/show.html.twig index 4582cae77..7998291fe 100644 --- a/templates/site/talks/show.html.twig +++ b/templates/site/talks/show.html.twig @@ -41,7 +41,7 @@ {% set event_date %} {% if event.dateStart == event.dateEnd %}le {{ event.dateStart|date('d') }}{% else %}les {{ event.dateStart|date('d') }} et {{ event.dateEnd|date('d') }}{% endif %} {{ event.dateEnd|format_date('none', 'MMMM YYYY') }} {% endset %} - {% set event_url = url('talks_list', {"fR": { "event.title" : [ event.title ]}}) %} + {% set event_url = url('talks_event', {path: event.path}) %} {% set speakers_label = speakers|map(speaker => speaker.label)|join(', ') %} {% if talk.hasYoutubeId %} diff --git a/templates/site/talks/speaker.html.twig b/templates/site/talks/speaker.html.twig index 3f8df467c..bb5453e5e 100644 --- a/templates/site/talks/speaker.html.twig +++ b/templates/site/talks/speaker.html.twig @@ -56,23 +56,14 @@
    {% for speaker_talk in profile.talks %} - {% set talk = speaker_talk.talk %} - {% set talk_url = path('talks_show', {id: talk.id, slug: talk.slug}) %}
  • -
    - -
    -

    - {{ talk.title }} -

    + {% embed 'site/talks/_talk_card.html.twig' with {talk: speaker_talk.talk} %} + {% block details %}

    - {{ speaker_talk.event.title }} · + {{ speaker_talk.event.title }} ·

    -
    -
    + {% endblock %} + {% endembed %}
  • {% endfor %}
diff --git a/tests/behat/bootstrap/FeatureContext.php b/tests/behat/bootstrap/FeatureContext.php index bbae0f62a..9bb31169c 100644 --- a/tests/behat/bootstrap/FeatureContext.php +++ b/tests/behat/bootstrap/FeatureContext.php @@ -436,4 +436,42 @@ public function assertJsonLdPropertyContains(string $type, string $property, str ); } } + + /** + * Le texte de chaque élément trouvé par le sélecteur CSS, dans l'ordre de la page : ni plus, ni moins. + */ + #[Then('/^the texts of "(?P[^"]+)" should be, in this order:$/')] + public function assertElementTextsInOrder(string $selector, PyStringNode $expectedTexts): void + { + $expected = array_values(array_filter(array_map(trim(...), $expectedTexts->getStrings()))); + $actual = array_map( + static fn(NodeElement $element): string => trim($element->getText()), + $this->minkContext->getSession()->getPage()->findAll('css', $selector), + ); + + if ($expected !== $actual) { + throw new ExpectationException( + sprintf('The texts of "%s" are %s, %s expected', $selector, json_encode($actual, JSON_UNESCAPED_UNICODE), json_encode($expected, JSON_UNESCAPED_UNICODE)), + $this->minkContext->getSession()->getDriver(), + ); + } + } + + /** + * La propriété :key de chaque élément de la liste :property du JSON-LD, dans l'ordre : ni plus, ni moins. + */ + #[Then('the :key of each item of the JSON-LD :type property :property should be, in this order:')] + public function assertJsonLdListValues(string $key, string $type, string $property, PyStringNode $expectedValues): void + { + $items = $this->findJsonLd($type)[$property] ?? null; + $actual = is_array($items) ? array_map(static fn($item): mixed => is_array($item) ? $item[$key] ?? null : null, $items) : null; + $expected = array_values(array_filter(array_map(trim(...), $expectedValues->getStrings()))); + + if ($expected !== $actual) { + throw new ExpectationException( + sprintf('The "%s" of the JSON-LD "%s" property "%s" are %s, %s expected', $key, $type, $property, json_encode($actual, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE), json_encode($expected, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)), + $this->minkContext->getSession()->getDriver(), + ); + } + } } diff --git a/tests/behat/features/PublicSite/Sitemaps.feature b/tests/behat/features/PublicSite/Sitemaps.feature index 92f844e72..ddcc6b3e6 100644 --- a/tests/behat/features/PublicSite/Sitemaps.feature +++ b/tests/behat/features/PublicSite/Sitemaps.feature @@ -16,7 +16,10 @@ Feature: Site Public - Sitemaps And the response should contain "https://apachephptest:80/talks/speakers/geoffrey-bachelet" And the response should contain "https://apachephptest:80/talks/speakers/" And the response should not contain "fR%5Bspeakers" - And the response should contain "https://apachephptest:80/talks/?fR%5Bevent.title%5D%5B0%5D=forum" + And the response should contain "https://apachephptest:80/talks/evenements/forum" + And the response should contain "https://apachephptest:80/talks/evenements/passed" + And the response should contain "https://apachephptest:80/talks/evenements/" + And the response should not contain "fR%5Bevent" And the response should contain "https://apachephptest:80/talks/" @reloadDbWithTestData diff --git a/tests/behat/features/PublicSite/Talks.feature b/tests/behat/features/PublicSite/Talks.feature index f32fb4a0a..414512c89 100644 --- a/tests/behat/features/PublicSite/Talks.feature +++ b/tests/behat/features/PublicSite/Talks.feature @@ -48,6 +48,7 @@ Feature: Site Public - Talks 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/6-revolutionons-php\"" And I should see "Un évènement du passé" + And the response should contain "href=\"/talks/evenements/passed\"" And the response should contain "https://img.youtube.com/vi/MseSkWbhxV8/hqdefault.jpg" And the response should contain "/images/no_video.jpg" And the response should contain "href=\"https://phpc.social/@ubermuda\"" @@ -100,3 +101,73 @@ Feature: Site Public - Talks And I follow "Voir tous ses talks" Then the url should match "/talks/speakers/geoffrey-bachelet" And I should see "Geoffrey Bachelet" in the "h1" element + + @reloadDbWithTestData + Scenario: Page d'un événement rendue côté serveur + When I go to "/talks/evenements/forum" + Then the response status code should be 200 + And the response should contain "forum : les talks et vidéos – AFUP" + And I should see "forum : les talks et vidéos" in the "h1" element + And I should see "à Paris" + And the response should contain "href=\"https://event.afup.org/forum/\"" + And the texts of "main ol article h3" should be, in this order: + """ + Jouons tous ensemble à un petit jeu + REST ou GraphQL ? Exemples illustrés avec Symfony et API Platform + """ + And I should not see "Révolutionons PHP" + And the response should contain "https://img.youtube.com/vi/QhAToFl_Omo/hqdefault.jpg" + And the response should contain "href=\"/talks/speakers/geoffrey-bachelet\"" + And the JSON-LD "ItemList" should have the following properties: + | name | forum : les talks et vidéos | + | url | https://apachephptest:80/talks/evenements/forum | + | numberOfItems | 2 | + And the "url" of each item of the JSON-LD "ItemList" property "itemListElement" should be, in this order: + """ + https://apachephptest:80/talks/1-jouons-tous-ensemble-a-un-petit-jeu + https://apachephptest:80/talks/2-rest-ou-graphql-exemples-illustres-avec-symfony-et-api-platform + """ + + @reloadDbWithTestData + Scenario: Page d'un événement inconnu ou sans talk publié + When I go to "/talks/evenements/evenement-inconnu" + Then the response status code should be 404 + When I go to "/talks/evenements/afup-day-lyon" + Then the response status code should be 404 + + @reloadDbWithTestData + Scenario: Index des événements groupé par année + When I go to "/talks/evenements/" + Then the response status code should be 200 + And I should see "2020" in the "section#evenements-2020 h2" element + And the texts of "section#evenements-2020 li a" should be, in this order: + """ + Un évènement du passé + """ + And the texts of "section#evenements-2020 li p" should be, in this order: + """ + 1 talk · 0 vidéo + """ + And the response should contain "href=\"/talks/evenements/forum\"" + And I should see "2 talks · 2 vidéos" + And I should not see "AFUP Day Lyon" + + @reloadDbWithTestData + Scenario: L'ancienne facette d'un événement redirige vers sa page + Given I do not follow redirects + When I go to "/talks/?fR[event.title][0]=forum" + Then the response status code should be 301 + And the response header "Location" should match "#^(https?://[^/]+)?/talks/evenements/forum$#" + + @reloadDbWithTestData + Scenario: Une facette événement combinée à d'autres paramètres reste une recherche + Given I do not follow redirects + When I go to "/talks/?fR[event.title][0]=forum&p=1" + Then the response status code should be 200 + And I should see "forum les vidéos" + + @reloadDbWithTestData + Scenario: Le bandeau de la page d'un talk renvoie vers la page de son événement + 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" diff --git a/tests/integration/AppBundle/Event/Model/Repository/TalkRepositoryTest.php b/tests/integration/AppBundle/Event/Model/Repository/TalkRepositoryTest.php new file mode 100644 index 000000000..66fe15581 --- /dev/null +++ b/tests/integration/AppBundle/Event/Model/Repository/TalkRepositoryTest.php @@ -0,0 +1,124 @@ +connection = self::getContainer()->get(Connection::class); + + $this->connection->insert('afup_forum', ['id' => 1, 'titre' => 'Forum PHP 2019', 'path' => 'forumphp2019', 'date_debut' => '2019-10-24', 'date_fin' => '2019-10-25', 'nb_places' => 100]); + $this->connection->insert('afup_forum', ['id' => 2, 'titre' => 'AFUP Day 2021', 'path' => 'afupday2021', 'date_debut' => '2021-05-28', 'date_fin' => '2021-05-28', 'nb_places' => 100]); + $this->connection->insert('afup_forum', ['id' => 3, 'titre' => 'Forum PHP 2018', 'path' => 'forumphp2018', 'date_debut' => '2018-10-25', 'date_fin' => '2018-10-26', 'nb_places' => 100]); + $this->connection->insert('afup_forum', ['id' => 4, 'titre' => 'Sans talk publié', 'path' => 'sanstalk', 'date_debut' => '2020-10-25', 'date_fin' => '2020-10-26', 'nb_places' => 100]); + + foreach ([10 => 'Alice', 11 => 'Bob', 12 => 'Chloé'] as $speakerId => $firstname) { + $this->connection->insert('afup_conferenciers', ['conferencier_id' => $speakerId, 'id_forum' => 1, 'prenom' => $firstname, 'nom' => 'Martin', 'email' => $speakerId . '@example.com']); + } + + // Les créneaux sont dans un autre ordre que les identifiants ; deux talks partagent un créneau dans deux salles. + $this->insertTalk(100, 1, 'Clôture', strtotime('2019-10-25 17:00:00'), room: 1, speakerIds: [10], youtubeId: 'video100'); + $this->insertTalk(101, 1, 'Keynote', strtotime('2019-10-24 09:00:00'), room: 1, speakerIds: [12, 11]); + $this->insertTalk(102, 1, 'Salle 2', strtotime('2019-10-24 10:00:00'), room: 2, speakerIds: [10], youtubeId: 'video102'); + $this->insertTalk(103, 1, 'Salle 1', strtotime('2019-10-24 10:00:00'), room: 1, speakerIds: []); + $this->insertTalk(104, 1, 'Clinique', strtotime('2019-10-24 11:00:00'), type: Talk::TYPE_CLINIC, youtubeId: 'video104'); + $this->insertTalk(105, 1, 'Présentation des speakers', strtotime('2019-10-24 11:00:00'), type: Talk::TYPE_SPEAKER_INTRODUCTIONS); + $this->insertTalk(106, 1, 'Non planifié', strtotime('2019-10-24 11:00:00'), scheduled: false); + $this->insertTalk(107, 1, 'Publication à venir', strtotime('2019-10-24 11:00:00'), publishedOn: '+1 day', youtubeId: 'video107'); + $this->insertTalk(108, 1, 'Sans créneau', null); + $this->insertTalk(109, 1, 'Créneau pas encore terminé', time() - 600, slotEnd: time() + 600); + $this->insertTalk(200, 2, 'AFUP Day', strtotime('2021-05-28 10:00:00'), youtubeId: ''); + $this->insertTalk(300, 3, 'Forum 2018', strtotime('2018-10-25 10:00:00'), youtubeId: 'video300', publishedOn: '-1 day'); + $this->insertTalk(400, 4, 'Non planifié', strtotime('2020-10-25 10:00:00'), scheduled: false); + } + + public function testGetPublishedByEventWithSpeakersFollowsThePlanning(): void + { + $eventTalks = self::getContainer()->get(TalkRepository::class)->getPublishedByEventWithSpeakers($this->getEvent('forumphp2019')); + + self::assertSame( + [ + [101, 'Keynote', '2019-10-24 09:00', [11, 12], null], + [103, 'Salle 1', '2019-10-24 10:00', [], null], + [102, 'Salle 2', '2019-10-24 10:00', [10], 'video102'], + [100, 'Clôture', '2019-10-25 17:00', [10], 'video100'], + ], + array_map(static fn(EventTalk $eventTalk): array => [ + $eventTalk->talk->getId(), + $eventTalk->talk->getTitle(), + $eventTalk->startsAt->format('Y-m-d H:i'), + array_map(static fn(Speaker $speaker): ?int => $speaker->getId(), $eventTalk->speakers), + $eventTalk->talk->getYoutubeId(), + ], $eventTalks), + ); + self::assertSame([], self::getContainer()->get(TalkRepository::class)->getPublishedByEventWithSpeakers($this->getEvent('sanstalk'))); + } + + public function testGetEventTalksSummariesCountsPublishedTalksAndVideos(): void + { + self::assertSame( + [ + ['afupday2021', 1, 0, 2021], + ['forumphp2019', 4, 2, 2019], + ['forumphp2018', 1, 1, 2018], + ], + array_map(static fn(EventTalksSummary $summary): array => [ + $summary->event->getPath(), + $summary->talkCount, + $summary->videoCount, + $summary->getYear(), + ], self::getContainer()->get(TalkRepository::class)->getEventTalksSummaries()), + ); + } + + private function getEvent(string $path): Event + { + $event = self::getContainer()->get(EventRepository::class)->getByPath($path); + self::assertNotNull($event); + + return $event; + } + + /** + * @param list $speakerIds + */ + private function insertTalk(int $id, int $eventId, string $title, ?int $slotStart, int $type = Talk::TYPE_FULL_LONG, int $room = 1, array $speakerIds = [], ?string $youtubeId = null, bool $scheduled = true, ?string $publishedOn = null, ?int $slotEnd = null): void + { + $this->connection->insert('afup_sessions', [ + 'session_id' => $id, + 'id_forum' => $eventId, + 'date_soumission' => '2019-01-01', + 'titre' => $title, + 'abstract' => '', + 'genre' => $type, + 'plannifie' => (int) $scheduled, + 'youtube_id' => $youtubeId, + 'date_publication' => null !== $publishedOn ? date('Y-m-d H:i:s', (int) strtotime($publishedOn)) : null, + ]); + + foreach ($speakerIds as $speakerId) { + $this->connection->insert('afup_conferenciers_sessions', ['session_id' => $id, 'conferencier_id' => $speakerId]); + } + + if (null !== $slotStart) { + $this->connection->insert('afup_forum_planning', ['id_session' => $id, 'debut' => $slotStart, 'fin' => $slotEnd ?? $slotStart + 2400, 'id_forum' => $eventId, 'id_salle' => $room]); + } + } +} diff --git a/tests/unit/AppBundle/Event/Talk/EventTalksJsonLdTest.php b/tests/unit/AppBundle/Event/Talk/EventTalksJsonLdTest.php new file mode 100644 index 000000000..510c2158b --- /dev/null +++ b/tests/unit/AppBundle/Event/Talk/EventTalksJsonLdTest.php @@ -0,0 +1,61 @@ +setTitle('Forum PHP 2025')->setPath('forumphp2025'); + + self::assertSame([ + '@context' => 'https://schema.org', + '@type' => 'ItemList', + 'name' => 'Forum PHP 2025 : les talks et vidéos', + 'url' => 'https://afup.org/talks/evenements/forumphp2025', + 'numberOfItems' => 2, + 'itemListElement' => [ + ['@type' => 'ListItem', 'position' => 1, 'url' => 'https://afup.org/talks/12-keynote-d-ouverture', 'name' => 'Keynote d\'ouverture'], + ['@type' => 'ListItem', 'position' => 2, 'url' => 'https://afup.org/talks/7-cloture', 'name' => 'Clôture'], + ], + ], self::jsonLd()->getData($event, [self::eventTalk(12, 'Keynote d\'ouverture'), self::eventTalk(7, 'Clôture')])); + } + + public function testEncodedJsonCannotCloseTheScriptTag(): void + { + $event = new Event()->setTitle('')->setPath('x'); + + $json = json_encode(self::jsonLd()->getData($event, [self::eventTalk(1, '')]), PersonJsonLd::JSON_FLAGS); + + self::assertIsString($json); + self::assertStringNotContainsString('<', $json); + self::assertSame('', json_decode($json, true)['itemListElement'][0]['name']); + } + + private static function jsonLd(): EventTalksJsonLd + { + $routes = new RouteCollection(); + $routes->add('talks_show', new Route('/talks/{id}-{slug}')); + $routes->add('talks_event', new Route('/talks/evenements/{path}')); + + return new EventTalksJsonLd(new UrlGenerator($routes, new RequestContext(host: 'afup.org', scheme: 'https'))); + } + + private static function eventTalk(int $id, string $title): EventTalk + { + return new EventTalk(new Talk()->setId($id)->setTitle($title), new \DateTimeImmutable(), []); + } +}