From 98d1801934d93c3ed26307e0d2c3c5e36f34adf0 Mon Sep 17 00:00:00 2001 From: Mh-Asmi Date: Mon, 22 Apr 2024 19:09:41 +0400 Subject: [PATCH] hide the exact location of geoposts --- .../Http/Resources/Post/PostGeometryResource.php | 14 ++++++++++++++ .../V5/Repository/Post/EloquentPostRepository.php | 1 + 2 files changed, 15 insertions(+) diff --git a/src/Ushahidi/Modules/V5/Http/Resources/Post/PostGeometryResource.php b/src/Ushahidi/Modules/V5/Http/Resources/Post/PostGeometryResource.php index 275755bf73..6f347d75e0 100644 --- a/src/Ushahidi/Modules/V5/Http/Resources/Post/PostGeometryResource.php +++ b/src/Ushahidi/Modules/V5/Http/Resources/Post/PostGeometryResource.php @@ -16,12 +16,26 @@ class PostGeometryResource extends BaseResource */ public function toArray($request) { + $map_config = service('map.config'); + if (is_a($this->resource, "stdClass")) { $data = (array) $this->resource; } else { $data = $this->resource->toArray(); } + $data['geojson'] = json_decode($data['geojson'], true); + + if (isset($data['hide_location']) && $data['hide_location']) { + foreach ($data['geojson']['features'] as $key => $feature) { + $feature['geometry']['coordinates'][0] = + round($feature['geometry']['coordinates'][0], $map_config['location_precision']); + $feature['geometry']['coordinates'][1] = + round($feature['geometry']['coordinates'][1], $map_config['location_precision']); + $data['geojson']['features'][$key] = $feature; + } + } + unset($data['hide_location']); return $data; } } diff --git a/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostRepository.php b/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostRepository.php index 3b0da79794..bc943887d6 100644 --- a/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostRepository.php +++ b/src/Ushahidi/Modules/V5/Repository/Post/EloquentPostRepository.php @@ -378,6 +378,7 @@ private function getGeoJsonQuery(PostSearchFields $search_fields = null) $select_raw .= ",Max(IFNULL(messages.type,'web')) as source ,Max(messages.data_source_message_id) as 'data_source_message_id'"; $select_raw .= ",Max(forms.color) as 'marker-color'"; + $select_raw .= ",Max(forms.hide_location) as 'hide_location'"; $select_raw .= ",CONCAT( '{\"type\":\"FeatureCollection\",' ,'\"features\":[',