Yaron Koren has submitted this change and it was merged.

Change subject: Added extended handling of MongoDB results.  If an answer 
column is an array, return as JSON.  If an answer column is a GeoJSON geometry, 
return as a string  Maps can understand, i.e. latlong pairs delimited by 
colons. Otherwise, return as usual - as a st
......................................................................


Added extended handling of MongoDB results. 
If an answer column is an array, return as JSON. 
If an answer column is a GeoJSON geometry, return as a string 
Maps can understand, i.e. latlong pairs delimited by colons.
Otherwise, return as usual - as a string literal.

Change-Id: If4198035f06ee8134620457cbb8e00a67f01cd0f
---
M ED_Utils.php
1 file changed, 19 insertions(+), 1 deletion(-)

Approvals:
  Yaron Koren: Verified; Looks good to me, approved



diff --git a/ED_Utils.php b/ED_Utils.php
index a4df405..cfcb1c4 100644
--- a/ED_Utils.php
+++ b/ED_Utils.php
@@ -356,7 +356,25 @@
                $values = array();
                foreach ( $resultsCursor as $doc ) {
                        foreach ( $columns as $column ) {
-                               $values[$column][] = $doc[$column];
+                               // if MongoDB returns an array for a column, do 
some extra processing
+                               if (is_array($doc[$column])) {
+                                       // check if its GeoJSON geometry. 
http://www.geojson.org/geojson-spec.html#geometry-objects 
+                                       // If so, return it in a format that 
Maps can understand
+                                       if ($column == 'geometry' && 
array_key_exists('coordinates', $doc['geometry'])) {
+                                               $coordinates = 
$doc['geometry']['coordinates'][0];
+                                               $sgeometry = '';
+                                               foreach ($coordinates as 
$coordinate) {
+                                                       $sgeometry .= 
$coordinate[1] . ',' . $coordinate[0] . ':';
+                                               }
+                                               $values[$column][] =  
substr($sgeometry,0,strlen($sgeometry)-1);
+                                       } else {
+                                               // just return it as a JSON 
string - the lingua franca of MongoDB
+                                               $values[$column][] = 
json_encode($doc[$column]);
+                                       }
+                               } else {
+                                       // its a simple literal
+                                       $values[$column][] = $doc[$column];
+                               }
                        }
                }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/63858
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: If4198035f06ee8134620457cbb8e00a67f01cd0f
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/ExternalData
Gerrit-Branch: master
Gerrit-Owner: Jqnatividad <[email protected]>
Gerrit-Reviewer: Jqnatividad <[email protected]>
Gerrit-Reviewer: Yaron Koren <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to