FiCoreController::stampatabellaAction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
8
class FiCoreController extends FiController
9
{
10 2
    public function stampatabellaAction(Request $request)
11
    {
12 2
        $this->setup($request);
13 2
        $stampaservice = $this->get("ficorebundle.tabelle.stampa.pdf");
14
15 2
        $parametri = $this->prepareOutput($request);
16
17 2
        $stampaservice->stampa($parametri);
18
19 2
        return new Response('OK');
20
    }
21 2
    public function esportaexcelAction(Request $request)
22
    {
23 2
        $this->setup($request);
24 2
        $stampaservice = $this->get("ficorebundle.tabelle.stampa.xls");
25
26 2
        $parametri = $this->prepareOutput($request);
27
28 2
        $fileexcel = $stampaservice->esportaexcel($parametri);
29
30 2
        $response = new Response();
31
32 2
        $response->headers->set('Content-Type', 'text/csv');
33 2
        $response->headers->set('Content-Disposition', 'attachment;filename="' . basename($fileexcel) . '"');
34
35 2
        $response->setContent(file_get_contents($fileexcel));
36 2
        if (file_exists($fileexcel)) {
37 2
            unlink($fileexcel);
38
        }
39
40 2
        return $response;
41
    }
42 4
    public function prepareOutput($request)
43
    {
44 4
        $namespace = $this->getNamespace();
45 4
        $bundle = $this->getBundle();
46 4
        $container = $this->container;
47
48 4
        $nomebundle = $namespace . $bundle . 'Bundle';
49
50 4
        $em = $this->getDoctrine()->getManager();
51
52
        $paricevuti = array(
53 4
            'nomebundle' => $nomebundle,
54 4
            'nometabella' => $request->get('nometabella'),
55 4
            'container' => $container,
56 4
            'request' => $request,
57
        );
58
59 4
        $parametripertestatagriglia = $this->getParametersTestataPerGriglia($request, $container, $em, $paricevuti);
60
61 4
        $griglia = $this->get("ficorebundle.griglia");
62 4
        $testatagriglia = $griglia->testataPerGriglia($parametripertestatagriglia);
63
64 4
        if ($request->get('titolo')) {
65
            $testatagriglia['titolo'] = $request->get('titolo');
66
        }
67 4
        $parametridatipergriglia = $this->getParametersDatiPerGriglia($request, $container, $em, $paricevuti);
68 4
        $corpogriglia = $griglia->datiPerGriglia($parametridatipergriglia);
69
70 4
        $parametri = array('request' => $request, 'testata' => $testatagriglia, 'griglia' => $corpogriglia);
71 4
        return $parametri;
72
    }
73
}
74