OpzioniTabellaController   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 272
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 16
eloc 172
dl 0
loc 272
ccs 121
cts 143
cp 0.8462
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setParametriGriglia() 0 24 2
A createAction() 0 50 4
B indexAction() 0 70 1
B updateAction() 0 69 6
A deleteAction() 0 32 3
1
<?php
2
3
/* Qui Bundle */
4
//namespace Fi\DemoBundle\Controller;
5
6
namespace Fi\CoreBundle\Controller;
7
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
11
12
/**
13
 * OpzioniTabella controller.
14
 */
15
class OpzioniTabellaController extends FiCoreController
16
{
17
18
    /**
19
     * Lists all opzioniTabella entities.
20
     */
21 1
    public function indexAction(Request $request)
22
    {
23
        /* @var $em \Doctrine\ORM\EntityManager */
24 1
        $this->setup($request);
25 1
        $namespace = $this->getNamespace();
26 1
        $bundle = $this->getBundle();
27 1
        $controller = $this->getController();
28 1
        $container = $this->container;
29
30 1
        $nomebundle = $namespace . $bundle . 'Bundle';
31
32
        $dettaglij = array(
33 1
            'descrizione' => array(
34
                array(
35
                    'nomecampo' => 'descrizione',
36
                    'lunghezza' => '400',
37
                    'descrizione' => 'Descrizione',
38
                    'tipo' => 'text',),),
39
            'parametro' => array(
40
                array(
41
                    'nomecampo' => 'parametro',
42
                    'lunghezza' => '300',
43
                    'descrizione' => 'Parametro',
44
                    'tipo' => 'text',),),
45
            'valore' => array(
46
                array(
47
                    'nomecampo' => 'valore',
48
                    'lunghezza' => '300',
49
                    'descrizione' => 'Valore',
50
                    'tipo' => 'text',),),
51
            'tabelle_id' => array(
52
                array(
53
                    'nomecampo' => 'tabelle.nometabella',
54
                    'lunghezza' => '400',
55
                    'descrizione' => 'Tabella',
56
                    'tipo' => 'text',),
57
            ),
58
        );
59
60 1
        $escludi = array();
61
        $paricevuti = array(
62 1
            'nomebundle' => $nomebundle,
63 1
            'nometabella' => $controller,
64 1
            'dettaglij' => $dettaglij,
65 1
            'escludere' => $escludi,
66 1
            'container' => $container,
67
        );
68
69 1
        $griglia = $this->get("ficorebundle.griglia");
70 1
        $testatagriglia = $griglia->testataPerGriglia($paricevuti);
71
72 1
        $testatagriglia['multisearch'] = 1;
73 1
        $testatagriglia['showconfig'] = 1;
74 1
        $testatagriglia['showadd'] = 1;
75 1
        $testatagriglia['showedit'] = 1;
76 1
        $testatagriglia['showdel'] = 1;
77 1
        $testatagriglia['editinline'] = 0;
78 1
        $testatagriglia['overlayopen'] = 1;
79
80 1
        $testatagriglia['parametritesta'] = json_encode($paricevuti);
81 1
        $this->setParametriGriglia(array('request' => $request));
82 1
        $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia);
83
84 1
        $testata = json_encode($testatagriglia);
85
        $twigparms = array(
86 1
            'nomecontroller' => $controller,
87 1
            'testata' => $testata,
88
        );
89
90 1
        return $this->render($nomebundle . ':' . $controller . ':index.html.twig', $twigparms);
91
    }
92
93 1
    public function setParametriGriglia($prepar = array())
94
    {
95 1
        $this->setup($prepar['request']);
96 1
        $namespace = $this->getNamespace();
97 1
        $bundle = $this->getBundle();
98 1
        $controller = $this->getController();
99
100 1
        $nomebundle = $namespace . $bundle . 'Bundle';
101 1
        $escludi = array();
102 1
        $tabellej = array();
103 1
        $tabellej['tabelle_id'] = array('tabella' => 'tabelle', 'campi' => array('nometabella'));
104
105
        $paricevuti = array(
106 1
            'container' => $this->container,
107 1
            'nomebundle' => $nomebundle,
108 1
            'tabellej' => $tabellej,
109 1
            'nometabella' => $controller,
110 1
            'escludere' => $escludi,);
111
112 1
        if (!empty($prepar)) {
113 1
            $paricevuti = array_merge($paricevuti, $prepar);
114
        }
115
116 1
        self::$parametrigriglia = $paricevuti;
117 1
    }
118
119
    /**
120
     * Creates a new table entity.
121
     */
122 1
    public function createAction(Request $request)
123
    {
124 1
        $this->setup($request);
125 1
        $namespace = $this->getNamespace();
126 1
        $bundle = $this->getBundle();
127 1
        $controller = $this->getController();
128
129 1
        if (!self::$canCreate) {
130
            throw new AccessDeniedException("Non si hanno i permessi per creare questo contenuto");
131
        }
132
133 1
        $nomebundle = $namespace . $bundle . 'Bundle';
134 1
        $classbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Entity\\' . $controller;
135 1
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
136
137 1
        $entity = new $classbundle();
138 1
        $formType = $formbundle . 'Type';
139
140 1
        $form = $this->createForm(
141 1
            $formType,
142 1
            $entity,
143
            array('attr' => array(
144 1
                'id' => 'formdati' . $controller,
145
                ),
146 1
                'action' => $this->generateUrl($controller . '_create'),
147
                )
148
        );
149
150 1
        $form->submit($request->request->get($form->getName()));
151
152 1
        if ($form->isValid()) {
153 1
            $em = $this->getDoctrine()->getManager();
154 1
            $em->persist($entity);
155 1
            $em->flush();
156 1
            $em->getConfiguration()->getResultCacheImpl()->delete($controller);
0 ignored issues
show
Bug introduced by
The method getConfiguration() does not exist on Doctrine\Persistence\ObjectManager. It seems like you code against a sub-type of Doctrine\Persistence\ObjectManager such as Doctrine\ORM\EntityManagerInterface or Doctrine\ORM\Decorator\EntityManagerDecorator. ( Ignorable by Annotation )

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

156
            $em->/** @scrutinizer ignore-call */ 
157
                 getConfiguration()->getResultCacheImpl()->delete($controller);
Loading history...
157
158 1
            $continua = (int) $request->get('continua');
159 1
            if ($continua === 0) {
160 1
                return new Response('OK');
161
            } else {
162
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $entity->getId())));
163
            }
164
        }
165
166
        return $this->render(
167
            $nomebundle . ':' . $controller . ':new.html.twig',
168
            array(
169
                    'nomecontroller' => $controller,
170
                    'entity' => $entity,
171
                    'form' => $form->createView(),
172
                        )
173
        );
174
    }
175
176
    /**
177
     * Edits an existing table entity.
178
     */
179 1
    public function updateAction(Request $request, $id)
180
    {
181
        /* @var $em \Doctrine\ORM\EntityManager */
182 1
        $this->setup($request);
183 1
        $namespace = $this->getNamespace();
184 1
        $bundle = $this->getBundle();
185 1
        $controller = $this->getController();
186
187 1
        if (!self::$canUpdate) {
188
            throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto");
189
        }
190
191 1
        $nomebundle = $namespace . $bundle . 'Bundle';
192 1
        $formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller;
193 1
        $formType = $formbundle . 'Type';
194
195 1
        $repoStorico = $this->container->get('Storicomodifiche_repository');
196
197 1
        $em = $this->getDoctrine()->getManager();
198
199 1
        $entity = $em->getRepository($nomebundle . ':' . $controller)->find($id);
200
201 1
        if (!$entity) {
202
            throw $this->createNotFoundException('Unable to find ' . $controller . ' entity.');
203
        }
204
205 1
        $deleteForm = $this->createDeleteForm($id);
206
207 1
        $editForm = $this->createForm(
208 1
            $formType,
209 1
            $entity,
210
            array('attr' => array(
211 1
                'id' => 'formdati' . $controller,
212
                ),
213 1
                'action' => $this->generateUrl($controller . '_update', array('id' => $entity->getId())),
214
                )
215
        );
216
217 1
        $editForm->submit($request->request->get($editForm->getName()));
218
219 1
        if ($editForm->isValid()) {
220 1
            $originalData = $em->getUnitOfWork()->getOriginalEntityData($entity);
0 ignored issues
show
Bug introduced by
The method getUnitOfWork() does not exist on Doctrine\Persistence\ObjectManager. It seems like you code against a sub-type of Doctrine\Persistence\ObjectManager such as Doctrine\ORM\EntityManagerInterface or Doctrine\ORM\Decorator\EntityManagerDecorator. ( Ignorable by Annotation )

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

220
            $originalData = $em->/** @scrutinizer ignore-call */ getUnitOfWork()->getOriginalEntityData($entity);
Loading history...
221
222 1
            $em->persist($entity);
223 1
            $em->flush();
224 1
            $em->getConfiguration()->getResultCacheImpl()->delete($controller);
225
226 1
            $newData = $em->getUnitOfWork()->getOriginalEntityData($entity);
227 1
            $changes = $repoStorico->isRecordChanged($nomebundle, $controller, $originalData, $newData);
228
229 1
            if ($changes) {
230
                $repoStorico->saveHistory($controller, $changes, $id, $this->getUser());
231
            }
232
233 1
            $continua = (int) $request->get('continua');
234 1
            if ($continua === 0) {
235 1
                return new Response('OK');
236
            } else {
237
                return $this->redirect($this->generateUrl($controller . '_edit', array('id' => $id)));
238
            }
239
        }
240
241
        return $this->render(
242
            $nomebundle . ':' . $controller . ':edit.html.twig',
243
            array(
244
                    'entity' => $entity,
245
                    'edit_form' => $editForm->createView(),
246
                    'delete_form' => $deleteForm->createView(),
247
                    'nomecontroller' => $controller,
248
                        )
249
        );
250
    }
251
252
    /**
253
     * Deletes a table entity.
254
     */
255 1
    public function deleteAction(Request $request)
256
    {
257
        /* @var $em \Doctrine\ORM\EntityManager */
258 1
        $this->setup($request);
259 1
        if (!self::$canDelete) {
260
            throw new AccessDeniedException("Non si hanno i permessi per aggiornare questo contenuto");
261
        }
262 1
        $namespace = $this->getNamespace();
263 1
        $bundle = $this->getBundle();
264 1
        $controller = $this->getController();
265
266 1
        $nomebundle = $namespace . $bundle . 'Bundle';
267
268
        try {
269 1
            $em = $this->getDoctrine()->getManager();
270 1
            $qb = $em->createQueryBuilder();
0 ignored issues
show
Bug introduced by
The method createQueryBuilder() does not exist on Doctrine\Persistence\ObjectManager. It seems like you code against a sub-type of Doctrine\Persistence\ObjectManager such as Doctrine\ORM\EntityManagerInterface or Doctrine\ORM\Decorator\EntityManagerDecorator. ( Ignorable by Annotation )

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

270
            /** @scrutinizer ignore-call */ 
271
            $qb = $em->createQueryBuilder();
Loading history...
271 1
            $ids = explode(',', $request->get('id'));
0 ignored issues
show
Bug introduced by
It seems like $request->get('id') can also be of type null; however, parameter $string of explode() 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

271
            $ids = explode(',', /** @scrutinizer ignore-type */ $request->get('id'));
Loading history...
272 1
            $qb->delete($nomebundle . ':' . $controller, 'u')
273 1
                    ->andWhere('u.id IN (:ids)')
274 1
                    ->setParameter('ids', $ids);
275
276 1
            $query = $qb->getQuery();
277 1
            $query->execute();
278 1
            $em->getConfiguration()->getResultCacheImpl()->delete($controller);
279
        } catch (\Exception $e) {
280
            $response = new Response();
281
            $response->setStatusCode('200');
282
283
            return new Response('404');
284
        }
285
286 1
        return new Response('OK');
287
    }
288
}
289