| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Fi\CoreBundle\Utils\Tabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Fi\CoreBundle\Utils\Tabella\ParametriTabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Fi\CoreBundle\Utils\Entity\EntityUtils; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class TabellaBase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     protected $parametri; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |     protected $colonnedatabase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     protected $opzionitabellacore; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     protected $configurazionecolonnetabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     protected $permessi; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     protected $records; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     protected $paginetotali; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected $righetotali; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected $traduzionefiltri; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     protected $em; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     protected $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 | 12 |  |     public function __construct($doctrine, $parametri = '{}') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 | 12 |  |         $this->parametri = $parametri; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 | 12 |  |         if (isset($this->parametri['em'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 12 |  |             $this->em = $doctrine->getManager(ParametriTabella::getParameter($this->parametri['em'])); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             $this->em = $doctrine->getManager(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 12 |  |         $this->tablename = $this->getTabellaParameter("tablename"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 12 |  |         $this->entityname = $this->getTabellaParameter("entityclass"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 12 |  |         $this->entityname = str_replace("FiCoreBundle", "CoreBundle", $this->entityname); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 12 |  |         $this->permessi = json_decode($this->getTabellaParameter("permessi")); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 12 |  |         $this->modellocolonne = json_decode($this->getTabellaParameter('modellocolonne', array()), true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 12 |  |         $this->paginacorrente = $this->getTabellaParameter("paginacorrente"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 12 |  |         $this->paginetotali = $this->getTabellaParameter("paginetotali"); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 12 |  |         $this->righeperpagina = $this->getTabellaParameter('righeperpagina', 15); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 | 12 |  |         $this->estraituttirecords = $this->getTabellaParameter('estraituttirecords', 0) === "1" ? true : false; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 12 |  |         $this->colonneordinamento = json_decode($this->getTabellaParameter('colonneordinamento', array()), true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 | 12 |  |         $this->prefiltri = json_decode($this->getTabellaParameter('prefiltri', array()), true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 12 |  |         $this->filtri = json_decode($this->getTabellaParameter('filtri', array()), true); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 12 |  |         $this->wheremanuale = $this->getTabellaParameter("wheremanuale", null); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 12 |  |         $this->user = $this->parametri["user"]; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 12 |  |         $this->colonnedatabase = $this->getColonneDatabase(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 12 |  |         $this->opzionitabellacore = $this->getOpzionitabellaFromCore(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 12 |  |         $this->configurazionecolonnetabella = $this->getAllOpzioniTabella(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 12 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 12 |  |     private function getTabellaParameter($name, $default = null) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 12 |  |         $risposta = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 | 12 |  |         if (isset($this->parametri[$name])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 12 |  |             $risposta = ParametriTabella::getParameter($this->parametri[$name]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 12 |  |             $risposta = $default; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 12 |  |         return $risposta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 5 |  |     protected function bonificaNomeCampo($nomecampo) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 5 |  |         $parti = explode(".", $nomecampo); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 5 |  |         $campo = ""; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 5 |  |         for ($index = 0; $index < count($parti); $index++) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 5 |  |             if ($index == count($parti) - 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 5 |  |                 $campo .= "." . lcfirst($parti[$index]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 5 |  |                 $campo .= "." . ucfirst($parti[$index]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 5 |  |         return substr($campo, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 12 |  |     public function getPaginacorrente() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 12 |  |         return $this->paginacorrente; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 7 |  |     public function getPaginetotali() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 7 |  |         return $this->paginetotali; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 | 12 |  |     public function getRigheperpagina() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 | 12 |  |         return $this->righeperpagina; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 12 |  |     public function getRighetotali() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 12 |  |         return $this->righetotali; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 93 | 7 |  |     public function getTraduzionefiltri() | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 95 | 7 |  |         return $this->traduzionefiltri; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 12 |  |     public function getColonneDatabase() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 12 |  |         $utils = new EntityUtils($this->em, $this->entityname); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 | 12 |  |         return $utils->getEntityColumns($this->entityname); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 | 10 |  |     public function getConfigurazionecolonnetabella() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 | 10 |  |         return $this->configurazionecolonnetabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 107 |  |  |  |