From d1297596428fd8a17434abcb94ceec3c5831040e Mon Sep 17 00:00:00 2001 From: Edmar Moretti Date: Sat, 22 Nov 2014 22:31:18 +0000 Subject: [PATCH] Correção na listagem de elementos selecionados na tabela de atributos --- classesphp/classe_atributos.php | 17 ++++++++++------- classesphp/funcoes_gerais.php | 32 +++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/classesphp/classe_atributos.php b/classesphp/classe_atributos.php index 562ab9a..5bd6117 100755 --- a/classesphp/classe_atributos.php +++ b/classesphp/classe_atributos.php @@ -438,7 +438,7 @@ class Atributos else{ $alias = $items; } - $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa); + $shapes = retornaShapesSelecionados($this->layer,$this->arquivo,$this->mapa,true); $res_count = count($shapes); $resultadoFinal[] = array("totalSelecionados"=>$res_count,"itens"=>$items,"alias"=>$alias); $registros = array(); @@ -451,6 +451,11 @@ class Atributos } if ($tipolista == "selecionados"){ $chk = "CHECKED"; + //cria um novo array apenas para funcionar no contador + $s = array(); + foreach($shapes as $shape){ + $s[] = $shape; + } if ($fim != ""){ if (($res_count >= $fim) && ($fim < $res_count)){ $res_count = $fim; @@ -458,7 +463,8 @@ class Atributos } for ($i = $inicio; $i < $res_count; ++$i){ $valitem = array(); - $shape = $shapes[$i]; + $shape = $s[$i]; + $indx = $shape->index; foreach ($items as $item){ $valori = trim($shape->values[$item]); if($convC == true){ @@ -482,10 +488,7 @@ class Atributos } if ($tipolista == "tudo"){ //ini_set('memory_limit', '500M'); - $shp_atual = array(); - for ($i = 0; $i < $res_count;++$i){ - $shp_atual[$i] = $shapes[$i];; - } + $shp_atual = $shapes; $chk = ""; if (@$this->layer->queryByrect($this->mapa->extent) == MS_SUCCESS){ $res_count = $this->layer->getNumresults(); @@ -2408,4 +2411,4 @@ class Atributos return $texto; } } -?> \ No newline at end of file +?> diff --git a/classesphp/funcoes_gerais.php b/classesphp/funcoes_gerais.php index 7823b6b..10f7c5d 100755 --- a/classesphp/funcoes_gerais.php +++ b/classesphp/funcoes_gerais.php @@ -2465,13 +2465,13 @@ function retornaShapesMapext($objLayer,$objMapa){ $objLayer->close(); return $shapes; } -function retornaShapesSelecionados($objLayer,$map_file,$objMapa){ +function retornaShapesSelecionados($objLayer,$map_file,$objMapa,$indexado=false){ $shapes = array(); $qyfile = dirname($map_file)."/".$objLayer->name.".php"; - + if(!file_exists($qyfile)) {return $shapes;} - + $handle = fopen ($qyfile, "r"); $conteudo = fread ($handle, filesize ($qyfile)); fclose ($handle); @@ -2479,12 +2479,14 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa){ //echo count($listaDeIndices);exit; if(count($listaDeIndices) == 0) {return $shapes;} - + $versao = versao(); $versao = $versao["principal"]; + if ($objLayer->connectiontype != MS_POSTGIS){ //pega os shapes selecionados carregaquery2($map_file,$objLayer,$objMapa); + $sopen = $objLayer->open(); if($sopen == MS_FAILURE){return "erro";} $objLayer->open(); @@ -2492,17 +2494,24 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa){ $centroides = array(); $shapes = array(); //pega um shape especifico - + for ($i = 0; $i < $res_count; ++$i) { - if($versao == 6) - {$shape = $objLayer->getShape($objLayer->getResult($i));} + if($versao == 6){ + $shape = $objLayer->getShape($objLayer->getResult($i)); + $shp_index = $shape->index; + } else{ $result = $objLayer->getResult($i); $shp_index = $result->shapeindex; $shape = $objLayer->getfeature($shp_index,-1); } - $shapes[] = $shape; + if($indexado == true){ + $shapes[$shp_index] = $shape; + } + else{ + $shapes[] = $shape; + } } $fechou = $objLayer->close(); } @@ -2518,7 +2527,12 @@ function retornaShapesSelecionados($objLayer,$map_file,$objMapa){ while ($shape = $objLayer->nextShape()) { if(in_array($shape->index,$listaDeIndices)){ - $shapes[] = $shape; + if($indexado == true){ + $shapes[$shape->index] = $shape; + } + else{ + $shapes[] = $shape; + } } } $objLayer->close(); -- libgit2 0.21.2