Commit 113e9551954ffa64f6e51bb2cd470b15142336cd
1 parent
533a2553
Exists in
master
and in
7 other branches
--no commit message
Showing
3 changed files
with
51 additions
and
38 deletions
Show diff stats
admin/admin.db
No preview for this file type
admin/php/classe_metaestat.php
... | ... | @@ -514,32 +514,39 @@ class Metaestat{ |
514 | 514 | * @return array lista de ids de regioes sequenciais do filho ate chegar ao pai indicado |
515 | 515 | */ |
516 | 516 | function regiaoFilhaAoPai($codigo_tipo_regiao,$codigo_tipo_regiao_pai=""){ |
517 | - //echo $codigo_tipo_regiao." ".$codigo_tipo_regiao_pai; | |
518 | 517 | $pais = $this->listaAgregaRegiao($codigo_tipo_regiao); |
519 | 518 | $caminho = array($codigo_tipo_regiao); |
520 | 519 | $colunas = array(); |
521 | 520 | if(count($pais) == 0){ |
522 | 521 | return $caminho; |
523 | 522 | } |
524 | - $achou = false; | |
525 | 523 | foreach($pais as $pai){ |
526 | 524 | $caminho[] = $pai["codigo_tipo_regiao_pai"]; |
527 | 525 | $colunas[$pai["codigo_tipo_regiao"]] = $pai; |
528 | 526 | if($pai["codigo_tipo_regiao_pai"] == $codigo_tipo_regiao_pai){ |
529 | - $achou = true; | |
530 | 527 | return array("caminho"=>$caminho,"colunas"=>$colunas); |
531 | 528 | } |
532 | - $testaPai = $this->regiaoFilhaAoPai($pai["codigo_tipo_regiao_pai"],$codigo_tipo_regiao_pai); | |
533 | - if(count($testaPai) == 0 && $codigo_tipo_regiao_pai == ""){ | |
534 | - return array("caminho"=>$caminho,"colunas"=>$colunas); | |
535 | - } | |
536 | - if(count($testaPai) == 0){ | |
537 | - $caminho = array(); | |
538 | - $colunas = array(); | |
539 | - } | |
540 | 529 | } |
541 | - | |
542 | 530 | } |
531 | + function hierarquiaPath($node){ | |
532 | + $query="select codigo_tipo_regiao as parent from ".$this->esquemaadmin."i3geoestat_agregaregiao WHERE codigo_tipo_regiao_pai = $node"; | |
533 | + $result=$this->execSQL($query,"",false); | |
534 | + $row = $result[0]; | |
535 | + // save the path in this array | |
536 | + $path = array(); | |
537 | + // only continue if this $node isn't the root node | |
538 | + // (that's the node with no parent) | |
539 | + if ($row['parent']!='') { | |
540 | + // the last part of the path to $node, is the name | |
541 | + // of the parent of $node | |
542 | + $path[] = $row['parent']; | |
543 | + // we should add the path to the parent of this node | |
544 | + // to the path | |
545 | + $path = array_merge($this->hierarquiaPath($row['parent']), $path); | |
546 | + } | |
547 | + // return the path | |
548 | + return $path; | |
549 | + } | |
543 | 550 | /** |
544 | 551 | * Cria um arquivo mapfile para uma medida de variavel |
545 | 552 | * Inclui no arquivo o layer de acesso aos dados |
... | ... | @@ -2018,7 +2025,7 @@ class Metaestat{ |
2018 | 2025 | * @param codigo da regiao |
2019 | 2026 | */ |
2020 | 2027 | function listaHierarquiaRegioes($codigoregiaopai=""){ |
2021 | - $sql = "select i3geoestat_agregaregiao.colunaligacao_regiaopai,i3geoestat_tipo_regiao.codigo_tipo_regiao,i3geoestat_tipo_regiao.nome_tipo_regiao from ".$this->esquemaadmin."i3geoestat_tipo_regiao "; | |
2028 | + $sql = "select i3geoestat_agregaregiao.id_agregaregiao,i3geoestat_agregaregiao.colunaligacao_regiaopai,i3geoestat_tipo_regiao.codigo_tipo_regiao,i3geoestat_tipo_regiao.nome_tipo_regiao from ".$this->esquemaadmin."i3geoestat_tipo_regiao "; | |
2022 | 2029 | $sql .= "LEFT JOIN ".$this->esquemaadmin."i3geoestat_agregaregiao "; |
2023 | 2030 | $sql .= "ON i3geoestat_tipo_regiao.codigo_tipo_regiao = i3geoestat_agregaregiao.codigo_tipo_regiao "; |
2024 | 2031 | if($codigoregiaopai != ""){ |
... | ... | @@ -2083,13 +2090,15 @@ class Metaestat{ |
2083 | 2090 | * @param codigo do tipo de regiao |
2084 | 2091 | * @param id da agregacao |
2085 | 2092 | */ |
2086 | - function listaAgregaRegiao($codigo_tipo_regiao,$id_agregaregiao=""){ | |
2093 | + function listaAgregaRegiao($codigo_tipo_regiao="",$id_agregaregiao=""){ | |
2087 | 2094 | $sql = "select * from ".$this->esquemaadmin."i3geoestat_agregaregiao "; |
2088 | 2095 | if($id_agregaregiao != ""){ |
2089 | 2096 | $sql .= "WHERE id_agregaregiao = $id_agregaregiao "; |
2090 | 2097 | } |
2091 | 2098 | else{ |
2092 | - $sql .= "WHERE codigo_tipo_regiao = $codigo_tipo_regiao"; | |
2099 | + if($codigo_tipo_regiao != ""){ | |
2100 | + $sql .= "WHERE codigo_tipo_regiao = $codigo_tipo_regiao"; | |
2101 | + } | |
2093 | 2102 | } |
2094 | 2103 | $sql .= " ORDER BY colunaligacao_regiaopai"; |
2095 | 2104 | //echo $sql;exit; | ... | ... |
ferramentas/saiku/esquemaxml.php
... | ... | @@ -3,17 +3,12 @@ include(dirname(__FILE__)."/../../admin/php/classe_metaestat.php"); |
3 | 3 | $m = new Metaestat(); |
4 | 4 | |
5 | 5 | $regioes = $m->listaTipoRegiao(); |
6 | -$hierarquia = array(); | |
7 | -//hierarquia de cada regiao | |
8 | -foreach($regioes as $regiao){ | |
9 | - $hregioes = $m->listaHierarquiaRegioes($regiao["codigo_tipo_regiao"]); | |
10 | - $hierarquias[$regiao["codigo_tipo_regiao"]] = $hregioes; | |
11 | -} | |
12 | -echo "<pre>";var_dump($hierarquias);exit; | |
13 | 6 | $xml = "<Schema name='i3Geo Metaestat'>"; |
14 | 7 | foreach($regioes as $regiao){ |
8 | + $caminho = $m->hierarquiaPath($regiao["codigo_tipo_regiao"]); | |
9 | + // | |
15 | 10 | //verifica se a regiao tem hierarquia |
16 | - if(count($hierarquias[$regiao["codigo_tipo_regiao"]]) == 0){ | |
11 | + if(empty($caminho)){ | |
17 | 12 | $xml .= " |
18 | 13 | <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='".converte($regiao["nome_tipo_regiao"])."'> |
19 | 14 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> |
... | ... | @@ -24,27 +19,36 @@ foreach($regioes as $regiao){ |
24 | 19 | "; |
25 | 20 | } |
26 | 21 | else{ |
27 | - $caminho = $m->regiaoFilhaAoPai($regiao["codigo_tipo_regiao"]); | |
28 | - //echo "<pre>";var_dump($caminho); | |
29 | 22 | $xml .= " |
30 | 23 | <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='".converte($regiao["nome_tipo_regiao"])."'> |
31 | 24 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> |
32 | 25 | "; |
33 | 26 | //cria uma view juntando as tabelas da hierarquia de regioes |
34 | - $ri = $regioes[$caminho[0]]; | |
35 | - $sql = "SELECT * FROM {$ri['esquemadb']}.{$ri['tabela']} AS regiao "; | |
36 | - $nc = count($caminho) - 1; | |
37 | - for($i=0;$i<$nc;$i++){ | |
38 | - $r = $regioes[$caminho[$i]]; | |
39 | - $sql .= "INNER JOIN {$r['esquemadb']}.{$r['tabela']} | |
40 | - AS j$i ON j$i.{$r['identificador']}::text = regiao.{$regiao['identificador']}::text | |
41 | - "; | |
27 | + $n = count($caminho); | |
28 | + $r = $m->listaTipoRegiao($caminho[0]); | |
29 | + $colunas = array(); | |
30 | + $sql = "SELECT __COLUNAS__ FROM {$r['esquemadb']}.{$r['tabela']} AS regiao "; | |
31 | + $colunas[] = "regiao.".$r['identificador']; | |
32 | + $colunas[] = "regiao.".$r['colunanomeregiao']; | |
33 | + $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; | |
43 | + } | |
42 | 44 | } |
43 | - $h = $hierarquias[$caminho[0]]; | |
44 | - $h = $h[0]; | |
45 | 45 | $sql .= "INNER JOIN {$regiao['esquemadb']}.{$regiao['tabela']} |
46 | - AS j ON j.{$regiao['identificador']}::text = regiao.{$h['colunaligacao_regiaopai']}::text | |
47 | - "; | |
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,","); | |
51 | + $sql = str_replace("__COLUNAS__",$colunas,$sql); | |
48 | 52 | $xml .= " |
49 | 53 | <view><sql>$sql</sql></view> |
50 | 54 | "; |
... | ... | @@ -94,4 +98,4 @@ function converte($texto) |
94 | 98 | $texto = str_replace("&","&",htmlentities($texto)); |
95 | 99 | return $texto; |
96 | 100 | } |
97 | -?> | |
98 | 101 | \ No newline at end of file |
102 | +?> | ... | ... |