Configurable PDF exports (#5641)

This commit is contained in:
Kevin Papst
2025-09-23 18:32:31 +02:00
committed by GitHub
parent 5d3e46cce2
commit 6d78c6ba36
107 changed files with 2428 additions and 1575 deletions

View File

@@ -12,22 +12,71 @@ namespace App\Form;
use App\Entity\ExportTemplate;
use App\Form\Type\ExportColumnsType;
use App\Form\Type\ExportRendererType;
use App\Form\Type\ExportSummaryColumnsType;
use App\Form\Type\LanguageType;
use App\Form\Type\PdfFontType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Length;
class ExportTemplateSpreadsheetForm extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('title', TextType::class);
$builder->add('title', TextType::class, ['label' => 'name']);
$builder->add('renderer', ExportRendererType::class, ['label' => 'type']);
$builder->add('language', LanguageType::class, ['required' => false]);
$builder->add('columns', ExportColumnsType::class, ['required' => true]);
$builder->add('separator', ChoiceType::class, ['choices' => ['Comma (,)' => ',', 'Semicolon (;)' => ';'], 'required' => true]);
$builder->add('separator', ChoiceType::class, [
'choices' => ['Comma (,)' => ',', 'Semicolon (;)' => ';'],
'row_attr' => ['data-type' => 'csv'],
'required' => true,
]);
$builder->add('name', TextType::class, [
'label' => 'title',
'constraints' => [new Length(max: 100)],
'attr' => ['maxlength' => 100],
'row_attr' => ['data-type' => 'pdf'],
'required' => false,
]);
$builder->add('summaryColumns', ExportSummaryColumnsType::class, [
'row_attr' => ['data-type' => 'pdf'],
'required' => false,
]);
$builder->add('font', PdfFontType::class, [
'row_attr' => ['data-type' => 'pdf'],
'required' => false,
]);
$builder->add('pageSize', ChoiceType::class, [
'label' => 'pageSize',
'choices' => [
'A4' => 'A4',
'A5' => 'A5',
'A6' => 'A6',
'Legal' => 'Legal',
'Letter' => 'Letter',
],
'row_attr' => ['data-type' => 'pdf'],
'required' => false,
]);
$builder->add('orientation', ChoiceType::class, [
'label' => 'orientation',
'choices' => [
'portrait' => 'portrait',
'landscape' => 'landscape',
],
'row_attr' => ['data-type' => 'pdf'],
'required' => false,
]);
}
public function configureOptions(OptionsResolver $resolver): void

View File

@@ -18,7 +18,11 @@ final class ExportRendererType extends AbstractType
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'choices' => ['button.csv' => 'csv', 'button.xlsx' => 'xlsx'],
'choices' => [
'button.csv' => 'csv',
'button.xlsx' => 'xlsx',
'button.pdf' => 'pdf'
],
]);
}

View File

@@ -0,0 +1,47 @@
<?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\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
final class ExportSummaryColumnsType extends AbstractType
{
public function __construct(
private readonly TranslatorInterface $translator,
)
{
}
public function configureOptions(OptionsResolver $resolver): void
{
$columns = [
$this->translator->trans('duration') . ' (1:30)' => 'duration',
$this->translator->trans('duration') . ' (1.5)' => 'duration_decimal',
'rate' => 'rate',
'internalRate' => 'internal_rate',
\sprintf('%s (%s)', $this->translator->trans('remaining_budget'), $this->translator->trans('budget')) => 'project_budget_money',
\sprintf('%s (%s)', $this->translator->trans('remaining_budget'), $this->translator->trans('timeBudget')) => 'project_budget_time',
];
$resolver->setDefaults([
'choices' => $columns,
'label' => 'export.summary',
'multiple' => true,
]);
}
public function getParent(): string
{
return ChoiceType::class;
}
}

View File

@@ -0,0 +1,48 @@
<?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\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
final class PdfFontType extends AbstractType
{
public const AVAILABLE_FONTS = [
'times', 'serif', 'helvetica', 'sans', 'courier', 'monospace', 'mono', 'sans-serif',
'dejavusanscondensed', 'dejavusans', 'dejavuserif', 'dejavuserifcondensed', 'dejavusansmono',
'freesans', 'freeserif', ' freemono',
// needed for: japanese + hebrew, cyrillic
'sun-exta', 'unbatang'
// deactivated for now, maybe later
// 'ocrb', 'abyssinicasil', 'aboriginalsans', 'jomolhari', 'taiheritagepro', 'aegean', 'aegyptus', 'akkadian',
// 'quivira', 'lannaalif', 'daibannasilbook', 'garuda', 'khmeros', 'dhyana', 'tharlon',
// 'padaukbook', 'zawgyi-one', 'ayar', 'taameydavidclm', 'mph2bdamase', 'briyaz', 'lateef',
];
public function configureOptions(OptionsResolver $resolver): void
{
$columns = [];
foreach (self::AVAILABLE_FONTS as $font) {
$columns[ucfirst($font)] = $font;
}
$resolver->setDefaults([
'choices' => $columns,
'label' => 'font',
'multiple' => false,
]);
}
public function getParent(): string
{
return ChoiceType::class;
}
}