Commit 4a9b29d37e052b9c33c9b79f682a3a21efd52434
1 parent
2b4665d1
Exists in
master
and in
7 other branches
--no commit message
Showing
2 changed files
with
46 additions
and
19 deletions
Show diff stats
admin/admin.db
No preview for this file type
ferramentas/saiku/esquemaxml.php
| ... | ... | @@ -16,12 +16,19 @@ exit; |
| 16 | 16 | |
| 17 | 17 | //cria as dimensoes de tipo temporal |
| 18 | 18 | $sqlAno = "select nu_ano from i3geo_metaestat.dim_tempo group by nu_ano order by nu_ano"; |
| 19 | +$sqlMes = "select nu_ano,nu_mes,ds_mes_abreviado as mes,nu_ano::text||'-'||nu_mes::text as nu_anomes from i3geo_metaestat.dim_tempo group by nu_ano,nu_mes,mes,nu_anomes order by nu_ano,nu_mes"; | |
| 19 | 20 | $xml .= " |
| 20 | - <Dimension name='Anual' type='TimeDimension' caption='Tempo: ano'> | |
| 21 | + <Dimension name='Anual' type='TimeDimension' caption='Tempo: Anual'> | |
| 21 | 22 | <Hierarchy hasAll='true' primaryKey='nu_ano'> |
| 22 | 23 | <view alias='tempo_ano' ><SQL dialect='generic' >$sqlAno</SQL></view> |
| 23 | - <Level name='Ano' column='nu_ano' type='Numeric' uniqueMembers='true' | |
| 24 | - levelType='TimeYears'/> | |
| 24 | + <Level name='Ano' column='nu_ano' type='Numeric' uniqueMembers='true' levelType='TimeYears'/> | |
| 25 | + </Hierarchy> | |
| 26 | + </Dimension> | |
| 27 | + <Dimension name='Mensal' type='TimeDimension' caption='Tempo: Mensal'> | |
| 28 | + <Hierarchy hasAll='true' primaryKey='nu_anomes'> | |
| 29 | + <view alias='tempo_ano' ><SQL dialect='generic' >$sqlMes</SQL></view> | |
| 30 | + <Level name='Ano' column='nu_ano' type='Numeric' uniqueMembers='true' levelType='TimeYears'/> | |
| 31 | + <Level nameColumn='mes' name='Mes' column='nu_mes' type='Numeric' uniqueMembers='false' levelType='TimeMonths'/> | |
| 25 | 32 | </Hierarchy> |
| 26 | 33 | </Dimension> |
| 27 | 34 | "; |
| ... | ... | @@ -62,17 +69,17 @@ foreach($regioes as $regiao){ |
| 62 | 69 | $tabelaAnt = "j".$i; |
| 63 | 70 | $niveis[] = " |
| 64 | 71 | <Level name='".converte($r["nome_tipo_regiao"])."' |
| 65 | - column='j$i{$r['identificador']}' | |
| 72 | + column='j$i{$r['identificador']}' | |
| 66 | 73 | nameColumn='j$i{$r["colunanomeregiao"]}' uniqueMembers='false'/> |
| 67 | 74 | "; |
| 68 | 75 | |
| 69 | 76 | } |
| 70 | 77 | $niveis[] = " |
| 71 | 78 | <Level name='".converte($regiao["nome_tipo_regiao"])."' |
| 72 | - column='codigo' | |
| 79 | + column='codigo' | |
| 73 | 80 | nameColumn='nome' uniqueMembers='true'> |
| 74 | 81 | "; |
| 75 | - | |
| 82 | + | |
| 76 | 83 | //verifica outras colunas |
| 77 | 84 | $vis = $regiao['colunasvisiveis']; |
| 78 | 85 | if($vis != ""){ |
| ... | ... | @@ -111,7 +118,7 @@ foreach($regioes as $regiao){ |
| 111 | 118 | <Property name='{$apelidos[$i]}' column='{$vis[$i]}'/> |
| 112 | 119 | "; |
| 113 | 120 | } |
| 114 | - } | |
| 121 | + } | |
| 115 | 122 | //fecha os elementos. LEVEL deve ser fechado pois o ultimo recebe as propriedades |
| 116 | 123 | $xml .= " |
| 117 | 124 | </Level> |
| ... | ... | @@ -143,28 +150,48 @@ foreach($tbs as $tb){ |
| 143 | 150 | $VirtualCubeDimension[] = " |
| 144 | 151 | <VirtualCubeDimension name='codigo_tipo_regiao_{$c["codigo_tipo_regiao"]}' /> |
| 145 | 152 | "; |
| 146 | - $xml .= " | |
| 147 | - <Cube name='{$c["esquemadb"]}{$c["tabela"]}'>"; | |
| 148 | - $xml .= " | |
| 149 | - <Table name='".$c["tabela"]."' schema='".$c["esquemadb"]."' /> | |
| 150 | - <DimensionUsage foreignKey='".$c["colunaidgeo"]."' name='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."' source='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."'/> | |
| 151 | - "; | |
| 152 | 153 | //verifica as dimensoes do tipo tempo |
| 153 | 154 | $dimTempo = array(); |
| 154 | 155 | foreach($tb as $medida){ |
| 155 | 156 | $parametros = $m->listaParametro($medida["id_medida_variavel"],"","",$apenasTempo=true,$ordenaPeloPai=false); |
| 157 | + $parComposto = array(); //guarda a composicao da chave que liga com a dimensao | |
| 156 | 158 | foreach($parametros as $parametro){ |
| 157 | 159 | if($parametro["tipo"] == 1){ |
| 158 | - $VirtualCubeDimension[] = " | |
| 159 | - <VirtualCubeDimension name='Anual' /> | |
| 160 | - "; | |
| 161 | - $dimTempo[] = " | |
| 162 | - <DimensionUsage foreignKey='".$parametro["coluna"]."' name='Anual_{$c["esquemadb"]}{$c["tabela"]}' source='Anual'/> | |
| 163 | - "; | |
| 160 | + if(count($parametros) == 1){ | |
| 161 | + $VirtualCubeDimension[] = " | |
| 162 | + <VirtualCubeDimension name='Anual' /> | |
| 163 | + "; | |
| 164 | + $dimTempo[] = " | |
| 165 | + <DimensionUsage foreignKey='".$parametro["coluna"]."' name='Anual' source='Anual'/> | |
| 166 | + "; | |
| 167 | + } | |
| 168 | + $parComposto[] = $parametro["coluna"]; | |
| 169 | + } | |
| 170 | + if($parametro["tipo"] == 2){ | |
| 171 | + $parComposto[] = $parametro["coluna"]; | |
| 172 | + if(count($parametros) == 2){ | |
| 173 | + $VirtualCubeDimension[] = " | |
| 174 | + <VirtualCubeDimension name='Mensal' /> | |
| 175 | + "; | |
| 176 | + $dimTempo[] = " | |
| 177 | + <DimensionUsage foreignKey='".implode("_",$parComposto)."' name='Mensal' source='Mensal'/> | |
| 178 | + "; | |
| 179 | + } | |
| 164 | 180 | } |
| 165 | 181 | } |
| 166 | 182 | //echo "<pre>";var_dump($parametro);exit; |
| 167 | 183 | } |
| 184 | + $xml .= " | |
| 185 | + <Cube name='{$c["esquemadb"]}{$c["tabela"]}'>"; | |
| 186 | + $sql = "select * from {$c["esquemadb"]}.{$c["tabela"]}"; | |
| 187 | + if(count($parComposto) > 0){ | |
| 188 | + $sql = "select *,".implode("||'-'||",$parComposto)." as ".implode("_",$parComposto)." from {$c["esquemadb"]}.{$c["tabela"]}"; | |
| 189 | + } | |
| 190 | + $xml .= " | |
| 191 | + <view alias='view_{$c["esquemadb"]}{$c["tabela"]}' ><SQL dialect='generic' >$sql</SQL></view> | |
| 192 | + <DimensionUsage foreignKey='".$c["colunaidgeo"]."' name='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."' source='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."'/> | |
| 193 | + "; | |
| 194 | + | |
| 168 | 195 | $xml .= implode(" ",array_unique($dimTempo)); |
| 169 | 196 | |
| 170 | 197 | //inclui cada elemento em medida | ... | ... |