[fusion-commits] r1354 - sandbox/aboudreault/MapServer/php

svn_fusion at osgeo.org svn_fusion at osgeo.org
Mon Mar 31 13:12:50 EDT 2008


Author: pagameba
Date: 2008-03-31 13:12:50 -0400 (Mon, 31 Mar 2008)
New Revision: 1354

Modified:
   sandbox/aboudreault/MapServer/php/Query.php
Log:
Re #24, minor reformatting for code style consistency.

Modified: sandbox/aboudreault/MapServer/php/Query.php
===================================================================
--- sandbox/aboudreault/MapServer/php/Query.php	2008-03-31 14:35:37 UTC (rev 1353)
+++ sandbox/aboudreault/MapServer/php/Query.php	2008-03-31 17:12:50 UTC (rev 1354)
@@ -102,8 +102,9 @@
     }
     $oLayer->set('tolerance', 0);
     if ($oLayer->type ==  MS_LAYER_RASTER || $oLayer->type == MS_LAYER_QUERY ||
-        $oLayer->type ==  MS_LAYER_CIRCLE ||  $oLayer->type == MS_LAYER_CHART)
-      continue;
+        $oLayer->type ==  MS_LAYER_CIRCLE ||  $oLayer->type == MS_LAYER_CHART) {
+        continue;            
+    }
 
     
     if (@$oLayer->queryByShape($oSpatialFilter) == MS_SUCCESS) {
@@ -123,8 +124,7 @@
 
 header('Content-type: text/x-json');
 header('X-JSON: true');
-if ($result->hasSelection) 
-{
+if ($result->hasSelection) {
     $oMap->savequery(getSessionSavePath()."query.qry");
     $result->queryFile = getSessionSavePath()."query.qry";
 
@@ -139,13 +139,12 @@
     
     $bFirstElement = 1;
     $nLayers = $oMap->numlayers;
-    for ($i=0; $i<$nLayers; $i++)
-    { 
+    for ($i=0; $i<$nLayers; $i++) { 
         $oLayer = $oMap->GetLayer($i);
         $numResults = $oLayer->getNumResults();
-        if ($numResults == 0)
+        if ($numResults == 0){
           continue;
-
+        }
         $oLayer->open();
         $layerName = $oLayer->name != "" ? $oLayer->name : "Layer_".$i; 
         
@@ -169,80 +168,69 @@
         $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
         $selFields = array();
         
-        if (isset($_SESSION[$mapName][$layerName]['query_items']))
-        {
-           $aQueryItems = $_SESSION[$mapName][$layerName]['query_items'];
-        }
-        else
-        {
-          //token separator (for parsing displayed attributes on a query)
-          $tokenSeparator = ","; 
-          // checking if metadata "query_include_items" is set
-          $metadataItems = $oLayer->getMetaData('query_include_items');
-          if ( ($metadataItems == "") || ($metadataItems == "all") )
-          {
-              while ( list($key,$val) = each($oShape->values) )
-              {
-                $aQueryItems[$key]  = NULL;
+        if (isset($_SESSION[$mapName][$layerName]['query_items'])) {
+            $aQueryItems = $_SESSION[$mapName][$layerName]['query_items'];
+        } else {
+            //token separator (for parsing displayed attributes on a query)
+            $tokenSeparator = ","; 
+            // checking if metadata "query_include_items" is set
+            $metadataItems = $oLayer->getMetaData('query_include_items');
+            if ( ($metadataItems == "") || ($metadataItems == "all") ) {
+                while ( list($key,$val) = each($oShape->values) ) {
+                    $aQueryItems[$key]  = NULL;
+                }
+            } else {
+              $token = strtok($metadataItems, $tokenSeparator);
+              while ($token !== false) {
+                  $aQueryItems[$token] = NULL;
+                  $token = strtok($tokenSeparator);
               }
-          }
-          else
-          {
-            $token = strtok($metadataItems, $tokenSeparator);
-            while ($token !== false) 
-            {
-               $aQueryItems[$token] = NULL;
-              $token = strtok($tokenSeparator);
             }
-          }
           
-           // checking if metadata "query_exclude_items" is set
-          $metadataItems = $oLayer->getMetaData('query_exclude_items');
-          if ($metadataItems != "")
-          {
-            $token = strtok($metadataItems, $tokenSeparator);
-            while ($token !== false) 
-            {
-              if (array_key_exists($token, $aQueryItems))
-                unset($aQueryItems[$token]);
-              $token = strtok($tokenSeparator);
+            // checking if metadata "query_exclude_items" is set
+            $metadataItems = $oLayer->getMetaData('query_exclude_items');
+            if ($metadataItems != "") {
+                $token = strtok($metadataItems, $tokenSeparator);
+                while ($token !== false) {
+                    if (array_key_exists($token, $aQueryItems)) {
+                        unset($aQueryItems[$token]);
+                    }
+                    $token = strtok($tokenSeparator);
+                }
             }
-          }
-          
-          // get all alias
-          while ( list($key,$val) = each($aQueryItems) )
-          {
-            $keyAlias = $oLayer->getMetaData("query_".$key."_alias");
-            trim($keyAlias);
-            if ($keyAlias != "")
-              $aQueryItems[$key] = $keyAlias;
-          }
-          $_SESSION[$mapName][$layerName]['query_items'] = $aQueryItems;
+            
+            // get all alias
+            while ( list($key,$val) = each($aQueryItems) ) {
+                $keyAlias = $oLayer->getMetaData("query_".$key."_alias");
+                trim($keyAlias);
+                if ($keyAlias != "") {
+                    $aQueryItems[$key] = $keyAlias;
+                }
+            }
+            $_SESSION[$mapName][$layerName]['query_items'] = $aQueryItems;
         }
         
         $oShape = $oLayer->getShape($oRes->tileindex,$oRes->shapeindex);
-        while ( list($key,$val) = each($oShape->values) )
-        {
-          if (array_key_exists($key, $aQueryItems))
-          {
-              array_push($selFields, $key);
+        while ( list($key,$val) = each($oShape->values) ) {
+            if (array_key_exists($key, $aQueryItems)) {
+                array_push($selFields, $key);
 
-              //we check if an alias if provided
-              if (isset($aQueryItems[$key]) && ($keyAlias != ""))
-                $key = $aQueryItems[$key];
+                //we check if an alias if provided
+                if (isset($aQueryItems[$key]) && ($keyAlias != "")){
+                    $key = $aQueryItems[$key];
+                }
 
-              array_push($properties->$layerName->propertynames, $key);
-              //TODO : we should define away to give alias to field names
-              array_push($properties->$layerName->propertyvalues, $val);
+                array_push($properties->$layerName->propertynames, $key);
+                //TODO : we should define away to give alias to field names
+                array_push($properties->$layerName->propertyvalues, $val);
 
-              //TODO we do not know the types of the attributes in MS. Just output 0
-              //we shouls possibly use OGR to get the attributes
-              array_push($properties->$layerName->propertytypes, 0);
-          }
+                //TODO we do not know the types of the attributes in MS. Just output 0
+                //we shouls possibly use OGR to get the attributes
+                array_push($properties->$layerName->propertytypes, 0);
+            }
         }
         
-        for ($iRes=0; $iRes < $numResults; $iRes++)
-        {
+        for ($iRes=0; $iRes < $numResults; $iRes++) {
             $properties->$layerName->values[$iRes] = array();
             $properties->$layerName->metadata[$iRes] = array();
 
@@ -254,25 +242,26 @@
             $maxx =  $oShape->bounds->maxx;
             $maxy =  $oShape->bounds->maxy;
 
-            if ($bFirstElement)
-            {
+            if ($bFirstElement) {
                 $bFirstElement = 0;
                 $totalminx =  $minx;
                 $totalminy =  $miny;
                 $totalmaxx =  $maxx;
                 $totalmaxy =  $maxy;
+            } else {
+                if ($totalminx > $minx) {
+                    $totalminx = $minx;
+                }
+                if ($totalminy > $miny) {
+                    $totalminy = $miny;
+                }
+                if ($totalmaxx < $maxx) {
+                    $totalmaxx = $maxx;
+                }
+                if ($totalmaxy < $maxy) {
+                    $totalmaxy = $maxy;
+                }
             }
-            else
-            {
-                if ($totalminx > $minx)
-                  $totalminx = $minx;
-                if ($totalminy > $miny)
-                  $totalminy = $miny;
-                if ($totalmaxx < $maxx)
-                  $totalmaxx = $maxx;
-                if ($totalmaxy < $maxy)
-                  $totalmaxy = $maxy;
-            }
 
             //metadata : TODO dimension, area, length and distance are not set
             $dimension = 0;
@@ -288,8 +277,7 @@
             array_push($properties->$layerName->metadata[$iRes], $length);
 
             //field values
-            for($iField=0; $iField < count($selFields); $iField++)
-            {
+            for($iField=0; $iField < count($selFields); $iField++) {
                 $value = $oShape->values[$selFields[$iField]];
                 //$value = preg_replace( "/\r?\n/", "<br>", $value );
                 $value = str_replace("'", "\'", $value);



More information about the fusion-commits mailing list