configurable csv/xlsx export templates (#5531)

This commit is contained in:
Kevin Papst
2025-06-11 13:06:33 +02:00
committed by GitHub
parent 46129c7ab9
commit 05aaa1950a
83 changed files with 2632 additions and 412 deletions

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
#[\Attribute(\Attribute::TARGET_PROPERTY)]
final class ExportRenderer extends Constraint
{
public const UNKNOWN_TYPE = 'kimai-export-type-00';
protected const ERROR_NAMES = [
self::UNKNOWN_TYPE => 'Unknown exporter type.',
];
public string $message = 'Unknown exporter type.';
}

View File

@@ -0,0 +1,41 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
final class ExportRendererValidator extends ConstraintValidator
{
/**
* @param string|mixed $value
*/
public function validate(mixed $value, Constraint $constraint): void
{
if (!($constraint instanceof ExportRenderer)) {
throw new UnexpectedTypeException($constraint, ExportRenderer::class);
}
if ($value === null) {
return;
}
$ids = ['csv', 'xlsx'];
if (!\is_string($value) || !\in_array($value, $ids, true)) {
$this->context->buildViolation(ExportRenderer::getErrorName(ExportRenderer::UNKNOWN_TYPE))
->setParameter('{{ value }}', $this->formatValue($value))
->setTranslationDomain('validators')
->setCode(ExportRenderer::UNKNOWN_TYPE)
->addViolation();
}
}
}