-
Notifications
You must be signed in to change notification settings - Fork 70
Publication des interviews via le BO #2321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Phinx\Migration\AbstractMigration; | ||
|
|
||
| final class CreateInterviewTables extends AbstractMigration | ||
| { | ||
| public function change(): void | ||
| { | ||
| $this->table('interview') | ||
| ->addColumn('event_id', 'integer', [ | ||
| 'null' => false, | ||
| 'signed' => false, | ||
| ]) | ||
| ->addColumn('date_publication', 'datetime', ['null' => false]) | ||
| ->addColumn('wordpress_post_id', 'integer', [ | ||
| 'null' => true, | ||
| 'default' => null, | ||
| ]) | ||
| ->create(); | ||
|
|
||
| $this->table('interview_question') | ||
| ->addColumn('interview_id', 'integer', [ | ||
| 'null' => false, | ||
| 'signed' => false, | ||
| ]) | ||
| ->addColumn('position', 'integer', [ | ||
| 'null' => false, | ||
| 'default' => 0, | ||
| ]) | ||
| ->addColumn('question', 'text', ['null' => false]) | ||
| ->addColumn('reponse', 'text', ['null' => false]) | ||
| ->addForeignKey('interview_id', 'interview', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) | ||
| ->create(); | ||
|
|
||
| // Une interview peut avoir un ou plusieurs speakers, mais un speaker ne peut avoir | ||
| // qu'une seule interview par event. Vu que pour chaque event, les speakers sont uniques, | ||
| // une unicité sur speaker_id suffit, et permet de rechercher rapidement par speaker. | ||
| $this->table('interview_speaker') | ||
| ->addColumn('interview_id', 'integer', [ | ||
| 'null' => false, | ||
| 'signed' => false, | ||
| ]) | ||
| ->addColumn('speaker_id', 'integer', [ | ||
| 'null' => false, | ||
| 'signed' => false, | ||
| ]) | ||
| ->addForeignKey('interview_id', 'interview', 'id', ['delete' => 'CASCADE', 'update' => 'NO_ACTION']) | ||
| ->addIndex('speaker_id', ['unique' => true]) | ||
| ->create(); | ||
|
|
||
| $this->table('afup_forum') | ||
| ->addColumn('interviews_wp_category_id', 'integer', ['null' => true]) | ||
| ->addColumn('interviews_intro', 'text', ['null' => true]) | ||
| ->addColumn('interviews_cta_text', 'text', ['null' => true]) | ||
| ->save(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace AppBundle\Controller\Admin\Event\Interview; | ||
|
|
||
| use AppBundle\Event\AdminEventSelection; | ||
| use AppBundle\Event\Entity\Interview; | ||
| use AppBundle\Event\Entity\InterviewQuestion; | ||
| use AppBundle\Event\Entity\Repository\InterviewRepository; | ||
| use AppBundle\Event\Entity\Repository\SpeakerRepository as DoctrineSpeakerRepository; | ||
| use AppBundle\Event\Entity\Speaker as DoctrineSpeaker; | ||
| use AppBundle\Event\Form\InterviewType; | ||
| use AppBundle\Event\Model\Event; | ||
| use AppBundle\Event\Model\Repository\SpeakerRepository as TingSpeakerRepository; | ||
| use AppBundle\Event\Model\Repository\TalkRepository; | ||
| use AppBundle\Event\Model\Speaker as TingSpeaker; | ||
| use AppBundle\Event\Model\Talk; | ||
| use AppBundle\Event\Wordpress\WordpressClient; | ||
| use Psr\Log\LoggerInterface; | ||
| use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||
| use Symfony\Component\HttpFoundation\Request; | ||
| use Symfony\Component\HttpFoundation\Response; | ||
|
|
||
| class AddOrEditAction extends AbstractController | ||
| { | ||
| public function __construct( | ||
| private readonly TingSpeakerRepository $tingSpeakerRepository, | ||
| private readonly DoctrineSpeakerRepository $doctrineSpeakerRepository, | ||
| private readonly InterviewRepository $interviewRepository, | ||
| private readonly TalkRepository $talkRepository, | ||
| private readonly WordpressClient $wordpressClient, | ||
| private readonly LoggerInterface $logger, | ||
| ) {} | ||
|
|
||
| public function __invoke(Request $request, AdminEventSelection $eventSelection, ?int $interviewId = null): Response | ||
| { | ||
| $event = $eventSelection->event; | ||
|
|
||
| if ($interviewId !== null) { | ||
| $interview = $this->interviewRepository->find($interviewId); | ||
| if ($interview === null) { | ||
| throw $this->createNotFoundException('Interview introuvable.'); | ||
| } | ||
| } else { | ||
| $interview = new Interview(); | ||
| $interview->eventId = (int) $event->getId(); | ||
| $interview->addQuestion(new InterviewQuestion()); | ||
| } | ||
|
|
||
| $form = $this->createForm(InterviewType::class, $interview, [ | ||
| 'available_speakers' => $this->getAvailableSpeakers($event, $interview), | ||
| ]); | ||
|
|
||
| $form->handleRequest($request); | ||
|
|
||
| if ($form->isSubmitted() && $form->isValid()) { | ||
| $this->interviewRepository->save($interview); | ||
|
|
||
| $savedToWordpress = $this->saveToWordpress($interview, $event); | ||
|
|
||
| if ($savedToWordpress) { | ||
| $this->addFlash('success', "L'interview a été enregistrée en base et sur WordPress."); | ||
| } else { | ||
| $this->addFlash('notice', "L'interview a été enregistrée en base uniquement. L'enregistrement sur WordPress n'a pas fonctionné."); | ||
| } | ||
|
|
||
| return $this->redirectToRoute('admin_event_interview_list', ['id' => $event->getId()]); | ||
| } | ||
|
|
||
| return $this->render('admin/event/interview/edit.html.twig', [ | ||
| 'event' => $event, | ||
| 'interview' => $interview, | ||
| 'form' => $form->createView(), | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, DoctrineSpeaker> | ||
| */ | ||
| private function getAvailableSpeakers(Event $event, Interview $interview): array | ||
| { | ||
| $scheduledSpeakerIds = []; | ||
| foreach ($this->tingSpeakerRepository->getScheduledSpeakersByEvent($event, true) as $row) { | ||
| $speaker = $row['speaker'] ?? null; | ||
| if ($speaker instanceof TingSpeaker) { | ||
| $scheduledSpeakerIds[] = (int) $speaker->getId(); | ||
| } | ||
| } | ||
|
|
||
| $existingInterviews = $this->interviewRepository->findIndexedBySpeakerIds($scheduledSpeakerIds); | ||
|
|
||
| $available = []; | ||
| foreach ($scheduledSpeakerIds as $id) { | ||
| if (!isset($existingInterviews[$id]) || in_array($id, $interview->getSpeakerIds(), true)) { | ||
| $available[] = $this->doctrineSpeakerRepository->find($id); | ||
| } | ||
| } | ||
|
|
||
| $available = array_filter($available); | ||
| usort($available, fn(DoctrineSpeaker $a, DoctrineSpeaker $b) => strcmp($a->label, $b->label)); | ||
|
|
||
| $choices = []; | ||
| /** @var DoctrineSpeaker $speaker */ | ||
| foreach ($available as $speaker) { | ||
| $choices[$speaker->label] = $speaker; | ||
| } | ||
|
|
||
| return $choices; | ||
| } | ||
|
|
||
| private function saveToWordpress(Interview $interview, Event $event): bool | ||
| { | ||
| $plannedTalks = []; | ||
| foreach ($interview->speakers as $speaker) { | ||
| foreach ($this->talkRepository->getTalksBySpeaker($event, $speaker->id) as $talk) { | ||
| foreach ($this->talkRepository->getByTalkWithSpeakers($talk) as $row) { | ||
| if ($row['talk'] instanceof Talk) { | ||
| $plannedTalks[] = $row['talk']; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| try { | ||
| $wordpressPostId = $this->wordpressClient->persistInterview( | ||
| $interview, | ||
| $event, | ||
| $interview->speakers->toArray(), | ||
| $plannedTalks, | ||
| ); | ||
|
|
||
| $interview->wordpressPostId = $wordpressPostId; | ||
| $this->interviewRepository->save($interview); | ||
|
|
||
| return true; | ||
| } catch (\Exception $e) { | ||
| $this->addFlash('error', 'Erreur WordPress : ' . $e->getMessage()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. j'allais dire qu'il y avait peut-être un risque d'envoyer des informations qui ne devraient pas être affichées (secrétaire ou autre) en catchant tout \Exception et renvoyant le message, mais vu le public qui utilisera la fonctionnalité ça ne devrait pas être gênant.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm oui ça me paraissait ok. J'ai rajouté un log pour avoir une trace si besoin de debug plus tard. |
||
| $this->logger->error('Erreur WordPress : ' . $e->getMessage()); | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attention, l'unicité porte uniquement sur speaker_id, sans notion d'événement.
Du coup un speaker ne peut être rattaché à une seule interview, alors que la description dit "une personne ne peut être que dans une seule interview par évènement".
Je me trompe peut être mais j'ai l'impression qu'il y a un souci avec le modèle de donnée.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah oui c'est normal ça.
Dans la table des speakers (afup_conferenciers) il y a l'id de l'event (id_forum). Quand une personne est speaker à plusieurs events, il y a plusieurs lignes dans la table des speakers.
Donc pas besoin de refaire un lien vers l'event, on l'a via le speaker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui je suis d'accord avec toi, pas besoin de refaire le lien mais la contrainte d'unicité n'est pas bonne car uniquement sur la colonne
speaker_id.Si un speaker est interviewé pour un premier event, on ne pourra pas rajouter d'interview pour un évènement suivant.
A priori il faudrait mettre la contrainte d'unicité sur
interview_idetspeaker_id. Je me trompe ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dans notre modèle de données, un
speaker_idne peut pas être dans plusieurs events.Si je soumet au CFP du Forum 2025 et au Forum 2026, j'aurais 2
speaker_iddifférents, un par Forum. Avec à chaque fois les données dupliquées (pour garder l'historique). Et du coup pas de soucis pour avoir une interview par event, vu que j'aurais unspeaker_iddifférent pour chaque event.Donc un
speaker_idne peut pas, et ne doit pas, être présent plusieurs fois dans la tableinterview_speaker. Avoir la contrainte sur la pair interview_id/speaker_id aurait le même effet en pratique mais aide moins à la perf quand on cherche une interview parspeaker_id.Est-ce que c'est plus clair ?