Completed
Push — master ( c6735e...5bf063 )
by Andrea
09:55
created

GrigliaColonneUtils::getEtichettaNomeColonna()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
3
namespace Fi\CoreBundle\DependencyInjection;
4
5
class GrigliaColonneUtils
6
{
7
8 4
    public static function getColonne(&$nomicolonne, &$modellocolonne, &$indice, $paricevuti)
9
    {
10 4
        $doctrine = GrigliaParametriUtils::getDoctrineByEm($paricevuti);
11
12 4
        $nometabella = $paricevuti['nometabella'];
13 4
        $bundle = $paricevuti['nomebundle'];
14 4
        $entityName = $bundle . ':' . $nometabella;
15
16 4
        $colonne = self::getColonneDatabase(array('entityName' => $entityName, 'doctrine' => $doctrine));
17
18 4
        foreach ($colonne as $chiave => $colonna) {
19 4
            self::elaboraColonna($chiave, $colonna, $nomicolonne, $modellocolonne, $indice, $paricevuti);
20
        }
21 4
    }
22
23 4
    public static function elaboraColonna(&$chiave, &$colonna, &$nomicolonne, &$modellocolonne, &$indice, $paricevuti)
24
    {
25 4
        $alias = GrigliaParametriUtils::getAliasTestataPerGriglia($paricevuti);
26 4
        $escludere = GrigliaParametriUtils::getCampiEsclusiTestataPerGriglia($paricevuti);
27 4
        $escludereutente = GrigliaRegoleUtils::campiesclusi($paricevuti);
28
29 4
        if ((!isset($escludere) || !(in_array($chiave, $escludere))) && (!isset($escludereutente) || !(in_array($chiave, $escludereutente)))) {
30 4
            if (isset($alias[$chiave])) {
31 3
                self::getAliasCampi($nomicolonne, $modellocolonne, $indice, $chiave, $colonna, $paricevuti);
32
            } else {
33 4
                self::getDettagliCampi($nomicolonne, $modellocolonne, $alias, $indice, $chiave, $colonna, $paricevuti);
34
            }
35
        }
36 4
    }
37
38 4
    public static function getColonneDatabase($parametri = array())
39
    {
40 4
        $entityName = $parametri['entityName'];
41
        /* @var $doctrine \Doctrine\ORM\EntityManager */
42 4
        $doctrine = $parametri['doctrine'];
43
44
        /* $infocolonne = $doctrine->getClassMetadata($entityName)->getColumnNames(); */
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45 4
        $infocolonne = $doctrine->getMetadataFactory()->getMetadataFor($entityName);
46
        /* $infocolonne = get_object_vars($infocolonne); */
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47 4
        $colonne = array();
48 4
        foreach ($infocolonne->fieldMappings as $colonna) {
49
            /* getFieldMapping */
50
            /* $ret = $doctrine->getMetadataFactory()->getMetadataFor($entityName)->; */
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
51 4
            $colonne[$colonna['fieldName']] = $colonna;
52
53
            /* $colonne[$colonna] = $doctrine->getClassMetadata($entityName)->getTypeOfField($colonna);
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
              $colonne[$colonna] = $doctrine->getClassMetadata($entityName)->getColumnName($colonna);
55
              $colonne[$colonna] = $doctrine->getClassMetadata($entityName)->getFieldForColumn($colonna);
56
              $colonne[$colonna] = $doctrine->getClassMetadata($entityName)->getTypeOfColumn($colonna);
57
              $colonne[$colonna] = $doctrine->getClassMetadata($entityName)->getColumnNames();
58
             */
59 4
            if ($colonne[$colonna['fieldName']]['type'] == 'integer' || !(isset($colonne[$colonna['fieldName']]['length']))) {
60 4
                $colonne[$colonna['fieldName']]['length'] = 11;
61
            }
62
        }
63
64 4
        return $colonne;
65
    }
66
67 4
    public static function getColonneOrdinate($ordine)
68
    {
69 4
        $ordinecolonne = null;
70
71 4
        if (count($ordine) > 0) {
72
            $ordinecolonne = array();
73
            foreach ($ordine as $value) {
74
                $ordinecolonne[] = $value;
75
            }
76
        }
77
78 4
        return $ordinecolonne;
79
    }
80
81 3
    public static function getAliasCampi(&$nomicolonne, &$modellocolonne, &$indice, &$chiave, &$colonna, $paricevuti)
82
    {
83 3
        $alias = GrigliaParametriUtils::getAliasTestataPerGriglia($paricevuti);
84 3
        $etichetteutente = GrigliaUtils::etichettecampi($paricevuti);
85 3
        $larghezzeutente = GrigliaUtils::larghezzecampi($paricevuti);
86 3
        $ordinecolonne = GrigliaParametriUtils::getOrdineColonneTestataPerGriglia($paricevuti);
87
88 3
        $moltialias = (isset($alias[$chiave]) ? $alias[$chiave] : null);
89
90 3
        $indicecolonna = 0;
91
92 3
        foreach ($moltialias as $singoloalias) {
93 3
            GrigliaInfoCampiUtils::setOrdineColonne($ordinecolonne, $chiave, $indice, $indicecolonna);
94
95 3
            GrigliaInfoCampiUtils::getSingoloAliasNormalizzato($singoloalias);
96
97 3
            GrigliaInfoCampiUtils::setNomiColonne($nomicolonne, $chiave, $singoloalias, $indicecolonna, $etichetteutente);
98
99 3
            GrigliaInfoCampiUtils::setModelliColonne($modellocolonne, $colonna, $chiave, $singoloalias, $indicecolonna, $larghezzeutente);
100
        }
101 3
    }
102
103
    public static function getEtichettaDescrizioneColonna(&$singoloalias, $chiave)
104
    {
105
        $parametri = array('str' => $chiave, 'primamaiuscola' => true);
106
107
        return isset($singoloalias['descrizione']) ? $singoloalias['descrizione'] : GrigliaUtils::toCamelCase($parametri);
108
    }
109
110
    public static function getEtichettaNomeColonna(&$etichetteutente, $chiave)
111
    {
112
        return GrigliaUtils::toCamelCase(array('str' => trim($etichetteutente[$chiave]), 'primamaiuscola' => true));
113
    }
114
115
    public static function getWidthCampo(&$colonna, &$chiave, $singoloalias, $larghezzeutente)
116
    {
117
        if ((isset($larghezzeutente[$chiave])) && ($larghezzeutente[$chiave] != '') && ($larghezzeutente[$chiave] != 0)) {
118
            $widthcampo = $larghezzeutente[$chiave];
119
        } else {
120
            $moltiplicatorelarghezza = GrigliaUtils::MOLTIPLICATORELARGHEZZA;
121
            $larghezzamassima = GrigliaUtils::LARGHEZZAMASSIMA;
122
            $singoloaliaslunghezza = $singoloalias['lunghezza'];
123
            $moltiplicatore = $colonna['length'] * $moltiplicatorelarghezza;
124
            $larghezzacalc = $colonna['length'] * GrigliaUtils::MOLTIPLICATORELARGHEZZA;
125
            $larghezzaricalcolata = ($moltiplicatore > $larghezzamassima ? $larghezzamassima : $larghezzacalc);
126
127
            $widthcampo = isset($singoloaliaslunghezza) ? $singoloaliaslunghezza : $larghezzaricalcolata;
128
        }
129
130
        return $widthcampo;
131
    }
132
133 4
    public static function getDettagliCampi(&$nomicolonne, &$modellocolonne, &$alias, &$indice, &$chiave, &$colonna, &$paricevuti)
134
    {
135 4
        $etichetteutente = GrigliaUtils::etichettecampi($paricevuti);
136 4
        $larghezzeutente = GrigliaUtils::larghezzecampi($paricevuti);
137 4
        $ordinecolonne = GrigliaParametriUtils::getOrdineColonneTestataPerGriglia($paricevuti);
138
139 4
        $indicecolonna = 0;
140
141 4
        GrigliaInfoCampiUtils::setOrdineColonne($ordinecolonne, $chiave, $indice, $indicecolonna);
142
143 4
        GrigliaInfoCampiUtils::setNomiColonne($nomicolonne, $chiave, $alias, $indicecolonna, $etichetteutente);
144
145 4
        if ((isset($larghezzeutente[$chiave])) && ($larghezzeutente[$chiave] != '') && ($larghezzeutente[$chiave] != 0)) {
146
            $widthcampo = $larghezzeutente[$chiave];
147
        } else {
148 4
            $widthcampo = ($colonna['length'] * GrigliaUtils::MOLTIPLICATORELARGHEZZA > GrigliaUtils::LARGHEZZAMASSIMA ?
149
                    GrigliaUtils::LARGHEZZAMASSIMA :
150 4
                    $colonna['length'] * GrigliaUtils::MOLTIPLICATORELARGHEZZA);
151
        }
152
153 4
        $modellocolonne[$indicecolonna] = array('name' => $chiave, 'id' => $chiave, 'width' => $widthcampo, 'tipocampo' => $colonna['type']);
154 4
    }
155
}
156