1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
6
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
7
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
8
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\Tabella; |
9
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
10
|
|
|
use Cdf\BiCoreBundle\Utils\Export\TabellaXls; |
11
|
|
|
|
12
|
|
|
trait FiCoreTabellaControllerTrait |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
private $tabellaxls; |
16
|
|
|
|
17
|
8 |
|
public function tabella(Request $request) |
18
|
|
|
{ |
19
|
8 |
|
if (!$this->permessi->canRead($this->getController())) { |
|
|
|
|
20
|
1 |
|
throw new AccessDeniedException('Non si hanno i permessi per visualizzare questo contenuto'); |
21
|
|
|
} |
22
|
|
|
|
23
|
7 |
|
$parametripassati = array_merge($request->get('parametri'), array('user' => $this->getUser())); |
|
|
|
|
24
|
7 |
|
$parametriform = isset($parametripassati['parametriform']) ? |
25
|
7 |
|
json_decode(ParametriTabella::getParameter($parametripassati['parametriform']), true) : array(); |
26
|
7 |
|
$classbundle = ParametriTabella::getParameter($parametripassati['entityclass']); |
27
|
7 |
|
$formbundle = ParametriTabella::getParameter($parametripassati['formclass']); |
28
|
7 |
|
$formType = $formbundle . 'Type'; |
29
|
|
|
|
30
|
7 |
|
$entity = new $classbundle(); |
31
|
7 |
|
$controller = ParametriTabella::getParameter($parametripassati['nomecontroller']); |
32
|
7 |
|
$form = $this->createForm( |
|
|
|
|
33
|
7 |
|
$formType, |
34
|
7 |
|
$entity, |
35
|
|
|
array('attr' => array( |
36
|
7 |
|
'id' => 'formdati' . $controller, |
37
|
|
|
), |
38
|
7 |
|
'action' => $this->generateUrl($controller . '_new'), |
|
|
|
|
39
|
7 |
|
'parametriform' => $parametriform, |
40
|
|
|
) |
41
|
|
|
); |
42
|
|
|
|
43
|
7 |
|
$parametri = array_merge($parametripassati, $this->getParametriTabella($parametripassati)); |
44
|
7 |
|
$parametri['form'] = $form->createView(); |
45
|
7 |
|
$templateobj = $this->getTabellaTemplateInformations($controller); |
46
|
7 |
|
$parametri['templatelocation'] = $templateobj["path"]; |
47
|
|
|
|
48
|
7 |
|
return $this->render( |
|
|
|
|
49
|
7 |
|
$templateobj["template"], |
50
|
7 |
|
array('parametri' => $parametri) |
51
|
|
|
); |
52
|
|
|
} |
53
|
3 |
|
public function setTabellaxls(TabellaXls $tabellaxls) |
54
|
|
|
{ |
55
|
3 |
|
$this->tabellaxls = $tabellaxls; |
56
|
3 |
|
} |
57
|
3 |
|
public function exportXls(Request $request) |
58
|
|
|
{ |
59
|
|
|
try { |
60
|
3 |
|
$parametripassati = array_merge($request->get('parametri'), array('user' => $this->getUser())); |
|
|
|
|
61
|
3 |
|
$parametripassati['estraituttirecords'] = ParametriTabella::setParameter('1'); |
62
|
|
|
|
63
|
3 |
|
$filexls = $this->tabellaxls->esportaexcel($this->getParametriTabellaXls($parametripassati)); |
64
|
3 |
|
if (file_exists($filexls)) { |
65
|
|
|
$response = array( |
66
|
3 |
|
'status' => '200', |
67
|
3 |
|
'file' => 'data:application/vnd.ms-excel;base64,' . base64_encode(file_get_contents($filexls)), |
68
|
|
|
); |
69
|
3 |
|
@unlink($filexls); |
|
|
|
|
70
|
|
|
} else { |
71
|
|
|
$response = array( |
72
|
3 |
|
'status' => '501', |
73
|
|
|
'file' => 'Impossibile generare il file excel', |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} catch (\Exception $exc) { |
77
|
|
|
$response = array( |
78
|
|
|
'status' => '500', |
79
|
|
|
'file' => $exc->getFile() . ' -> Riga: ' . $exc->getLine() . ' -> ' . $exc->getMessage(), |
80
|
|
|
); |
81
|
|
|
} |
82
|
|
|
|
83
|
3 |
|
return new JsonResponse($response); |
84
|
|
|
} |
85
|
7 |
|
protected function getParametriTabella(array $parametripassati) |
86
|
|
|
{ |
87
|
7 |
|
$doctrine = $this->get('doctrine'); |
|
|
|
|
88
|
7 |
|
$configurazionetabella = new Tabella($doctrine, $parametripassati); |
89
|
|
|
$parametritabella = array( |
90
|
7 |
|
'parametritabella' => $configurazionetabella->getConfigurazionecolonnetabella(), |
91
|
7 |
|
'recordstabella' => $configurazionetabella->getRecordstabella(), |
92
|
7 |
|
'paginacorrente' => $configurazionetabella->getPaginacorrente(), |
93
|
7 |
|
'paginetotali' => $configurazionetabella->getPaginetotali(), |
94
|
7 |
|
'righetotali' => $configurazionetabella->getRighetotali(), |
95
|
7 |
|
'traduzionefiltri' => $configurazionetabella->getTraduzionefiltri() |
96
|
|
|
); |
97
|
7 |
|
return $parametritabella; |
98
|
|
|
} |
99
|
3 |
|
protected function getParametriTabellaXls(array $parametripassati) |
100
|
|
|
{ |
101
|
3 |
|
$doctrine = $this->get('doctrine'); |
102
|
3 |
|
$configurazionetabella = new Tabella($doctrine, $parametripassati); |
103
|
|
|
$parametritabella = array( |
104
|
3 |
|
'parametritabella' => $configurazionetabella->getConfigurazionecolonnetabella(), |
105
|
3 |
|
'recordstabella' => $configurazionetabella->getRecordstabella(), |
106
|
3 |
|
'paginacorrente' => $configurazionetabella->getPaginacorrente(), |
107
|
3 |
|
'paginetotali' => $configurazionetabella->getPaginetotali(), |
108
|
3 |
|
'righetotali' => $configurazionetabella->getRighetotali(), |
109
|
3 |
|
'traduzionefiltri' => $configurazionetabella->getTraduzionefiltri(), |
110
|
3 |
|
'nomecontroller' => ParametriTabella::getParameter($parametripassati['nomecontroller']), |
111
|
|
|
); |
112
|
3 |
|
return $parametritabella; |
113
|
|
|
} |
114
|
7 |
|
protected function getTabellaTemplateInformations($controller) |
115
|
|
|
{ |
116
|
7 |
|
$template = $controller . '/Tabella/tabellacontainer.html.twig'; |
117
|
7 |
|
$path = $controller . '/'; |
118
|
7 |
|
if (!$this->get('templating')->exists($template)) { |
119
|
6 |
|
$template = 'BiCoreBundle:' . $controller . ':Tabella/tabellacontainer.html.twig'; |
120
|
6 |
|
$path = 'BiCoreBundle:' . $controller . ':'; |
121
|
6 |
|
if (!$this->get('templating')->exists($template)) { |
122
|
5 |
|
$path = 'BiCoreBundle:Standard:'; |
123
|
5 |
|
$template = $path . 'Tabella/tabellacontainer.html.twig'; |
124
|
|
|
} |
125
|
|
|
} |
126
|
7 |
|
return array("path" => $path, "template" => $template); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|