Skip to content

Commit

Permalink
Fix: #2406 wrong parameter source in location edit controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Roach committed May 4, 2019
1 parent e1ab195 commit d83420d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
29 changes: 15 additions & 14 deletions app/Http/Controllers/Admin/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function __construct(GedcomService $gedcom_service)
public function mapData(ServerRequestInterface $request): ResponseInterface
{
$parent_id = (int) ($request->getQueryParams()['parent_id'] ?? 0);
$hierarchy = $this->gethierarchy($parent_id);
$hierarchy = $this->getHierarchy($parent_id);
$title = I18N::translate('Geographic data');
$breadcrumbs = [
route('admin-control-panel') => I18N::translate('Control panel'),
Expand All @@ -91,7 +91,7 @@ public function mapData(ServerRequestInterface $request): ResponseInterface
*
* @return array
*/
private function gethierarchy(int $id): array
private function getHierarchy(int $id): array
{
$arr = [];
$fqpn = [];
Expand Down Expand Up @@ -124,7 +124,7 @@ private function getPlaceListLocation(int $id): array
if ($id === 0) {
$fqpn = '';
} else {
$hierarchy = $this->gethierarchy($id);
$hierarchy = $this->getHierarchy($id);
$fqpn = ', ' . $hierarchy[0]->fqpn;
}

Expand Down Expand Up @@ -233,7 +233,7 @@ public function mapDataEdit(ServerRequestInterface $request): ResponseInterface
{
$parent_id = (int) $request->getQueryParams()['parent_id'];
$place_id = (int) $request->getQueryParams()['place_id'];
$hierarchy = $this->gethierarchy($place_id);
$hierarchy = $this->getHierarchy($place_id);
$fqpn = empty($hierarchy) ? '' : $hierarchy[0]->fqpn;
$location = new Location($fqpn);

Expand Down Expand Up @@ -318,13 +318,13 @@ private function mapLocationData(int $id): array
*/
public function mapDataSave(ServerRequestInterface $request): ResponseInterface
{
$parent_id = (int) $request->getParsedBody()['parent_id'];
$place_id = (int) $request->getParsedBody()['place_id'];
$parent_id = (int) $request->getQueryParams()['parent_id'];
$place_id = (int) $request->getQueryParams()['place_id'];
$lat = round($request->getParsedBody()['new_place_lati'], 5); // 5 decimal places (locate to within about 1 metre)
$lat = ($lat < 0 ? 'S' : 'N') . abs($lat);
$lng = round($request->getParsedBody()['new_place_long'], 5);
$lng = ($lng < 0 ? 'W' : 'E') . abs($lng);
$hierarchy = $this->gethierarchy($parent_id);
$hierarchy = $this->getHierarchy($parent_id);
$level = count($hierarchy);
$icon = $request->getParsedBody()['icon'];
$zoom = (int) $request->getParsedBody()['new_zoom_factor'];
Expand All @@ -337,8 +337,8 @@ public function mapDataSave(ServerRequestInterface $request): ResponseInterface
'pl_parent_id' => $parent_id,
'pl_level' => $level,
'pl_place' => $request->getParsedBody()['new_place_name'],
'pl_lati' => $request->getParsedBody()['lati_control'] . $lat,
'pl_long' => $request->getParsedBody()['long_control'] . $lng,
'pl_lati' => $lat,
'pl_long' => $lng,
'pl_zoom' => $zoom,
'pl_icon' => $icon,
]);
Expand All @@ -347,12 +347,13 @@ public function mapDataSave(ServerRequestInterface $request): ResponseInterface
->where('pl_id', '=', $place_id)
->update([
'pl_place' => $request->getParsedBody()['new_place_name'],
'pl_lati' => $request->getParsedBody()['lati_control'] . $lat,
'pl_long' => $request->getParsedBody()['long_control'] . $lng,
'pl_zoom' => (int) $request->getParsedBody()['new_zoom_factor'],
'pl_lati' => $lat,
'pl_long' => $lng,
'pl_zoom' => $zoom,
'pl_icon' => $icon,
]);
}

FlashMessages::addMessage(
I18N::translate(
'The details for “%s” have been updated.',
Expand Down Expand Up @@ -413,7 +414,7 @@ public function exportLocations(ServerRequestInterface $request): ResponseInterf
$format = $request->getQueryParams()['format'];
$maxlevel = (int) DB::table('placelocation')->max('pl_level');
$startfqpn = [];
$hierarchy = $this->gethierarchy($parent_id);
$hierarchy = $this->getHierarchy($parent_id);

// Create the file name
$place_name = empty($hierarchy) ? 'Global' : $hierarchy[0]->fqpn; // $hierarchy[0] always holds the full placename
Expand Down Expand Up @@ -625,7 +626,7 @@ public function importLocationsAction(ServerRequestInterface $request): Response

// Check the filetype
if (stripos($string, 'FeatureCollection') !== false) {
$input_array = json_decode($string);
$input_array = json_decode($string, false);

foreach ($input_array->features as $feature) {
$places[] = array_combine($field_names, [
Expand Down
18 changes: 10 additions & 8 deletions tests/app/Http/Controllers/Admin/LocationControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,18 @@ public function testMapDataEdit(): void
public function testMapDataSave(): void
{
$controller = new LocationController(new GedcomService());
$request = self::createRequest('POST', ['route' => 'map-data-edit'], [
$request = self::createRequest('POST', [
'route' => 'map-data-edit',
'parent_id' => '0',
'place_id' => '0',
'new_place_lati' => '-12.345',
'new_place_long' => '-123.45',
'icon' => '',
'place_id' => '0',
], [
'new_place_lati' => '-12.345',
'new_place_long' => '-123.45',
'icon' => '',
'new_zoom_factor' => '2',
'new_place_name' => 'place',
'lati_control' => 'S',
'long_control' => 'W',
'new_place_name' => 'place',
'lati_control' => 'S',
'long_control' => 'W',
]);
$response = $controller->mapDataSave($request);

Expand Down

0 comments on commit d83420d

Please sign in to comment.