| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Cdf\BiCoreBundle\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Symfony\Component\HttpFoundation\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Cdf\BiCoreBundle\Utils\Export\TabellaXls; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Cdf\BiCoreBundle\Utils\Tabella\Tabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Symfony\Component\HttpFoundation\JsonResponse; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Security\Core\Exception\AccessDeniedException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | class FiTabellaController extends FiCrudController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 | 8 |  |     public function tabella(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 8 |  |         if (!$this->permessi->canRead()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 | 1 |  |             throw new AccessDeniedException("Non si hanno i permessi per visualizzare questo contenuto"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 7 |  |         $doctrine = $this->get("doctrine"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         //$em = $doctrine->getManager(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 7 |  |         $parametripassati = array_merge($request->get("parametri"), array('user' => $this->getUser())); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 7 |  |         $parametriform = isset($parametripassati["parametriform"]) ? | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 7 |  |                 json_decode(ParametriTabella::getParameter($parametripassati["parametriform"]), true) : array(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 7 |  |         $configurazionetabella = new Tabella($doctrine, $parametripassati); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $parametritabella = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 7 |  |             'parametritabella' => $configurazionetabella->getConfigurazionecolonnetabella(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 7 |  |             'recordstabella' => $configurazionetabella->getRecordstabella(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 7 |  |             'paginacorrente' => $configurazionetabella->getPaginacorrente(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 7 |  |             'paginetotali' => $configurazionetabella->getPaginetotali(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 7 |  |             'righetotali' => $configurazionetabella->getRighetotali(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 7 |  |             'traduzionefiltri' => $configurazionetabella->getTraduzionefiltri(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 7 |  |         $classbundle = ParametriTabella::getParameter($parametripassati["entityclass"]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         //$formbundle = $namespace . '\\' . $bundle . 'Bundle' . '\\Form\\' . $controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 7 |  |         $formbundle = ParametriTabella::getParameter($parametripassati["formclass"]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 7 |  |         $formType = $formbundle . 'Type'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 7 |  |         $entity = new $classbundle(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         //$tablename = ParametriTabella::getParameter($parametripassati["tablename"]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 7 |  |         $controller = ParametriTabella::getParameter($parametripassati["nomecontroller"]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 7 |  |         $form = $this->createForm( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 7 |  |             $formType, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 7 |  |             $entity, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             array('attr' => array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 7 |  |                 'id' => 'formdati' . $controller, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |                 ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 7 |  |                 'action' => $this->generateUrl($controller . '_new'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 7 |  |                 "parametriform" => $parametriform | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                 ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 7 |  |         $parametri = array_merge($parametripassati, $parametritabella); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 7 |  |         $parametri["form"] = $form->createView(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 7 |  |         $template = $controller . '/Tabella/tabellacontainer.html.twig'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 7 |  |         $templatelocation = $controller . "/"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 7 |  |         if (!$this->get('templating')->exists($template)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 6 |  |             $template = "BiCoreBundle:" . $controller . ':Tabella/tabellacontainer.html.twig'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 6 |  |             $templatelocation = "BiCoreBundle:" . $controller . ":"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 6 |  |             if (!$this->get('templating')->exists($template)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 5 |  |                 $templatelocation = 'BiCoreBundle:Standard:'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 5 |  |                 $template = $templatelocation . 'Tabella/tabellacontainer.html.twig'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 7 |  |         $parametri["templatelocation"] = $templatelocation; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 7 |  |         return $this->render( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 7 |  |             $template, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 7 |  |                     'parametri' => $parametri | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                         ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 77 | 3 |  |     public function exportXls(Request $request) | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 79 | 3 |  |         $doctrine = $this->get("doctrine"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 82 | 3 |  |             $parametripassati = array_merge($request->get("parametri"), array('user' => $this->getUser())); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 83 | 3 |  |             $parametripassati["estraituttirecords"] = ParametriTabella::setParameter("1"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 3 |  |             $configurazionetabella = new Tabella($doctrine, $parametripassati); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |             $parametritabella = array( | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 3 |  |                 'parametritabella' => $configurazionetabella->getConfigurazionecolonnetabella(), | 
            
                                                                        
                            
            
                                    
            
            
                | 87 | 3 |  |                 'recordstabella' => $configurazionetabella->getRecordstabella(), | 
            
                                                                        
                            
            
                                    
            
            
                | 88 | 3 |  |                 'paginacorrente' => $configurazionetabella->getPaginacorrente(), | 
            
                                                                        
                            
            
                                    
            
            
                | 89 | 3 |  |                 'paginetotali' => $configurazionetabella->getPaginetotali(), | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 3 |  |                 'righetotali' => $configurazionetabella->getRighetotali(), | 
            
                                                                        
                            
            
                                    
            
            
                | 91 | 3 |  |                 'traduzionefiltri' => $configurazionetabella->getTraduzionefiltri(), | 
            
                                                                        
                            
            
                                    
            
            
                | 92 | 3 |  |                 'nomecontroller' => ParametriTabella::getParameter($parametripassati["nomecontroller"]), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 94 | 3 |  |             $xls = new TabellaXls(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 95 | 3 |  |             $filexls = $xls->esportaexcel($parametritabella); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 96 | 3 |  |             if (file_exists($filexls)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |                 $response = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 98 | 3 |  |                     'status' => '200', | 
            
                                                                        
                            
            
                                    
            
            
                | 99 | 3 |  |                     'file' => "data:application/vnd.ms-excel;base64," . base64_encode(file_get_contents($filexls)) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |                 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 101 | 3 |  |                 @unlink($filexls); | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |                 $response = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 104 | 3 |  |                     'status' => '501', | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |                     'file' => "Impossibile generare il file excel" | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |                 ); | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |         } catch (\Exception $exc) { | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |             $response = array( | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |                 'status' => '500', | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |                 'file' => $exc->getFile() . " -> Riga: " . $exc->getLine() . " -> " . $exc->getMessage() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |             ); | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 115 | 3 |  |         return new JsonResponse($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 117 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |  | 
            
                        
PHP provides two ways to mark string literals. Either with single quotes
'literal'or with double quotes"literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\') and the backslash (\\). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is ValueIf your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.