-
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 1 commit
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,58 @@ | ||
| <?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(); | ||
|
|
||
| // One interview can group several speakers, and a speaker belongs to at most one | ||
| // interview (enforced by the unique index on speaker_id). | ||
| $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]) | ||
|
Collaborator
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. 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.
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. 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.
Collaborator
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. 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 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
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. Dans notre modèle de données, un Si je soumet au CFP du Forum 2025 et au Forum 2026, j'aurais 2 Donc un Est-ce que c'est plus clair ? |
||
| ->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,140 @@ | ||
| <?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 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, | ||
| ) {} | ||
|
|
||
| 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. |
||
| return false; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.