Fixed entity export.

This commit is contained in:
Jan Böhmer 2020-02-23 19:45:06 +01:00
parent b6f95ebe48
commit 181e0f72ed
5 changed files with 30 additions and 9 deletions

View file

@ -92,6 +92,11 @@ services:
tags: tags:
- name: doctrine.orm.entity_listener - name: doctrine.orm.entity_listener
# Dont use JSONSerializable Interface,
serializer.normalizer.json_serializable:
class: Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer
tags:
- {name: serializer.normalizer, priority: -9000}
App\Controller\RedirectController: App\Controller\RedirectController:
arguments: arguments:

View file

@ -152,6 +152,7 @@ abstract class BaseAdminController extends AbstractController
'entity' => $entity, 'entity' => $entity,
'form' => $form->createView(), 'form' => $form->createView(),
'attachment_helper' => $this->attachmentHelper, 'attachment_helper' => $this->attachmentHelper,
'route_base' => $this->route_base,
]); ]);
} }
@ -264,6 +265,7 @@ abstract class BaseAdminController extends AbstractController
'import_form' => $import_form->createView(), 'import_form' => $import_form->createView(),
'mass_creation_form' => $mass_creation_form->createView(), 'mass_creation_form' => $mass_creation_form->createView(),
'attachment_helper' => $this->attachmentHelper, 'attachment_helper' => $this->attachmentHelper,
'route_base' => $this->route_base,
]); ]);
} }

View file

@ -85,7 +85,7 @@ class Part extends AttachmentContainingDBElement
/** /**
* TODO. * TODO.
*/ */
protected $devices; protected $devices = [];
/** /**
* @ColumnSecurity(type="datetime") * @ColumnSecurity(type="datetime")

View file

@ -43,6 +43,14 @@ declare(strict_types=1);
namespace App\Services; namespace App\Services;
use App\Entity\Base\AbstractNamedDBElement; use App\Entity\Base\AbstractNamedDBElement;
use Symfony\Component\Serializer\Encoder\CsvEncoder;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Encoder\YamlEncoder;
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use function in_array; use function in_array;
use InvalidArgumentException; use InvalidArgumentException;
use function is_array; use function is_array;
@ -62,6 +70,10 @@ class EntityExporter
public function __construct(SerializerInterface $serializer) public function __construct(SerializerInterface $serializer)
{ {
/*$encoders = [new XmlEncoder(), new JsonEncoder(), new CSVEncoder(), new YamlEncoder()];
$normalizers = [new ObjectNormalizer(), new DateTimeNormalizer()];
$this->serializer = new Serializer($normalizers, $encoders);
$this->serializer-> */
$this->serializer = $serializer; $this->serializer = $serializer;
} }
@ -120,13 +132,15 @@ class EntityExporter
$entity_array = [$entity]; $entity_array = [$entity];
} }
$response = new Response($this->serializer->serialize($entity_array, $format, $serialized_data = $this->serializer->serialize($entity_array, $format,
[ [
'groups' => $groups, 'groups' => $groups,
'as_collection' => true, 'as_collection' => true,
'csv_delimiter' => ';', //Better for Excel 'csv_delimiter' => ';', //Better for Excel
'xml_root_node_name' => 'PartDBExport', 'xml_root_node_name' => 'PartDBExport',
])); ]);
$response = new Response($serialized_data);
$response->headers->set('Content-Type', $content_type); $response->headers->set('Content-Type', $content_type);

View file

@ -132,7 +132,7 @@
{% if entity.id %} {% if entity.id %}
<div id="export" class="tab-pane fade"> <div id="export" class="tab-pane fade">
{% include 'AdminPages/_export_form.html.twig' with {'path' : path('attachment_type_export', {'id': entity.id})} %} {% include 'AdminPages/_export_form.html.twig' with {'path' : path(route_base ~ '_export', {'id': entity.id})} %}
</div> </div>
{% else %} {# For new element we have a combined import/export tab #} {% else %} {# For new element we have a combined import/export tab #}
<div id="import_export" class="tab-pane fade"> <div id="import_export" class="tab-pane fade">