-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistUserPlaces.php
More file actions
91 lines (77 loc) · 2.12 KB
/
listUserPlaces.php
File metadata and controls
91 lines (77 loc) · 2.12 KB
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
<?php
include_once 'fbaccess.php';
if (!$user):
require_once 'logout.php';
else:
$mapName = null;
$lastPlace = null;
if(isset($_GET['mapName'])) {
$mapName = $_GET['mapName'];
}
if (isset($_GET['lastPlace'])) {
$lastPlace = $_GET['lastPlace'];
}
$result = array();
$responseCode = 200;
$success = "Successfully fetched map";
$mapName = strtolower($mapName);
$mapName = trim($mapName);
$mapName = str_replace(" ", ".", $mapName);
$mapId = $user.".".$mapName;
$rangeConditions = null;
if ($lastPlace) {
$rangeConditions = array("ComparisonOperator" => AmazonDynamoDB::CONDITION_GREATER_THAN,
"AttributeValueList" => array(array(AmazonDynamoDB::TYPE_STRING => $lastPlace)));
}
$maxPlaces = 50;
if ($rangeConditions) {
$listUserPlacesResponse = $dynamo->query(array(
"TableName" => "MapPlusPlusUserPlaces",
"HashKeyValue" => array(
AmazonDynamoDB::TYPE_STRING => $mapId
),
"RangeKeyCondition" => $rangeConditions,
"Limit" => $maxPlaces
));
}
else {
$listUserMapsResponse = $dynamo->query(array(
"TableName" => "MapPlusPlusUserPlaces",
"HashKeyValue" => array(
AmazonDynamoDB::TYPE_STRING => $mapId
),
"Limit" => $maxPlaces
));
}
$places = array();
$result = array();
if ($listUserMapsResponse->isOK()) {
foreach ($listUserMapsResponse->body->Items as $item) {
$placeName = $item->PlaceName->{AmazonDynamoDB::TYPE_STRING};
$placeDescription = $item->placeDescription->{AmazonDynamoDB::TYPE_STRING};
$lat = $item->latitude->{AmazonDynamoDB::TYPE_STRING};
$lng = $item->longitude->{AmazonDynamoDB::TYPE_STRING};
if ($placeName) {
$places[] = array("PlaceName" => $placeName,
"placeDescription" => $placeDescription,
"lng" => $lng,
"lat" => $lat
);
}
}
}
if (count($places) == 0) {
$result[] = array(
"placesReturned" => 0,
"message" => ($listUserMapsResponse->isOK()? "No places found for the map" : "Error while getting the places, please try again later.")
);
} else {
$result[] = array(
"places" => $places,
"maxPlaces" => $maxPlaces,
"placesReturned" => count($places),
"message" => "Successfully fetched places"
);
}
echo json_encode($result);
endif;