| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Fi\CoreBundle\Utils\Tabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use \Doctrine\Common\Collections\Expr\Comparison; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Fi\CoreBundle\Utils\Tabella\ParametriTabella; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class TabellaDecoder extends TabellaBase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     private $aliasGenerati; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     private $decodificaAlias; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 | 3 |  |     protected function getDescrizioneFiltro(&$descrizionefiltri, $filtrocorrente, $criteria) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 | 3 |  |         if ($filtrocorrente["prefiltro"] === false) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 | 2 |  |             $descrizionefiltri = $descrizionefiltri . ", " . $criteria->getDescrizioneFiltro(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 | 3 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 | 3 |  |     protected function getFieldValue($fieldvalue) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 | 3 |  |         if (isset($fieldvalue["date"])) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             //StdClassUtils::arrayToObject($fieldvalue, DatetimeTabella::class); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 | 1 |  |             return new \Datetime($fieldvalue["date"]); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 3 |  |             return $fieldvalue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 3 |  |     protected function getOperator($operator) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 | 3 |  |         switch (strtoupper($operator)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 3 |  |             case "LIKE": | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 | 1 |  |                 $operator = Comparison::CONTAINS; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 1 |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 3 |  |             case "IN": | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 | 1 |  |                 $operator = Comparison::IN; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 1 |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 3 |  |             case "NOT IN": | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 1 |  |                 $operator = Comparison::NIN; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 | 1 |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             default: | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 3 |  |                 break; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 3 |  |         return $operator; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 47 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 48 | 12 |  |     protected function generaAlias($nometabella, $nomepadre = false, $ancestors = array()) | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 | 12 |  |         $nometabellapulito = preg_replace('/[^a-z0-9\.]/i', '', $nometabella); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 | 12 |  |         $primalettera = strtolower(substr($nometabellapulito, 0, 1)); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 52 | 12 |  |         if ($nomepadre && !in_array($nomepadre, $ancestors)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |             $ancestors[] = $nomepadre; | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 | 12 |  |         if (!in_array($nometabella, $ancestors)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 56 | 12 |  |             $ancestors[] = $nometabella; | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 | 12 |  |         if (isset($this->aliasGenerati[$primalettera])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 60 | 3 |  |             $risposta = $primalettera . $this->aliasGenerati[$primalettera]; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 61 | 3 |  |             $this->aliasGenerati[$primalettera] = $this->aliasGenerati[$primalettera] + 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |         } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 63 | 12 |  |             $risposta = $primalettera; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 12 |  |             $this->aliasGenerati[$primalettera] = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 67 | 12 |  |         $this->decodificaAlias[ucfirst(implode(".", $ancestors))] = array("alias" => $risposta); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 69 | 12 |  |         return $risposta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 3 |  |     protected function findAliasByTablename($tablename) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 3 |  |         if (!array_key_exists($tablename, $this->decodificaAlias)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             $ex = "Fifree: table or association " . $tablename . " not found, did you mean one of these:\n" . | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                     implode("\n", array_keys($this->decodificaAlias)) . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                     " ?"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |             throw new \Exception($ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 3 |  |         return $this->getAliasGenerato($tablename); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 3 |  |     protected function findFieldnameByAlias($nomecampo) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 3 |  |         if (!array_key_exists($nomecampo, $this->configurazionecolonnetabella)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             $ex = "Fifree: field or association " . $nomecampo . " not found, did you mean one of these:\n" . | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                     implode("\n", array_keys($this->configurazionecolonnetabella)) . | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                     " ?"; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             throw new \Exception($ex); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 | 3 |  |         return $this->configurazionecolonnetabella[$nomecampo]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 | 10 |  |     public function getAliasGenerato($tablename) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 10 |  |         return $this->decodificaAlias[$tablename]["alias"]; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 95 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 96 |  |  |  | 
            
                        
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.