feat: dedicated list view for document batch downloading

This commit is contained in:
Björn Fromme
2025-02-01 11:42:21 +01:00
parent 3f839f9082
commit 24c8c46ca4
7 changed files with 195 additions and 18 deletions
@@ -8,7 +8,6 @@ use App\Service\Upload\UploadHandler;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\HeaderUtils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\Routing\Attribute\Route;
@@ -32,9 +31,9 @@ class BatchDownloadController extends AbstractController
defaults: ['type' => Upload::TYPE_INVOICE]
)]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function index(string $type, Request $request): Response
public function index(string $type): Response
{
$status = $request->query->get('status', Upload::STATUS_PAID);
$status = Upload::TYPE_INVOICE === $type ? Upload::STATUS_PAID : Upload::STATUS_CHECKED;
$uploads = $this
->uploadRepository
@@ -47,7 +46,7 @@ class BatchDownloadController extends AbstractController
return $this->redirectToRoute('app_administrative_document_index');
}
$zipFilename = sprintf('Honorarnoten_%s.zip', date('YmdHi'));
$zipFilename = sprintf('%ss_%s.zip', $type, date('YmdHi'));
$response = new StreamedResponse(function () use ($uploads, $zipFilename) {
$zip = new ZipStream(
@@ -2,6 +2,8 @@
namespace App\Controller\Administrative\Document;
use App\Entity\Upload;
use App\Model\DocumentFilterDto;
use App\Repository\UploadRepository;
use App\Service\Common\DocumentFilterHandler;
use Knp\Component\Pager\PaginatorInterface;
@@ -42,4 +44,32 @@ class IndexController extends AbstractController
'filterDto' => $filterDto,
]);
}
#[Route(
path: '/administrative/document/accepted/{type}',
name: 'app_administrative_document_accepted',
defaults: ['type' => Upload::TYPE_INVOICE]
)]
#[IsGranted('ROLE_ADMINISTRATIVE')]
public function accepted(string $type, Request $request): Response
{
$status = Upload::TYPE_INVOICE === $type ? Upload::STATUS_PAID : Upload::STATUS_CHECKED;
$query = $this
->uploadRepository
->getBatchDownloadListQuery($type, $status)
;
$pagination = $this->paginator->paginate(
$query,
$request->query->getInt('page', 1),
$request->query->getInt('limit', 50),
);
return $this->render('administrative/document/accepted.html.twig', [
'pagination' => $pagination,
'type' => $type,
'status' => $status,
]);
}
}
+8 -6
View File
@@ -33,12 +33,14 @@ class DownloadController extends AbstractController
$inline = (bool) $request->get('inline');
$disposition = $inline ? ResponseHeaderBag::DISPOSITION_INLINE : ResponseHeaderBag::DISPOSITION_ATTACHMENT;
// mark file downloaded
$upload
->setDownloaded()
->setDownloadedBy($this->getUser()->getUserIdentifier())
;
$this->entityManager->flush();
// mark file downloaded if applicable
if ($this->isGranted('ROLE_ADMINISTRATIVE' && false === $inline)) {
$upload
->setDownloaded()
->setDownloadedBy($this->getUser()->getUserIdentifier())
;
$this->entityManager->flush();
}
$this->logger->info('Download file', [
'file_id' => $upload->getId(),