diff --git a/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php b/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php index 2b3db1f189d1585f0ae49584d433f1e462ea4894..3511a07bb883b3b88a5af75dfda0c298ffe1ac28 100644 --- a/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php +++ b/src/Biopen/GeoDirectoryBundle/Services/ElementImportMappingService.php @@ -54,15 +54,15 @@ class ElementImportMappingService eval(str_replace('<?php', '', $import->getCustomCode())); if ($data == null || !is_array($data)) return []; - // elements is ofently stored nested in a data attribute - if (array_key_exists('data', $data)) $data = $data['data']; - if ($data == null || !is_array($data)) return []; - if (array_key_exists('elements', $data)) $data = $data['elements']; - if ($data == null || !is_array($data)) return []; + // elements is ofently stored nested in some attribute + if (array_key_exists('data', $data) && is_array($data['data'])) $data = $data['data']; + if (array_key_exists('elements', $data) && is_array($data['elements'])) $data = $data['elements']; + if (array_key_exists('features', $data) && is_array($data['features'])) $data = $data['features']; // Fixs gogocarto ontology when importing, to simplify import/export from gogocarto to gogocarto foreach ($data as $key => $row) { if (is_array($row)) { + // GOGOCARTO ONTOLGY if (array_key_exists('geo', $row)) { $data[$key]['latitude'] = $row['geo']['latitude']; @@ -87,6 +87,20 @@ class ElementImportMappingService $data[$key]['categories'] = $data[$key]['categoriesFull']; unset($data[$key]['categoriesFull']); } + + // GEOJSON + if (isset($row['geometry']) && isset($row['geometry']['coordinates'])) { + $data[$key]['latitude'] = $row['geometry']['coordinates'][1]; + $data[$key]['longitude'] = $row['geometry']['coordinates'][0]; + unset($data[$key]['geometry']); + + if (isset($row['properties']) && $this->isAssociativeArray($row['properties'])) { + foreach ($row['properties'] as $field => $value) { + $data[$key][$field] = $value; + } + unset($data[$key]['properties']); + } + } } else { // the $row is not an array, probably a string so we ignore it unset($data[$key]);