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