mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Allow to export all attachment_types via the new element dialog.
This commit is contained in:
parent
70c12e47a2
commit
a46bcd229b
2 changed files with 75 additions and 2 deletions
|
@ -33,6 +33,7 @@ namespace App\Controller;
|
|||
|
||||
|
||||
use App\Entity\AttachmentType;
|
||||
use App\Entity\NamedDBElement;
|
||||
use App\Entity\StructuralDBElement;
|
||||
use App\Form\BaseEntityAdminForm;
|
||||
use App\Form\ExportType;
|
||||
|
@ -73,6 +74,7 @@ class AttachmentTypeController extends AbstractController
|
|||
|
||||
/**
|
||||
* @Route("/new", name="attachment_type_new")
|
||||
* @Route("/")
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
|
@ -126,7 +128,7 @@ class AttachmentTypeController extends AbstractController
|
|||
}
|
||||
|
||||
/**
|
||||
* @Route("/export")
|
||||
* @Route("/export", name="attachment_type_export_all")
|
||||
* @param Request $request
|
||||
* @param SerializerInterface $serializer
|
||||
* @param EntityManagerInterface $em
|
||||
|
@ -198,7 +200,22 @@ class AttachmentTypeController extends AbstractController
|
|||
|
||||
//If view option is not specified, then download the file.
|
||||
if (!$request->get('view')) {
|
||||
$filename = "export_" . $entity->getName() . "_" . $level . "." . $format;
|
||||
if ($entity instanceof NamedDBElement) {
|
||||
$entity_name = $entity->getName();
|
||||
} elseif (is_array($entity)) {
|
||||
if (empty($entity)) {
|
||||
throw new \InvalidArgumentException('$entity must not be empty!');
|
||||
}
|
||||
|
||||
//Use the class name of the first element for the filename
|
||||
$reflection = new \ReflectionClass($entity[0]);
|
||||
$entity_name = $reflection->getShortName();
|
||||
} else {
|
||||
throw new \InvalidArgumentException('$entity type is not supported!');
|
||||
}
|
||||
|
||||
|
||||
$filename = "export_" . $entity_name . "_" . $level . "." . $format;
|
||||
|
||||
// Create the disposition of the file
|
||||
$disposition = $response->headers->makeDisposition(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue