Commit 294ab4fa1fcdbd60d3f5e27782cb21f148c3193e
1 parent
113e9551
Exists in
master
and in
7 other branches
$1
Showing
2 changed files
with
123 additions
and
44 deletions
Show diff stats
admin/php/classe_metaestat.php
| @@ -529,7 +529,7 @@ class Metaestat{ | @@ -529,7 +529,7 @@ class Metaestat{ | ||
| 529 | } | 529 | } |
| 530 | } | 530 | } |
| 531 | function hierarquiaPath($node){ | 531 | function hierarquiaPath($node){ |
| 532 | - $query="select codigo_tipo_regiao as parent from ".$this->esquemaadmin."i3geoestat_agregaregiao WHERE codigo_tipo_regiao_pai = $node"; | 532 | + $query="select codigo_tipo_regiao_pai as parent from ".$this->esquemaadmin."i3geoestat_agregaregiao WHERE codigo_tipo_regiao = $node"; |
| 533 | $result=$this->execSQL($query,"",false); | 533 | $result=$this->execSQL($query,"",false); |
| 534 | $row = $result[0]; | 534 | $row = $result[0]; |
| 535 | // save the path in this array | 535 | // save the path in this array |
| @@ -544,7 +544,8 @@ class Metaestat{ | @@ -544,7 +544,8 @@ class Metaestat{ | ||
| 544 | // to the path | 544 | // to the path |
| 545 | $path = array_merge($this->hierarquiaPath($row['parent']), $path); | 545 | $path = array_merge($this->hierarquiaPath($row['parent']), $path); |
| 546 | } | 546 | } |
| 547 | - // return the path | 547 | + // return the path |
| 548 | + sort($path); | ||
| 548 | return $path; | 549 | return $path; |
| 549 | } | 550 | } |
| 550 | /** | 551 | /** |
ferramentas/saiku/esquemaxml.php
| @@ -4,13 +4,23 @@ $m = new Metaestat(); | @@ -4,13 +4,23 @@ $m = new Metaestat(); | ||
| 4 | 4 | ||
| 5 | $regioes = $m->listaTipoRegiao(); | 5 | $regioes = $m->listaTipoRegiao(); |
| 6 | $xml = "<Schema name='i3Geo Metaestat'>"; | 6 | $xml = "<Schema name='i3Geo Metaestat'>"; |
| 7 | +/* | ||
| 8 | +echo "<pre>"; | ||
| 7 | foreach($regioes as $regiao){ | 9 | foreach($regioes as $regiao){ |
| 10 | + echo $regiao["codigo_tipo_regiao"]."<br>"; | ||
| 8 | $caminho = $m->hierarquiaPath($regiao["codigo_tipo_regiao"]); | 11 | $caminho = $m->hierarquiaPath($regiao["codigo_tipo_regiao"]); |
| 12 | + var_dump($caminho); | ||
| 13 | +} | ||
| 14 | +exit; | ||
| 15 | +*/ | ||
| 16 | +foreach($regioes as $regiao){ | ||
| 17 | + $caminho = $m->hierarquiaPath($regiao["codigo_tipo_regiao"]); | ||
| 18 | + | ||
| 9 | // | 19 | // |
| 10 | //verifica se a regiao tem hierarquia | 20 | //verifica se a regiao tem hierarquia |
| 11 | if(empty($caminho)){ | 21 | if(empty($caminho)){ |
| 12 | $xml .= " | 22 | $xml .= " |
| 13 | - <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='".converte($regiao["nome_tipo_regiao"])."'> | 23 | + <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='Onde: ".converte($regiao["nome_tipo_regiao"])."'> |
| 14 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> | 24 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> |
| 15 | <Table name='".$regiao["tabela"]."' schema='".$regiao["esquemadb"]."' /> | 25 | <Table name='".$regiao["tabela"]."' schema='".$regiao["esquemadb"]."' /> |
| 16 | <Level name='Nome - ".converte($regiao["nome_tipo_regiao"])."' column='".$regiao["colunanomeregiao"]."' uniqueMembers='true'/> | 26 | <Level name='Nome - ".converte($regiao["nome_tipo_regiao"])."' column='".$regiao["colunanomeregiao"]."' uniqueMembers='true'/> |
| @@ -20,73 +30,141 @@ foreach($regioes as $regiao){ | @@ -20,73 +30,141 @@ foreach($regioes as $regiao){ | ||
| 20 | } | 30 | } |
| 21 | else{ | 31 | else{ |
| 22 | $xml .= " | 32 | $xml .= " |
| 23 | - <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='".converte($regiao["nome_tipo_regiao"])."'> | ||
| 24 | - <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> | 33 | + <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='Onde: ".converte($regiao["nome_tipo_regiao"])."'> |
| 34 | + <Hierarchy hasAll='true' primaryKey='codigo'> | ||
| 25 | "; | 35 | "; |
| 26 | //cria uma view juntando as tabelas da hierarquia de regioes | 36 | //cria uma view juntando as tabelas da hierarquia de regioes |
| 27 | $n = count($caminho); | 37 | $n = count($caminho); |
| 28 | - $r = $m->listaTipoRegiao($caminho[0]); | ||
| 29 | $colunas = array(); | 38 | $colunas = array(); |
| 30 | - $sql = "SELECT __COLUNAS__ FROM {$r['esquemadb']}.{$r['tabela']} AS regiao "; | ||
| 31 | - $colunas[] = "regiao.".$r['identificador']; | ||
| 32 | - $colunas[] = "regiao.".$r['colunanomeregiao']; | 39 | + $niveis = array(); |
| 40 | + $sql = "SELECT __COLUNAS__ FROM {$regiao['esquemadb']}.{$regiao['tabela']} AS regiao "; | ||
| 41 | + $colunas[] = "regiao.{$regiao['identificador']} AS codigo "; | ||
| 42 | + $colunas[] = "regiao.{$regiao['colunanomeregiao']} AS nome"; | ||
| 33 | $tabelaAnt = "regiao"; | 43 | $tabelaAnt = "regiao"; |
| 34 | - if($n > 1){ | ||
| 35 | - for($i=1;$i<$n;$i++){ | ||
| 36 | - $r = $m->listaTipoRegiao($caminho[$i]); | ||
| 37 | - $colunas[] = "j".$i.".".$r['colunanomeregiao']; | ||
| 38 | - $colunas[] = "j".$i.".".$r['identificador']; | ||
| 39 | - $sql .= "INNER JOIN {$r['esquemadb']}.{$r['tabela']} | ||
| 40 | - AS j$i ON j$i.{$r['identificador']}::text = {$tabelaAnt}.{$r['identificador']}::text | ||
| 41 | - "; | ||
| 42 | - $tabelaAnt = "j".$i; | 44 | + for($i=0;$i<$n;$i++){ |
| 45 | + $r = $m->listaTipoRegiao($caminho[$i]); | ||
| 46 | + $colunas[] = "j$i.{$r['colunanomeregiao']} AS j$i{$r['colunanomeregiao']}"; | ||
| 47 | + $colunas[] = "j$i.{$r['identificador']} AS j$i{$r['identificador']}"; | ||
| 48 | + $sql .= "INNER JOIN {$r['esquemadb']}.{$r['tabela']} | ||
| 49 | + AS j$i ON j$i.{$r['identificador']}::text = {$tabelaAnt}.{$r['identificador']}::text | ||
| 50 | + "; | ||
| 51 | + $tabelaAnt = "j".$i; | ||
| 52 | + $niveis[] = " | ||
| 53 | + <Level name='".converte($r["nome_tipo_regiao"])."' | ||
| 54 | + column='j$i{$r['identificador']}' | ||
| 55 | + nameColumn='j$i{$r["colunanomeregiao"]}' uniqueMembers='false'/> | ||
| 56 | + "; | ||
| 57 | + | ||
| 58 | + } | ||
| 59 | + $niveis[] = " | ||
| 60 | + <Level name='".converte($regiao["nome_tipo_regiao"])."' | ||
| 61 | + column='codigo' | ||
| 62 | + nameColumn='nome' uniqueMembers='true'> | ||
| 63 | + "; | ||
| 64 | + | ||
| 65 | + //verifica outras colunas | ||
| 66 | + $vis = $regiao['colunasvisiveis']; | ||
| 67 | + if($vis != ""){ | ||
| 68 | + $vis = str_replace(";",",",$vis); | ||
| 69 | + $vis = str_replace(",,",",",$vis); | ||
| 70 | + $vis = explode(",",$vis); | ||
| 71 | + foreach($vis as $v){ | ||
| 72 | + //if($v != $regiao['colunanomeregiao'] && $v != $regiao['identificador']){ | ||
| 73 | + $colunas[] = "regiao.".$v." as ".$v; | ||
| 74 | + //} | ||
| 43 | } | 75 | } |
| 76 | + $colunas = array_unique($colunas); | ||
| 44 | } | 77 | } |
| 45 | - $sql .= "INNER JOIN {$regiao['esquemadb']}.{$regiao['tabela']} | ||
| 46 | - AS j$i ON j$i.{$regiao['identificador']}::text = {$tabelaAnt}.{$regiao['identificador']}::text | ||
| 47 | - "; | ||
| 48 | - $colunas[] = "j".$i.".".$regiao['colunanomeregiao']; | ||
| 49 | - $colunas[] = "j".$i.".".$regiao['identificador']; | ||
| 50 | $colunas = implode($colunas,","); | 78 | $colunas = implode($colunas,","); |
| 51 | $sql = str_replace("__COLUNAS__",$colunas,$sql); | 79 | $sql = str_replace("__COLUNAS__",$colunas,$sql); |
| 52 | $xml .= " | 80 | $xml .= " |
| 53 | - <view><sql>$sql</sql></view> | 81 | + <view alias='view_codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' ><SQL dialect='generic' >$sql</SQL></view> |
| 54 | "; | 82 | "; |
| 55 | - //<Level name='Nome - ".converte($regiao["nome_tipo_regiao"])."' column='".$regiao["colunanomeregiao"]."' uniqueMembers='true'/> | 83 | + $xml .= implode(" ",$niveis); |
| 84 | + //verifica se existem propriedades (colunas adicionais) | ||
| 85 | + if($vis != ""){ | ||
| 86 | + //apelidos | ||
| 87 | + $apelidos = $regiao['apelidos']; | ||
| 88 | + if($apelidos != ""){ | ||
| 89 | + $apelidos = str_replace(";",",",$apelidos); | ||
| 90 | + $apelidos = str_replace(",,",",",$apelidos); | ||
| 91 | + $apelidos = converte($apelidos); | ||
| 92 | + $apelidos = explode(",",$apelidos); | ||
| 93 | + } | ||
| 94 | + else{ | ||
| 95 | + $apelidos = $vis; | ||
| 96 | + } | ||
| 97 | + $nvis = count($vis); | ||
| 98 | + for($i = 0; $i < $nvis; $i++){ | ||
| 99 | + $xml .= " | ||
| 100 | + <Property name='{$apelidos[$i]}' column='{$vis[$i]}'/> | ||
| 101 | + "; | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + //fecha os elementos. LEVEL deve ser fechado pois o ultimo recebe as propriedades | ||
| 56 | $xml .= " | 105 | $xml .= " |
| 106 | + </Level> | ||
| 57 | </Hierarchy> | 107 | </Hierarchy> |
| 58 | </Dimension> | 108 | </Dimension> |
| 59 | "; | 109 | "; |
| 60 | } | 110 | } |
| 61 | } | 111 | } |
| 62 | - | ||
| 63 | -$xml .= " | ||
| 64 | - <Cube name='Vari&aacute;veis'>"; | 112 | +//junta as medidas conforme o nome da tabela utilizada |
| 65 | $medidas = $m->listaMedidaVariavel(); | 113 | $medidas = $m->listaMedidaVariavel(); |
| 66 | -$tabela = ""; | 114 | +$tbs = array(); |
| 115 | + | ||
| 67 | foreach($medidas as $medida){ | 116 | foreach($medidas as $medida){ |
| 68 | - $agregador = "sum"; | ||
| 69 | - if($medida["permitesoma"] == 0 && $medida["permitemedia"] == 1){ | ||
| 70 | - $agregador = "avg"; | 117 | + $k = $medida["esquemadb"].$medida["tabela"]; |
| 118 | + if(empty($tbs[$k])){ | ||
| 119 | + $tbs[$k] = array($medida); | ||
| 71 | } | 120 | } |
| 72 | - if($medida["permitesoma"] == 0 && $medida["permitemedia"] == 0){ | ||
| 73 | - $agregador = "count"; | 121 | + else{ |
| 122 | + array_push($tbs[$k],$medida); | ||
| 74 | } | 123 | } |
| 75 | - if($tabela != $medida["esquemadb"].".".$medida["tabela"]){ | 124 | +} |
| 125 | + | ||
| 126 | +//monta os cubos para cada esquema.tabela diferente | ||
| 127 | +$VirtualCubeDimension = array(); | ||
| 128 | +$VirtualCubeMeasure = array(); | ||
| 129 | +foreach($tbs as $tb){ | ||
| 130 | + //cabecalho de cada cubo obtido da primeira medida | ||
| 131 | + $c = $tb[0]; | ||
| 132 | + $VirtualCubeDimension[] = " | ||
| 133 | + <VirtualCubeDimension name='codigo_tipo_regiao_{$c["codigo_tipo_regiao"]}' /> | ||
| 134 | + "; | ||
| 135 | + $xml .= " | ||
| 136 | + <Cube name='{$c["esquemadb"]}{$c["tabela"]}'>"; | ||
| 137 | + $xml .= " | ||
| 138 | + <Table name='".$c["tabela"]."' schema='".$c["esquemadb"]."' /> | ||
| 139 | + <DimensionUsage foreignKey='".$c["colunaidgeo"]."' name='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."' source='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."'/> | ||
| 140 | + "; | ||
| 141 | + //inclui cada elemento em medida | ||
| 142 | + foreach($tb as $medida){ | ||
| 143 | + $agregador = "sum"; | ||
| 144 | + if($medida["permitesoma"] == 0 && $medida["permitemedia"] == 1){ | ||
| 145 | + $agregador = "avg"; | ||
| 146 | + } | ||
| 147 | + if($medida["permitesoma"] == 0 && $medida["permitemedia"] == 0){ | ||
| 148 | + $agregador = "count"; | ||
| 149 | + } | ||
| 76 | $xml .= " | 150 | $xml .= " |
| 77 | - <Table name='".$medida["tabela"]."' schema='".$medida["esquemadb"]."' /> | ||
| 78 | - <DimensionUsage foreignKey='".$medida["colunaidgeo"]."' name='codigo_tipo_regiao_".$medida["codigo_tipo_regiao"]."' source='codigo_tipo_regiao_".$medida["codigo_tipo_regiao"]."'/> | 151 | + <Measure name='id_medida_variavel_".$medida["id_medida_variavel"]."' caption='".converte($medida["nomemedida"])."' column='".$medida["colunavalor"]."' aggregator='".$agregador."' /> |
| 152 | + "; | ||
| 153 | + $VirtualCubeMeasure[] = " | ||
| 154 | + <VirtualCubeMeasure cubeName='{$c["esquemadb"]}{$c["tabela"]}' name='[Measures].[id_medida_variavel_".$medida["id_medida_variavel"]."]'/> | ||
| 79 | "; | 155 | "; |
| 80 | } | 156 | } |
| 81 | $xml .= " | 157 | $xml .= " |
| 82 | - <Measure name='id_medida_variavel_".$medida["id_medida_variavel"]."' caption='".converte($medida["nomemedida"])."' column='".$medida["colunavalor"]."' aggregator='".$agregador."' /> | ||
| 83 | - "; | ||
| 84 | - | ||
| 85 | - $tabela = $medida["esquemadb"].".".$medida["tabela"]; | 158 | + </Cube> |
| 159 | + "; | ||
| 86 | } | 160 | } |
| 87 | -$xml .= " | ||
| 88 | - </Cube> | ||
| 89 | - </Schema>"; | 161 | +$xml .= '<VirtualCube name="i3Geo - Metaestat" >'; |
| 162 | +$VirtualCubeDimension = array_unique($VirtualCubeDimension); | ||
| 163 | +$VirtualCubeMeasure = array_unique($VirtualCubeMeasure); | ||
| 164 | +$xml .= implode(" ",$VirtualCubeDimension); | ||
| 165 | +$xml .= implode(" ",$VirtualCubeMeasure); | ||
| 166 | +$xml .= '</VirtualCube>'; | ||
| 167 | +$xml .= "</Schema>"; | ||
| 90 | error_reporting(0); | 168 | error_reporting(0); |
| 91 | ob_end_clean(); | 169 | ob_end_clean(); |
| 92 | echo header("Content-type: application/xml"); | 170 | echo header("Content-type: application/xml"); |