Files
TijdVoorDeTest/src/Repository/CandidateRepository.php
T
Marijn 352e34a428 feat: add candidate rename and delete (#194)
Adds per-candidate rename and delete actions to the candidates tab,
guarded by confirmation modals since deletion also discards the
candidate's given answers.

Closes #18
2026-07-09 19:00:47 +02:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
namespace Tvdt\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Safe\Exceptions\UrlException;
use Tvdt\Entity\Candidate;
use Tvdt\Entity\Season;
use Tvdt\Helpers\Base64;
/** @extends ServiceEntityRepository<Candidate> */
class CandidateRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Candidate::class);
}
public function deleteCandidate(Candidate $candidate): void
{
$this->getEntityManager()->remove($candidate);
$this->getEntityManager()->flush();
}
public function getCandidateByHash(Season $season, string $hash): ?Candidate
{
try {
$name = Base64::base64UrlDecode($hash);
} catch (UrlException) {
return null;
}
return $this->getEntityManager()->createQuery(<<<DQL
select c from Tvdt\Entity\Candidate c
where c.season = :season
and lower(c.name) = lower(:name)
DQL
)->setParameter('season', $season)
->setParameter('name', $name)
->getOneOrNullResult();
}
}