1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
6
|
|
|
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; |
7
|
|
|
use Cdf\BiCoreBundle\Utils\Permessi\PermessiUtils; |
8
|
|
|
use Doctrine\Common\Persistence\ObjectManager; |
9
|
|
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; |
10
|
|
|
use Symfony\Component\Asset\Packages; |
11
|
|
|
|
12
|
11 |
|
class FiController extends FiTabellaController |
13
|
|
|
{ |
14
|
11 |
|
public function __construct(ObjectManager $em, TokenStorageInterface $user) |
15
|
11 |
|
{ |
16
|
|
|
$matches = array(); |
|
|
|
|
17
|
11 |
|
$controllo = new \ReflectionClass(get_class($this)); |
18
|
11 |
|
|
19
|
5 |
|
preg_match('/(.*)\\\(.*)\\\Controller\\\(.*)Controller/', $controllo->name, $matches); |
20
|
|
|
if (count($matches) == 0) { |
21
|
|
|
preg_match('/(.*)(.*)\\\Controller\\\(.*)Controller/', $controllo->name, $matches); |
22
|
11 |
|
} |
23
|
11 |
|
|
24
|
11 |
|
$this->bundle = ($matches[count($matches) - 2] ? $matches[count($matches) - 2] : $matches[count($matches) - 3]); |
|
|
|
|
25
|
11 |
|
$this->controller = $matches[count($matches) - 1]; |
26
|
|
|
$this->permessi = new PermessiUtils($em, $this->getController(), $user->getToken()->getUser()); |
|
|
|
|
27
|
|
|
} |
28
|
|
|
/** |
29
|
|
|
* Lists all tables entities. |
30
|
|
|
*/ |
31
|
|
|
public function index(Request $request, Packages $assetsmanager) |
32
|
|
|
{ |
33
|
|
|
$bundle = $this->getBundle(); |
|
|
|
|
34
|
|
|
$controller = $this->getController(); |
35
|
|
|
$idpassato = $request->get('id'); |
|
|
|
|
36
|
|
|
|
37
|
|
|
if (!$this->getPermessi()->canRead()) { |
38
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
39
|
|
|
} |
40
|
|
|
$crudtemplate = $this->getCrudTemplate($bundle, $controller, $this->getThisFunctionName()); |
41
|
|
|
|
42
|
|
|
$entityclassnotation = $this->getEntityClassNotation(); |
43
|
|
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
44
|
|
|
|
45
|
|
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$modellocolonne = array( |
48
|
|
|
/* |
|
|
|
|
49
|
|
|
$controller . ".nominativo" => array( |
50
|
|
|
"nometabella" => $controller, |
51
|
|
|
"nomecampo" => "nominativo", |
52
|
|
|
"etichetta" => "Nominativo", |
53
|
|
|
"ordine" => 10, |
54
|
|
|
"larghezza" => 200, |
55
|
|
|
"escluso" => false |
56
|
|
|
), |
57
|
|
|
$controller . ".datanascita" => array( |
58
|
|
|
"nometabella" => $controller, |
59
|
|
|
"nomecampo" => "datanascita", |
60
|
|
|
"etichetta" => "Data di nascita", |
61
|
|
|
"ordine" => 20, |
62
|
|
|
"larghezza" => 100, |
63
|
|
|
"escluso" => false |
64
|
|
|
), |
65
|
|
|
|
66
|
|
|
*/ |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$colonneordinamento = array($controller . '.id' => "DESC"); |
|
|
|
|
70
|
|
|
$filtri = array(); |
|
|
|
|
71
|
|
|
$prefiltri = array(); |
|
|
|
|
72
|
|
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
73
|
|
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
74
|
|
|
$colonneordinamento = array($tablenamefromentity . '.id' => "DESC"); |
|
|
|
|
75
|
|
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
76
|
|
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
77
|
|
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
78
|
|
|
'bundle' => ParametriTabella::setParameter($bundle), |
79
|
|
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
80
|
|
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
81
|
|
|
'formclass' => ParametriTabella::setParameter($formclass), |
82
|
|
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
83
|
|
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
84
|
|
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
85
|
|
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
86
|
|
|
'idpassato' => ParametriTabella::setParameter($idpassato), |
87
|
|
|
'titolotabella' => ParametriTabella::setParameter("Elenco " . $controller), |
|
|
|
|
88
|
|
|
'multiselezione' => ParametriTabella::setParameter("0"), |
|
|
|
|
89
|
|
|
'editinline' => ParametriTabella::setParameter("1"), |
|
|
|
|
90
|
|
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
91
|
|
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
92
|
|
|
'righetotali' => ParametriTabella::setParameter("0"), |
|
|
|
|
93
|
|
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
94
|
|
|
'estraituttirecords' => ParametriTabella::setParameter("0"), |
|
|
|
|
95
|
|
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
96
|
|
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
97
|
|
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
98
|
|
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
return $this->render($crudtemplate, array('parametritabella' => $parametritabella,)); |
102
|
|
|
} |
103
|
|
|
/** |
104
|
|
|
* Lists all tables entities. |
105
|
|
|
*/ |
106
|
|
|
public function indexDettaglio(Request $request, Packages $assetsmanager) |
107
|
|
|
{ |
108
|
|
|
if (!$this->getPermessi()->canRead()) { |
109
|
|
|
throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
$bundle = $this->getBundle(); |
|
|
|
|
113
|
|
|
$controller = $this->getController(); |
|
|
|
|
114
|
|
|
$parametripassati = json_decode($request->get('parametripassati'), true); |
115
|
|
|
|
116
|
|
|
$filtri = $this->getParametroIndexDettaglio($parametripassati, "filtri", array()); |
|
|
|
|
117
|
|
|
$prefiltri = $this->getParametroIndexDettaglio($parametripassati, "prefiltri", array()); |
|
|
|
|
118
|
|
|
$titolotabella = $this->getParametroIndexDettaglio($parametripassati, "titolotabella", "Elenco " . $controller); |
|
|
|
|
119
|
|
|
$modellocolonne = $this->getParametroIndexDettaglio($parametripassati, "modellocolonne", array()); |
|
|
|
|
120
|
|
|
$colonneordinamento = $this->getParametroIndexDettaglio($parametripassati, "colonneordinamento", array()); |
|
|
|
|
121
|
|
|
$multiselezione = $this->getParametroIndexDettaglio($parametripassati, "multiselezione", 0); |
|
|
|
|
122
|
|
|
$parametriform = $this->getParametroIndexDettaglio($parametripassati, "parametriform", array()); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$template = $bundle . ':' . $controller . ':' . $this->getThisFunctionName() . '.html.twig'; |
125
|
|
|
if (!$this->get('templating')->exists($template)) { |
126
|
|
|
$template = $controller . '/Crud/' . $this->getThisFunctionName() . '.html.twig'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$entityclassnotation = $this->getEntityClassNotation(); |
130
|
|
|
$entityclass = $this->getEntityClassName(); |
|
|
|
|
131
|
|
|
|
132
|
|
|
$formclass = str_replace("Entity", "Form", $entityclass); |
|
|
|
|
133
|
|
|
|
134
|
|
|
$entityutils = new \Cdf\BiCoreBundle\Utils\Entity\EntityUtils($this->get("doctrine")->getManager()); |
|
|
|
|
135
|
|
|
|
136
|
|
|
$tablenamefromentity = $entityutils->getTableFromEntity($entityclass); |
137
|
|
|
$parametritabella = array("em" => ParametriTabella::setParameter("default"), |
|
|
|
|
138
|
|
|
'tablename' => ParametriTabella::setParameter($tablenamefromentity), |
139
|
|
|
'nomecontroller' => ParametriTabella::setParameter($controller), |
140
|
|
|
'bundle' => ParametriTabella::setParameter($bundle), |
141
|
|
|
'entityname' => ParametriTabella::setParameter($entityclassnotation), |
142
|
|
|
'entityclass' => ParametriTabella::setParameter($entityclass), |
143
|
|
|
'formclass' => ParametriTabella::setParameter($formclass), |
144
|
|
|
'parametriform' => ParametriTabella::setParameter(json_encode($parametriform)), |
145
|
|
|
'modellocolonne' => ParametriTabella::setParameter(json_encode($modellocolonne)), |
146
|
|
|
'permessi' => ParametriTabella::setParameter(json_encode($this->getPermessi())), |
147
|
|
|
'urltabella' => ParametriTabella::setParameter($assetsmanager->getUrl('/') . $controller . '/' . 'tabella'), |
148
|
|
|
'baseurl' => ParametriTabella::setParameter($assetsmanager->getUrl('/')), |
149
|
|
|
'idpassato' => ParametriTabella::setParameter(0), |
150
|
|
|
'titolotabella' => ParametriTabella::setParameter($titolotabella), |
151
|
|
|
'multiselezione' => ParametriTabella::setParameter($multiselezione), |
152
|
|
|
'editinline' => ParametriTabella::setParameter("1"), |
|
|
|
|
153
|
|
|
'paginacorrente' => ParametriTabella::setParameter("1"), |
|
|
|
|
154
|
|
|
'paginetotali' => ParametriTabella::setParameter(""), |
|
|
|
|
155
|
|
|
'righeperpagina' => ParametriTabella::setParameter("15"), |
|
|
|
|
156
|
|
|
'colonneordinamento' => ParametriTabella::setParameter(json_encode($colonneordinamento)), |
157
|
|
|
'filtri' => ParametriTabella::setParameter(json_encode($filtri)), |
158
|
|
|
'prefiltri' => ParametriTabella::setParameter(json_encode($prefiltri)), |
159
|
|
|
'traduzionefiltri' => ParametriTabella::setParameter(""), |
|
|
|
|
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
return $this->render( |
163
|
|
|
$template, |
164
|
|
|
array( |
165
|
|
|
'parametritabella' => $parametritabella, |
166
|
|
|
) |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
private function getParametroIndexDettaglio($parametripassati, $keyparametro, $defaultvalue) |
171
|
|
|
{ |
172
|
|
|
if (isset($parametripassati[$keyparametro])) { |
173
|
|
|
$parametro = $parametripassati[$keyparametro]; |
174
|
|
|
} else { |
175
|
|
|
$parametro = $defaultvalue; |
176
|
|
|
} |
177
|
|
|
return $parametro; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.