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
40 changes: 2 additions & 38 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -4022,13 +4022,13 @@
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Speaker/SpeakerRegisterAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$speakers of method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkToSpeakersRepository\\:\\:replaceSpeakers\\(\\) expects array\\<AppBundle\\\\Event\\\\Model\\\\Speaker\\>, mixed given\\.$#',
'message' => '#^Parameter \\#2 \\$speakers of method AppBundle\\\\Event\\\\Entity\\\\Repository\\\\TalkToSpeakerRepository\\:\\:replaceSpeakers\\(\\) expects array\\<AppBundle\\\\Event\\\\Model\\\\Speaker\\>, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Talk/AddAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$speakers of method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkToSpeakersRepository\\:\\:replaceSpeakers\\(\\) expects array\\<AppBundle\\\\Event\\\\Model\\\\Speaker\\>, mixed given\\.$#',
'message' => '#^Parameter \\#2 \\$speakers of method AppBundle\\\\Event\\\\Entity\\\\Repository\\\\TalkToSpeakerRepository\\:\\:replaceSpeakers\\(\\) expects array\\<AppBundle\\\\Event\\\\Model\\\\Speaker\\>, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Admin/Talk/EditAction.php',
Expand Down Expand Up @@ -6511,12 +6511,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$speakers of class AppBundle\\\\Event\\\\Model\\\\EventStats\\\\CFPStats constructor expects int, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#3 \\$paying of class AppBundle\\\\Event\\\\Model\\\\EventStats\\\\TicketTypeStats constructor expects list\\<int\\>, array\\<mixed\\> given\\.$#',
'identifier' => 'argument.type',
Expand Down Expand Up @@ -7069,36 +7063,6 @@
'count' => 2,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'count\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkToSpeakersRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkToSpeakersRepository\\:\\:getNumberOfSpeakers\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkToSpeakersRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkToSpeakersRepository\\:\\:initMetadata\\(\\) has parameter \\$options with no value type specified in iterable type array\\.$#',
'identifier' => 'missingType.iterableValue',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkToSpeakersRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\TalkToSpeakersRepository\\:\\:initMetadata\\(\\) should return M of CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata but returns CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\<object\\>\\.$#',
'identifier' => 'return.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkToSpeakersRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$databaseName of method CCMBenchmark\\\\Ting\\\\Repository\\\\Metadata\\<object\\>\\:\\:setDatabase\\(\\) expects string, mixed given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/TalkToSpeakersRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method format\\(\\) on DateTime\\|null\\.$#',
'identifier' => 'method.nonObject',
Expand Down
4 changes: 2 additions & 2 deletions sources/AppBundle/Command/CfpNotificationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace AppBundle\Command;

use AppBundle\Event\Entity\Repository\TalkToSpeakerRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Repository\TalkToSpeakersRepository;
use AppBundle\Notifier\SlackNotifier;
use AppBundle\Slack\MessageFactory;
use Symfony\Component\Console\Command\Command;
Expand All @@ -22,7 +22,7 @@ public function __construct(
private readonly SlackNotifier $slackNotifier,
private readonly EventRepository $eventRepository,
private readonly TalkRepository $talkRepository,
private readonly TalkToSpeakersRepository $talkToSpeakersRepository,
private readonly TalkToSpeakerRepository $talkToSpeakersRepository,
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions sources/AppBundle/Controller/Admin/Talk/AddAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use AppBundle\AuditLog\Audit;
use AppBundle\Event\AdminEventSelection;
use AppBundle\Event\Entity\Repository\TalkToSpeakerRepository;
use AppBundle\Event\Form\TalkAdminType;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Repository\TalkToSpeakersRepository;
use AppBundle\Event\Model\Talk;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -18,7 +18,7 @@ class AddAction extends AbstractController
{
public function __construct(
private readonly TalkRepository $talkRepository,
private readonly TalkToSpeakersRepository $talkToSpeakersRepository,
private readonly TalkToSpeakerRepository $talkToSpeakersRepository,
private readonly Audit $audit,
) {}

Expand Down
4 changes: 2 additions & 2 deletions sources/AppBundle/Controller/Admin/Talk/EditAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
use AppBundle\AuditLog\Audit;
use AppBundle\Event\Form\TalkAdminType;
use AppBundle\Event\Form\TalkType;
use AppBundle\Event\Entity\Repository\TalkToSpeakerRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Repository\TalkToSpeakersRepository;
use AppBundle\Event\Model\Talk;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -21,7 +21,7 @@ class EditAction extends AbstractController
public function __construct(
private readonly EventRepository $eventRepository,
private readonly TalkRepository $talkRepository,
private readonly TalkToSpeakersRepository $talkToSpeakersRepository,
private readonly TalkToSpeakerRepository $talkToSpeakersRepository,
private readonly Audit $audit,
) {}

Expand Down
4 changes: 2 additions & 2 deletions sources/AppBundle/Controller/Event/CFP/InviteAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use AppBundle\CFP\SpeakerFactory;
use AppBundle\Controller\Event\EventActionHelper;
use AppBundle\Event\Entity\Repository\TalkToSpeakerRepository;
use AppBundle\Event\Model\Repository\TalkInvitationRepository;
use AppBundle\Event\Model\Repository\TalkRepository;
use AppBundle\Event\Model\Repository\TalkToSpeakersRepository;
use AppBundle\Event\Model\TalkInvitation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand All @@ -22,7 +22,7 @@ public function __construct(
private readonly TalkRepository $talkRepository,
private readonly SpeakerFactory $speakerFactory,
private readonly TalkInvitationRepository $talkInvitationRepository,
private readonly TalkToSpeakersRepository $talkToSpeakersRepository,
private readonly TalkToSpeakerRepository $talkToSpeakersRepository,
private readonly TranslatorInterface $translator,
) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity\Repository;

use AppBundle\Doctrine\EntityRepository;
use AppBundle\Event\Entity\TalkToSpeaker;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;
use Doctrine\Persistence\ManagerRegistry;
use Webmozart\Assert\Assert;

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

public function getNumberOfSpeakers(Event|int $event, ?\DateTime $since = null): int
{
if ($event instanceof Event) {
$event = $event->getId() ?? 0;
}

$queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder()
->select('COUNT(DISTINCT tts.conferencier_id)')
->from('afup_conferenciers_sessions', 'tts')
->innerJoin('tts', 'afup_sessions', 's', 'tts.session_id = s.session_id')
->where('s.id_forum = :event')
->setParameter('event', $event);

if ($since instanceof \DateTime) {
$queryBuilder->andWhere('s.date_soumission >= :since')
->setParameter('since', $since->format('Y-m-d'));
}

$count = $queryBuilder->executeQuery()->fetchOne();
Assert::numeric($count);

return (int) $count;
}

/**
* @param Speaker[] $speakers
*/
public function replaceSpeakers(Talk $talk, array $speakers): void
{
$talkId = $talk->getId();
Assert::notNull($talkId);

$targetSpeakerIds = [];
foreach ($speakers as $speaker) {
$speakerId = $speaker->getId();
Assert::notNull($speakerId);
$targetSpeakerIds[$speakerId] = $speakerId;
}

$entityManager = $this->getEntityManager();
$existingSpeakerIds = [];
foreach ($this->findBy(['talkId' => $talkId]) as $talkToSpeaker) {
$existingSpeakerIds[$talkToSpeaker->speakerId] = $talkToSpeaker->speakerId;
if (!isset($targetSpeakerIds[$talkToSpeaker->speakerId])) {
$entityManager->remove($talkToSpeaker);
}
}

foreach (array_diff_key($targetSpeakerIds, $existingSpeakerIds) as $speakerId) {
$entityManager->persist($this->createTalkToSpeaker($talkId, $speakerId));
}

$entityManager->flush();
}

public function addSpeakerToTalk(Talk $talk, Speaker $speaker): void
{
$talkId = $talk->getId();
$speakerId = $speaker->getId();
Assert::notNull($talkId);
Assert::notNull($speakerId);

if ($this->find(['talkId' => $talkId, 'speakerId' => $speakerId]) !== null) {
return;
}

$entityManager = $this->getEntityManager();
$entityManager->persist($this->createTalkToSpeaker($talkId, $speakerId));
$entityManager->flush();
}

private function createTalkToSpeaker(int $talkId, int $speakerId): TalkToSpeaker
{
$talkToSpeaker = new TalkToSpeaker();
$talkToSpeaker->talkId = $talkId;
$talkToSpeaker->speakerId = $speakerId;

return $talkToSpeaker;
}
}
21 changes: 21 additions & 0 deletions sources/AppBundle/Event/Entity/TalkToSpeaker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity;

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

#[ORM\Entity(repositoryClass: TalkToSpeakerRepository::class)]
#[ORM\Table(name: 'afup_conferenciers_sessions')]
class TalkToSpeaker
{
#[ORM\Id]
#[ORM\Column(name: 'session_id')]
public int $talkId;

#[ORM\Id]
#[ORM\Column(name: 'conferencier_id')]
public int $speakerId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace AppBundle\Event\Model\Repository;

use AppBundle\Event\Entity\Repository\TalkToSpeakerRepository;
use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\EventStats\CFPStats;
use AppBundle\Event\Model\EventStats\SalesPilotage;
Expand All @@ -26,7 +27,7 @@ class EventStatsRepository
public function __construct(
private readonly Connection $connection,
private readonly TalkRepository $talkRepository,
private readonly TalkToSpeakersRepository $talkToSpeakersRepository,
private readonly TalkToSpeakerRepository $talkToSpeakersRepository,
private readonly EventRepository $eventRepository,
) {}

Expand Down

This file was deleted.

Loading
Loading