This commit is contained in:
2025-05-19 22:29:56 +02:00
parent 58bda32f09
commit e0350c8c31
26 changed files with 295 additions and 34 deletions

View File

@@ -2,3 +2,4 @@
###> symfony/framework-bundle ###
APP_SECRET=e26b9552d9e7f969b160373effaa7690
###< symfony/framework-bundle ###
MAILER_SENDER=info@tijdvoordetest.nl

View File

@@ -36,12 +36,12 @@ jobs:
run: docker compose up --wait --no-build
- name: Coding Style
run: docker compose exec -T php vendor/bin/php-cs-fixer check --diff --show-progress=none
- name: Twig Coding Style
run: docker compose exec -T php vendor/bin/twig-cs-fixer check
- name: Check HTTP reachability
run: curl -v --fail-with-body http://localhost
- name: Check HTTPS reachability
if: false # Remove this line when the homepage will be configured, or change the path to check
run: curl -vk --fail-with-body https://localhost
- name: Check Mercure reachability
if: false
run: curl -vkI --fail-with-body https://localhost/.well-known/mercure?topic=test
- name: Create test database
run: docker compose exec -T php bin/console -e test doctrine:database:create

View File

@@ -33,7 +33,7 @@ RUN set -eux; \
zip \
uuid \
gd \
excimer \
excimer-1.2.3 \
;
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser

View File

@@ -12,9 +12,6 @@ services:
MERCURE_URL: ${CADDY_MERCURE_URL:-http://php/.well-known/mercure}
MERCURE_PUBLIC_URL: ${CADDY_MERCURE_PUBLIC_URL:-https://${SERVER_NAME:-localhost}/.well-known/mercure}
MERCURE_JWT_SECRET: ${CADDY_MERCURE_JWT_SECRET:-!ChangeThisMercureHubJWTSecretKey!}
# The two next lines can be removed after initial installation
SYMFONY_VERSION: ${SYMFONY_VERSION:-}
STABILITY: ${STABILITY:-stable}
volumes:
- caddy_data:/data
- caddy_config:/config

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250504101440 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE UNIQUE INDEX UNIQ_C8B28E445E237E064EC001D1 ON candidate (name, season_id)
SQL);
$this->addSql(<<<'SQL'
CREATE UNIQUE INDEX UNIQ_A412FA925E237E064EC001D1 ON quiz (name, season_id)
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
DROP INDEX UNIQ_A412FA925E237E064EC001D1
SQL);
$this->addSql(<<<'SQL'
DROP INDEX UNIQ_C8B28E445E237E064EC001D1
SQL);
}
}

View File

@@ -30,5 +30,4 @@ return RectorConfig::configure()
)
->withAttributesSets(all: true)
->withComposerBased(twig: true, doctrine: true, phpunit: true, symfony: true)
->withAttributesSets()
;

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace App\Command;
use App\Repository\SeasonRepository;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'app:claim-season',
description: 'Give a user owner rights on a season',
)]
class ClaimSeasonCommand extends Command
{
public function __construct(
private readonly UserRepository $userRepository,
private readonly SeasonRepository $seasonRepository,
private readonly EntityManagerInterface $entityManager)
{
parent::__construct();
}
protected function configure(): void
{
$this
->addArgument('email', InputArgument::REQUIRED, 'The email of the user to make admin')
->addArgument('season', InputArgument::REQUIRED, 'The season to claim')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$email = $input->getArgument('email');
$seasonCode = $input->getArgument('season');
try {
$season = $this->seasonRepository->findOneBy(['seasonCode' => $seasonCode]);
if (null === $season) {
throw new \InvalidArgumentException('Season not found');
}
$user = $this->userRepository->findOneBy(['email' => $email]);
if (null === $user) {
throw new \InvalidArgumentException('User not found');
}
$season->addOwner($user);
$this->entityManager->flush();
} catch (\InvalidArgumentException $invalidArgumentException) {
$io->error($invalidArgumentException->getMessage());
return Command::FAILURE;
}
return Command::SUCCESS;
}
}

View File

@@ -26,7 +26,7 @@ class MakeAdminCommand extends Command
protected function configure(): void
{
$this
->addArgument('email', InputArgument::OPTIONAL, 'The email of the user to make admin')
->addArgument('email', InputArgument::REQUIRED, 'The email of the user to make admin')
;
}

View File

@@ -87,6 +87,7 @@ final class BackofficeController extends AbstractController
}
#[Route('/backoffice/{seasonCode}/{quiz}', name: 'app_backoffice_quiz')]
#[IsGranted(SeasonVoter::EDIT, subject: 'season')]
public function quiz(Season $season, Quiz $quiz): Response
{
return $this->render('backoffice/quiz.html.twig', [
@@ -98,7 +99,7 @@ final class BackofficeController extends AbstractController
#[Route('/backoffice/{seasonCode}/{quiz}/enable', name: 'app_backoffice_enable')]
#[IsGranted(SeasonVoter::EDIT, subject: 'season')]
public function enableQuiz(Season $season, Quiz $quiz, EntityManagerInterface $em): Response
public function enableQuiz(Season $season, ?Quiz $quiz, EntityManagerInterface $em): Response
{
$season->setActiveQuiz($quiz);
$em->flush();
@@ -107,6 +108,7 @@ final class BackofficeController extends AbstractController
}
#[Route('/backoffice/{seasonCode}/add_candidate', name: 'app_backoffice_add_candidates', priority: 10)]
#[IsGranted(SeasonVoter::EDIT, subject: 'season')]
public function addCandidates(Season $season, Request $request, EntityManagerInterface $em): Response
{
$form = $this->createForm(AddCandidatesFormType::class);
@@ -114,9 +116,10 @@ final class BackofficeController extends AbstractController
if ($form->isSubmitted() && $form->isValid()) {
$candidates = $form->get('candidates')->getData();
foreach (explode("\r\n", $candidates) as $candidate) {
foreach (explode("\r\n", (string) $candidates) as $candidate) {
$season->addCandidate(new Candidate($candidate));
}
$em->flush();
return $this->redirectToRoute('app_backoffice_season', ['seasonCode' => $season->getSeasonCode()]);
@@ -126,6 +129,7 @@ final class BackofficeController extends AbstractController
}
#[Route('/backoffice/{seasonCode}/add', name: 'app_backoffice_quiz_add', priority: 10)]
#[IsGranted(SeasonVoter::EDIT, subject: 'season')]
public function addQuiz(Request $request, Season $season, QuizSpreadsheetService $quizSpreadsheet, EntityManagerInterface $em): Response
{
$quiz = new Quiz();

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Controller;
use App\Entity\Candidate;
use App\Entity\Season;
use App\Enum\FlashType;
use App\Helpers\Base64;
use App\Repository\CandidateRepository;
use App\Security\Voter\SeasonVoter;
use Symfony\Bridge\Doctrine\Attribute\MapEntity;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
use Symfony\Contracts\Translation\TranslatorInterface;
use function Symfony\Component\Translation\t;
#[AsController]
#[IsGranted('ROLE_USER')]
final class EliminationController extends AbstractController
{
public function __construct(private readonly TranslatorInterface $translator) {}
#[Route('/elimination/{seasonCode}', name: 'app_elimination')]
#[IsGranted(SeasonVoter::ELIMINATION, 'season')]
public function index(#[MapEntity] Season $season): Response
{
return $this->render('elimination/index.html.twig', [
'controller_name' => 'EliminationController',
]);
}
#[Route('/elimination/{seasonCode}/{candidateHash}', name: 'app_elimination_cadidate')]
#[IsGranted(SeasonVoter::ELIMINATION, 'season')]
public function candidateScreen(Season $season, string $candidateHash, CandidateRepository $candidateRepository): Response
{
$candidate = $candidateRepository->getCandidateByHash($season, $candidateHash);
if (!$candidate instanceof Candidate) {
$this->addFlash(FlashType::Warning,
t('Cound not find candidate with name %name%', ['%name%' => Base64::base64UrlDecode($candidateHash)])->trans($this->translator)
);
throw new \InvalidArgumentException('Candidate not found');
}
return $this->render('elimination/candidate.html.twig', [
'season' => $season,
'candidate' => $candidate,
]);
}
}

View File

@@ -4,17 +4,21 @@ declare(strict_types=1);
namespace App\Controller;
use App\Entity\Quiz;
use App\Entity\Season;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
final class PrepareEliminationController extends AbstractController
{
#[Route('/backoffice/elimination/prepare', name: 'app_prepare_elimination')]
public function index(): Response
#[Route('/backoffice/elimination/{seasonCode}/{quiz}/prepare', name: 'app_prepare_elimination')]
public function index(Season $season, Quiz $quiz): Response
{
return $this->render('prepare_elimination/index.html.twig', [
'controller_name' => 'PrepareEliminationController',
'season' => $season,
'quiz' => $quiz,
]);
}
}

View File

@@ -23,7 +23,7 @@ class Answer
private Uuid $id;
#[ORM\Column(type: Types::SMALLINT, options: ['default' => 0])]
private int $ordering;
private int $ordering = 0;
#[ORM\ManyToOne(inversedBy: 'answers')]
#[ORM\JoinColumn(nullable: false)]

View File

@@ -14,6 +14,7 @@ use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: CandidateRepository::class)]
#[ORM\UniqueConstraint(fields: ['name', 'season'])]
class Candidate
{
#[ORM\Id]

View File

@@ -20,6 +20,10 @@ class Elimination
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private Uuid $id;
#[ORM\ManyToOne(inversedBy: 'eliminations')]
#[ORM\JoinColumn(nullable: false)]
private Quiz $quiz;
/** @var array<string, mixed> */
#[ORM\Column(type: Types::JSON)]
private array $data = [];
@@ -42,4 +46,16 @@ class Elimination
return $this;
}
public function setQuiz(Quiz $quiz): self
{
$this->quiz = $quiz;
return $this;
}
public function getQuiz(): Quiz
{
return $this->quiz;
}
}

View File

@@ -13,6 +13,7 @@ use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: QuizRepository::class)]
#[ORM\UniqueConstraint(fields: ['name', 'season'])]
class Quiz
{
#[ORM\Id]
@@ -40,10 +41,15 @@ class Quiz
#[ORM\Column(nullable: true)]
private ?int $dropouts = null;
/** @var Collection<int, Elimination> */
#[ORM\OneToMany(targetEntity: Elimination::class, mappedBy: 'quiz', cascade: ['persist'], orphanRemoval: true)]
private Collection $eliminations;
public function __construct()
{
$this->questions = new ArrayCollection();
$this->corrections = new ArrayCollection();
$this->eliminations = new ArrayCollection();
}
public function getId(): ?Uuid
@@ -118,4 +124,17 @@ class Quiz
return $this;
}
/** @return Collection<int, Elimination> */
public function getEliminations(): Collection
{
return $this->eliminations;
}
public function addElimination(Elimination $elimination): self
{
$this->eliminations->add($elimination);
return $this;
}
}

View File

@@ -35,6 +35,7 @@ class Season
/** @var Collection<int, Candidate> */
#[ORM\OneToMany(targetEntity: Candidate::class, mappedBy: 'season', cascade: ['persist'], orphanRemoval: true)]
#[ORM\OrderBy(['name' => 'ASC'])]
private Collection $candidates;
/** @var Collection<int, User> */

View File

@@ -7,6 +7,7 @@ namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Types\UuidType;
@@ -31,7 +32,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
private string $email;
/** @var list<string> The user roles */
#[ORM\Column]
#[ORM\Column(type: Types::JSON)]
private array $roles = [];
/** @var string The hashed password */

View File

@@ -14,11 +14,13 @@ final class SeasonVoter extends Voter
{
public const string EDIT = 'SEASON_EDIT';
public const string ELIMINATION = 'SEASON_ELIMINATION';
public const string DELETE = 'SEASON_DELETE';
protected function supports(string $attribute, mixed $subject): bool
{
return \in_array($attribute, [self::EDIT, self::DELETE], true)
return \in_array($attribute, [self::EDIT, self::DELETE, self::ELIMINATION], true)
&& $subject instanceof Season;
}
@@ -34,16 +36,9 @@ final class SeasonVoter extends Voter
return true;
}
switch ($attribute) {
case self::EDIT:
case self::DELETE:
if ($subject->isOwner($user)) {
return true;
}
break;
}
return false;
return match ($attribute) {
self::EDIT, self::DELETE, self::ELIMINATION => $subject->isOwner($user),
default => false,
};
}
}

View File

@@ -94,6 +94,7 @@ class QuizSpreadsheetService
if (1 === $answerCounter) {
$errors[] = \sprintf('Question %d has no answers', $answerCounter);
}
break;
}

View File

@@ -1,6 +1,6 @@
<nav class="navbar navbar-expand-lg bg-body-tertiary">
<div class="container-fluid">
<a class="navbar-brand" href="#">Tijd voor de test</a>
<a class="navbar-brand" href="{{ path('app_backoffice_index') }}">Tijd voor de test</a>
<button class="navbar-toggler"
type="button"
data-bs-toggle="collapse"

View File

@@ -2,8 +2,15 @@
{% block body %}
<h2 class="py-2">{{ 'Quiz'|trans }}: {{ quiz.season.name }} - {{ quiz.name }}</h2>
<a class="py-2 btn btn-primary {% if quiz is same as(season.activeQuiz) %}disabled{% endif %}"
href="{{ path('app_backoffice_enable', {seasonCode: season.seasonCode, quiz: quiz.id}) }}">{{ 'Make active'|trans }}</a>
<div class="py-2 btn-group">
<a class="btn btn-primary {% if quiz is same as(season.activeQuiz) %}disabled{% endif %}"
href="{{ path('app_backoffice_enable', {seasonCode: season.seasonCode, quiz: quiz.id}) }}">{{ 'Make active'|trans }}</a>
{% if quiz is same as (season.activeQuiz) %}
<a class="btn btn-secondary"
href="{{ path('app_backoffice_enable', {seasonCode: season.seasonCode, quiz: 'null'}) }}">{{ 'Deactivate Quiz'|trans }}</a>
{% endif %}
</div>
<div id="questions">
<h4 class="py-2">{{ 'Questions'|trans }}</h4>
<div class="accordion">
@@ -51,7 +58,8 @@
<a class="btn btn-primary">{{ 'Start Elimination'|trans }}</a>
</div>
<div class="btn-group btn-group-lg">
<a class="btn btn-secondary">{{ 'Prepare Custom Elimination'|trans }}</a>
<a href="{{ path('app_prepare_elimination', {seasonCode: season.seasonCode, quiz: quiz.id}) }}"
class="btn btn-secondary">{{ 'Prepare Custom Elimination'|trans }}</a>
<a class="btn btn-secondary">{{ 'Load Prepared Elimination'|trans }}</a>
</div>
</div>

View File

@@ -3,7 +3,7 @@
{% block body %}
<div class="row">
<div class="col-md-6 col-12">
<h2 class="py-2">{{ 'Add a quiz to '|trans }} {{ season.name }}</h2>
<h2 class="py-2">{{ t('Add a quiz to %name%', {'%name%': season.name})|trans }} </h2>
{{ form_start(form) }}
{{ form_row(form.name) }}
{{ form_row(form.sheet) }}

View File

@@ -0,0 +1,3 @@
{% block body %}
{% endblock %}

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<title>Hello EliminationController!</title>
{% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper">
<h1>Hello {{ controller_name }}! ✅</h1>
This friendly message is coming from:
<ul>
<li>Your controller at <code>/app/src/Controller/EliminationController.php</code></li>
<li>Your template at <code>/app/templates/elimination/index.html.twig</code></li>
</ul>
</div>
{% endblock %}

View File

@@ -0,0 +1,26 @@
{% extends 'backoffice/base.html.twig' %}
{% block body %}
<div class="row">
<nav aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{{ path('app_backoffice_index') }}">Home</a></li>
<li class="breadcrumb-item"><a
href="{{ path('app_backoffice_season', {seasonCode: season.seasonCode}) }}">{{ season.name }}</a>
</li>
<li class="breadcrumb-item"><a
href="{{ path('app_backoffice_quiz', {seasonCode: season.seasonCode, quiz: quiz.id}) }}">{{ quiz.name }}</a>
</li>
<li class="breadcrumb-item active" aria-current="page">Prepare Elimination</li>
</ol>
</nav>
</div>
<div class="row">
<div class="col-12 col-md-6">
</div>
<div class="col-12 col-md-6">
<p>Hier kan dus weer wat uitleg komen</p>
</div>
</div>
{% endblock %}

View File

@@ -1,7 +1,8 @@
'Active Quiz': 'Actieve test'
Add: Toevoegen
'Add Candidate': 'Voeg kandidaat toe'
'Add a quiz to': 'Voeg een test toe aan'
'Add Candidates': 'Voeg kandidaten toe'
'Add a quiz to %name%': 'Voeg een test toe aan %name%'
'All Seasons': 'Alle seizoenen'
'Already have an account? Log in': 'Heb je al een account? Log in'
Candidate: Kandidaat
@@ -9,8 +10,10 @@ Candidate: Kandidaat
Candidates: Kandidaten
'Correct Answers': 'Goede antwoorden'
Corrections: Jokers
'Cound not find candidate with name %name%': 'Kon kandidaat met naam %name% niet vinden'
'Create a season': 'Maak een seizoen aan'
'Create an account': 'Maak een account aan'
'Deactivate Quiz': 'Deactiveer test'
'Download Template': 'Download sjabloon'
Email: E-mail
'Enter your name': 'Voor je naam in'
@@ -42,7 +45,7 @@ Register: Registreren
Score: Score
Season: Seizoen
'Season Code': Seizoenscode
'Season Name': 'Seizoensnaam'
'Season Name': Seizoensnaam
Seasons: Seizoenen
'Sign in': 'Log in'
'Start Elimination': 'Start eliminatie'