Completed
Push — master ( d3a1aa...33af6b )
by Andrea
08:15
created

FfprincipaleController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 95%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 68
ccs 38
cts 40
cp 0.95
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B indexAction() 0 60 4
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Fi\CoreBundle\DependencyInjection\GestionePermessi;
7
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
8
9
/**
10
 * Ffprincipale controller.
11
 */
12
class FfprincipaleController extends FiCoreController
13
{
14
15
    /**
16
     * Lists all tables entities.
17
     */
18
    /* @var $em \Doctrine\ORM\EntityManager */
19 2
    public function indexAction(Request $request)
20
    {
21 2
        $this->setup($request);
22 2
        $namespace = $this->getNamespace();
23 2
        $bundle = $this->getBundle();
24 2
        $controller = $this->getController();
25 2
        $container = $this->container;
26
27 2
        $gestionepermessi = $this->get("ficorebundle.gestionepermessi");
28 2
        $canRead = ($gestionepermessi->leggere(array('modulo' => $controller)) ? 1 : 0);
29
30 2
        $nomebundle = $namespace . $bundle . 'Bundle';
31
32 2
        $em = $container->get('doctrine')->getManager();
33 2
        $entities = $em->getRepository($nomebundle . ':' . $controller)->findAll();
34
35 2
        $paricevuti = array('nomebundle' => $nomebundle, 'nometabella' => $controller, 'container' => $container);
36
37 2
        $testatagriglia = Griglia::testataPerGriglia($paricevuti);
38
39 2
        $testatagriglia['multisearch'] = 1;
40 2
        $testatagriglia['showconfig'] = 1;
41 2
        $testatagriglia['showexcel'] = 1;
42 2
        $testatagriglia['showimportexcel'] = 1;
43 2
        $testatagriglia['larghezzagriglia'] = 700;
44 2
        $testatagriglia['overlayopen'] = 1;
45
46 2
        $testatagriglia['parametritesta'] = json_encode($paricevuti);
47
48 2
        $this->setParametriGriglia(array('request' => $request));
49
50 2
        $testatagriglia['parametrigriglia'] = json_encode(self::$parametrigriglia);
51
52
        /* @var $qb \Doctrine\ORM\QueryBuilder */
53 2
        $qb = $em->createQueryBuilder();
54 2
        $qb->select(array('a'));
55 2
        $qb->from('FiCoreBundle:OpzioniTabella', 'a');
56 2
        $qb->leftJoin('a.tabelle', 't');
57 2
        $qb->where('t.nometabella = :tabella');
58 2
        $qb->andWhere("t.nomecampo is null or t.nomecampo = ''");
59 2
        $qb->setParameter('tabella', $controller);
60 2
        $opzioni = $qb->getQuery()->getResult();
61 2
        foreach ($opzioni as $opzione) {
62
            $testatagriglia[$opzione->getParametro()] = $opzione->getValore();
63
        }
64
65 2
        $testata = json_encode($testatagriglia);
66
        $twigparms = array(
67 2
            'entities' => $entities,
68 2
            'nomecontroller' => $controller,
69 2
            'testata' => $testata,
70 2
            'canread' => $canRead,
71
        );
72
73 2
        if (!$canRead) {
74
            throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto");
75
        } else {
76 2
            return $this->render($nomebundle . ':' . $controller . ':index.html.twig', $twigparms);
77
        }
78
    }
79
}
80