mirror of
https://github.com/MarijnDoeve/TijdVoorDeTest.git
synced 2026-07-12 12:58:22 +02:00
352e34a428
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
46 lines
1.2 KiB
PHP
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();
|
|
}
|
|
}
|