feat: streamlined filenames of downloaded teamer documents

addresses #8698updx6
This commit is contained in:
Björn Fromme
2025-04-24 10:03:29 +02:00
parent fb0f8054d5
commit 3646661fed
3 changed files with 52 additions and 14 deletions
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace App\Service\Upload;
use App\Entity\Teamer;
use App\Entity\Upload;
use Symfony\Component\String\Slugger\AsciiSlugger;
class DownloadNamer
{
public function nameForTeamer(Upload $upload, Teamer $teamer): string
{
$pattern = match($upload->getType()) {
Upload::TYPE_INVOICE => 'hn-%d-%s-%s.pdf',
Upload::TYPE_CONTRACT => 'hv-%d-%s-%s.pdf',
default => null,
};
if (null === $pattern) {
return $upload->getOriginalFilename();
}
$slugger = new AsciiSlugger('de');
$teamerName = strtolower($slugger->slug($teamer->getFullName(true), '_'));
return sprintf(
$pattern,
$upload->getId(),
$teamerName,
$upload->getCreatedAt()->format('Ymd')
);
}
}