-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathExport.php
More file actions
76 lines (61 loc) · 2.47 KB
/
Copy pathExport.php
File metadata and controls
76 lines (61 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin\Export;
use eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute;
use Netgen\Bundle\InformationCollectionBundle\Form\ExportType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Netgen\InformationCollection\API\Value\Export\ExportCriteria;
use Netgen\InformationCollection\API\Service\Exporter;
use Netgen\InformationCollection\Core\Export\ExportResponseFormatterRegistry;
use Symfony\Component\HttpFoundation\Request;
use eZ\Publish\API\Repository\ContentService;
final class Export extends AbstractController
{
/**
* @var \eZ\Publish\API\Repository\ContentService
*/
protected $contentService;
/**
* @var \Netgen\InformationCollection\API\Service\Exporter
*/
protected $exporter;
/**
* @var \Netgen\InformationCollection\Core\Export\ExportResponseFormatterRegistry
*/
protected $formatterRegistry;
public function __construct(
ContentService $contentService,
Exporter $exporter,
ExportResponseFormatterRegistry $formatterRegistry
)
{
$this->contentService = $contentService;
$this->exporter = $exporter;
$this->formatterRegistry = $formatterRegistry;
}
public function __invoke($contentId, Request $request)
{
$attribute = new Attribute('infocollector', 'export');
$this->denyAccessUnlessGranted($attribute);
$content = $this->contentService->loadContent($contentId);
$form = $this->createForm(ExportType::class, null, [
'contentId' => $content->id,
]);
$form->handleRequest($request);
if ($form->get('cancel')->isClicked()) {
return $this->redirect($this->generateUrl('netgen_information_collection.route.admin.collection_list', ['contentId' => $contentId]));
}
if ($form->get('export')->isClicked() && $form->isSubmitted() && $form->isValid()) {
/** @var ExportCriteria $data */
$data = $form->getData();
$export = $this->exporter->export($data);
$formatter = $this->formatterRegistry->getExportResponseFormatter($data->getExportIdentifier());
return $formatter->format($export, $content);
}
return $this->render("@NetgenInformationCollection/admin/export_menu.html.twig",
[
'content' => $content,
'form' => $form->createView(),
]
);
}
}