From f77c9063944989b2a1544111784da7fce1279b6f Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Tue, 17 Nov 2026 18:20:40 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Regroupe=20les=20speakers=20de=20toutes=20l?= =?UTF-8?q?es=20=C3=A9ditions=20par=20leur=20personne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Un speaker est une ligne afup_conferenciers par édition. Les pages speaker de la vague 2 ont besoin d'une identité de personne et d'un slug stable : la table afup_speaker_person (T2.0a/T2.0b) les fournit, il n'y a plus à les deviner. SpeakerProfileResolver regroupe les lignes par person_id et lit le slug en base. Une ligne non rattachée à une personne n'a pas de page ; aucun regroupement par compte GitHub ou par libellé, aucun calcul de collision : le slug unique de la personne fait foi. getIdentityByLabel reste, pour rediriger les anciennes facettes Algolia speakers.label : un libellé normalisé (accents, casse, espaces) porté par plusieurs personnes ne désigne personne. L'index repose sur une requête légère sans hydratation ; seul le profil demandé est hydraté, ce qui évite un cache à invalider. --- .../Model/Repository/SpeakerRepository.php | 105 +++++++ .../Event/Speaker/SpeakerIdentity.php | 44 +++ .../Event/Speaker/SpeakerProfile.php | 29 ++ .../Event/Speaker/SpeakerProfileResolver.php | 249 ++++++++++++++++ .../AppBundle/Event/Speaker/SpeakerTalk.php | 23 ++ .../Repository/SpeakerRepositoryTest.php | 130 +++++++++ .../Speaker/SpeakerProfileResolverTest.php | 270 ++++++++++++++++++ 7 files changed, 850 insertions(+) create mode 100644 sources/AppBundle/Event/Speaker/SpeakerIdentity.php create mode 100644 sources/AppBundle/Event/Speaker/SpeakerProfile.php create mode 100644 sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php create mode 100644 sources/AppBundle/Event/Speaker/SpeakerTalk.php create mode 100644 tests/integration/AppBundle/Event/Model/Repository/SpeakerRepositoryTest.php create mode 100644 tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php diff --git a/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php b/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php index f0db52fa6..844576a62 100644 --- a/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php +++ b/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php @@ -9,9 +9,12 @@ use AppBundle\Event\Model\Speaker; use AppBundle\Event\Model\Talk; use AppBundle\Event\Speaker\MicrophoneType; +use AppBundle\Event\Speaker\SpeakerTalk; use AppBundle\Ting\JoinHydrator; use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean; 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; use CCMBenchmark\Ting\Repository\MetadataInitializer; @@ -25,6 +28,25 @@ */ 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. + */ + 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)'; + /** * @return CollectionInterface&iterable */ @@ -171,6 +193,89 @@ public function searchSpeakers(Event $event, $sort = 'name', $direction = 'asc', return $query->query($this->getCollection(new HydratorSingleObject())); } + /** + * Les lignes speaker rattachées à une personne qui ont un talk publié, toutes éditions confondues, + * une ligne par couple speaker / talk, sans hydrater d'entité : de quoi construire l'index des personnes. + * Les lignes sans personne sont écartées. + * + * @return list + */ + public function getPublishedTalkAppearances(): array + { + $query = $this->getQuery( + 'SELECT speaker.conferencier_id AS speaker_id, person.id AS person_id, person.slug, + 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, + ); + + $appearances = []; + /** @var array{speaker_id: int|string, person_id: int|string, slug: string, firstname: string|null, lastname: string|null, talk_id: int|string, starts_at: int|string} $row */ + foreach ($query->query($this->getCollection(new HydratorArray())) as $row) { + $appearances[] = [ + 'speaker_id' => (int) $row['speaker_id'], + 'person_id' => (int) $row['person_id'], + 'slug' => $row['slug'], + 'firstname' => (string) $row['firstname'], + 'lastname' => (string) $row['lastname'], + 'talk_id' => (int) $row['talk_id'], + 'starts_at' => (int) $row['starts_at'], + ]; + } + + return $appearances; + } + + /** + * Les talks publiés de ces lignes speaker, avec leur événement, du plus récent au plus ancien. + * + * @param list $speakerIds + * + * @return list + */ + public function getPublishedSpeakerTalks(array $speakerIds): array + { + if ($speakerIds === []) { + return []; + } + + $params = []; + foreach ($speakerIds as $index => $speakerId) { + $params['speaker' . $index] = $speakerId; + } + + $query = $this->getPreparedQuery( + 'SELECT speaker.conferencier_id, speaker.id_forum, speaker.nom, speaker.prenom, speaker.societe, + speaker.biographie, speaker.twitter, speaker.mastodon, speaker.bluesky, speaker.linkedin, + speaker.user_github, speaker.photo, + talk.session_id, talk.id_forum, talk.titre, talk.genre, talk.plannifie, talk.youtube_id, talk.language_code, + event.id, event.titre, event.path, event.date_debut, event.date_fin, + github.login AS github_login, + planning.debut AS starts_at' + . self::PUBLISHED_SPEAKER_TALKS_JOINS + . ' 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 + . ' ORDER BY planning.debut DESC, talk.session_id DESC, speaker.conferencier_id DESC', + )->setParams($params); + + $speakerTalks = []; + /** @var array{speaker: Speaker, talk: Talk, event: Event, 0: object{starts_at: int|string, github_login: string|null}} $row */ + foreach ($query->query($this->getCollection(new Hydrator())) as $row) { + $speakerTalks[] = new SpeakerTalk( + $row['speaker'], + $row['talk'], + $row['event'], + new \DateTimeImmutable('@' . $row[0]->starts_at)->setTimezone(new \DateTimeZone(date_default_timezone_get())), + $row[0]->github_login, + ); + } + + return $speakerTalks; + } + public function countByEvent(Event $event): int { $query = $this->getPreparedQuery('SELECT COUNT(*) AS nb FROM (SELECT nom, prenom FROM afup_conferenciers WHERE id_forum = :eventId GROUP BY nom, prenom) c') diff --git a/sources/AppBundle/Event/Speaker/SpeakerIdentity.php b/sources/AppBundle/Event/Speaker/SpeakerIdentity.php new file mode 100644 index 000000000..eef403050 --- /dev/null +++ b/sources/AppBundle/Event/Speaker/SpeakerIdentity.php @@ -0,0 +1,44 @@ + $speakerIds les lignes speaker (une par édition) de cette personne + */ + public function __construct( + public string $slug, + public string $firstname, + public string $lastname, + public array $speakerIds, + public \DateTimeImmutable $latestTalkAt, + ) {} + + /** + * « Prénom Nom », tel que saisi, espaces superflus retirés. + */ + public function getName(): string + { + return self::cleanSpaces($this->firstname . ' ' . $this->lastname); + } + + /** + * « Prénom NOM », comme Speaker::getLabel(), espaces superflus retirés. + */ + public function getLabel(): string + { + return self::cleanSpaces($this->firstname . ' ' . mb_strtoupper($this->lastname)); + } + + private static function cleanSpaces(string $value): string + { + return trim((string) preg_replace('/\s+/u', ' ', $value)); + } +} diff --git a/sources/AppBundle/Event/Speaker/SpeakerProfile.php b/sources/AppBundle/Event/Speaker/SpeakerProfile.php new file mode 100644 index 000000000..2800fc960 --- /dev/null +++ b/sources/AppBundle/Event/Speaker/SpeakerProfile.php @@ -0,0 +1,29 @@ + $socialLinks URL par réseau + * @param non-empty-list $talks les talks publiés, du plus récent au plus ancien + */ + public function __construct( + public SpeakerIdentity $identity, + public Speaker $speaker, + public ?string $biography, + public ?Speaker $photoSpeaker, + public array $socialLinks, + public array $talks, + ) {} +} diff --git a/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php b/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php new file mode 100644 index 000000000..61de17689 --- /dev/null +++ b/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php @@ -0,0 +1,249 @@ +, + * byPersonId: array, + * byLabel: array, + * }|null + */ + private ?array $index = null; + + private readonly Slugify $slugify; + + public function __construct(private readonly SpeakerRepository $speakerRepository) + { + // Le même slugifier que Talk::getSlug(), pour le tri. + $this->slugify = new Slugify(); + } + + /** + * Libellé normalisé : sans espaces superflus, sans accents, en minuscules. + */ + public static function normalizeLabel(string $label): string + { + return u($label)->ascii()->lower()->collapseWhitespace()->toString(); + } + + /** + * Toutes les personnes ayant au moins un talk publié, triées par nom puis prénom. + * + * @return list + */ + public function getIdentities(): array + { + return array_values($this->getIndex()['bySlug']); + } + + public function getIdentityBySlug(string $slug): ?SpeakerIdentity + { + return $this->getIndex()['bySlug'][$slug] ?? null; + } + + /** + * La personne qui porte ce libellé sur l'une de ses lignes speaker (par exemple la facette Algolia + * `speakers.label`), aux accents, à la casse et aux espaces près. Null si personne ou plusieurs personnes le portent. + */ + public function getIdentityByLabel(string $label): ?SpeakerIdentity + { + $index = $this->getIndex(); + $slug = $index['byLabel'][self::normalizeLabel($label)] ?? null; + + return null !== $slug ? $index['bySlug'][$slug] : null; + } + + /** + * La personne d'une ligne speaker de n'importe quelle édition, y compris une édition dont + * les talks ne sont pas encore publiés. Null si la ligne n'est rattachée à aucune personne + * ou si sa personne n'a aucun talk publié. + */ + public function getIdentityForSpeaker(Speaker $speaker): ?SpeakerIdentity + { + $personId = $speaker->getPersonId(); + if (null === $personId) { + return null; + } + + $index = $this->getIndex(); + $slug = $index['byPersonId'][$personId] ?? null; + + return null !== $slug ? $index['bySlug'][$slug] : null; + } + + /** + * Le profil consolidé et les talks publiés de la personne qui porte ce slug. + */ + public function getProfileBySlug(string $slug): ?SpeakerProfile + { + $identity = $this->getIdentityBySlug($slug); + if (null === $identity) { + return null; + } + + $speakerTalks = $this->speakerRepository->getPublishedSpeakerTalks($identity->speakerIds); + if ($speakerTalks === []) { + return null; + } + + return $this->buildProfile($identity, $speakerTalks); + } + + public function reset(): void + { + $this->index = null; + } + + /** + * @return array{ + * bySlug: array, + * byPersonId: array, + * byLabel: array, + * } + */ + private function getIndex(): array + { + return $this->index ??= $this->buildIndex($this->speakerRepository->getPublishedTalkAppearances()); + } + + /** + * @param list $appearances + * + * @return array{ + * bySlug: array, + * byPersonId: array, + * byLabel: array, + * } + */ + private function buildIndex(array $appearances): array + { + // Du plus récent au plus ancien, quel que soit l'ordre de lecture. + usort($appearances, static fn(array $a, array $b): int => [$b['starts_at'], $b['talk_id'], $b['speaker_id']] <=> [$a['starts_at'], $a['talk_id'], $a['speaker_id']]); + + /** @var array> $groups */ + $groups = []; + $slugsByLabel = []; + foreach ($appearances as $appearance) { + $groups[$appearance['person_id']][] = $appearance; + $slugsByLabel[self::normalizeLabel($appearance['firstname'] . ' ' . $appearance['lastname'])][$appearance['slug']] = true; + } + + $index = ['bySlug' => [], 'byPersonId' => [], 'byLabel' => []]; + $identities = []; + foreach ($groups as $personId => $personAppearances) { + $latest = $personAppearances[0]; + $identities[] = new SpeakerIdentity( + $latest['slug'], + $latest['firstname'], + $latest['lastname'], + array_values(array_unique(array_column($personAppearances, 'speaker_id'))), + new \DateTimeImmutable('@' . $latest['starts_at'])->setTimezone(new \DateTimeZone(date_default_timezone_get())), + ); + $index['byPersonId'][$personId] = $latest['slug']; + } + + // Un libellé porté par deux personnes distinctes ne désigne personne. + foreach ($slugsByLabel as $label => $slugs) { + $index['byLabel'][$label] = count($slugs) === 1 ? array_key_first($slugs) : null; + } + + $sortKeys = array_map(fn(SpeakerIdentity $identity): string => $this->slugify->slugify($identity->lastname . ' ' . $identity->firstname) . ' ' . $identity->slug, $identities); + array_multisort($sortKeys, SORT_STRING, $identities); + + foreach ($identities as $identity) { + $index['bySlug'][$identity->slug] = $identity; + } + + return $index; + } + + /** + * @param non-empty-list $speakerTalks + */ + private function buildProfile(SpeakerIdentity $identity, array $speakerTalks): SpeakerProfile + { + // Du plus récent au plus ancien, quel que soit l'ordre de lecture. + usort($speakerTalks, static fn(SpeakerTalk $a, SpeakerTalk $b): int => [ + $b->startsAt->getTimestamp(), + $b->talk->getId(), + $b->speaker->getId(), + ] <=> [ + $a->startsAt->getTimestamp(), + $a->talk->getId(), + $a->speaker->getId(), + ]); + + /** @var non-empty-array $speakers lignes speaker, de la plus récente à la plus ancienne */ + $speakers = []; + $githubLogins = []; + $talks = []; + foreach ($speakerTalks as $speakerTalk) { + $speakers[(int) $speakerTalk->speaker->getId()] ??= $speakerTalk->speaker; + if (null !== $speakerTalk->githubLogin) { + $githubLogins[] = $speakerTalk->githubLogin; + } + // Deux lignes de la même personne sur un même talk : le talk n'est listé qu'une fois. + $talks[(int) $speakerTalk->talk->getId()] ??= $speakerTalk; + } + + $socialLinks = array_filter([ + 'twitter' => self::first($speakers, static fn(Speaker $speaker): string => $speaker->getUrlTwitter()), + 'mastodon' => self::first($speakers, static fn(Speaker $speaker): string => (string) $speaker->getUrlMastodon()), + 'bluesky' => self::first($speakers, static fn(Speaker $speaker): string => trim((string) $speaker->getBluesky()) !== '' ? (string) $speaker->getUrlBluesky() : ''), + 'linkedin' => self::first($speakers, static fn(Speaker $speaker): string => (string) $speaker->getUrlLinkedin()), + 'github' => self::first($githubLogins, static fn(string $login): string => '' !== $login ? 'https://github.com/' . $login : ''), + ], static fn(?string $url): bool => null !== $url); + + $photoSpeakers = array_filter($speakers, static fn(Speaker $speaker): bool => trim((string) $speaker->getPhoto()) !== ''); + + return new SpeakerProfile( + $identity, + reset($speakers), + self::first($speakers, static fn(Speaker $speaker): string => trim((string) $speaker->getBiography())), + reset($photoSpeakers) ?: null, + $socialLinks, + array_values($talks), + ); + } + + /** + * La première valeur non vide, dans l'ordre des éléments. + * + * @template T + * + * @param array $items + * @param callable(T): string $value + */ + private static function first(array $items, callable $value): ?string + { + foreach ($items as $item) { + $result = $value($item); + if ('' !== $result) { + return $result; + } + } + + return null; + } +} diff --git a/sources/AppBundle/Event/Speaker/SpeakerTalk.php b/sources/AppBundle/Event/Speaker/SpeakerTalk.php new file mode 100644 index 000000000..09119768f --- /dev/null +++ b/sources/AppBundle/Event/Speaker/SpeakerTalk.php @@ -0,0 +1,23 @@ +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' => 'Forum PHP 2021', 'path' => 'forumphp2021', 'date_debut' => '2021-10-14', 'date_fin' => '2021-10-15', 'nb_places' => 100]); + $this->connection->insert('afup_user_github', ['id' => 7, 'github_id' => 1007, 'login' => 'hschapira', 'profile_url' => '', 'avatar_url' => '', 'afup_crew' => 0]); + + $this->connection->insert('afup_speaker_person', ['id' => 1, 'slug' => 'helene-schapira']); + $this->connection->insert('afup_speaker_person', ['id' => 2, 'slug' => 'benjamin-moules']); + + $this->insertSpeaker(10, 1, 'Hélène', 'SCHAPIRA', null, 1); + $this->insertSpeaker(20, 2, 'Helene', 'SCHAPIRA ', 7, 1); + $this->insertSpeaker(30, 2, 'Benjamin', 'MOULÈS', null, 2); + // Homonyme non rattaché à une personne : pas de page, même avec un talk publié + $this->insertSpeaker(40, 1, 'Hélène', 'SCHAPIRA', null, null); + + $past = strtotime('2019-10-24 10:00:00'); + $this->insertTalk(100, 1, 10, 'Talk publié 2019', Talk::TYPE_FULL_LONG, $past); + $this->insertTalk(200, 2, 20, 'Talk publié 2021', Talk::TYPE_FULL_LONG, strtotime('2021-10-14 10:00:00'), publishedOn: '2021-11-01 00:00:00'); + $this->insertTalk(201, 2, 20, 'Clinique', Talk::TYPE_CLINIC, $past); + $this->insertTalk(202, 2, 20, 'Présentation des speakers', Talk::TYPE_SPEAKER_INTRODUCTIONS, $past); + $this->insertTalk(203, 2, 20, 'Non planifié', Talk::TYPE_FULL_LONG, $past, scheduled: false); + $this->insertTalk(204, 2, 20, 'Publication à venir', Talk::TYPE_FULL_LONG, $past, publishedOn: '+1 day'); + $this->insertTalk(205, 2, 20, 'Créneau pas encore terminé', Talk::TYPE_FULL_LONG, time() - 600, slotEnd: time() + 600); + $this->insertTalk(206, 2, 20, 'Sans créneau', Talk::TYPE_FULL_LONG, null); + $this->insertTalk(300, 2, 30, 'Talk à venir', Talk::TYPE_FULL_LONG, strtotime('+1 month')); + $this->insertTalk(400, 1, 40, 'Talk publié sans personne', Talk::TYPE_FULL_LONG, $past); + } + + public function testGetPublishedTalkAppearancesOnlyReturnsPublishedTalksOfLinkedSpeakers(): void + { + $appearances = self::getContainer()->get(SpeakerRepository::class)->getPublishedTalkAppearances(); + + usort($appearances, static fn(array $a, array $b): int => $a['talk_id'] <=> $b['talk_id']); + self::assertSame([ + ['speaker_id' => 10, 'person_id' => 1, 'slug' => 'helene-schapira', 'firstname' => 'Hélène', 'lastname' => 'SCHAPIRA', 'talk_id' => 100, 'starts_at' => strtotime('2019-10-24 10:00:00')], + ['speaker_id' => 20, 'person_id' => 1, 'slug' => 'helene-schapira', 'firstname' => 'Helene', 'lastname' => 'SCHAPIRA ', 'talk_id' => 200, 'starts_at' => strtotime('2021-10-14 10:00:00')], + ], $appearances); + } + + public function testGetPublishedSpeakerTalksHydratesTalksEventsAndGithubLogins(): void + { + $speakerTalks = self::getContainer()->get(SpeakerRepository::class)->getPublishedSpeakerTalks([10, 20, 30]); + + self::assertSame( + [ + [200, 'Talk publié 2021', 20, 'Forum PHP 2021', 'forumphp2021', 'hschapira', '2021-10-14 10:00'], + [100, 'Talk publié 2019', 10, 'Forum PHP 2019', 'forumphp2019', null, '2019-10-24 10:00'], + ], + array_map(static fn(SpeakerTalk $speakerTalk): array => [ + $speakerTalk->talk->getId(), + $speakerTalk->talk->getTitle(), + $speakerTalk->speaker->getId(), + $speakerTalk->event->getTitle(), + $speakerTalk->event->getPath(), + $speakerTalk->githubLogin, + $speakerTalk->startsAt->format('Y-m-d H:i'), + ], $speakerTalks), + ); + self::assertSame([], self::getContainer()->get(SpeakerRepository::class)->getPublishedSpeakerTalks([])); + } + + public function testResolverBuildsTheProfileOfASpeakerAcrossEditions(): void + { + $resolver = new SpeakerProfileResolver(self::getContainer()->get(SpeakerRepository::class)); + + self::assertSame(['helene-schapira'], array_map(static fn($identity): string => $identity->slug, $resolver->getIdentities())); + self::assertSame('helene-schapira', $resolver->getIdentityByLabel('Hélène SCHAPIRA')?->slug); + + $profile = $resolver->getProfileBySlug('helene-schapira'); + self::assertNotNull($profile); + self::assertSame([20, 10], $profile->identity->speakerIds); + self::assertSame('Bio de 20', $profile->biography); + self::assertSame(['github' => 'https://github.com/hschapira'], $profile->socialLinks); + self::assertSame([200, 100], array_map(static fn(SpeakerTalk $speakerTalk): ?int => $speakerTalk->talk->getId(), $profile->talks)); + } + + private function insertSpeaker(int $id, int $eventId, string $firstname, string $lastname, ?int $githubUserId, ?int $personId): void + { + $this->connection->insert('afup_conferenciers', [ + 'conferencier_id' => $id, + 'id_forum' => $eventId, + 'prenom' => $firstname, + 'nom' => $lastname, + 'email' => 'speaker' . $id . '@example.com', + 'biographie' => 'Bio de ' . $id, + 'user_github' => $githubUserId, + 'person_id' => $personId, + ]); + } + + private function insertTalk(int $id, int $eventId, int $speakerId, string $title, int $type, ?int $slotStart, 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, + 'date_publication' => null !== $publishedOn ? date('Y-m-d H:i:s', (int) strtotime($publishedOn)) : null, + ]); + $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]); + } + } +} diff --git a/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php b/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php new file mode 100644 index 000000000..429f51bc5 --- /dev/null +++ b/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php @@ -0,0 +1,270 @@ + ['Hélène SCHAPIRA', 'helene schapira']; + yield 'sans accent' => ['Helene SCHAPIRA', 'helene schapira']; + yield 'double espace et accent majuscule' => ['Benjamin MOULÈS', 'benjamin moules']; + yield 'espace final' => ['Cyrille GRANDVAL ', 'cyrille grandval']; + yield 'espaces en tête et tabulation' => [" \tCyrille\t GRANDVAL", 'cyrille grandval']; + } + + public function testGroupsSpeakerRowsByPerson(): void + { + $resolver = $this->resolver([ + self::appearance(1, 1, 'helene-schapira', 'Hélène', 'SCHAPIRA', 10, '2019-10-24'), + self::appearance(2, 1, 'helene-schapira', 'H.', 'Schapira-Martin', 20, '2021-10-14'), + self::appearance(3, 2, 'benjamin-moules', 'Benjamin', 'MOULÈS', 30, '2019-10-24'), + // Même libellé qu'une ligne de la personne 1, mais une autre personne + self::appearance(4, 3, 'helene-schapira-2', 'Hélène', 'SCHAPIRA', 40, '2022-10-13'), + // Deux talks pour la même ligne + self::appearance(3, 2, 'benjamin-moules', 'Benjamin', 'MOULÈS', 31, '2019-10-25'), + ]); + + // Triées sur le nom le plus récent : « Schapira-Martin » après « Schapira » + self::assertSame(['benjamin-moules', 'helene-schapira-2', 'helene-schapira'], self::slugs($resolver)); + self::assertSame([2, 1], $resolver->getIdentityBySlug('helene-schapira')?->speakerIds); + self::assertSame([3], $resolver->getIdentityBySlug('benjamin-moules')?->speakerIds); + self::assertSame([4], $resolver->getIdentityBySlug('helene-schapira-2')?->speakerIds); + } + + public function testSlugComesFromTheDatabaseAndNameFromTheMostRecentSpeaker(): void + { + $resolver = $this->resolver([ + self::appearance(1, 7, 'fred-dupont', 'Fred', 'Dupont', 10, '2015-10-24'), + self::appearance(2, 7, 'fred-dupont', 'Frédéric', 'Dupont', 20, '2023-10-12'), + ]); + + self::assertNull($resolver->getIdentityBySlug('frederic-dupont'), 'le slug n\'est pas recalculé depuis le nom'); + $identity = $resolver->getIdentityBySlug('fred-dupont'); + self::assertNotNull($identity); + self::assertSame('fred-dupont', $identity->slug); + self::assertSame('Frédéric Dupont', $identity->getName()); + self::assertSame('Frédéric DUPONT', $identity->getLabel()); + self::assertSame([2, 1], $identity->speakerIds); + self::assertSame('2023-10-12', $identity->latestTalkAt->format('Y-m-d')); + } + + public function testLabelDesignatesThePersonCarryingItOnAnyOfItsRows(): void + { + $resolver = $this->resolver([ + self::appearance(1, 7, 'frederic-dupont', 'Fred', 'Dupont', 10, '2015-10-24'), + self::appearance(2, 7, 'frederic-dupont', 'Frédéric', 'Dupont', 20, '2023-10-12'), + ]); + + self::assertSame('frederic-dupont', $resolver->getIdentityByLabel('Frédéric DUPONT')?->slug); + self::assertSame('frederic-dupont', $resolver->getIdentityByLabel('Fred DUPONT ')?->slug); + self::assertSame('frederic-dupont', $resolver->getIdentityByLabel('Frederic dupont')?->slug); + self::assertNull($resolver->getIdentityByLabel('Inconnu SPEAKER')); + } + + public function testLabelCarriedBySeveralPersonsDesignatesNoOne(): void + { + $resolver = $this->resolver([ + self::appearance(1, 5, 'jean-martin', 'Jean', 'Martin', 10, '2012-11-20'), + self::appearance(2, 6, 'jean-martin-lyon', 'Jean', 'MARTIN ', 20, '2018-10-25'), + self::appearance(3, 6, 'jean-martin-lyon', 'Jean-Paul', 'Martin', 30, '2020-10-25'), + ]); + + self::assertSame(['jean-martin', 'jean-martin-lyon'], self::slugs($resolver)); + self::assertNull($resolver->getIdentityByLabel('Jean MARTIN'), 'un libellé porté par plusieurs personnes ne désigne personne'); + self::assertSame('jean-martin-lyon', $resolver->getIdentityByLabel('Jean-Paul MARTIN')?->slug); + } + + public function testIdentitiesDoNotDependOnReadingOrder(): void + { + $appearances = [ + self::appearance(1, 1, 'helene-schapira', 'Hélène', 'SCHAPIRA', 10, '2019-10-24'), + self::appearance(2, 1, 'helene-schapira', 'Helene', 'Schapira', 20, '2021-10-14'), + self::appearance(3, 2, 'julien-durand', 'Julien', 'Durand', 30, '2016-10-27'), + self::appearance(4, 3, 'julien-durand-2', 'Julien', 'Durand', 40, '2014-06-23'), + self::appearance(5, 3, 'julien-durand-2', 'Julien', 'Durand', 50, '2024-10-10'), + self::appearance(6, 4, 'benjamin-moules', 'Benjamin', 'MOULÈS', 60, '2022-10-13'), + self::appearance(6, 4, 'benjamin-moules', 'Benjamin', 'MOULÈS', 70, '2022-10-14'), + ]; + + $expected = self::identities($this->resolver($appearances)); + + self::assertEquals($expected, self::identities($this->resolver(array_reverse($appearances)))); + // Toutes les rotations de la liste + for ($offset = 1, $count = count($appearances); $offset < $count; $offset++) { + $rotated = [...array_slice($appearances, $offset), ...array_slice($appearances, 0, $offset)]; + self::assertEquals($expected, self::identities($this->resolver($rotated))); + } + } + + public function testIdentitiesAreSortedByLastnameThenFirstname(): void + { + $resolver = $this->resolver([ + self::appearance(1, 1, 'zoe-elan', 'Zoé', 'Élan', 10, '2019-10-24'), + self::appearance(2, 2, 'anne-martin', 'Anne', 'Martin', 20, '2019-10-24'), + self::appearance(3, 3, 'aline-martin', 'Aline', 'Martin', 30, '2019-10-24'), + self::appearance(4, 4, 'paul-albert', 'Paul', 'Albert', 40, '2019-10-24'), + ]); + + self::assertSame(['paul-albert', 'zoe-elan', 'aline-martin', 'anne-martin'], self::slugs($resolver)); + } + + public function testFindsTheIdentityOfASpeakerFromAnyEditionByItsPerson(): void + { + $resolver = $this->resolver([ + self::appearance(1, 1, 'helene-schapira', 'Hélène', 'SCHAPIRA', 10, '2019-10-24'), + self::appearance(2, 5, 'cyrille-grandval', 'Cyrille', 'Grandval', 20, '2018-10-25'), + ]); + + // Une ligne speaker connue + self::assertSame('helene-schapira', $resolver->getIdentityForSpeaker(self::speaker(1, 'Hélène', 'SCHAPIRA', 1))?->slug); + // Une ligne d'une édition à venir, rattachée à la personne + self::assertSame('cyrille-grandval', $resolver->getIdentityForSpeaker(self::speaker(99, 'C.', 'Grandval', 5))?->slug); + // Une ligne non rattachée n'a pas de personne, même si son libellé est connu + self::assertNull($resolver->getIdentityForSpeaker(self::speaker(100, 'Hélène', 'SCHAPIRA'))); + // Une personne sans talk publié + self::assertNull($resolver->getIdentityForSpeaker(self::speaker(101, 'Inconnu', 'Speaker', 9))); + + self::assertNull($resolver->getIdentityBySlug('inconnu')); + } + + public function testProfileConsolidatesTheMostRecentNonEmptyValues(): void + { + $old = self::speaker(1, 'Hélène', 'SCHAPIRA') + ->setBiography('Ancienne bio') + ->setPhoto('1.jpg') + ->setTwitter('@helene_old') + ->setLinkedin('helene-schapira'); + $middle = self::speaker(2, 'Helene', 'SCHAPIRA') + ->setBiography('Bio intermédiaire') + ->setPhoto('') + ->setMastodon('https://phpc.social/@helene') + ->setBluesky(''); + $latest = self::speaker(3, 'Hélène', 'Schapira', 1) + ->setBiography(' ') + ->setPhoto(null) + ->setTwitter('helene'); + + $speakerTalks = [ + self::speakerTalk($old, 10, '2017-10-26'), + self::speakerTalk($latest, 30, '2023-10-12', 'hschapira'), + self::speakerTalk($middle, 20, '2020-10-22'), + self::speakerTalk($middle, 21, '2020-10-23'), + // La même personne deux fois sur un même talk + self::speakerTalk($old, 21, '2020-10-23'), + ]; + + $speakerRepository = $this->createMock(SpeakerRepository::class); + $speakerRepository->method('getPublishedTalkAppearances')->willReturn(array_map( + static fn(SpeakerTalk $speakerTalk): array => self::appearance( + (int) $speakerTalk->speaker->getId(), + 1, + 'helene-schapira', + (string) $speakerTalk->speaker->getFirstname(), + (string) $speakerTalk->speaker->getLastname(), + (int) $speakerTalk->talk->getId(), + $speakerTalk->startsAt->format('Y-m-d'), + ), + $speakerTalks, + )); + $speakerRepository->expects(self::once()) + ->method('getPublishedSpeakerTalks') + ->with([3, 2, 1]) + ->willReturn($speakerTalks); + + $profile = new SpeakerProfileResolver($speakerRepository)->getProfileBySlug('helene-schapira'); + + self::assertNotNull($profile); + self::assertSame('helene-schapira', $profile->identity->slug); + self::assertSame($latest, $profile->speaker); + self::assertSame('Bio intermédiaire', $profile->biography); + self::assertSame($old, $profile->photoSpeaker); + self::assertSame([ + 'twitter' => 'https://x.com/helene', + 'mastodon' => 'https://phpc.social/@helene', + 'linkedin' => 'https://www.linkedin.com/in/helene-schapira', + 'github' => 'https://github.com/hschapira', + ], $profile->socialLinks); + self::assertSame([30, 21, 20, 10], array_map(static fn(SpeakerTalk $speakerTalk): ?int => $speakerTalk->talk->getId(), $profile->talks)); + } + + public function testNoProfileForAnUnknownSlug(): void + { + $speakerRepository = $this->createMock(SpeakerRepository::class); + $speakerRepository->method('getPublishedTalkAppearances')->willReturn([]); + $speakerRepository->expects(self::never())->method('getPublishedSpeakerTalks'); + + self::assertNull(new SpeakerProfileResolver($speakerRepository)->getProfileBySlug('inconnu')); + } + + /** + * @param list $appearances + */ + private function resolver(array $appearances): SpeakerProfileResolver + { + $speakerRepository = $this->createStub(SpeakerRepository::class); + $speakerRepository->method('getPublishedTalkAppearances')->willReturn($appearances); + + return new SpeakerProfileResolver($speakerRepository); + } + + /** + * @return array{speaker_id: int, person_id: int, slug: string, firstname: string, lastname: string, talk_id: int, starts_at: int} + */ + private static function appearance(int $speakerId, int $personId, string $slug, string $firstname, string $lastname, int $talkId, string $date): array + { + return [ + 'speaker_id' => $speakerId, + 'person_id' => $personId, + 'slug' => $slug, + 'firstname' => $firstname, + 'lastname' => $lastname, + 'talk_id' => $talkId, + 'starts_at' => new \DateTimeImmutable($date)->getTimestamp(), + ]; + } + + private static function speaker(int $id, string $firstname, string $lastname, ?int $personId = null): Speaker + { + return new Speaker()->setId($id)->setFirstname($firstname)->setLastname($lastname)->setPersonId($personId); + } + + private static function speakerTalk(Speaker $speaker, int $talkId, string $date, ?string $githubLogin = null): SpeakerTalk + { + return new SpeakerTalk($speaker, new Talk()->setId($talkId), new Event(), new \DateTimeImmutable($date), $githubLogin); + } + + /** + * @return list + */ + private static function slugs(SpeakerProfileResolver $resolver): array + { + return array_map(static fn(SpeakerIdentity $identity): string => $identity->slug, $resolver->getIdentities()); + } + + /** + * @return list + */ + private static function identities(SpeakerProfileResolver $resolver): array + { + return $resolver->getIdentities(); + } +} From 6b80abe2aa64c2b31d52c97e313f060611635aa5 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Fri, 20 Nov 2026 15:34:18 +0100 Subject: [PATCH 2/3] =?UTF-8?q?Lit=20les=20talks=20publi=C3=A9s=20des=20sp?= =?UTF-8?q?eakers=20en=20DBAL=20suivant=20l'ADR-002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les requêtes de l'index des personnes et de leurs talks quittent le repository Ting des conférenciers pour PublishedTalkRepository (DBAL), qui renvoie des DTO de talk et d'événement. Les lignes speaker du profil sont chargées par SpeakerRepository::get(). « person » devient « personne » suivant l'ADR-001. --- .../Model/Repository/SpeakerRepository.php | 105 ------------ .../Event/Speaker/SpeakerProfileResolver.php | 70 +++++--- .../AppBundle/Event/Speaker/SpeakerTalk.php | 8 +- .../AppBundle/Event/Talk/PublishedEvent.php | 19 +++ .../AppBundle/Event/Talk/PublishedTalk.php | 31 ++++ .../Event/Talk/PublishedTalkRepository.php | 155 ++++++++++++++++++ .../PublishedTalkRepositoryTest.php} | 47 +++--- .../Speaker/SpeakerProfileResolverTest.php | 66 ++++---- 8 files changed, 318 insertions(+), 183 deletions(-) create mode 100644 sources/AppBundle/Event/Talk/PublishedEvent.php create mode 100644 sources/AppBundle/Event/Talk/PublishedTalk.php create mode 100644 sources/AppBundle/Event/Talk/PublishedTalkRepository.php rename tests/integration/AppBundle/Event/{Model/Repository/SpeakerRepositoryTest.php => Talk/PublishedTalkRepositoryTest.php} (72%) diff --git a/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php b/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php index 844576a62..f0db52fa6 100644 --- a/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php +++ b/sources/AppBundle/Event/Model/Repository/SpeakerRepository.php @@ -9,12 +9,9 @@ use AppBundle\Event\Model\Speaker; use AppBundle\Event\Model\Talk; use AppBundle\Event\Speaker\MicrophoneType; -use AppBundle\Event\Speaker\SpeakerTalk; use AppBundle\Ting\JoinHydrator; use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean; 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; use CCMBenchmark\Ting\Repository\MetadataInitializer; @@ -28,25 +25,6 @@ */ 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. - */ - 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)'; - /** * @return CollectionInterface&iterable */ @@ -193,89 +171,6 @@ public function searchSpeakers(Event $event, $sort = 'name', $direction = 'asc', return $query->query($this->getCollection(new HydratorSingleObject())); } - /** - * Les lignes speaker rattachées à une personne qui ont un talk publié, toutes éditions confondues, - * une ligne par couple speaker / talk, sans hydrater d'entité : de quoi construire l'index des personnes. - * Les lignes sans personne sont écartées. - * - * @return list - */ - public function getPublishedTalkAppearances(): array - { - $query = $this->getQuery( - 'SELECT speaker.conferencier_id AS speaker_id, person.id AS person_id, person.slug, - 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, - ); - - $appearances = []; - /** @var array{speaker_id: int|string, person_id: int|string, slug: string, firstname: string|null, lastname: string|null, talk_id: int|string, starts_at: int|string} $row */ - foreach ($query->query($this->getCollection(new HydratorArray())) as $row) { - $appearances[] = [ - 'speaker_id' => (int) $row['speaker_id'], - 'person_id' => (int) $row['person_id'], - 'slug' => $row['slug'], - 'firstname' => (string) $row['firstname'], - 'lastname' => (string) $row['lastname'], - 'talk_id' => (int) $row['talk_id'], - 'starts_at' => (int) $row['starts_at'], - ]; - } - - return $appearances; - } - - /** - * Les talks publiés de ces lignes speaker, avec leur événement, du plus récent au plus ancien. - * - * @param list $speakerIds - * - * @return list - */ - public function getPublishedSpeakerTalks(array $speakerIds): array - { - if ($speakerIds === []) { - return []; - } - - $params = []; - foreach ($speakerIds as $index => $speakerId) { - $params['speaker' . $index] = $speakerId; - } - - $query = $this->getPreparedQuery( - 'SELECT speaker.conferencier_id, speaker.id_forum, speaker.nom, speaker.prenom, speaker.societe, - speaker.biographie, speaker.twitter, speaker.mastodon, speaker.bluesky, speaker.linkedin, - speaker.user_github, speaker.photo, - talk.session_id, talk.id_forum, talk.titre, talk.genre, talk.plannifie, talk.youtube_id, talk.language_code, - event.id, event.titre, event.path, event.date_debut, event.date_fin, - github.login AS github_login, - planning.debut AS starts_at' - . self::PUBLISHED_SPEAKER_TALKS_JOINS - . ' 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 - . ' ORDER BY planning.debut DESC, talk.session_id DESC, speaker.conferencier_id DESC', - )->setParams($params); - - $speakerTalks = []; - /** @var array{speaker: Speaker, talk: Talk, event: Event, 0: object{starts_at: int|string, github_login: string|null}} $row */ - foreach ($query->query($this->getCollection(new Hydrator())) as $row) { - $speakerTalks[] = new SpeakerTalk( - $row['speaker'], - $row['talk'], - $row['event'], - new \DateTimeImmutable('@' . $row[0]->starts_at)->setTimezone(new \DateTimeZone(date_default_timezone_get())), - $row[0]->github_login, - ); - } - - return $speakerTalks; - } - public function countByEvent(Event $event): int { $query = $this->getPreparedQuery('SELECT COUNT(*) AS nb FROM (SELECT nom, prenom FROM afup_conferenciers WHERE id_forum = :eventId GROUP BY nom, prenom) c') diff --git a/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php b/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php index 61de17689..f371c1726 100644 --- a/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php +++ b/sources/AppBundle/Event/Speaker/SpeakerProfileResolver.php @@ -6,15 +6,16 @@ use AppBundle\Event\Model\Repository\SpeakerRepository; use AppBundle\Event\Model\Speaker; +use AppBundle\Event\Talk\PublishedTalkRepository; use Cocur\Slugify\Slugify; use Symfony\Contracts\Service\ResetInterface; use function Symfony\Component\String\u; /** - * Les personnes (afup_speaker_person) qui ont au moins un talk publié, avec le slug enregistré en base. + * Les personnes (afup_conferenciers_personnes) qui ont au moins un talk publié, avec le slug enregistré en base. * - * Une personne regroupe ses lignes speaker (une par édition) par afup_conferenciers.person_id. + * Une personne regroupe ses lignes speaker (une par édition) par afup_conferenciers.personne_id. * Une ligne sans personne n'a pas de page : elle n'apparaît pas tant qu'elle n'est pas rattachée. * * L'index repose sur une requête légère (sans hydratation d'entités), faite une fois @@ -25,7 +26,7 @@ final class SpeakerProfileResolver implements ResetInterface /** * @var array{ * bySlug: array, - * byPersonId: array, + * byPersonneId: array, * byLabel: array, * }|null */ @@ -33,8 +34,10 @@ final class SpeakerProfileResolver implements ResetInterface private readonly Slugify $slugify; - public function __construct(private readonly SpeakerRepository $speakerRepository) - { + public function __construct( + private readonly PublishedTalkRepository $publishedTalkRepository, + private readonly SpeakerRepository $speakerRepository, + ) { // Le même slugifier que Talk::getSlug(), pour le tri. $this->slugify = new Slugify(); } @@ -81,13 +84,13 @@ public function getIdentityByLabel(string $label): ?SpeakerIdentity */ public function getIdentityForSpeaker(Speaker $speaker): ?SpeakerIdentity { - $personId = $speaker->getPersonId(); - if (null === $personId) { + $personneId = $speaker->getPersonneId(); + if (null === $personneId) { return null; } $index = $this->getIndex(); - $slug = $index['byPersonId'][$personId] ?? null; + $slug = $index['byPersonneId'][$personneId] ?? null; return null !== $slug ? $index['bySlug'][$slug] : null; } @@ -102,7 +105,7 @@ public function getProfileBySlug(string $slug): ?SpeakerProfile return null; } - $speakerTalks = $this->speakerRepository->getPublishedSpeakerTalks($identity->speakerIds); + $speakerTalks = $this->loadSpeakerTalks($identity->speakerIds); if ($speakerTalks === []) { return null; } @@ -118,21 +121,21 @@ public function reset(): void /** * @return array{ * bySlug: array, - * byPersonId: array, + * byPersonneId: array, * byLabel: array, * } */ private function getIndex(): array { - return $this->index ??= $this->buildIndex($this->speakerRepository->getPublishedTalkAppearances()); + return $this->index ??= $this->buildIndex($this->publishedTalkRepository->getSpeakerAppearances()); } /** - * @param list $appearances + * @param list $appearances * * @return array{ * bySlug: array, - * byPersonId: array, + * byPersonneId: array, * byLabel: array, * } */ @@ -141,26 +144,26 @@ private function buildIndex(array $appearances): array // Du plus récent au plus ancien, quel que soit l'ordre de lecture. usort($appearances, static fn(array $a, array $b): int => [$b['starts_at'], $b['talk_id'], $b['speaker_id']] <=> [$a['starts_at'], $a['talk_id'], $a['speaker_id']]); - /** @var array> $groups */ + /** @var array> $groups */ $groups = []; $slugsByLabel = []; foreach ($appearances as $appearance) { - $groups[$appearance['person_id']][] = $appearance; + $groups[$appearance['personne_id']][] = $appearance; $slugsByLabel[self::normalizeLabel($appearance['firstname'] . ' ' . $appearance['lastname'])][$appearance['slug']] = true; } - $index = ['bySlug' => [], 'byPersonId' => [], 'byLabel' => []]; + $index = ['bySlug' => [], 'byPersonneId' => [], 'byLabel' => []]; $identities = []; - foreach ($groups as $personId => $personAppearances) { - $latest = $personAppearances[0]; + foreach ($groups as $personneId => $personneAppearances) { + $latest = $personneAppearances[0]; $identities[] = new SpeakerIdentity( $latest['slug'], $latest['firstname'], $latest['lastname'], - array_values(array_unique(array_column($personAppearances, 'speaker_id'))), + array_values(array_unique(array_column($personneAppearances, 'speaker_id'))), new \DateTimeImmutable('@' . $latest['starts_at'])->setTimezone(new \DateTimeZone(date_default_timezone_get())), ); - $index['byPersonId'][$personId] = $latest['slug']; + $index['byPersonneId'][$personneId] = $latest['slug']; } // Un libellé porté par deux personnes distinctes ne désigne personne. @@ -178,6 +181,27 @@ private function buildIndex(array $appearances): array return $index; } + /** + * Les talks publiés de ces lignes speaker ; chaque ligne speaker est chargée une fois, pour le profil. + * + * @param list $speakerIds + * + * @return list + */ + private function loadSpeakerTalks(array $speakerIds): array + { + $speakers = []; + $speakerTalks = []; + foreach ($this->publishedTalkRepository->getSpeakerTalks($speakerIds) as $row) { + $speaker = $speakers[$row['speaker_id']] ??= $this->speakerRepository->get($row['speaker_id']); + if ($speaker instanceof Speaker) { + $speakerTalks[] = new SpeakerTalk($speaker, $row['talk'], $row['event'], $row['starts_at'], $row['github_login']); + } + } + + return $speakerTalks; + } + /** * @param non-empty-list $speakerTalks */ @@ -186,11 +210,11 @@ private function buildProfile(SpeakerIdentity $identity, array $speakerTalks): S // Du plus récent au plus ancien, quel que soit l'ordre de lecture. usort($speakerTalks, static fn(SpeakerTalk $a, SpeakerTalk $b): int => [ $b->startsAt->getTimestamp(), - $b->talk->getId(), + $b->talk->id, $b->speaker->getId(), ] <=> [ $a->startsAt->getTimestamp(), - $a->talk->getId(), + $a->talk->id, $a->speaker->getId(), ]); @@ -204,7 +228,7 @@ private function buildProfile(SpeakerIdentity $identity, array $speakerTalks): S $githubLogins[] = $speakerTalk->githubLogin; } // Deux lignes de la même personne sur un même talk : le talk n'est listé qu'une fois. - $talks[(int) $speakerTalk->talk->getId()] ??= $speakerTalk; + $talks[$speakerTalk->talk->id] ??= $speakerTalk; } $socialLinks = array_filter([ diff --git a/sources/AppBundle/Event/Speaker/SpeakerTalk.php b/sources/AppBundle/Event/Speaker/SpeakerTalk.php index 09119768f..f052efe44 100644 --- a/sources/AppBundle/Event/Speaker/SpeakerTalk.php +++ b/sources/AppBundle/Event/Speaker/SpeakerTalk.php @@ -4,9 +4,9 @@ namespace AppBundle\Event\Speaker; -use AppBundle\Event\Model\Event; use AppBundle\Event\Model\Speaker; -use AppBundle\Event\Model\Talk; +use AppBundle\Event\Talk\PublishedEvent; +use AppBundle\Event\Talk\PublishedTalk; /** * Un talk publié, vu depuis l'un de ses speakers (une ligne `afup_conferenciers` d'une édition). @@ -15,8 +15,8 @@ { public function __construct( public Speaker $speaker, - public Talk $talk, - public Event $event, + public PublishedTalk $talk, + public PublishedEvent $event, public \DateTimeImmutable $startsAt, public ?string $githubLogin = null, ) {} diff --git a/sources/AppBundle/Event/Talk/PublishedEvent.php b/sources/AppBundle/Event/Talk/PublishedEvent.php new file mode 100644 index 000000000..b1ffd4116 --- /dev/null +++ b/sources/AppBundle/Event/Talk/PublishedEvent.php @@ -0,0 +1,19 @@ +slug = new Slugify()->slugify($title); + } + + public function hasYoutubeId(): bool + { + return null !== $this->youtubeId && '' !== $this->youtubeId; + } +} diff --git a/sources/AppBundle/Event/Talk/PublishedTalkRepository.php b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php new file mode 100644 index 000000000..f6c9cf69d --- /dev/null +++ b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php @@ -0,0 +1,155 @@ + + */ + public function getSpeakerAppearances(): array + { + $rows = $this->connection->fetchAllAssociative( + 'SELECT speaker.conferencier_id, personne.id AS personne_id, personne.slug, speaker.prenom, speaker.nom, + talk.session_id, planning.debut + FROM afup_conferenciers speaker + INNER JOIN afup_conferenciers_personnes personne ON personne.id = speaker.personne_id + 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' + . self::PLANNING_JOIN . ' + WHERE ' . self::CONDITIONS, + ); + + return array_map(static fn(array $row): array => [ + 'speaker_id' => self::toInt($row['conferencier_id']), + 'personne_id' => self::toInt($row['personne_id']), + 'slug' => self::toString($row['slug']), + 'firstname' => self::toString($row['prenom']), + 'lastname' => self::toString($row['nom']), + 'talk_id' => self::toInt($row['session_id']), + 'starts_at' => self::toInt($row['debut']), + ], $rows); + } + + /** + * Les talks publiés de ces lignes speaker, avec leur événement, du plus récent au plus ancien. + * + * @param list $speakerIds + * + * @return list + */ + public function getSpeakerTalks(array $speakerIds): array + { + if ($speakerIds === []) { + return []; + } + + $rows = $this->connection->fetchAllAssociative( + 'SELECT speaker.conferencier_id, github.login AS github_login, planning.debut, ' . self::TALK_AND_EVENT_COLUMNS . ' + 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' + . self::PLANNING_JOIN . ' + 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 (:speakerIds) + AND ' . self::CONDITIONS . ' + ORDER BY planning.debut DESC, talk.session_id DESC, speaker.conferencier_id DESC', + ['speakerIds' => $speakerIds], + ['speakerIds' => ArrayParameterType::INTEGER], + ); + + return array_map(static fn(array $row): array => [ + 'speaker_id' => self::toInt($row['conferencier_id']), + 'talk' => self::talk($row), + 'event' => self::event($row), + 'starts_at' => self::timestamp($row['debut']), + 'github_login' => null !== $row['github_login'] ? self::toString($row['github_login']) : null, + ], $rows); + } + + /** + * @param array $row + */ + private static function talk(array $row): PublishedTalk + { + return new PublishedTalk( + self::toInt($row['session_id']), + self::toString($row['titre']), + self::nullableString($row['youtube_id']), + ); + } + + /** + * @param array $row + */ + private static function event(array $row): PublishedEvent + { + return new PublishedEvent( + self::toInt($row['event_id']), + self::toString($row['event_titre']), + self::toString($row['event_path']), + null !== $row['event_date_debut'] ? new \DateTimeImmutable(self::toString($row['event_date_debut'])) : null, + null !== $row['event_date_fin'] ? new \DateTimeImmutable(self::toString($row['event_date_fin'])) : null, + ); + } + + private static function timestamp(mixed $value): \DateTimeImmutable + { + return new \DateTimeImmutable('@' . self::toInt($value))->setTimezone(new \DateTimeZone(date_default_timezone_get())); + } + + private static function toInt(mixed $value): int + { + Assert::integerish($value); + + return (int) $value; + } + + private static function toString(mixed $value): string + { + Assert::scalar($value); + + return (string) $value; + } + + private static function nullableString(mixed $value): ?string + { + return null !== $value && '' !== $value ? self::toString($value) : null; + } +} diff --git a/tests/integration/AppBundle/Event/Model/Repository/SpeakerRepositoryTest.php b/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php similarity index 72% rename from tests/integration/AppBundle/Event/Model/Repository/SpeakerRepositoryTest.php rename to tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php index dc748e61d..07dd4fbd6 100644 --- a/tests/integration/AppBundle/Event/Model/Repository/SpeakerRepositoryTest.php +++ b/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php @@ -2,16 +2,17 @@ declare(strict_types=1); -namespace AppBundle\IntegrationTests\Event\Model\Repository; +namespace AppBundle\IntegrationTests\Event\Talk; use Afup\Tests\Support\IntegrationTestCase; use AppBundle\Event\Model\Repository\SpeakerRepository; use AppBundle\Event\Model\Talk; use AppBundle\Event\Speaker\SpeakerProfileResolver; use AppBundle\Event\Speaker\SpeakerTalk; +use AppBundle\Event\Talk\PublishedTalkRepository; use Doctrine\DBAL\Connection; -final class SpeakerRepositoryTest extends IntegrationTestCase +final class PublishedTalkRepositoryTest extends IntegrationTestCase { private Connection $connection; @@ -25,8 +26,8 @@ protected function setUp(): void $this->connection->insert('afup_forum', ['id' => 2, 'titre' => 'Forum PHP 2021', 'path' => 'forumphp2021', 'date_debut' => '2021-10-14', 'date_fin' => '2021-10-15', 'nb_places' => 100]); $this->connection->insert('afup_user_github', ['id' => 7, 'github_id' => 1007, 'login' => 'hschapira', 'profile_url' => '', 'avatar_url' => '', 'afup_crew' => 0]); - $this->connection->insert('afup_speaker_person', ['id' => 1, 'slug' => 'helene-schapira']); - $this->connection->insert('afup_speaker_person', ['id' => 2, 'slug' => 'benjamin-moules']); + $this->connection->insert('afup_conferenciers_personnes', ['id' => 1, 'slug' => 'helene-schapira']); + $this->connection->insert('afup_conferenciers_personnes', ['id' => 2, 'slug' => 'benjamin-moules']); $this->insertSpeaker(10, 1, 'Hélène', 'SCHAPIRA', null, 1); $this->insertSpeaker(20, 2, 'Helene', 'SCHAPIRA ', 7, 1); @@ -47,42 +48,42 @@ protected function setUp(): void $this->insertTalk(400, 1, 40, 'Talk publié sans personne', Talk::TYPE_FULL_LONG, $past); } - public function testGetPublishedTalkAppearancesOnlyReturnsPublishedTalksOfLinkedSpeakers(): void + public function testSpeakerAppearancesOnlyReturnPublishedTalksOfLinkedSpeakers(): void { - $appearances = self::getContainer()->get(SpeakerRepository::class)->getPublishedTalkAppearances(); + $appearances = new PublishedTalkRepository($this->connection)->getSpeakerAppearances(); usort($appearances, static fn(array $a, array $b): int => $a['talk_id'] <=> $b['talk_id']); self::assertSame([ - ['speaker_id' => 10, 'person_id' => 1, 'slug' => 'helene-schapira', 'firstname' => 'Hélène', 'lastname' => 'SCHAPIRA', 'talk_id' => 100, 'starts_at' => strtotime('2019-10-24 10:00:00')], - ['speaker_id' => 20, 'person_id' => 1, 'slug' => 'helene-schapira', 'firstname' => 'Helene', 'lastname' => 'SCHAPIRA ', 'talk_id' => 200, 'starts_at' => strtotime('2021-10-14 10:00:00')], + ['speaker_id' => 10, 'personne_id' => 1, 'slug' => 'helene-schapira', 'firstname' => 'Hélène', 'lastname' => 'SCHAPIRA', 'talk_id' => 100, 'starts_at' => strtotime('2019-10-24 10:00:00')], + ['speaker_id' => 20, 'personne_id' => 1, 'slug' => 'helene-schapira', 'firstname' => 'Helene', 'lastname' => 'SCHAPIRA ', 'talk_id' => 200, 'starts_at' => strtotime('2021-10-14 10:00:00')], ], $appearances); } - public function testGetPublishedSpeakerTalksHydratesTalksEventsAndGithubLogins(): void + public function testSpeakerTalksReturnTalksEventsAndGithubLogins(): void { - $speakerTalks = self::getContainer()->get(SpeakerRepository::class)->getPublishedSpeakerTalks([10, 20, 30]); + $speakerTalks = new PublishedTalkRepository($this->connection)->getSpeakerTalks([10, 20, 30]); self::assertSame( [ [200, 'Talk publié 2021', 20, 'Forum PHP 2021', 'forumphp2021', 'hschapira', '2021-10-14 10:00'], [100, 'Talk publié 2019', 10, 'Forum PHP 2019', 'forumphp2019', null, '2019-10-24 10:00'], ], - array_map(static fn(SpeakerTalk $speakerTalk): array => [ - $speakerTalk->talk->getId(), - $speakerTalk->talk->getTitle(), - $speakerTalk->speaker->getId(), - $speakerTalk->event->getTitle(), - $speakerTalk->event->getPath(), - $speakerTalk->githubLogin, - $speakerTalk->startsAt->format('Y-m-d H:i'), + array_map(static fn(array $speakerTalk): array => [ + $speakerTalk['talk']->id, + $speakerTalk['talk']->title, + $speakerTalk['speaker_id'], + $speakerTalk['event']->title, + $speakerTalk['event']->path, + $speakerTalk['github_login'], + $speakerTalk['starts_at']->format('Y-m-d H:i'), ], $speakerTalks), ); - self::assertSame([], self::getContainer()->get(SpeakerRepository::class)->getPublishedSpeakerTalks([])); + self::assertSame([], new PublishedTalkRepository($this->connection)->getSpeakerTalks([])); } public function testResolverBuildsTheProfileOfASpeakerAcrossEditions(): void { - $resolver = new SpeakerProfileResolver(self::getContainer()->get(SpeakerRepository::class)); + $resolver = new SpeakerProfileResolver(new PublishedTalkRepository($this->connection), self::getContainer()->get(SpeakerRepository::class)); self::assertSame(['helene-schapira'], array_map(static fn($identity): string => $identity->slug, $resolver->getIdentities())); self::assertSame('helene-schapira', $resolver->getIdentityByLabel('Hélène SCHAPIRA')?->slug); @@ -92,10 +93,10 @@ public function testResolverBuildsTheProfileOfASpeakerAcrossEditions(): void self::assertSame([20, 10], $profile->identity->speakerIds); self::assertSame('Bio de 20', $profile->biography); self::assertSame(['github' => 'https://github.com/hschapira'], $profile->socialLinks); - self::assertSame([200, 100], array_map(static fn(SpeakerTalk $speakerTalk): ?int => $speakerTalk->talk->getId(), $profile->talks)); + self::assertSame([200, 100], array_map(static fn(SpeakerTalk $speakerTalk): int => $speakerTalk->talk->id, $profile->talks)); } - private function insertSpeaker(int $id, int $eventId, string $firstname, string $lastname, ?int $githubUserId, ?int $personId): void + private function insertSpeaker(int $id, int $eventId, string $firstname, string $lastname, ?int $githubUserId, ?int $personneId): void { $this->connection->insert('afup_conferenciers', [ 'conferencier_id' => $id, @@ -105,7 +106,7 @@ private function insertSpeaker(int $id, int $eventId, string $firstname, string 'email' => 'speaker' . $id . '@example.com', 'biographie' => 'Bio de ' . $id, 'user_github' => $githubUserId, - 'person_id' => $personId, + 'personne_id' => $personneId, ]); } diff --git a/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php b/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php index 429f51bc5..a8344e6ae 100644 --- a/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php +++ b/tests/unit/AppBundle/Event/Speaker/SpeakerProfileResolverTest.php @@ -4,13 +4,14 @@ namespace AppBundle\Tests\Event\Speaker; -use AppBundle\Event\Model\Event; use AppBundle\Event\Model\Repository\SpeakerRepository; use AppBundle\Event\Model\Speaker; -use AppBundle\Event\Model\Talk; use AppBundle\Event\Speaker\SpeakerIdentity; use AppBundle\Event\Speaker\SpeakerProfileResolver; use AppBundle\Event\Speaker\SpeakerTalk; +use AppBundle\Event\Talk\PublishedEvent; +use AppBundle\Event\Talk\PublishedTalk; +use AppBundle\Event\Talk\PublishedTalkRepository; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -31,7 +32,7 @@ public static function labels(): \Generator yield 'espaces en tête et tabulation' => [" \tCyrille\t GRANDVAL", 'cyrille grandval']; } - public function testGroupsSpeakerRowsByPerson(): void + public function testGroupsSpeakerRowsByPersonne(): void { $resolver = $this->resolver([ self::appearance(1, 1, 'helene-schapira', 'Hélène', 'SCHAPIRA', 10, '2019-10-24'), @@ -67,7 +68,7 @@ public function testSlugComesFromTheDatabaseAndNameFromTheMostRecentSpeaker(): v self::assertSame('2023-10-12', $identity->latestTalkAt->format('Y-m-d')); } - public function testLabelDesignatesThePersonCarryingItOnAnyOfItsRows(): void + public function testLabelDesignatesThePersonneCarryingItOnAnyOfItsRows(): void { $resolver = $this->resolver([ self::appearance(1, 7, 'frederic-dupont', 'Fred', 'Dupont', 10, '2015-10-24'), @@ -80,7 +81,7 @@ public function testLabelDesignatesThePersonCarryingItOnAnyOfItsRows(): void self::assertNull($resolver->getIdentityByLabel('Inconnu SPEAKER')); } - public function testLabelCarriedBySeveralPersonsDesignatesNoOne(): void + public function testLabelCarriedBySeveralPersonnesDesignatesNoOne(): void { $resolver = $this->resolver([ self::appearance(1, 5, 'jean-martin', 'Jean', 'Martin', 10, '2012-11-20'), @@ -127,7 +128,7 @@ public function testIdentitiesAreSortedByLastnameThenFirstname(): void self::assertSame(['paul-albert', 'zoe-elan', 'aline-martin', 'anne-martin'], self::slugs($resolver)); } - public function testFindsTheIdentityOfASpeakerFromAnyEditionByItsPerson(): void + public function testFindsTheIdentityOfASpeakerFromAnyEditionByItsPersonne(): void { $resolver = $this->resolver([ self::appearance(1, 1, 'helene-schapira', 'Hélène', 'SCHAPIRA', 10, '2019-10-24'), @@ -172,25 +173,34 @@ public function testProfileConsolidatesTheMostRecentNonEmptyValues(): void self::speakerTalk($old, 21, '2020-10-23'), ]; - $speakerRepository = $this->createMock(SpeakerRepository::class); - $speakerRepository->method('getPublishedTalkAppearances')->willReturn(array_map( + $publishedTalkRepository = $this->createMock(PublishedTalkRepository::class); + $publishedTalkRepository->method('getSpeakerAppearances')->willReturn(array_map( static fn(SpeakerTalk $speakerTalk): array => self::appearance( (int) $speakerTalk->speaker->getId(), 1, 'helene-schapira', (string) $speakerTalk->speaker->getFirstname(), (string) $speakerTalk->speaker->getLastname(), - (int) $speakerTalk->talk->getId(), + $speakerTalk->talk->id, $speakerTalk->startsAt->format('Y-m-d'), ), $speakerTalks, )); - $speakerRepository->expects(self::once()) - ->method('getPublishedSpeakerTalks') + $publishedTalkRepository->expects(self::once()) + ->method('getSpeakerTalks') ->with([3, 2, 1]) - ->willReturn($speakerTalks); + ->willReturn(array_map(static fn(SpeakerTalk $speakerTalk): array => [ + 'speaker_id' => (int) $speakerTalk->speaker->getId(), + 'talk' => $speakerTalk->talk, + 'event' => $speakerTalk->event, + 'starts_at' => $speakerTalk->startsAt, + 'github_login' => $speakerTalk->githubLogin, + ], $speakerTalks)); + // Chaque ligne speaker est chargée une seule fois, quel que soit son nombre de talks. + $speakerRepository = $this->createMock(SpeakerRepository::class); + $speakerRepository->expects(self::exactly(3))->method('get')->willReturnMap([[3, $latest], [2, $middle], [1, $old]]); - $profile = new SpeakerProfileResolver($speakerRepository)->getProfileBySlug('helene-schapira'); + $profile = new SpeakerProfileResolver($publishedTalkRepository, $speakerRepository)->getProfileBySlug('helene-schapira'); self::assertNotNull($profile); self::assertSame('helene-schapira', $profile->identity->slug); @@ -203,37 +213,37 @@ public function testProfileConsolidatesTheMostRecentNonEmptyValues(): void 'linkedin' => 'https://www.linkedin.com/in/helene-schapira', 'github' => 'https://github.com/hschapira', ], $profile->socialLinks); - self::assertSame([30, 21, 20, 10], array_map(static fn(SpeakerTalk $speakerTalk): ?int => $speakerTalk->talk->getId(), $profile->talks)); + self::assertSame([30, 21, 20, 10], array_map(static fn(SpeakerTalk $speakerTalk): int => $speakerTalk->talk->id, $profile->talks)); } public function testNoProfileForAnUnknownSlug(): void { - $speakerRepository = $this->createMock(SpeakerRepository::class); - $speakerRepository->method('getPublishedTalkAppearances')->willReturn([]); - $speakerRepository->expects(self::never())->method('getPublishedSpeakerTalks'); + $publishedTalkRepository = $this->createMock(PublishedTalkRepository::class); + $publishedTalkRepository->method('getSpeakerAppearances')->willReturn([]); + $publishedTalkRepository->expects(self::never())->method('getSpeakerTalks'); - self::assertNull(new SpeakerProfileResolver($speakerRepository)->getProfileBySlug('inconnu')); + self::assertNull(new SpeakerProfileResolver($publishedTalkRepository, $this->createStub(SpeakerRepository::class))->getProfileBySlug('inconnu')); } /** - * @param list $appearances + * @param list $appearances */ private function resolver(array $appearances): SpeakerProfileResolver { - $speakerRepository = $this->createStub(SpeakerRepository::class); - $speakerRepository->method('getPublishedTalkAppearances')->willReturn($appearances); + $publishedTalkRepository = $this->createStub(PublishedTalkRepository::class); + $publishedTalkRepository->method('getSpeakerAppearances')->willReturn($appearances); - return new SpeakerProfileResolver($speakerRepository); + return new SpeakerProfileResolver($publishedTalkRepository, $this->createStub(SpeakerRepository::class)); } /** - * @return array{speaker_id: int, person_id: int, slug: string, firstname: string, lastname: string, talk_id: int, starts_at: int} + * @return array{speaker_id: int, personne_id: int, slug: string, firstname: string, lastname: string, talk_id: int, starts_at: int} */ - private static function appearance(int $speakerId, int $personId, string $slug, string $firstname, string $lastname, int $talkId, string $date): array + private static function appearance(int $speakerId, int $personneId, string $slug, string $firstname, string $lastname, int $talkId, string $date): array { return [ 'speaker_id' => $speakerId, - 'person_id' => $personId, + 'personne_id' => $personneId, 'slug' => $slug, 'firstname' => $firstname, 'lastname' => $lastname, @@ -242,14 +252,14 @@ private static function appearance(int $speakerId, int $personId, string $slug, ]; } - private static function speaker(int $id, string $firstname, string $lastname, ?int $personId = null): Speaker + private static function speaker(int $id, string $firstname, string $lastname, ?int $personneId = null): Speaker { - return new Speaker()->setId($id)->setFirstname($firstname)->setLastname($lastname)->setPersonId($personId); + return new Speaker()->setId($id)->setFirstname($firstname)->setLastname($lastname)->setPersonneId($personneId); } private static function speakerTalk(Speaker $speaker, int $talkId, string $date, ?string $githubLogin = null): SpeakerTalk { - return new SpeakerTalk($speaker, new Talk()->setId($talkId), new Event(), new \DateTimeImmutable($date), $githubLogin); + return new SpeakerTalk($speaker, new PublishedTalk($talkId, 'Talk ' . $talkId), new PublishedEvent(1, 'Forum PHP', 'forumphp'), new \DateTimeImmutable($date), $githubLogin); } /** From 0f057512eaa765ead7da6e71aaa388a9813dd9b1 Mon Sep 17 00:00:00 2001 From: Xavier Leune Date: Fri, 20 Nov 2026 17:04:19 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Accepte=20un=20pr=C3=A9nom=20ou=20un=20nom?= =?UTF-8?q?=20NULL=20dans=20les=20apparitions=20des=20speakers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Des lignes conférencier (entreprises) ont un prénom NULL en base : le cast strict levait une exception et cassait /talks/. --- .../Event/Talk/PublishedTalkRepository.php | 4 ++-- .../Event/Talk/PublishedTalkRepositoryTest.php | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sources/AppBundle/Event/Talk/PublishedTalkRepository.php b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php index f6c9cf69d..62a06053c 100644 --- a/sources/AppBundle/Event/Talk/PublishedTalkRepository.php +++ b/sources/AppBundle/Event/Talk/PublishedTalkRepository.php @@ -59,8 +59,8 @@ public function getSpeakerAppearances(): array 'speaker_id' => self::toInt($row['conferencier_id']), 'personne_id' => self::toInt($row['personne_id']), 'slug' => self::toString($row['slug']), - 'firstname' => self::toString($row['prenom']), - 'lastname' => self::toString($row['nom']), + 'firstname' => self::nullableString($row['prenom']) ?? '', + 'lastname' => self::nullableString($row['nom']) ?? '', 'talk_id' => self::toInt($row['session_id']), 'starts_at' => self::toInt($row['debut']), ], $rows); diff --git a/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php b/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php index 07dd4fbd6..32a8832d8 100644 --- a/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php +++ b/tests/integration/AppBundle/Event/Talk/PublishedTalkRepositoryTest.php @@ -59,6 +59,21 @@ public function testSpeakerAppearancesOnlyReturnPublishedTalksOfLinkedSpeakers() ], $appearances); } + public function testSpeakerAppearancesAcceptARowWithoutFirstname(): void + { + // Une entreprise saisie comme speaker : prénom NULL en base (cas réel en prod). + $this->connection->insert('afup_conferenciers_personnes', ['id' => 3, 'slug' => 'alterway']); + $this->insertSpeaker(50, 1, null, 'ALTERWAY', null, 3); + $this->insertTalk(500, 1, 50, 'Talk sponsor', Talk::TYPE_FULL_LONG, strtotime('2019-10-24 11:00:00')); + + $appearances = array_values(array_filter( + new PublishedTalkRepository($this->connection)->getSpeakerAppearances(), + static fn(array $appearance): bool => $appearance['speaker_id'] === 50, + )); + + self::assertSame([['speaker_id' => 50, 'personne_id' => 3, 'slug' => 'alterway', 'firstname' => '', 'lastname' => 'ALTERWAY', 'talk_id' => 500, 'starts_at' => strtotime('2019-10-24 11:00:00')]], $appearances); + } + public function testSpeakerTalksReturnTalksEventsAndGithubLogins(): void { $speakerTalks = new PublishedTalkRepository($this->connection)->getSpeakerTalks([10, 20, 30]); @@ -96,7 +111,7 @@ public function testResolverBuildsTheProfileOfASpeakerAcrossEditions(): void self::assertSame([200, 100], array_map(static fn(SpeakerTalk $speakerTalk): int => $speakerTalk->talk->id, $profile->talks)); } - private function insertSpeaker(int $id, int $eventId, string $firstname, string $lastname, ?int $githubUserId, ?int $personneId): void + private function insertSpeaker(int $id, int $eventId, ?string $firstname, ?string $lastname, ?int $githubUserId, ?int $personneId): void { $this->connection->insert('afup_conferenciers', [ 'conferencier_id' => $id,