TabelleController::getRequestValue()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
9
10
/**
11
 * Tabelle controller.
12
 */
13
class TabelleController extends FiCoreController
14
{
15
16 1
    public function aggiornaAction(Request $request)
17
    {
18 1
        if ($request->get('oper') == 'edit') {
19 1
            $gestionepermessi = $this->get("ficorebundle.gestionepermessi");
20 1
            $operatore = $gestionepermessi->utentecorrente();
21
22 1
            $id = $request->get('id');
23
24 1
            $em = $this->getDoctrine()->getManager();
25 1
            $tabelle = $em->getRepository('FiCoreBundle:Tabelle')->find($id);
26 1
            if (!$tabelle) {
27
                throw new AccessDeniedException("Oggetto non trovato");
28
            }
29 1
            $tabelle->setOperatoriId($operatore['id']);
30 1
            $nometabella = $this->getRequestValue($request, 'nometabella');
31 1
            if ($nometabella) {
32
                $tabelle->setNometabella($nometabella);
33
            }
34 1
            $nomecampo = $this->getRequestValue($request, 'nomecampo');
35 1
            if ($nomecampo) {
36
                $tabelle->setNomecampo($nomecampo);
37
            }
38 1
            $mostraindex = $this->getRequestValue($request, 'mostraindex');
39 1
            $tabelle->setMostraindex($mostraindex);
40 1
            $ordineindex = $this->getRequestValue($request, 'ordineindex');
41 1
            $tabelle->setOrdineindex($ordineindex);
42 1
            $etichettaindex = $this->getRequestValue($request, 'etichettaindex');
43 1
            $tabelle->setEtichettaindex($etichettaindex);
44
45 1
            $larghezzaindex = $this->getRequestValue($request, 'larghezzaindex');
46 1
            $tabelle->setLarghezzaindex($larghezzaindex);
47
48 1
            $mostrastampa = $this->getRequestValue($request, 'mostrastampa');
49 1
            $tabelle->setMostrastampa($mostrastampa);
50
51 1
            $ordinestampa = $this->getRequestValue($request, 'ordinestampa');
52 1
            $tabelle->setOrdinestampa($ordinestampa);
53
54 1
            $etichettastampa = $this->getRequestValue($request, 'etichettastampa');
55 1
            $tabelle->setEtichettastampa($etichettastampa);
56
57 1
            $larghezzastampa = $this->getRequestValue($request, 'larghezzastampa');
58 1
            $tabelle->setLarghezzastampa($larghezzastampa);
59 1
            $em->persist($tabelle);
60 1
            $em->flush();
61
        }
62
63 1
        return new Response('OK');
64
    }
65
66 1
    private function getRequestValue($request, $attribute)
67
    {
68 1
        if (($request->get($attribute) !== null) && ($request->get($attribute) !== '')) {
69 1
            return $request->get($attribute);
70
        } else {
71 1
            return null;
72
        }
73
    }
74
75 1
    public function configuraAction(Request $request, $nometabella)
76
    {
77 1
        $this->setup($request);
78 1
        $namespace = $this->getNamespace();
79 1
        $bundle = $this->getBundle();
80 1
        $gestionepermessi = $this->get("ficorebundle.gestionepermessi");
81 1
        $operatore = $gestionepermessi->utentecorrente();
82
83 1
        $utilitytabelle = $this->get("ficorebundle.tabelle.utility");
84
85
        $parametritabella = array(
86 1
            'tabella' => $nometabella,
87 1
            "namespace" => $namespace,
88 1
            "bundle" => $bundle
89
        );
90
        $parametritabellaoperatore = array(
91 1
            'tabella' => $nometabella,
92 1
            "namespace" => $namespace,
93 1
            "bundle" => $bundle,
94 1
            'operatore' => $operatore['id']
95
        );
96
97 1
        $utilitytabelle->generaDB($parametritabella);
98 1
        $utilitytabelle->generaDB($parametritabellaoperatore);
99
100 1
        $controller = $this->getController();
101 1
        $container = $this->container;
102
103 1
        $nomebundle = $namespace . $bundle . 'Bundle';
104
105 1
        $em = $this->getDoctrine()->getManager();
106 1
        $entities = $em->getRepository($nomebundle . ':' . $controller)->findAll();
107
108
        $dettaglij = array(
109 1
            'nomecampo' => array(
110
                array('nomecampo' => 'nomecampo', 'lunghezza' => '150', 'descrizione' => 'Campo', 'tipo' => 'text', 'editable' => false),),
111
            'mostraindex' => array(
112
                array('nomecampo' => 'mostraindex', 'lunghezza' => '100', 'descrizione' => 'Vedi in griglia', 'tipo' => 'boolean'),
113
            ),
114
            'ordineindex' => array(
115
                array('nomecampo' => 'ordineindex', 'lunghezza' => '100', 'descrizione' => 'Ordine in griglia', 'tipo' => 'text'),
116
            ),
117
            'etichettaindex' => array(
118
                array('nomecampo' => 'etichettaindex', 'lunghezza' => '150', 'descrizione' => 'Label in griglia', 'tipo' => 'text'),
119
            ),
120
            'larghezzaindex' => array(
121
                array('nomecampo' => 'larghezzaindex', 'lunghezza' => '100', 'descrizione' => 'Largh. in griglia', 'tipo' => 'text'),
122
            ),
123
            'mostrastampa' => array(
124
                array('nomecampo' => 'mostrastampa', 'lunghezza' => '100', 'descrizione' => 'Vedi in stampa', 'tipo' => 'boolean'),
125
            ),
126
            'ordinestampa' => array(
127
                array('nomecampo' => 'ordinestampa', 'lunghezza' => '100', 'descrizione' => 'Ordine in stampa', 'tipo' => 'text'),
128
            ),
129
            'etichettastampa' => array(
130
                array('nomecampo' => 'etichettastampa', 'lunghezza' => '150', 'descrizione' => 'Label in stampa', 'tipo' => 'text'),
131
            ),
132
            'larghezzastampa' => array(
133
                array('nomecampo' => 'larghezzastampa', 'lunghezza' => '100', 'descrizione' => 'Largh. in stampa', 'tipo' => 'text'),
134
            ),
135
        );
136
137
        $paricevuti = array(
138 1
            'doctrine' => $em,
139 1
            'nomebundle' => $nomebundle,
140 1
            'nometabella' => $controller,
141 1
            'dettaglij' => $dettaglij,
142 1
            'container' => $container,
143
        );
144
145 1
        $paricevuti['escludere'] = array('nometabella', 'operatori_id');
146
147 1
        $griglia = $this->get("ficorebundle.griglia");
148 1
        $testata = $griglia->testataPerGriglia($paricevuti);
149
150 1
        $testata['titolo'] = sprintf("Configurazione colonne per tabella %s", $nometabella);
151 1
        $testata['multisearch'] = 0;
152 1
        $testata['showdel'] = 0;
153 1
        $testata['showadd'] = 0;
154 1
        $testata['showedit'] = 0;
155 1
        $testata['showprint'] = 0;
156 1
        $testata['editinline'] = 1;
157 1
        $testata['nomelist'] = '#listconfigura';
158 1
        $testata['nomepager'] = '#pagerconfigura';
159 1
        $testata['tastochiudi'] = 1;
160 1
        $testata['div'] = '#dettaglioconf';
161 1
        $testata['chiamante'] = $nometabella;
162 1
        $testata['percorsogriglia'] = $nometabella . '/grigliapopup';
163 1
        $testata['altezzagriglia'] = '300';
164 1
        $testata['larghezzagriglia'] = '900';
165
166 1
        $testata['permessiedit'] = 1;
167 1
        $testata['permessidelete'] = 1;
168 1
        $testata['permessicreate'] = 1;
169 1
        $testata['permessiread'] = 1;
170
        $twigparm = array(
171 1
            'entities' => $entities,
172 1
            'nomecontroller' => $controller,
173 1
            'testata' => json_encode($testata),
174 1
            'chiamante' => $nometabella,
175
        );
176
177 1
        return $this->render($nomebundle . ':' . $controller . ':configura.html.twig', $twigparm);
178
    }
179
180 1
    public function grigliapopupAction(Request $request, $chiamante)
181
    {
182 1
        $this->setup($request);
183 1
        $namespace = $this->getNamespace();
184 1
        $bundle = $this->getBundle();
185 1
        $controller = $this->getController();
186
187 1
        $nomebundle = $namespace . $bundle . 'Bundle';
188 1
        $em = $this->getDoctrine()->getManager();
189
190 1
        $gestionepermessi = $this->get("ficorebundle.gestionepermessi");
191 1
        $operatore = $gestionepermessi->utentecorrente();
192 1
        $tabellej = array();
193 1
        $tabellej['operatori_id'] = array('tabella' => 'operatori', 'campi' => array('username', 'operatore'));
194
195
        $paricevuti = array(
196 1
            'request' => $request,
197 1
            'doctrine' => $em,
198 1
            'container' => $this->container,
199 1
            'nomebundle' => $nomebundle,
200 1
            'nometabella' => $controller,
201 1
            'tabellej' => $tabellej,);
202
203 1
        $paricevuti['escludere'] = array('nometabella', 'operatori_id');
204 1
        $paricevuti['precondizioni'] = array('Tabelle.nometabella' => $chiamante, 'Tabelle.operatori_id' => $operatore['id']);
205
206 1
        $griglia = $this->get("ficorebundle.griglia");
207 1
        return new Response($griglia->datiPerGriglia($paricevuti));
208
    }
209
210 1
    protected function setParametriGriglia($prepar = array())
211
    {
212 1
        $this->setup($prepar['request']);
213 1
        $namespace = $this->getNamespace();
214 1
        $bundle = $this->getBundle();
215 1
        $controller = $this->getController();
216
217 1
        $gestionepermessi = $this->get("ficorebundle.gestionepermessi");
218 1
        $canRead = ($gestionepermessi->leggere(array('modulo' => $controller)) ? 1 : 0);
219 1
        if (!$canRead) {
220
            throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto");
221
        }
222
223 1
        $nomebundle = $namespace . $bundle . 'Bundle';
224 1
        $tabellej = array();
225 1
        $tabellej['operatori_id'] = array('tabella' => 'operatori', 'campi' => array('username'));
226 1
        $escludi = array("operatori"); //'operatori_id'
227
228
        $paricevuti = array(
229 1
            'container' => $this->container,
230 1
            'nomebundle' => $nomebundle,
231 1
            'nometabella' => $controller,
232 1
            'tabellej' => $tabellej,
233 1
            'escludere' => $escludi
234
        );
235
236 1
        if (!empty($prepar)) {
237 1
            $paricevuti = array_merge($paricevuti, $prepar);
238
        }
239
240 1
        self::$parametrigriglia = $paricevuti;
241 1
    }
242
243 1
    public function listacampitabellaAction(Request $request)
244
    {
245 1
        $nometabella = trim($request->get('tabella'));
0 ignored issues
show
Bug introduced by
It seems like $request->get('tabella') can also be of type null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

245
        $nometabella = trim(/** @scrutinizer ignore-type */ $request->get('tabella'));
Loading history...
246 1
        if (!isset($nometabella)) {
247
            return false;
248
        }
249
250 1
        $escludiid = $request->get('escludiid');
251 1
        if (!isset($escludiid)) {
252
            $escludiid = 0;
253
        }
254 1
        $parametri = array("nometabella" => $nometabella, "escludiid" => $escludiid);
255
256 1
        $utilitytabelle = $this->container->get("ficorebundle.tabelle.utility");
257 1
        $risposta = $utilitytabelle->getListacampitabella($parametri);
258 1
        return new JsonResponse($risposta);
259
    }
260
}
261