Commit 55a06a0e7a2247773d590b4c48d5c1c20096572c
1 parent
a24ca97d
Exists in
master
and in
7 other branches
Correção na inclusão de parâmetros no sistema de metadados estatísticos e acesso via SAIKU
Showing
3 changed files
with
66 additions
and
36 deletions
Show diff stats
admin/admin.db
No preview for this file type
admin/php/classe_metaestat.php
| @@ -1940,7 +1940,7 @@ class Metaestat{ | @@ -1940,7 +1940,7 @@ class Metaestat{ | ||
| 1940 | $sql .= "AND i3geoestat_parametro_medida.id_parametro_medida = $id_parametro_medida "; | 1940 | $sql .= "AND i3geoestat_parametro_medida.id_parametro_medida = $id_parametro_medida "; |
| 1941 | } | 1941 | } |
| 1942 | } | 1942 | } |
| 1943 | - else{ | 1943 | + elseif ($id_parametro_medida != ""){ |
| 1944 | $sql .= "WHERE i3geoestat_parametro_medida.id_parametro_medida = $id_parametro_medida "; | 1944 | $sql .= "WHERE i3geoestat_parametro_medida.id_parametro_medida = $id_parametro_medida "; |
| 1945 | } | 1945 | } |
| 1946 | if($id_pai != ""){ | 1946 | if($id_pai != ""){ |
| @@ -1956,6 +1956,17 @@ class Metaestat{ | @@ -1956,6 +1956,17 @@ class Metaestat{ | ||
| 1956 | //echo $sql;exit; | 1956 | //echo $sql;exit; |
| 1957 | return $this->execSQL($sql,$id_parametro_medida); | 1957 | return $this->execSQL($sql,$id_parametro_medida); |
| 1958 | } | 1958 | } |
| 1959 | + /** | ||
| 1960 | + * Lista todos os parametros cadastrados | ||
| 1961 | + */ | ||
| 1962 | + function listaTodosParametros(){ | ||
| 1963 | + $sql = "SELECT i3geoestat_parametro_medida.*,i3geoestat_medida_variavel.* "; | ||
| 1964 | + $sql .= "FROM ".$this->esquemaadmin."i3geoestat_parametro_medida "; | ||
| 1965 | + $sql .= "INNER JOIN ".$this->esquemaadmin."i3geoestat_medida_variavel "; | ||
| 1966 | + $sql .= "ON i3geoestat_parametro_medida.id_medida_variavel = i3geoestat_medida_variavel.id_medida_variavel "; | ||
| 1967 | + $sql .= " ORDER BY nome"; | ||
| 1968 | + return $this->execSQL($sql); | ||
| 1969 | + } | ||
| 1959 | /** | 1970 | /** |
| 1960 | * Lista os valores (unicos) que ocorrem em um parametro de uma medida de variavel | 1971 | * Lista os valores (unicos) que ocorrem em um parametro de uma medida de variavel |
| 1961 | * @param id do parametro | 1972 | * @param id do parametro |
ferramentas/saiku/esquemaxml.php
| 1 | <?php | 1 | <?php |
| 2 | +//utilize output=xml para debug | ||
| 2 | //quando o saiku e iniciado de fora do i3geo, e necessario inicializar um mapfile para uso como base dos mapas | 3 | //quando o saiku e iniciado de fora do i3geo, e necessario inicializar um mapfile para uso como base dos mapas |
| 3 | if(empty($_GET["g_sid"])){ | 4 | if(empty($_GET["g_sid"])){ |
| 4 | include(dirname(__FILE__)."/../../ms_criamapa.php"); | 5 | include(dirname(__FILE__)."/../../ms_criamapa.php"); |
| 5 | //reinicia a url | 6 | //reinicia a url |
| 6 | - $urln = "?g_sid=".session_id()."&locaplic=".$_GET["locaplic"]."&mapext=".$mapext."&origem=".$_GET["origem"]; | 7 | + $urln = "?g_sid=".session_id()."&locaplic=".$_GET["locaplic"]."&mapext=".$mapext."&origem=".$_GET["origem"]."&output=".$_GET["output"]; |
| 7 | header("Location:".$urln); | 8 | header("Location:".$urln); |
| 8 | exit; | 9 | exit; |
| 9 | } | 10 | } |
| @@ -126,6 +127,7 @@ if(empty($saikuConfigDataSource['tabelaDimensaoTempo'])){ | @@ -126,6 +127,7 @@ if(empty($saikuConfigDataSource['tabelaDimensaoTempo'])){ | ||
| 126 | } | 127 | } |
| 127 | $sqlAno = "select nu_ano from ".$saikuConfigDataSource['tabelaDimensaoTempo']." group by nu_ano order by nu_ano"; | 128 | $sqlAno = "select nu_ano from ".$saikuConfigDataSource['tabelaDimensaoTempo']." group by nu_ano order by nu_ano"; |
| 128 | $sqlMes = "select nu_ano::text,nu_mes::text,ds_mes_abreviado as mes,COALESCE (nu_ano::text||'-'||nu_mes::text,nu_ano::text) as nu_anomes from ".$saikuConfigDataSource['tabelaDimensaoTempo']." group by nu_ano,nu_mes,mes,nu_anomes order by nu_ano,nu_mes"; | 129 | $sqlMes = "select nu_ano::text,nu_mes::text,ds_mes_abreviado as mes,COALESCE (nu_ano::text||'-'||nu_mes::text,nu_ano::text) as nu_anomes from ".$saikuConfigDataSource['tabelaDimensaoTempo']." group by nu_ano,nu_mes,mes,nu_anomes order by nu_ano,nu_mes"; |
| 130 | +//dimensoes temporais | ||
| 129 | $xml .= " | 131 | $xml .= " |
| 130 | <Dimension name='Anual' type='TimeDimension' caption='Tempo: Anual'> | 132 | <Dimension name='Anual' type='TimeDimension' caption='Tempo: Anual'> |
| 131 | <Hierarchy hasAll='true' primaryKey='nu_ano'> | 133 | <Hierarchy hasAll='true' primaryKey='nu_ano'> |
| @@ -148,6 +150,7 @@ $xml .= " | @@ -148,6 +150,7 @@ $xml .= " | ||
| 148 | </Hierarchy> | 150 | </Hierarchy> |
| 149 | </Dimension> | 151 | </Dimension> |
| 150 | "; | 152 | "; |
| 153 | +//dimensoes geograficas | ||
| 151 | //as dimensoes sao duplicadas | 154 | //as dimensoes sao duplicadas |
| 152 | //uma delas contem o geocodigo que permite a geracao do mapa | 155 | //uma delas contem o geocodigo que permite a geracao do mapa |
| 153 | $xml1 = ""; | 156 | $xml1 = ""; |
| @@ -232,28 +235,6 @@ foreach($regioes as $regiao){ | @@ -232,28 +235,6 @@ foreach($regioes as $regiao){ | ||
| 232 | "; | 235 | "; |
| 233 | $xml1 .= implode(" ",$niveis1); | 236 | $xml1 .= implode(" ",$niveis1); |
| 234 | $xml2 .= implode(" ",$niveis2); | 237 | $xml2 .= implode(" ",$niveis2); |
| 235 | - /* | ||
| 236 | - //verifica se existem propriedades (colunas adicionais) | ||
| 237 | - if($vis != ""){ | ||
| 238 | - //apelidos | ||
| 239 | - $apelidos = $regiao['apelidos']; | ||
| 240 | - if($apelidos != ""){ | ||
| 241 | - $apelidos = str_replace(";",",",$apelidos); | ||
| 242 | - $apelidos = str_replace(",,",",",$apelidos); | ||
| 243 | - $apelidos = converte($apelidos); | ||
| 244 | - $apelidos = explode(",",$apelidos); | ||
| 245 | - } | ||
| 246 | - else{ | ||
| 247 | - $apelidos = $vis; | ||
| 248 | - } | ||
| 249 | - $nvis = count($vis); | ||
| 250 | - for($i = 0; $i < $nvis; $i++){ | ||
| 251 | - $xml .= " | ||
| 252 | - <Property name='{$apelidos[$i]}' column='{$vis[$i]}'/> | ||
| 253 | - "; | ||
| 254 | - } | ||
| 255 | - } | ||
| 256 | - */ | ||
| 257 | $xml1 .= " | 238 | $xml1 .= " |
| 258 | </Hierarchy> | 239 | </Hierarchy> |
| 259 | </Dimension> | 240 | </Dimension> |
| @@ -263,7 +244,41 @@ foreach($regioes as $regiao){ | @@ -263,7 +244,41 @@ foreach($regioes as $regiao){ | ||
| 263 | </Dimension> | 244 | </Dimension> |
| 264 | "; | 245 | "; |
| 265 | } | 246 | } |
| 266 | -$xml .= $xml1.$xml2; | 247 | +//outras dimensoes definidas nos parametros e que nao sejam do tipo tempo |
| 248 | +$parametros = $m->listaTodosParametros(); | ||
| 249 | +$dimOutras = array(); | ||
| 250 | +foreach($parametros as $p){ | ||
| 251 | + //apenas as nao tempo | ||
| 252 | + if($p["tipo"] < 1 || $p["tipo"] > 5){ | ||
| 253 | + $k = $p["esquema"]."_".$p["tabela"]."_".$p["coluna"]; | ||
| 254 | + if(empty($tbs[$k])){ | ||
| 255 | + $dimOutras[$k] = $p; | ||
| 256 | + } | ||
| 257 | + else{ | ||
| 258 | + array_push($dimOutras[$k],$p); | ||
| 259 | + } | ||
| 260 | + } | ||
| 261 | +} | ||
| 262 | +$xml3 = ""; | ||
| 263 | +foreach($dimOutras as $d){ | ||
| 264 | + $k = $p["esquemadb"]."_".$d["tabela"]."_".$d["coluna"]; | ||
| 265 | + $xml3 .= " | ||
| 266 | + <Dimension name='".$k."' caption='".converte($d["nome"])."'> | ||
| 267 | + <Hierarchy hasAll='true' primaryKey='{$d["coluna"]}'> | ||
| 268 | + "; | ||
| 269 | + //cria uma view juntando as tabelas da hierarquia de regioes | ||
| 270 | + $colunas = "dim.{$d['coluna']}, "; | ||
| 271 | + $colunas .= "dim.{$d['coluna']} AS nome"; | ||
| 272 | + $sql = "SELECT {$colunas} FROM ".$d['esquemadb'].".".$d['tabela']." as dim group by ".$d['coluna']; | ||
| 273 | + $xml3 .= "<view alias='".$k."' ><SQL dialect='generic' >$sql</SQL></view>"; | ||
| 274 | + $xml3 .= "<Level name='".converte($d["nome"])."' | ||
| 275 | + column='{$d['coluna']}' | ||
| 276 | + nameColumn='nome' uniqueMembers='true' /> | ||
| 277 | + "; | ||
| 278 | + $xml3 .= "</Hierarchy> | ||
| 279 | + </Dimension>"; | ||
| 280 | +} | ||
| 281 | +$xml .= $xml1.$xml2.$xml3; | ||
| 267 | //junta as medidas conforme o nome da tabela utilizada | 282 | //junta as medidas conforme o nome da tabela utilizada |
| 268 | $medidas = $m->listaMedidaVariavel(); | 283 | $medidas = $m->listaMedidaVariavel(); |
| 269 | //var_dump($medidas);exit; | 284 | //var_dump($medidas);exit; |
| @@ -300,7 +315,7 @@ foreach($tbs as $tb){ | @@ -300,7 +315,7 @@ foreach($tbs as $tb){ | ||
| 300 | foreach($tb as $medida){ | 315 | foreach($tb as $medida){ |
| 301 | //echo "<pre>";var_dump($medida)."<br>"; | 316 | //echo "<pre>";var_dump($medida)."<br>"; |
| 302 | $parametros = $m->listaParametro($medida["id_medida_variavel"],"","",false,false); | 317 | $parametros = $m->listaParametro($medida["id_medida_variavel"],"","",false,false); |
| 303 | - | 318 | + |
| 304 | $parComposto = array(); //guarda a composicao da chave que liga com a dimensao | 319 | $parComposto = array(); //guarda a composicao da chave que liga com a dimensao |
| 305 | $colunaAdicionais = array(); | 320 | $colunaAdicionais = array(); |
| 306 | //parametro do tipo tempo | 321 | //parametro do tipo tempo |
| @@ -320,31 +335,32 @@ foreach($tbs as $tb){ | @@ -320,31 +335,32 @@ foreach($tbs as $tb){ | ||
| 320 | //outros parametros | 335 | //outros parametros |
| 321 | $outrosParametros = array(); | 336 | $outrosParametros = array(); |
| 322 | //TODO criar as dimensoes aqui | 337 | //TODO criar as dimensoes aqui |
| 338 | + //echo "<pre>";var_dump($parametros); | ||
| 323 | foreach($parametros as $parametro){ | 339 | foreach($parametros as $parametro){ |
| 340 | + $k = $parametro["esquemadb"]."_".$parametro["tabela"]."_".$parametro["coluna"]; | ||
| 324 | if($parametro["tipo"] > 5 || $parametro["tipo"] == 0){ | 341 | if($parametro["tipo"] > 5 || $parametro["tipo"] == 0){ |
| 325 | - //$outrosParametros[] = $parametro["coluna"]; | ||
| 326 | - //$VirtualCubeDimension[] = "<VirtualCubeDimension name='{$parametro["coluna"]}' />"; | ||
| 327 | - //$dimEnsoes[] = "<DimensionUsage foreignKey='{$parametro["coluna"]}_' name='{$parametro["coluna"]}' source='{$parametro["coluna"]}'/>"; | 342 | + $outrosParametros[] = $k; |
| 343 | + $VirtualCubeDimension[] = "<VirtualCubeDimension name='{$k}' />"; | ||
| 344 | + $dimEnsoes[] = "<DimensionUsage foreignKey='{$parametro["coluna"]}' name='nome' source='{$k}'/>"; | ||
| 328 | } | 345 | } |
| 329 | } | 346 | } |
| 330 | } | 347 | } |
| 331 | - //exit; | ||
| 332 | $xml .= " | 348 | $xml .= " |
| 333 | <Cube cache='false' name='{$c["esquemadb"]}{$c["tabela"]}'>"; | 349 | <Cube cache='false' name='{$c["esquemadb"]}{$c["tabela"]}'>"; |
| 334 | $incluirChaves = array("*"); | 350 | $incluirChaves = array("*"); |
| 335 | - | 351 | + |
| 336 | if(count($parComposto) > 0){ | 352 | if(count($parComposto) > 0){ |
| 337 | //$sql = "select *,".implode("||'-'||",$parComposto)."::text as ".implode("_",$parComposto)."_ from {$c["esquemadb"]}.{$c["tabela"]}"; | 353 | //$sql = "select *,".implode("||'-'||",$parComposto)."::text as ".implode("_",$parComposto)."_ from {$c["esquemadb"]}.{$c["tabela"]}"; |
| 338 | $incluirChaves[] = implode("||'-'||",$parComposto)."::text as ".implode("_",$parComposto)."_"; | 354 | $incluirChaves[] = implode("||'-'||",$parComposto)."::text as ".implode("_",$parComposto)."_"; |
| 339 | } | 355 | } |
| 340 | if(count($outrosParametros) > 0){ | 356 | if(count($outrosParametros) > 0){ |
| 341 | foreach($outrosParametros as $o){ | 357 | foreach($outrosParametros as $o){ |
| 342 | - $incluirChaves[] = $o."::text as ".$o."_"; | 358 | + //$incluirChaves[] = $o."::text as ".$o."_"; |
| 343 | } | 359 | } |
| 344 | } | 360 | } |
| 345 | - | 361 | + |
| 346 | $sql = "select ".implode(",",$incluirChaves)." from {$c["esquemadb"]}.{$c["tabela"]}"; | 362 | $sql = "select ".implode(",",$incluirChaves)." from {$c["esquemadb"]}.{$c["tabela"]}"; |
| 347 | - | 363 | + |
| 348 | $xml .= " | 364 | $xml .= " |
| 349 | <view alias='view_{$c["esquemadb"]}{$c["tabela"]}' ><SQL dialect='generic' >$sql</SQL></view> | 365 | <view alias='view_{$c["esquemadb"]}{$c["tabela"]}' ><SQL dialect='generic' >$sql</SQL></view> |
| 350 | <DimensionUsage foreignKey='".$c["colunaidgeo"]."' name='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."' source='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."'/> | 366 | <DimensionUsage foreignKey='".$c["colunaidgeo"]."' name='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."' source='codigo_tipo_regiao_".$c["codigo_tipo_regiao"]."'/> |
| @@ -373,7 +389,6 @@ foreach($tbs as $tb){ | @@ -373,7 +389,6 @@ foreach($tbs as $tb){ | ||
| 373 | </Cube> | 389 | </Cube> |
| 374 | "; | 390 | "; |
| 375 | } | 391 | } |
| 376 | - | ||
| 377 | $xml .= '<VirtualCube name="Todas as medidas" >'; | 392 | $xml .= '<VirtualCube name="Todas as medidas" >'; |
| 378 | $VirtualCubeDimension = array_unique($VirtualCubeDimension); | 393 | $VirtualCubeDimension = array_unique($VirtualCubeDimension); |
| 379 | $VirtualCubeMeasure = array_unique($VirtualCubeMeasure); | 394 | $VirtualCubeMeasure = array_unique($VirtualCubeMeasure); |
| @@ -383,7 +398,11 @@ $xml .= '</VirtualCube>'; | @@ -383,7 +398,11 @@ $xml .= '</VirtualCube>'; | ||
| 383 | $xml .= "</Schema>"; | 398 | $xml .= "</Schema>"; |
| 384 | error_reporting(0); | 399 | error_reporting(0); |
| 385 | ob_end_clean(); | 400 | ob_end_clean(); |
| 386 | -//echo $xml;exit; | 401 | + |
| 402 | +if($_GET["output"] == "xml"){ | ||
| 403 | + echo header("Content-type: application/xml"); | ||
| 404 | + echo $xml;exit; | ||
| 405 | +} | ||
| 387 | gravaDados(array($xml),$arquivoXmlEsquema); | 406 | gravaDados(array($xml),$arquivoXmlEsquema); |
| 388 | 407 | ||
| 389 | header("Location:".$saikuUrl."/?nomeConexao=".$nomeConexao."&locaplic=".$_GET["locaplic"]."&g_sid=".$_GET["g_sid"]."&mapext=".$_GET["mapext"]."&origem=".$_GET["origem"]); | 408 | header("Location:".$saikuUrl."/?nomeConexao=".$nomeConexao."&locaplic=".$_GET["locaplic"]."&g_sid=".$_GET["g_sid"]."&mapext=".$_GET["mapext"]."&origem=".$_GET["origem"]); |