Jqnatividad has uploaded a new change for review. https://gerrit.wikimedia.org/r/69557
Change subject: Added dot notation support for retrieving values from compound MongoDB result documents ...................................................................... Added dot notation support for retrieving values from compound MongoDB result documents Change-Id: I1ce049587d5b7a7024fb89dd6278299c90d2947a --- M ED_Utils.php 1 file changed, 28 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ExternalData refs/changes/57/69557/1 diff --git a/ED_Utils.php b/ED_Utils.php index 543d347..9a0c2a5 100644 --- a/ED_Utils.php +++ b/ED_Utils.php @@ -266,6 +266,24 @@ return $values; } + + static function dotresolve(array $a, $path, $default = null) + { + $current = $a; + $p = strtok($path, '.'); + + while ($p !== false) { + if (!isset($current[$p])) { + return $default; + } + $current = $current[$p]; + $p = strtok('.'); + } + + return $current; + } + + /** * Handles #get_db_data for the non-relational database system * MongoDB. @@ -365,14 +383,17 @@ $values = array(); foreach ( $resultsCursor as $doc ) { foreach ( $columns as $column ) { - // If MongoDB returns an array for a column, - // do some extra processing. - if ( is_array( $doc[$column] ) ) { - // Check if it's GeoJSON geometry: - // http://www.geojson.org/geojson-spec.html#geometry-objects - // If so, return it in a format that - // the Maps extension can understand. + if ( strstr($column, ".") ) { + // If the user specified dot notation to retrieve values from the MongoDB result array + $values[$column][] = self::dotresolve($doc, $column); + } elseif ( is_array( $doc[$column] ) ) { + // If MongoDB returns an array for a column, but the user didnt specify dot notation + // do some extra processing. if ( $column == 'geometry' && array_key_exists( 'coordinates', $doc['geometry'] ) ) { + // Check if it's GeoJSON geometry: + // http://www.geojson.org/geojson-spec.html#geometry-objects + // If so, return it in a format that + // the Maps extension can understand. $coordinates = $doc['geometry']['coordinates'][0]; $coordinateStrings = array(); foreach ( $coordinates as $coordinate ) { -- To view, visit https://gerrit.wikimedia.org/r/69557 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1ce049587d5b7a7024fb89dd6278299c90d2947a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/ExternalData Gerrit-Branch: master Gerrit-Owner: Jqnatividad <joel.nativi...@ontodia.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits