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
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_person
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_person:
path: /person
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerPersonAction}

admin_speaker_person_create:
path: /person/create
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerPersonCreateAction}

admin_speaker_person_attach:
path: /person/attach
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerPersonAttachAction}

admin_speaker_person_detach:
path: /person/detach
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerPersonDetachAction}

admin_speaker_person_merge:
path: /person/merge
methods: [POST]
defaults: {_controller: AppBundle\Controller\Admin\Speaker\SpeakerPersonMergeAction}
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
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
46 changes: 46 additions & 0 deletions db/seeds/SpeakerPersons.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 SpeakerPersons extends AbstractSeed
{
#[\Override]
public function getDependencies(): array
{
return ['Conferenciers'];
}

public function run(): void
{
$persons = [
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 person_id = NULL');
$this->execute('DELETE FROM afup_speaker_person');

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

foreach ($persons as $id => $person) {
$this->execute(sprintf(
'UPDATE afup_conferenciers SET person_id = %d WHERE conferencier_id IN (%s)',
$id,
implode(',', $person['speakers']),
));
}
}
}
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
29 changes: 23 additions & 6 deletions sources/AppBundle/CFP/SpeakerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,31 @@ 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;
}

$personId = null;
if (is_int($user)) {
$personId = $this->speakerRepository->findLatestPersonIdByGithubUser($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.
$adminSpeaker = $personId !== null ? $this->speakerRepository->findOneByPersonInEventWithoutGithubUser($personId, $event) : null;
if ($adminSpeaker !== null) {
$adminSpeaker->setUser($user);
$this->speakerRepository->save($adminSpeaker);

return $adminSpeaker;
}
}

$speaker = new Speaker();
$speaker
->setUser($user)
->setEventId($event->getId())
->setPersonId($personId)
;

return $speaker;
}
}
49 changes: 45 additions & 4 deletions sources/AppBundle/Controller/Admin/Speaker/SpeakerAddAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
use AppBundle\AuditLog\Audit;
use AppBundle\CFP\PhotoStorage;
use AppBundle\Event\Form\SpeakerFormData;
use AppBundle\Event\Form\SpeakerFormDataFactory;
use AppBundle\Event\Form\SpeakerType;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Speaker\SpeakerPersonLinker;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -24,16 +26,38 @@ public function __construct(
private readonly EventRepository $eventRepository,
private readonly SpeakerRepository $speakerRepository,
private readonly PhotoStorage $photoStorage,
private readonly SpeakerFormDataFactory $speakerFormDataFactory,
private readonly SpeakerPersonLinker $speakerPersonLinker,
private readonly Audit $audit,
) {}

public function __invoke(Request $request): Response
{
$event = $this->eventRepository->get($request->query->get('eventId'));
Assert::notNull($event);
$data = new SpeakerFormData();

// Reprise d'un conférencier d'une édition passée (?from=<speakerId>)
$source = $request->query->has('from') ? $this->speakerRepository->get($request->query->getInt('from')) : null;
$sourcePhoto = null;
if ($source instanceof Speaker) {
$personId = $this->speakerPersonLinker->findPersonId($source);
$existing = $personId !== null ? $this->speakerPersonLinker->findRowInEvent($personId, $event) : null;
if ($existing instanceof Speaker) {
$this->addFlash('notice', 'Ce conférencier existe déjà pour cet événement');

return $this->redirectToRoute('admin_speaker_edit', ['id' => $existing->getId()]);
}
$data = $this->speakerFormDataFactory->fromSpeaker($source);
if ($source->getPhoto() !== null) {
$sourcePhoto = $this->photoStorage->getUrl($source, PhotoStorage::DIR_ORIGINAL);
}
} else {
$data = new SpeakerFormData();
}

$form = $this->createForm(SpeakerType::class, $data, [
SpeakerType::OPT_USER_GITHUB => true,
SpeakerType::OPT_PHOTO_REQUIRED => null === $sourcePhoto,
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
Expand All @@ -50,15 +74,30 @@ public function __invoke(Request $request): Response
$speaker->setEmail($data->email);
$speaker->setUser($data->githubUser !== null ? $data->githubUser->getId() : null);
$speaker->setCompany($data->company);
$speaker->setLocality($data->locality);
$speaker->setPhoneNumber($data->phoneNumber);
$speaker->setReferentPerson($data->referentPerson);
$speaker->setReferentPersonEmail($data->referentPersonEmail);
if ($source instanceof Speaker) {
// La source rejoint la même personne que la nouvelle ligne.
if ($source->getPersonId() === null) {
$this->speakerPersonLinker->ensurePerson($source);
$this->speakerRepository->save($source);
}
$speaker->setPersonId($source->getPersonId());
} else {
$this->speakerPersonLinker->ensurePerson($speaker);
}
$this->speakerRepository->save($speaker);
if (null !== $data->photoFile) {
$fileName = $this->photoStorage->store($data->photoFile, $speaker);
$speaker->setPhoto($fileName);
$speaker->setPhoto($this->photoStorage->store($data->photoFile, $speaker));
$this->speakerRepository->save($speaker);
} elseif ($source instanceof Speaker && null !== $sourcePhoto) {
$speaker->setPhoto($this->photoStorage->copyFrom($source, $speaker));
$this->speakerRepository->save($speaker);
}
$this->audit->log('Ajout du conférencier de ' . $speaker->getFirstname() . ' ' . $speaker->getLastname());
$this->audit->log('Ajout du conférencier de ' . $speaker->getFirstname() . ' ' . $speaker->getLastname()
. ($source instanceof Speaker ? ' (repris de ' . $source->getId() . ')' : ''));

$this->addFlash('notice', 'Le conférencier a été ajouté');

Expand All @@ -70,6 +109,8 @@ public function __invoke(Request $request): Response
return $this->render('admin/speaker/add.html.twig', [
'event' => $event,
'form' => $form->createView(),
'source' => $source,
'sourcePhoto' => $sourcePhoto,
]);
}
}
Loading
Loading