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
2 changes: 2 additions & 0 deletions config/packages/backoffice_menu.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ parameters:
- admin_speaker_list
- admin_speaker_add
- admin_speaker_edit
- admin_speaker_pick
- admin_speaker_personne
admin_event_speakers_management:
nom: 'Infos speakers'
niveau: 'ROLE_EVENT_READER'
Expand Down
28 changes: 28 additions & 0 deletions config/routing/admin_speaker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,31 @@ admin_speaker_link_gravatar:
admin_speaker_register:
path: /register
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerRegisterAction}

admin_speaker_pick:
path: /pick
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerPickAction}

admin_speaker_personne:
path: /personne
defaults: {_controller: AppBundle\Controller\Admin\Speaker\PersonneConferencierAction}

admin_speaker_personne_create:
path: /personne/create
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\PersonneConferencierCreateAction}

admin_speaker_personne_attach:
path: /personne/attach
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\PersonneConferencierAttachAction}

admin_speaker_personne_detach:
path: /personne/detach
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\PersonneConferencierDetachAction}

admin_speaker_personne_merge:
path: /personne/merge
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\PersonneConferencierMergeAction}
43 changes: 43 additions & 0 deletions db/seeds/Conferenciers.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class Conferenciers extends AbstractSeed
{
public const ID_CONFERENCIER = 1;
public const ID_CONFERENCIER_ANCIEN = 4;

public function run(): void
{
Expand Down Expand Up @@ -72,6 +73,48 @@ public function run(): void
'special_diet_description' => null,
'hotel_nights' => null,
],
// Conférencière d'une édition passée, pas encore inscrite au forum : reprise en back-office et CFP prérempli
[
'conferencier_id' => self::ID_CONFERENCIER_ANCIEN,
'id_forum' => Event::ID_PASSED,
'genre' => Genre::Femme->value,
'nom' => 'Ancienne',
'prenom' => 'Marie',
'email' => 'marie@example.com',
'societe' => 'Ancienne Société',
'ville' => 'Lyon',
'biographie' => 'Bio Marie',
'twitter' => '',
'mastodon' => '',
'bluesky' => '',
'user_github' => GithubUsers::ID_GITHUBUSER_ANCIEN,
'photo' => self::ID_CONFERENCIER_ANCIEN . '.png',
'will_attend_speakers_diner' => null,
'has_special_diet' => null,
'special_diet_description' => null,
'hotel_nights' => null,
],
// Fiche historique non rattachée, homonyme de Geoffrey Bachelet : suggestion de rattachement
[
'conferencier_id' => 5,
'id_forum' => Event::ID_PASSED,
'genre' => null,
'nom' => 'Bachelet',
'prenom' => 'Geoffrey',
'email' => 'geoffrey@example.com',
'societe' => null,
'ville' => null,
'biographie' => 'Ancienne bio',
'twitter' => null,
'mastodon' => null,
'bluesky' => null,
'user_github' => null,
'photo' => null,
'will_attend_speakers_diner' => null,
'has_special_diet' => null,
'special_diet_description' => null,
'hotel_nights' => null,
],
];

$table = $this->table('afup_conferenciers');
Expand Down
46 changes: 46 additions & 0 deletions db/seeds/ConferenciersPersonnes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

use Phinx\Seed\AbstractSeed;

/**
* Personnes des conférenciers de Conferenciers.php. La fiche 5 reste volontairement non rattachée.
*/
class ConferenciersPersonnes extends AbstractSeed
{
#[\Override]
public function getDependencies(): array
{
return ['Conferenciers'];
}

public function run(): void
{
$personnes = [
1 => ['slug' => 'geoffrey-bachelet', 'speakers' => [1]],
2 => ['slug' => 'adrien-gallou', 'speakers' => [2]],
3 => ['slug' => 'john-doe', 'speakers' => [3]],
4 => ['slug' => 'marie-ancienne', 'speakers' => [Conferenciers::ID_CONFERENCIER_ANCIEN]],
];

$this->execute('UPDATE afup_conferenciers SET personne_id = NULL');
$this->execute('DELETE FROM afup_conferenciers_personnes');

$this->table('afup_conferenciers_personnes')
->insert(array_map(
static fn(int $id, array $personne): array => ['id' => $id, 'slug' => $personne['slug']],
array_keys($personnes),
$personnes,
))
->save();

foreach ($personnes as $id => $personne) {
$this->execute(sprintf(
'UPDATE afup_conferenciers SET personne_id = %d WHERE conferencier_id IN (%s)',
$id,
implode(',', $personne['speakers']),
));
}
}
}
12 changes: 12 additions & 0 deletions db/seeds/GithubUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
class GithubUsers extends AbstractSeed
{
public const ID_GITHUBUSER_UBERMUDA = 1;
/** Conférencier d'une édition passée, sans fiche sur le forum courant (voir TestGithubAuthenticator) */
public const ID_GITHUBUSER_ANCIEN = 4;

public function run(): void
{
Expand Down Expand Up @@ -41,6 +43,16 @@ public function run(): void
'avatar_url' => 'https://avatars.githubusercontent.com/u/1090307?v=4',
'afup_crew' => 1,
],
[
'id' => self::ID_GITHUBUSER_ANCIEN,
'github_id' => 77,
'login' => 'ancien',
'name' => 'Marie Ancienne',
'company' => 'AFUP',
'profile_url' => 'https://github.com/ancien',
'avatar_url' => 'https://avatars.githubusercontent.com/u/77?v=4',
'afup_crew' => 0,
],
];

$table = $this->table('afup_user_github');
Expand Down
42 changes: 35 additions & 7 deletions sources/AppBundle/CFP/PhotoStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,47 @@ public function store(File $photo, Speaker $speaker): string
$fileName = $speaker->getId() . '.' . $photo->guessExtension();
$directory = $this->basePath . '/' . $speaker->getEventId() . '/' . self::DIR_ORIGINAL;
$this->createDirectory($directory);
// delete all formats
if ($speaker->getId() !== null) {
foreach (array_keys(self::FORMAT) as $format) {
$files = glob($this->basePath . '/' . $speaker->getEventId() . '/' . $format . '/' . $speaker->getId() . '.*');
$this->filesystem->remove($files);
}
}
$this->removeAllFormats($speaker);

$photo->move($directory, $fileName);

return $fileName;
}

/**
* Copie la photo originale d'une ligne (autre édition) vers une ligne déjà enregistrée.
* Retourne le nom de fichier de la cible, ou null si la source n'a pas de photo.
*/
public function copyFrom(Speaker $source, Speaker $target): ?string
{
if ($source->getPhoto() === null || $target->getId() === null) {
return null;
}
$sourcePath = $this->getPath($source, self::DIR_ORIGINAL);
if (!is_file($sourcePath)) {
return null;
}

$fileName = $target->getId() . '.' . pathinfo($sourcePath, PATHINFO_EXTENSION);
$directory = $this->basePath . '/' . $target->getEventId() . '/' . self::DIR_ORIGINAL;
$this->createDirectory($directory);
$this->removeAllFormats($target);
$this->filesystem->copy($sourcePath, $directory . '/' . $fileName, true);

return $fileName;
}

private function removeAllFormats(Speaker $speaker): void
{
if ($speaker->getId() === null) {
return;
}
foreach (array_keys(self::FORMAT) as $format) {
$files = glob($this->basePath . '/' . $speaker->getEventId() . '/' . $format . '/' . $speaker->getId() . '.*');
$this->filesystem->remove($files);
}
}

public function getUrl(Speaker $speaker, $format = null): ?string
{
if ($format === null) {
Expand Down
36 changes: 29 additions & 7 deletions sources/AppBundle/CFP/SpeakerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

namespace AppBundle\CFP;

use AppBundle\Event\Model\Event;
use AppBundle\Event\Entity\GithubUser;
use AppBundle\Event\Entity\Repository\PersonneConferencierRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Speaker;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
Expand All @@ -16,6 +17,7 @@ class SpeakerFactory
public function __construct(
private readonly TokenStorageInterface $tokenStorage,
private readonly SpeakerRepository $speakerRepository,
private readonly PersonneConferencierRepository $personneConferencierRepository,
) {}

/**
Expand All @@ -37,14 +39,34 @@ public function getSpeaker(Event $event): Speaker
'eventId' => $event->getId(),
]);

if ($speaker === null) {
$speaker = new Speaker();
$speaker
->setUser($user)
->setEventId($event->getId())
;
if ($speaker !== null) {
return $speaker;
}

$personneId = null;
if (is_int($user)) {
$personneId = $this->personneConferencierRepository->findLatestIdByGithubUser($user);
// La personne a peut-être déjà une ligne pour cet événement, saisie par l'admin sans compte GitHub :
// on la reprend plutôt que de créer un doublon.
$adminSpeakerId = $personneId !== null && $event->getId() !== null
? $this->personneConferencierRepository->findSpeakerIdInEvent($personneId, $event->getId(), withoutGithubUser: true)
: null;
$adminSpeaker = $adminSpeakerId !== null ? $this->speakerRepository->get($adminSpeakerId) : null;
if ($adminSpeaker instanceof Speaker) {
$adminSpeaker->setUser($user);
$this->speakerRepository->save($adminSpeaker);

return $adminSpeaker;
}
}

$speaker = new Speaker();
$speaker
->setUser($user)
->setEventId($event->getId())
->setPersonneId($personneId)
;

return $speaker;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace AppBundle\Controller\Admin\Speaker;

use AppBundle\Event\Entity\Repository\PersonneConferencierRepository;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Speaker\SpeakerSearchResult;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Attribute\IsGranted;

/**
* Fiche personne : ses lignes conférencier (une par édition), les suggestions de rattachement et la fusion.
*/
#[IsGranted('ROLE_EVENT_WRITER')]
final class PersonneConferencierAction extends AbstractController
{
public function __construct(
private readonly PersonneConferencierRepository $personneConferencierRepository,
private readonly SpeakerRepository $speakerRepository,
private readonly EventRepository $eventRepository,
) {}

public function __invoke(Request $request): Response
{
$personne = $this->personneConferencierRepository->find($request->query->getInt('id'));
if ($personne === null) {
throw $this->createNotFoundException('Personne non trouvée');
}
$search = $request->query->getString('q');

$eventTitles = [];
foreach ($this->eventRepository->getAll() as $event) {
if ($event->getId() !== null) {
$eventTitles[$event->getId()] = $event->getTitle();
}
}

return $this->render('admin/speaker/personne.html.twig', [
'personne' => $personne,
'speakers' => $this->loadSpeakers($this->personneConferencierRepository->findSpeakerIds($personne->id)),
'suggestions' => $this->loadSpeakers($this->personneConferencierRepository->findSuggestedSpeakerIds($personne->id)),
'search' => $search,
'mergeCandidates' => array_values(array_filter(
$this->personneConferencierRepository->searchAcrossEvents($search),
static fn(SpeakerSearchResult $result): bool => $result->personneId !== null && $result->personneId !== $personne->id,
)),
'eventTitles' => $eventTitles,
]);
}

/**
* @param list<int> $speakerIds
* @return list<Speaker>
*/
private function loadSpeakers(array $speakerIds): array
{
$speakers = [];
foreach ($speakerIds as $speakerId) {
$speaker = $this->speakerRepository->get($speakerId);
if ($speaker instanceof Speaker) {
$speakers[] = $speaker;
}
}

return $speakers;
}
}
Loading
Loading