geoproject-app/public/site/plugins/map-editor/routes/mapdata/save.php

70 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/**
* PATCH save map data (center, zoom) directly to the page content
*/
return [
'pattern' => 'map-editor/pages/(:all)/mapdata',
'method' => 'PATCH',
'auth' => false,
'action' => function (string $pageId) {
try {
$user = kirby()->user();
if (!$user && !kirby()->option('debug', false)) {
return [
'status' => 'error',
'message' => 'Unauthorized',
'code' => 401
];
}
$page = kirby()->page($pageId);
if (!$page) {
return [
'status' => 'error',
'message' => 'Page not found',
'code' => 404
];
}
if (!$page->permissions()->can('update')) {
return [
'status' => 'error',
'message' => 'Forbidden',
'code' => 403
];
}
$data = kirby()->request()->data();
if (!isset($data['mapdata'])) {
return [
'status' => 'error',
'message' => 'mapdata is required',
'code' => 400
];
}
$page->update([
'mapdata' => $data['mapdata']
]);
return [
'status' => 'success',
'data' => [
'message' => 'Map data saved successfully'
]
];
} catch (Exception $e) {
return [
'status' => 'error',
'message' => $e->getMessage(),
'code' => 500
];
}
}
];