diff --git a/classesphp/classe_metaestatinfo.php b/classesphp/classe_metaestatinfo.php index a395e11..bddf28a 100755 --- a/classesphp/classe_metaestatinfo.php +++ b/classesphp/classe_metaestatinfo.php @@ -1889,16 +1889,25 @@ class MetaestatInfo{ else{ $vs = $this->listaVariavel(); } + + $lista = $this->listaMedidaVariavel(); + $lista = array_group_by($lista, "codigo_variavel"); + foreach($vs as $v){ $nivel1["id"] = $v["codigo_variavel"]; $nivel1["titulo"] = $v["nome"]; $nivel1["descricao"] = $v["descricao"]; - $ms = $this->listaMedidaVariavel($v["codigo_variavel"]); + //$ms = $this->listaMedidaVariavel($v["codigo_variavel"]); + + $ms = $lista[$v["codigo_variavel"]]; + $nivel1["filhos"] = array(); foreach($ms as $m){ $nivel2["id"] = $m["id_medida_variavel"]; $nivel2["titulo"] = $m["nomemedida"]; - $unidade = $this->listaUnidadeMedida($m["codigo_unidade_medida"]); + //$unidade = $this->listaUnidadeMedida($m["codigo_unidade_medida"]); + + $unidade = $lista[$m["codigo_unidade_medida"]]; $unidade = "Unidade de medida: ".$unidade["nome"]; $periodo = $this->listaTipoPeriodo($m["codigo_tipo_periodo"]); $periodo = "Período de tempo: ".$periodo["nome"]; diff --git a/classesphp/classe_temas.php b/classesphp/classe_temas.php index 3b6dda1..113021a 100755 --- a/classesphp/classe_temas.php +++ b/classesphp/classe_temas.php @@ -959,18 +959,22 @@ $wkt - boolean indicando se $xy e um WKT } $pinlayer->addfeature($shp); - if($nomeTema != ""){ - $pinlayer->setmetadata("tema",$nomeTema); - } + //verifica a projecao $c = $shp->getCentroid(); - $c = $c->x; - if($c > -181 && $c < 181){ + if($c->x > -181 && $c->x < 181){ $pinlayer->setprojection(pegaProjecaoDefault("proj4")); + $extensao = ($c->x - 0.01)." ".($c->y - 0.01)." ".($c->x + 0.01)." ".($c->y + 0.01); } else{ $pinlayer->setprojection($this->mapa->getProjection()); + $extensao = ($c->x - 50000)." ".($c->y - 50000)." ".($c->x + 50000)." ".($c->y + 50000); } + $pinlayer->setmetadata("extensao",$extensao); + if($nomeTema != ""){ + $pinlayer->setmetadata("tema",$nomeTema); + } + return("ok"); } /* diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index ad01d8f..5639f48 100755 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -3556,4 +3556,70 @@ function pegaDadosAdmin($sql,$dbh=""){ throw new Exception("pegaDadosAdmin"); } } +/** + * Groups an array by a given key. + * + * Groups an array into arrays by a given key, or set of keys, shared between all array members. + * + * Based on {@author Jake Zatecky}'s {@link https://github.com/jakezatecky/array_group_by array_group_by()} function. + * This variant allows $key to be closures. + * + * @param array $array The array to have grouping performed on. + * @param mixed $key,... The key to group or split by. Can be a _string_, + * an _integer_, a _float_, or a _callable_. + * + * If the key is a callback, it must return + * a valid key from the array. + * + * If the key is _NULL_, the iterated element is skipped. + * + * ``` + * string|int callback ( mixed $item ) + * ``` + * + * @return array|null Returns a multidimensional array or `null` if `$key` is invalid. + */ +function array_group_by(array $array, $key) +{ + if (!is_string($key) && !is_int($key) && !is_float($key) && !is_callable($key) ) { + //trigger_error('array_group_by(): The key should be a string, an integer, or a callback', E_USER_ERROR); + return null; + } + + $func = (!is_string($key) && is_callable($key) ? $key : null); + $_key = $key; + + // Load the new array, splitting by the target key + $grouped = []; + foreach ($array as $value) { + $key = null; + + if (is_callable($func)) { + $key = call_user_func($func, $value); + } elseif (is_object($value) && isset($value->{$_key})) { + $key = $value->{$_key}; + } elseif (isset($value[$_key])) { + $key = $value[$_key]; + } + + if ($key === null) { + continue; + } + + $grouped[$key][] = $value; + } + + // Recursively build a nested grouping if more parameters are supplied + // Each grouped array value is grouped according to the next sequential key + if (func_num_args() > 2) { + $args = func_get_args(); + + foreach ($grouped as $key => $value) { + $params = array_merge([ $value ], array_slice($args, 2, func_num_args())); + $grouped[$key] = call_user_func_array('array_group_by', $params); + } + } + + return $grouped; +} ?> diff --git a/classesphp/metaestat_controle.php b/classesphp/metaestat_controle.php index ca0bfd4..9cf547c 100755 --- a/classesphp/metaestat_controle.php +++ b/classesphp/metaestat_controle.php @@ -38,6 +38,22 @@ switch (strtoupper($funcao)) { $layers = explode(",", $_pg["layers"]); $map = ms_newMapObj($map_file); break; + case "LISTACOMPLETA": + $arq = $dir_tmp."/listaDeVariaveis.json"; + if (file_exists($arq)){ + $dados = unserialize(file_get_contents($arq)); + retornaJSON($dados); + exit; + } + $m = new MetaestatInfo(); + $dados = $m->relatorioCompleto(); + if(empty($_pg["cache"]) || $_pg["cache"] == "false" || $_pg["cache"] == false){ + if (!file_exists($arq)){ + gravaDados([serialize($dados)], $arq); + } + } + retornaJSON($dados); + break; case "RELATORIOCOMPLETO": $m = new MetaestatInfo(); if (empty($_pg["codigo_variavel"])) { -- libgit2 0.21.2