PublishedMapController.php
This handles the storage, deletion, and retrieval of published maps, allowing users to store and manage JSON data representing published maps.
storePublishedMap
storePublishedMappublic function storePublishedMap(Request $request)
{
// Retrieve JSON data from the request
$jsonData = $request->input('jsonData');
// Decode the JSON data into an associative array
$jsonData = json_decode($jsonData, true);
// Extract a unique identifier (ID) from the JSON data
$uniqueHash = $jsonData['ID'];
// Define the directory where the published maps will be stored
$directory = 'PublishedMap';
// Construct the file path using the unique ID and set the file extension to '.json'
$filePublishedMap = $directory . '/' . $uniqueHash . '.json';
// Check if the directory exists; if not, create it recursively with full permissions
if (!file_exists($directory)) {
mkdir($directory, 0777, true);
}
// Convert the JSON data back to a pretty-printed JSON format
$prettyPrintedJson = json_encode($jsonData, JSON_PRETTY_PRINT);
// Open the file for writing; if the file does not exist, it will be created
$file = fopen($filePublishedMap, 'w');
// Check if the file was successfully opened
if ($file) {
// Write the pretty-printed JSON data to the file
fwrite($file, $prettyPrintedJson);
// Close the file
fclose($file);
}
// Prepare a success response
$response = [
'SUCCESS' => 1,
];
// Return the response
return $response;
}deletePublishedMap
deletePublishedMapgetPublishedMap
getPublishedMapLast updated