-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathExport.php
More file actions
85 lines (70 loc) · 2.78 KB
/
Export.php
File metadata and controls
85 lines (70 loc) · 2.78 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
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace Netgen\Bundle\InformationCollectionBundle\Controller\Admin\Export;
use Ibexa\Contracts\Core\Repository\ContentService;
use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute;
use Netgen\Bundle\InformationCollectionBundle\Form\Type\ExportType;
use Netgen\InformationCollection\API\Service\Exporter;
use Netgen\InformationCollection\API\Value\Export\ExportCriteria;
use Netgen\InformationCollection\Core\Export\ExportResponseFormatterRegistry;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class Export extends AbstractController
{
protected ContentService $contentService;
protected Exporter $exporter;
protected ExportResponseFormatterRegistry $formatterRegistry;
public function __construct(
ContentService $contentService,
Exporter $exporter,
ExportResponseFormatterRegistry $formatterRegistry
) {
$this->contentService = $contentService;
$this->exporter = $exporter;
$this->formatterRegistry = $formatterRegistry;
}
/**
* @param int $contentId
* @param Request $request
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException
*
* @return Response
*/
public function __invoke($contentId, Request $request): Response
{
$attribute = new Attribute('infocollector', 'export');
$this->denyAccessUnlessGranted($attribute);
$content = $this->contentService->loadContent((int) $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->isSubmitted() && $form->isValid() && $form->get('export')->isClicked()) {
/** @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(),
]
);
}
}