Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions sources/AppBundle/Event/Model/Repository/SpeakerRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ public function getSpeakersByTalk(Talk $talk)
return $query->query($this->getCollection(new HydratorSingleObject()));
}

/**
* Conférenciers liés à au moins une des sessions données, triés par identifiant.
*
* @param list<int> $talkIds
*
* @return list<Speaker>
*/
public function getSpeakersByTalkIds(array $talkIds): array
{
if ($talkIds === []) {
return [];
}

$placeholders = [];
$params = [];
foreach ($talkIds as $index => $talkId) {
$placeholders[] = ':talk' . $index;
$params['talk' . $index] = $talkId;
}

$query = $this->getPreparedQuery(sprintf(
'SELECT DISTINCT c.conferencier_id, c.id_forum, c.genre, c.nom, c.prenom, c.email, c.societe,
c.biographie, c.twitter, c.user_github, c.photo, c.bluesky, c.mastodon, c.linkedin
FROM afup_conferenciers c
INNER JOIN afup_conferenciers_sessions cs ON cs.conferencier_id = c.conferencier_id
WHERE cs.session_id IN (%s)
ORDER BY c.conferencier_id ASC',
implode(', ', $placeholders),
))->setParams($params);

/** @var list<Speaker> $speakers */
$speakers = iterator_to_array($query->query($this->getCollection(new HydratorSingleObject())), false);

return $speakers;
}

/**
* Retrieve speakers with a scheduled talk for a given event
* @param bool $returnTalksThatWillBePublished
Expand Down
145 changes: 92 additions & 53 deletions sources/AppBundle/Subscriber/SitemapXmlSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
use Afup\Site\Corporate\Feuille;
use AppBundle\Association\Model\CompanyMember;
use AppBundle\Association\Model\Repository\CompanyMemberRepository;
use AppBundle\Controller\Website\News\ListAction;
use AppBundle\Event\Entity\Repository\PlanningRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;
use AppBundle\Site\Entity\Repository\FeuilleRepository;
use AppBundle\Site\Entity\Repository\ArticleRepository;
Expand All @@ -29,6 +28,7 @@ class SitemapXmlSubscriber implements EventSubscriberInterface
public function __construct(
private readonly UrlGeneratorInterface $urlGenerator,
private readonly TalkRepository $talkRepository,
private readonly PlanningRepository $planningRepository,
private readonly SpeakerRepository $speakerRepository,
private readonly EventRepository $eventRepository,
private readonly ArticleRepository $articleRepository,
Expand All @@ -45,31 +45,54 @@ public static function getSubscribedEvents(): array

public function populate(SitemapPopulateEvent $event): void
{
$this->registerTalksUrls($event->getUrlContainer());
$this->registerSpeakersTalksUrls($event->getUrlContainer());
$this->registerEventsTalksUrls($event->getUrlContainer());
$publishedTalks = $this->getPublishedTalks();

$this->registerTalksUrls($event->getUrlContainer(), $publishedTalks);
$this->registerSpeakersTalksUrls($event->getUrlContainer(), $publishedTalks);
$this->registerEventsTalksUrls($event->getUrlContainer(), $publishedTalks);
$this->registerNewsUrls($event->getUrlContainer());
$this->registerMembers($event->getUrlContainer());
$this->registerDefaultPages($event->getUrlContainer());
}

public function registerTalksUrls(UrlContainerInterface $urls): void
/**
* Talks passés visibles dans l'historique, indexés par identifiant
* (un talk planifié sur plusieurs créneaux n'apparaît qu'une fois).
*
* @return array<int, Talk>
*/
private function getPublishedTalks(): array
{
/** @var Talk[] $talks */
$talks = $this->talkRepository->getAllPastTalks(new \DateTime());
$publishedTalks = [];

foreach ($talks as $talk) {
if (!$talk->isDisplayedOnHistory()) {
continue;
/** @var iterable<Talk> $pastTalks */
$pastTalks = $this->talkRepository->getAllPastTalks(new \DateTime());

foreach ($pastTalks as $talk) {
$talkId = $talk->getId();
if ($talkId !== null && $talk->isDisplayedOnHistory()) {
$publishedTalks[$talkId] = $talk;
}
}

return $publishedTalks;
}

/**
* @param array<int, Talk> $publishedTalks
*/
private function registerTalksUrls(UrlContainerInterface $urls, array $publishedTalks): void
{
$plannings = $this->planningRepository->findIndexedByTalkIds(array_keys($publishedTalks));

foreach ($publishedTalks as $talkId => $talk) {
$url = new UrlConcrete(
$this->urlGenerator->generate(
'talks_show',
['id' => $talk->getId(), 'slug' => $talk->getSlug()],
['id' => $talkId, 'slug' => $talk->getSlug()],
UrlGeneratorInterface::ABSOLUTE_URL,
),
$talk->getSubmittedOn(),
$plannings[$talkId]->end ?? null,
);
$urls->addUrl($url, 'talks');

Expand All @@ -87,42 +110,70 @@ public function registerTalksUrls(UrlContainerInterface $urls): void
}
}

public function registerSpeakersTalksUrls(UrlContainerInterface $urls): void
/**
* Facettes speaker de la liste des talks : uniquement les speakers ayant
* au moins un talk publié, une seule URL par label normalisé.
*
* @param array<int, Talk> $publishedTalks
*/
private function registerSpeakersTalksUrls(UrlContainerInterface $urls, array $publishedTalks): void
{
/** @var Speaker[] $speakers */
$speakers = $this->speakerRepository->getAll();
foreach ($speakers as $speaker) {
$url = new UrlConcrete(
$this->urlGenerator->generate(
'talks_list',
['fR' => ['speakers.label' => [$speaker->getLabel()]]],
UrlGeneratorInterface::ABSOLUTE_URL,
$labels = [];
foreach ($this->speakerRepository->getSpeakersByTalkIds(array_keys($publishedTalks)) as $speaker) {
$label = self::normalizeLabel($speaker->getLabel());
if ($label !== '') {
$labels[$label] ??= $speaker->getLabel();
}
}

foreach ($labels as $label) {
$urls->addUrl(
new UrlConcrete(
$this->urlGenerator->generate(
'talks_list',
['fR' => ['speakers.label' => [$label]]],
UrlGeneratorInterface::ABSOLUTE_URL,
),
),
'talks',
);
$urls->addUrl($url, 'talks');
}
}

public function registerEventsTalksUrls(UrlContainerInterface $urls): void
/**
* Facettes événement de la liste des talks : uniquement les événements
* ayant au moins un talk publié, une seule URL par titre.
*
* @param array<int, Talk> $publishedTalks
*/
private function registerEventsTalksUrls(UrlContainerInterface $urls, array $publishedTalks): void
{
/** @var Event[] $events */
$events = $this->eventRepository->getAll();
foreach ($events as $event) {
$url = new UrlConcrete(
$this->urlGenerator->generate(
'talks_list',
['fR' => ['event.title' => [$event->getTitle()]]],
UrlGeneratorInterface::ABSOLUTE_URL,
$eventIds = array_map(static fn(Talk $talk): ?int => $talk->getForumId(), $publishedTalks);

$registeredTitles = [];
/** @var Event $event */
foreach ($this->eventRepository->getAll() as $event) {
$title = $event->getTitle();
if (!in_array($event->getId(), $eventIds, true) || in_array($title, $registeredTitles, true)) {
continue;
}
$registeredTitles[] = $title;

$urls->addUrl(
new UrlConcrete(
$this->urlGenerator->generate(
'talks_list',
['fR' => ['event.title' => [$title]]],
UrlGeneratorInterface::ABSOLUTE_URL,
),
$event->getDateEnd(),
),
$event->getDateEnd(),
UrlConcrete::CHANGEFREQ_DAILY,
1,
'talks',
);
$urls->addUrl($url, 'talks');
}
}

public function registerNewsUrls(UrlContainerInterface $urls): void
private function registerNewsUrls(UrlContainerInterface $urls): void
{
$news = $this->articleRepository->findAllPublishedArticles();

Expand All @@ -141,23 +192,11 @@ public function registerNewsUrls(UrlContainerInterface $urls): void
'news',
);
}
}

$total = $this->articleRepository->countPublishedArticles([]);
$byPage = ListAction::ARTICLES_PER_PAGE;
$lastPage = ceil($total / $byPage);

for ($page = max($lastPage, 1); $page <= $lastPage; $page++) {
$urls->addUrl(
new UrlConcrete(
$this->urlGenerator->generate(
'news_list',
['page' => $page],
UrlGeneratorInterface::ABSOLUTE_URL,
),
),
'news',
);
}
private static function normalizeLabel(string $label): string
{
return (string) preg_replace('/\s+/u', ' ', trim($label));
}

private function registerMembers(UrlContainerInterface $urls): void
Expand Down
6 changes: 6 additions & 0 deletions tests/behat/features/PublicSite/Sitemaps.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Feature: Site Public - Sitemaps
And the response should contain "<loc>https://apachephptest:80/talks/?fR%5Bspeakers.label%5D%5B0%5D=Geoffrey%20BACHELET</loc>"
And the response should contain "<loc>https://apachephptest:80/talks/?fR%5Bevent.title%5D%5B0%5D=forum</loc>"
And the response should contain "<loc>https://apachephptest:80/talks/</loc>"
# lastmod = fin du créneau de planning, et non date de soumission au CFP
And the response should contain "<loc>https://apachephptest:80/talks/6-revolutionons-php</loc><lastmod>2020-09-15T10:40:00+02:00</lastmod>"
# Speaker et événement sans talk publié : pas de facette
And the response should not contain "speakers.label%5D%5B0%5D=John%20DOE"
And the response should not contain "event.title%5D%5B0%5D=AFUP%20Day%20Lyon"

@reloadDbWithTestData
Scenario: On accède sitemap video
Expand All @@ -26,6 +31,7 @@ Feature: Site Public - Sitemaps
Scenario: On accède sitemap news
Given I am on "/sitemap.news.xml"
And the response should contain "<loc>https://apachephptest:80/news/1-les-videos-du-forum-2018-en-ligne</loc>"
And the response should not contain "?page="

@reloadDbWithTestData
Scenario: On accède sitemap members
Expand Down
Loading
Loading