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,32 +514,39 @@ class Metaestat{ | ||
514 | * @return array lista de ids de regioes sequenciais do filho ate chegar ao pai indicado | 514 | * @return array lista de ids de regioes sequenciais do filho ate chegar ao pai indicado |
515 | */ | 515 | */ |
516 | function regiaoFilhaAoPai($codigo_tipo_regiao,$codigo_tipo_regiao_pai=""){ | 516 | function regiaoFilhaAoPai($codigo_tipo_regiao,$codigo_tipo_regiao_pai=""){ |
517 | - //echo $codigo_tipo_regiao." ".$codigo_tipo_regiao_pai; | ||
518 | $pais = $this->listaAgregaRegiao($codigo_tipo_regiao); | 517 | $pais = $this->listaAgregaRegiao($codigo_tipo_regiao); |
519 | $caminho = array($codigo_tipo_regiao); | 518 | $caminho = array($codigo_tipo_regiao); |
520 | $colunas = array(); | 519 | $colunas = array(); |
521 | if(count($pais) == 0){ | 520 | if(count($pais) == 0){ |
522 | return $caminho; | 521 | return $caminho; |
523 | } | 522 | } |
524 | - $achou = false; | ||
525 | foreach($pais as $pai){ | 523 | foreach($pais as $pai){ |
526 | $caminho[] = $pai["codigo_tipo_regiao_pai"]; | 524 | $caminho[] = $pai["codigo_tipo_regiao_pai"]; |
527 | $colunas[$pai["codigo_tipo_regiao"]] = $pai; | 525 | $colunas[$pai["codigo_tipo_regiao"]] = $pai; |
528 | if($pai["codigo_tipo_regiao_pai"] == $codigo_tipo_regiao_pai){ | 526 | if($pai["codigo_tipo_regiao_pai"] == $codigo_tipo_regiao_pai){ |
529 | - $achou = true; | ||
530 | return array("caminho"=>$caminho,"colunas"=>$colunas); | 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 | * Cria um arquivo mapfile para uma medida de variavel | 551 | * Cria um arquivo mapfile para uma medida de variavel |
545 | * Inclui no arquivo o layer de acesso aos dados | 552 | * Inclui no arquivo o layer de acesso aos dados |
@@ -2018,7 +2025,7 @@ class Metaestat{ | @@ -2018,7 +2025,7 @@ class Metaestat{ | ||
2018 | * @param codigo da regiao | 2025 | * @param codigo da regiao |
2019 | */ | 2026 | */ |
2020 | function listaHierarquiaRegioes($codigoregiaopai=""){ | 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 | $sql .= "LEFT JOIN ".$this->esquemaadmin."i3geoestat_agregaregiao "; | 2029 | $sql .= "LEFT JOIN ".$this->esquemaadmin."i3geoestat_agregaregiao "; |
2023 | $sql .= "ON i3geoestat_tipo_regiao.codigo_tipo_regiao = i3geoestat_agregaregiao.codigo_tipo_regiao "; | 2030 | $sql .= "ON i3geoestat_tipo_regiao.codigo_tipo_regiao = i3geoestat_agregaregiao.codigo_tipo_regiao "; |
2024 | if($codigoregiaopai != ""){ | 2031 | if($codigoregiaopai != ""){ |
@@ -2083,13 +2090,15 @@ class Metaestat{ | @@ -2083,13 +2090,15 @@ class Metaestat{ | ||
2083 | * @param codigo do tipo de regiao | 2090 | * @param codigo do tipo de regiao |
2084 | * @param id da agregacao | 2091 | * @param id da agregacao |
2085 | */ | 2092 | */ |
2086 | - function listaAgregaRegiao($codigo_tipo_regiao,$id_agregaregiao=""){ | 2093 | + function listaAgregaRegiao($codigo_tipo_regiao="",$id_agregaregiao=""){ |
2087 | $sql = "select * from ".$this->esquemaadmin."i3geoestat_agregaregiao "; | 2094 | $sql = "select * from ".$this->esquemaadmin."i3geoestat_agregaregiao "; |
2088 | if($id_agregaregiao != ""){ | 2095 | if($id_agregaregiao != ""){ |
2089 | $sql .= "WHERE id_agregaregiao = $id_agregaregiao "; | 2096 | $sql .= "WHERE id_agregaregiao = $id_agregaregiao "; |
2090 | } | 2097 | } |
2091 | else{ | 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 | $sql .= " ORDER BY colunaligacao_regiaopai"; | 2103 | $sql .= " ORDER BY colunaligacao_regiaopai"; |
2095 | //echo $sql;exit; | 2104 | //echo $sql;exit; |
ferramentas/saiku/esquemaxml.php
@@ -3,17 +3,12 @@ include(dirname(__FILE__)."/../../admin/php/classe_metaestat.php"); | @@ -3,17 +3,12 @@ include(dirname(__FILE__)."/../../admin/php/classe_metaestat.php"); | ||
3 | $m = new Metaestat(); | 3 | $m = new Metaestat(); |
4 | 4 | ||
5 | $regioes = $m->listaTipoRegiao(); | 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 | $xml = "<Schema name='i3Geo Metaestat'>"; | 6 | $xml = "<Schema name='i3Geo Metaestat'>"; |
14 | foreach($regioes as $regiao){ | 7 | foreach($regioes as $regiao){ |
8 | + $caminho = $m->hierarquiaPath($regiao["codigo_tipo_regiao"]); | ||
9 | + // | ||
15 | //verifica se a regiao tem hierarquia | 10 | //verifica se a regiao tem hierarquia |
16 | - if(count($hierarquias[$regiao["codigo_tipo_regiao"]]) == 0){ | 11 | + if(empty($caminho)){ |
17 | $xml .= " | 12 | $xml .= " |
18 | <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='".converte($regiao["nome_tipo_regiao"])."'> | 13 | <Dimension name='codigo_tipo_regiao_".$regiao["codigo_tipo_regiao"]."' caption='".converte($regiao["nome_tipo_regiao"])."'> |
19 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> | 14 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> |
@@ -24,27 +19,36 @@ foreach($regioes as $regiao){ | @@ -24,27 +19,36 @@ foreach($regioes as $regiao){ | ||
24 | "; | 19 | "; |
25 | } | 20 | } |
26 | else{ | 21 | else{ |
27 | - $caminho = $m->regiaoFilhaAoPai($regiao["codigo_tipo_regiao"]); | ||
28 | - //echo "<pre>";var_dump($caminho); | ||
29 | $xml .= " | 22 | $xml .= " |
30 | <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='".converte($regiao["nome_tipo_regiao"])."'> |
31 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> | 24 | <Hierarchy hasAll='true' primaryKey='".$regiao["identificador"]."'> |
32 | "; | 25 | "; |
33 | //cria uma view juntando as tabelas da hierarquia de regioes | 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 | $sql .= "INNER JOIN {$regiao['esquemadb']}.{$regiao['tabela']} | 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 | $xml .= " | 52 | $xml .= " |
49 | <view><sql>$sql</sql></view> | 53 | <view><sql>$sql</sql></view> |
50 | "; | 54 | "; |
@@ -94,4 +98,4 @@ function converte($texto) | @@ -94,4 +98,4 @@ function converte($texto) | ||
94 | $texto = str_replace("&","&",htmlentities($texto)); | 98 | $texto = str_replace("&","&",htmlentities($texto)); |
95 | return $texto; | 99 | return $texto; |
96 | } | 100 | } |
97 | -?> | ||
98 | \ No newline at end of file | 101 | \ No newline at end of file |
102 | +?> |