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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace AppBundle\Controller\Admin\Event;

use AppBundle\Event\AdminEventSelection;
use AppBundle\Event\Entity\Repository\EventThemeRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventThemeRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Talk;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
Expand All @@ -31,7 +31,7 @@ public function __invoke(Request $request, AdminEventSelection $eventSelection):

$eventId = $event->getId() ?? 0;
$hasThemes = $event->getHasThemes();
$themes = $hasThemes ? iterator_to_array($this->eventThemeRepository->getByThemesOrderedByPriority($eventId)) : [];
$themes = $hasThemes ? $this->eventThemeRepository->getByThemesOrderedByPriority($eventId) : [];
$scheduledTalks = iterator_to_array($this->talkRepository->getScheduledTalksByEvent($eventId));

$talkGroups = $this->groupTalks($scheduledTalks, $themes, $hasThemes);
Expand All @@ -47,8 +47,8 @@ public function __invoke(Request $request, AdminEventSelection $eventSelection):

/**
* @param array<Talk> $scheduledTalks
* @param array<\AppBundle\Event\Model\EventTheme> $themes
* @return array<array{theme: ?\AppBundle\Event\Model\EventTheme, talks: array<Talk>}>
* @param array<\AppBundle\Event\Entity\EventTheme> $themes
* @return array<array{theme: ?\AppBundle\Event\Entity\EventTheme, talks: array<Talk>}>
*/
private function groupTalks(array $scheduledTalks, array $themes, bool $hasThemes): array
{
Expand All @@ -61,7 +61,7 @@ private function groupTalks(array $scheduledTalks, array $themes, bool $hasTheme

$talksByThemeId = [];
foreach ($themes as $theme) {
$talksByThemeId[(int) $theme->getId()] = [];
$talksByThemeId[(int) $theme->id] = [];
}

$noThemeTalks = [];
Expand All @@ -78,7 +78,7 @@ private function groupTalks(array $scheduledTalks, array $themes, bool $hasTheme
$groups = [['theme' => null, 'talks' => $noThemeTalks]];

foreach ($themes as $theme) {
$talks = $talksByThemeId[(int) $theme->getId()];
$talks = $talksByThemeId[(int) $theme->id];
usort($talks, $this->compareTalks(...));
$groups[] = ['theme' => $theme, 'talks' => $talks];
}
Expand Down
10 changes: 5 additions & 5 deletions sources/AppBundle/Controller/Admin/Event/EventThemeAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace AppBundle\Controller\Admin\Event;

use AppBundle\Event\AdminEventSelection;
use AppBundle\Event\Entity\Repository\EventThemeRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventThemeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -25,11 +25,11 @@ public function __invoke(Request $request, AdminEventSelection $eventSelection):
return $this->handleAjaxRequest($request, $event);
}
if ($request->getMethod() === 'POST' && $request->request->has('delete')) {
$theme = $this->eventThemeRepository->get($request->request->getInt('theme_id'));
$theme = $this->eventThemeRepository->find($request->request->getInt('theme_id'));
if ($theme === null) {
$this->addFlash('error', 'Thème introuvable.');
} else {
$name = $theme->getName();
$name = $theme->name;
$this->eventThemeRepository->delete($theme);
$this->addFlash('notice', sprintf('Le thème "%s" a été supprimé.', $name));
}
Expand Down Expand Up @@ -61,12 +61,12 @@ private function updateThemePriority(Request $request): JsonResponse
$themeId = $request->request->getInt('theme_id');
$priority = $request->request->getInt('priority');

$theme = $this->eventThemeRepository->get($themeId);
$theme = $this->eventThemeRepository->find($themeId);
if (!$theme) {
return new JsonResponse(['error' => 'Thème non trouvé'], 404);
}

$theme->setPriority($priority);
$theme->priority = $priority;
$this->eventThemeRepository->save($theme);

return new JsonResponse(['success' => true]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

namespace AppBundle\Controller\Admin\Event;

use AppBundle\Event\Entity\EventTheme;
use AppBundle\Event\Entity\Repository\EventThemeRepository;
use AppBundle\Event\Form\EventThemeType;
use AppBundle\Event\Model\EventTheme;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\EventThemeRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use CCMBenchmark\TingBundle\Attribute\MapEntity;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -29,12 +29,12 @@ public function __invoke(Request $request, #[MapEntity] ?EventTheme $eventTheme
$new = true;
$eventTheme = new EventTheme();
if ($request->query->has('idForum')) {
$eventTheme->setIdForum($request->query->getInt('idForum'));
$eventTheme->idForum = $request->query->getInt('idForum');
}
} else {
$event = $this->eventRepository->get($eventTheme->getIdForum());
$event = $this->eventRepository->get($eventTheme->idForum);
if ($event !== null) {
$talks = $this->talkRepository->getByEventWithSpeakers($event, false, false, $eventTheme->getId());
$talks = $this->talkRepository->getByEventWithSpeakers($event, false, false, $eventTheme->id);
}
}

Expand All @@ -45,7 +45,7 @@ public function __invoke(Request $request, #[MapEntity] ?EventTheme $eventTheme
$this->eventThemeRepository->save($eventTheme);

$this->addFlash('notice', 'Thème ' . ($new ? 'ajouté' : 'modifié'));
return $this->redirectToRoute('admin_event_themes_list', ['id' => $eventTheme->getIdForum()]);
return $this->redirectToRoute('admin_event_themes_list', ['id' => $eventTheme->idForum]);
}

return $this->render('admin/event/theme_add_edit.html.twig', [
Expand Down
8 changes: 4 additions & 4 deletions sources/AppBundle/Controller/Event/Blog/ProgramAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace AppBundle\Controller\Event\Blog;

use AppBundle\Controller\Event\EventActionHelper;
use AppBundle\Event\Entity\Repository\EventThemeRepository;
use AppBundle\Event\JsonLd;
use AppBundle\Event\Model\Repository\EventThemeRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -28,9 +28,9 @@ public function __invoke(Request $request, $eventSlug): Response
$talkAggregates = $this->talkRepository->getByEventWithSpeakers($event, $request->query->getBoolean('apply-publication-date-filters', true), $event->getHasThemes());
$themes = null;
if ($event->getHasThemes()) {
$themes = iterator_to_array($this->eventThemeRepository->getBy(['idForum' => $event->getId()]));
usort($themes, fn($a, $b): int => $a->getPriority() === $b->getPriority() ? $a->getName() <=> $b->getName() : $a->getPriority() <=> $b->getPriority());
$themes = array_combine(array_map(fn($theme): int => (int) $theme->getId(), $themes), $themes);
$themes = $this->eventThemeRepository->findBy(['idForum' => $event->getId()]);
usort($themes, fn($a, $b): int => $a->priority === $b->priority ? $a->name <=> $b->name : $a->priority <=> $b->priority);
$themes = array_combine(array_map(fn($theme): int => (int) $theme->id, $themes), $themes);
}
$now = new \DateTime();

Expand Down
30 changes: 30 additions & 0 deletions sources/AppBundle/Event/Entity/EventTheme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity;

use AppBundle\Event\Entity\Repository\EventThemeRepository;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: EventThemeRepository::class)]
#[ORM\Table(name: 'afup_conference_theme')]
class EventTheme
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public ?int $id = null;

#[ORM\Column(name: 'id_forum', nullable: false)]
public int $idForum;

#[ORM\Column(nullable: false)]
public string $name;

#[ORM\Column(type: 'text', nullable: true)]
public ?string $description = null;

#[ORM\Column(nullable: false, options: ['default' => 0])]
public int $priority = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity\Repository;

use AppBundle\Doctrine\EntityRepository;
use AppBundle\Event\Entity\EventTheme;
use Doctrine\Persistence\ManagerRegistry;

/**
* @extends EntityRepository<EventTheme>
*/
final class EventThemeRepository extends EntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, EventTheme::class);
}

/**
* @return array<EventTheme>
*/
public function getByThemesOrderedByPriority(int $eventId): array
{
return $this->findBy(['idForum' => $eventId], ['priority' => 'ASC', 'name' => 'ASC']);
}
}
2 changes: 1 addition & 1 deletion sources/AppBundle/Event/Form/EventThemeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace AppBundle\Event\Form;

use AppBundle\Event\Entity\EventTheme;
use AppBundle\Event\Form\Support\EventHelper;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\EventTheme;
use AppBundle\Event\Model\Repository\EventRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\CallbackTransformer;
Expand Down
86 changes: 0 additions & 86 deletions sources/AppBundle/Event/Model/EventTheme.php

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace AppBundle\IntegrationTests\Event\Entity\Repository;

use Afup\Tests\Support\IntegrationTestCase;
use AppBundle\Event\Entity\EventTheme;
use AppBundle\Event\Entity\Repository\EventThemeRepository;

final class EventThemeRepositoryTest extends IntegrationTestCase
{
public function testSaveFindByEventAndDelete(): void
{
$eventThemeRepository = self::getContainer()->get(EventThemeRepository::class);

$themeAtelier = $this->buildEventTheme(42, 'Atelier', 2, 'Description de l\'atelier');
$themeConference = $this->buildEventTheme(42, 'Conference', 1, null);
$themeLightning = $this->buildEventTheme(42, 'Lightning talks', 1, null);
$themeAutreEvenement = $this->buildEventTheme(43, 'Autre evenement', 3, null);

$eventThemeRepository->save($themeAtelier);
$eventThemeRepository->save($themeConference);
$eventThemeRepository->save($themeLightning);
$eventThemeRepository->save($themeAutreEvenement);

$loaded = $eventThemeRepository->find($themeAtelier->id);
self::assertInstanceOf(EventTheme::class, $loaded);
self::assertSame('Atelier', $loaded->name);
self::assertSame(42, $loaded->idForum);
self::assertSame('Description de l\'atelier', $loaded->description);
self::assertSame(2, $loaded->priority);
self::assertNull($themeConference->description);

// Tri attendu : priorité croissante puis nom alphabétique, filtré par évènement
$themes = $eventThemeRepository->getByThemesOrderedByPriority(42);
self::assertSame(['Conference', 'Lightning talks', 'Atelier'], array_map(fn(EventTheme $theme): string => $theme->name, $themes));
self::assertCount(0, $eventThemeRepository->getByThemesOrderedByPriority(99));

// L'identifiant est réinitialisé par Doctrine après la suppression, on le récupère avant
$lightningThemeId = $themeLightning->id;
$eventThemeRepository->delete($themeLightning);
self::assertNull($eventThemeRepository->find($lightningThemeId));
self::assertCount(2, $eventThemeRepository->getByThemesOrderedByPriority(42));
}

private function buildEventTheme(int $idForum, string $name, int $priority, ?string $description): EventTheme
{
$eventTheme = new EventTheme();
$eventTheme->idForum = $idForum;
$eventTheme->name = $name;
$eventTheme->description = $description;
$eventTheme->priority = $priority;

return $eventTheme;
}
}
Loading