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
66 changes: 0 additions & 66 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -4483,54 +4483,12 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/Speaker/SuggestionAction.php',
];
$ignoreErrors[] = [
'message' => '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\\.$#',
'identifier' => 'foreach.nonIterable',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/ExportAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'created_on\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/ExportAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'email\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/ExportAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'nom\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/ExportAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'prenom\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/ExportAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot call method format\\(\\) on DateTime\\|null\\.$#',
'identifier' => 'method.nonObject',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/ExportAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$sponsorTicketId of method AppBundle\\\\Event\\\\Model\\\\SponsorScan\\:\\:setSponsorTicketId\\(\\) expects int, int\\|null given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/FlashAction.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$ticketId of method AppBundle\\\\Event\\\\Model\\\\SponsorScan\\:\\:setTicketId\\(\\) expects int, int\\|null given\\.$#',
'identifier' => 'argument.type',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Controller/Event/SponsorScan/FlashAction.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access offset \'code\' on mixed\\.$#',
'identifier' => 'offsetAccess.nonOffsetAccessible',
Expand Down Expand Up @@ -6649,30 +6607,6 @@
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/SpeakerSuggestionRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\SponsorScanRepository\\:\\:getBySponsorTicket\\(\\) has no return type specified\\.$#',
'identifier' => 'missingType.return',
'count' => 1,
'path' => __DIR__ . '/sources/AppBundle/Event/Model/Repository/SponsorScanRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\SponsorScanRepository\\:\\: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/SponsorScanRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\SponsorScanRepository\\:\\: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/SponsorScanRepository.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/SponsorScanRepository.php',
];
$ignoreErrors[] = [
'message' => '#^Method AppBundle\\\\Event\\\\Model\\\\Repository\\\\SponsorTicketRepository\\:\\:getByEvent\\(\\) return type with generic interface CCMBenchmark\\\\Ting\\\\Repository\\\\CollectionInterface does not specify its types\\: T$#',
'identifier' => 'missingType.generics',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use AppBundle\Controller\Event\EventActionHelper;
use AppBundle\Controller\Exception\InvalidSponsorTokenException;
use AppBundle\Event\Model\Repository\SponsorScanRepository;
use AppBundle\Event\Entity\Repository\SponsorScanRepository;
use AppBundle\Event\Entity\SponsorScan;
use AppBundle\Event\Model\Repository\SponsorTicketRepository;
use AppBundle\Event\Model\SponsorScan;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

Expand All @@ -32,10 +32,10 @@ public function __invoke(Request $request, string $eventSlug, string $scanId): R
return $this->redirectToRoute('sponsor_ticket_home', ['eventSlug' => $eventSlug]);
}

$scan = $this->sponsorScanRepository->getOneBy(['sponsorTicketId' => $sponsorTicket->getId(), 'id' => $scanId]);
$scan = $this->sponsorScanRepository->findOneBy(['sponsorTicketId' => $sponsorTicket->getId(), 'id' => (int) $scanId]);

if ($scan instanceof SponsorScan) {
$scan->setDeletedOn(new \DateTime('now'));
$scan->deletedOn = new \DateTimeImmutable('now');
$this->sponsorScanRepository->save($scan);
$this->addFlash('success', "QR Code supprimé !");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use AppBundle\Controller\Event\EventActionHelper;
use AppBundle\Controller\Exception\InvalidSponsorTokenException;
use AppBundle\Event\Model\Repository\SponsorScanRepository;
use AppBundle\Event\Entity\Repository\SponsorScanRepository;
use AppBundle\Event\Model\Repository\SponsorTicketRepository;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down
33 changes: 24 additions & 9 deletions sources/AppBundle/Controller/Event/SponsorScan/FlashAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

use AppBundle\Controller\Event\EventActionHelper;
use AppBundle\Controller\Exception\InvalidSponsorTokenException;
use AppBundle\Event\Model\Repository\SponsorScanRepository;
use AppBundle\Event\Entity\Repository\SponsorScanRepository;
use AppBundle\Event\Entity\SponsorScan;
use AppBundle\Event\Model\Repository\SponsorTicketRepository;
use AppBundle\Event\Model\Repository\TicketRepository;
use AppBundle\Event\Model\SponsorScan;
use AppBundle\Event\Model\SponsorTicket;
use AppBundle\Event\Model\Ticket;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;

Expand Down Expand Up @@ -42,25 +44,38 @@ public function __invoke(Request $request, string $code, string $eventSlug): Red
return $this->redirectToRoute('sponsor_scan', ['eventSlug' => $eventSlug]);
}

$scan = $this->sponsorScanRepository->getOneBy(['sponsorTicketId' => $sponsorTicket->getId(), 'ticketId' => $ticket->getId()]);
$scan = $this->sponsorScanRepository->findOneBy(['sponsorTicketId' => $sponsorTicket->getId(), 'ticketId' => $ticket->getId()]);

if ($scan instanceof SponsorScan && $scan->getDeletedOn() === null) {
if ($scan instanceof SponsorScan && $scan->deletedOn === null) {
$this->addFlash('error', 'Code déjà scanné.');
return $this->redirectToRoute('sponsor_scan', ['eventSlug' => $eventSlug]);
}

if (!$scan instanceof SponsorScan) {
$scan = new SponsorScan()
->setSponsorTicketId($sponsorTicket->getId())
->setTicketId($ticket->getId());
$scan = $this->createSponsorScan($sponsorTicket, $ticket);
}

$scan->setCreatedOn(new \DateTime('now'))
->setDeletedOn(null);
$scan->createdOn = new \DateTimeImmutable('now');
$scan->deletedOn = null;
$this->sponsorScanRepository->save($scan);

$this->addFlash('success', 'QR Code ajouté !');

return $this->redirectToRoute('sponsor_scan', ['eventSlug' => $eventSlug]);
}

private function createSponsorScan(SponsorTicket $sponsorTicket, Ticket $ticket): SponsorScan
{
$sponsorTicketId = $sponsorTicket->getId();
$ticketId = $ticket->getId();
if ($sponsorTicketId === null || $ticketId === null) {
throw new \InvalidArgumentException('Le ticket sponsor et le billet doivent être enregistrés');
}

$scan = new SponsorScan();
$scan->sponsorTicketId = $sponsorTicketId;
$scan->ticketId = $ticketId;

return $scan;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use AppBundle\Controller\Event\EventActionHelper;
use AppBundle\Controller\Exception\InvalidSponsorTokenException;
use AppBundle\Event\Model\Repository\SponsorScanRepository;
use AppBundle\Event\Entity\Repository\SponsorScanRepository;
use AppBundle\Event\Model\Repository\SponsorTicketRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace AppBundle\Event\Entity\Repository;

use AppBundle\Doctrine\EntityRepository;
use AppBundle\Event\Entity\SponsorScan;
use AppBundle\Event\Model\SponsorTicket;
use Doctrine\Persistence\ManagerRegistry;

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

/**
* Liste des scans actifs d'un ticket sponsor, avec les informations du billet scanné.
*
* @return list<array<string, mixed>>
*/
public function getBySponsorTicket(SponsorTicket $sponsorTicket): array
{
$sponsorTicketId = $sponsorTicket->getId();
if ($sponsorTicketId === null) {
throw new \InvalidArgumentException('Le ticket sponsor doit être enregistré');
}

$queryBuilder = $this->getEntityManager()->getConnection()->createQueryBuilder()
->select('scan.id', 'inscription.nom', 'inscription.prenom', 'inscription.email', 'scan.created_on')
->from('afup_forum_sponsor_scan', 'scan')
->innerJoin('scan', 'afup_inscription_forum', 'inscription', 'inscription.id = scan.ticket_id')
->where('scan.sponsor_ticket_id = :sponsorTicketId')
->andWhere('scan.deleted_on IS NULL')
->orderBy('scan.created_on', 'DESC')
->setParameter('sponsorTicketId', $sponsorTicketId);

/** @var list<array<string, mixed>> $scans */
$scans = $queryBuilder->executeQuery()->fetchAllAssociative();

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

declare(strict_types=1);

namespace AppBundle\Event\Entity;

use AppBundle\Event\Entity\Repository\SponsorScanRepository;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: SponsorScanRepository::class)]
#[ORM\Table(name: 'afup_forum_sponsor_scan')]
class SponsorScan
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
public int $id;

#[ORM\Column(name: 'sponsor_ticket_id', nullable: false)]
public int $sponsorTicketId;

#[ORM\Column(name: 'ticket_id', nullable: false)]
public int $ticketId;

#[ORM\Column(name: 'created_on', type: 'datetime_immutable', nullable: false)]
public DateTimeImmutable $createdOn;

#[ORM\Column(name: 'deleted_on', type: 'datetime_immutable', nullable: true)]
public ?DateTimeImmutable $deletedOn = null;
}

This file was deleted.

Loading
Loading