WIP: Implement teamer document upload handling
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/delete/{uuid}', name: 'app_admin_document_delete')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
#[IsGranted('DELETE', subject: 'document')]
|
||||
public function index(Upload $document): Response
|
||||
{
|
||||
$this->entityManager->remove($document);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Das Dokument wurde gelöscht');
|
||||
$this->logger->info('Delete document', [
|
||||
'document' => $document->getOriginalFilename(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_admin_document_index');
|
||||
}
|
||||
}
|
||||
@@ -22,14 +22,17 @@ class IndexController extends AbstractController
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = $this->uploadRepository->getDocumentListQuery();
|
||||
$query = $this
|
||||
->uploadRepository
|
||||
->getUploadListQuery()
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$request->query->getInt('page', 1),
|
||||
10,
|
||||
[
|
||||
'defaultSortFieldName' => 'upload.originalFilename',
|
||||
'defaultSortFieldName' => 'upload.createdAt',
|
||||
'defaultSortDirection' => 'asc',
|
||||
]
|
||||
);
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class RenameController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/rename/{uuid}', name: 'app_admin_document_rename')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_rename', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder($upload, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->add('displayName', TextType::class, [
|
||||
'label' => 'angezeigter Name',
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Das Dokument wurden umbenannt');
|
||||
$this->logger->info('Rename document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/rename.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class ReplaceController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/replace/{uuid}', name: 'app_admin_document_replace')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
// Handle upload independently from form submission to avoid issues with failing validation
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
if (true === $request->isMethod('POST') && 0 < $uploadSession->getCount()) {
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_DOCUMENT, $upload);
|
||||
$this->entityManager->flush();
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_DOCUMENT, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
}
|
||||
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_replace', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->addFlash('success', 'Das Dokument wurden ersetzt');
|
||||
$this->logger->info('Replace document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/replace.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class UploadController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/upload', name: 'app_admin_document_upload')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
// Handle upload independently from form submission to avoid issues with failing validation
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
if (true === $request->isMethod('POST') && 0 < $uploadSession->getCount()) {
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
foreach ($uploadSession->getUploads() as $upload) {
|
||||
$document = Upload::fromUploadDto($upload, $user, Upload::TYPE_DOCUMENT);
|
||||
$this->entityManager->persist($document);
|
||||
}
|
||||
$this->entityManager->flush();
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_DOCUMENT, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
}
|
||||
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_upload');
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->addFlash('success', 'Das/die Dokument/e wurden hochgeladen');
|
||||
$this->logger->info('Upload document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/upload.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user