-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddPlaceToUserMap.php
103 lines (90 loc) · 2.51 KB
/
addPlaceToUserMap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
include_once 'fbaccess.php';
if (!$user):
require_once 'logout.php';
else:
$mapName = $_POST['mapName'];
$placeName = $_POST['placeName'];
$lat = $_POST['lat'];
$lng = $_POST['lng'];
$placeDescription = $_POST['placeDescription'];
$result = array();
$responseCode = 200;
$success = "Successfully added map";
$mapName = strtolower($mapName);
$mapName = trim($mapName);
$mapName = str_replace(" ", ".", $mapName);
$mapId = $user.$mapName;
$getMapResponse = $dynamo->get_item(array(
"TableName" => "MapPlusPlusUserMaps",
"Key" => $dynamo->attributes(array(
'HashKeyElement' => $user,
'RangeKeyElement' => $mapName,
)),
"AttributesToGet" => array("UserId", "originalName", "totalPlaces"),
));
if ($getMapResponse->isOK()) {
if ($getMapResponse->body->Item) {
// Check if the map exists.
$getPlaceResponse = $dynamo->get_item(array(
"TableName" => "MapPlusPlusUserPlaces",
"Key" => $dynamo->attributes(array(
'HashKeyElement' => $mapId,
'RangeKeyElement' => $placeName,
)),
"AttributesToGet" => array("MapId", "PlaceName", "placeDescription"),
)
);
//print_r($getMapResponse);
// Check if the place already exists.
if ($getPlaceResponse->isOK()) {
if ($getPlaceResponse->body->Item) {
// This place is already marked.
$result = array(
"responseCode" => 200,
"success" => "The ".$placeName." already exists in the map"
);
} else {
$addPlaceResponse = $dynamo->put_item(array(
"TableName" => "MapPlusPlusUserPlaces",
"Item" => $dynamo->attributes(array(
"MapId" => $mapId,
"PlaceName" => $placeName,
"placeDescription" => $placeDescription,
"latitude" => $lat,
"longitude" => $lng,
"createdBy" => $user,
"creationDate" => $date
))
));
if ($addPlaceResponse->isOK()) {
// Adding place was successful.
$result = array(
"responseCode" => $responseCode,
"message" => $success
);
} else {
$result = array(
"responseCode" => 500,
"message" => "Unable to add this place at this time, please try again later"
);
// Adding place was failure.
}
}
}
} else {
$result = array(
"responseCode" => 404,
"message" => "The specified map doesn't exist, please create this map."
);
}
} else {
//print_r($getMapResponse);
$result = array(
"responseCode" => 500,
"message" => "Unable to add this place at this time, please try again later"
);
}
echo json_encode($result);
endif;
?>