-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistUserMaps.php
More file actions
123 lines (114 loc) · 3.23 KB
/
listUserMaps.php
File metadata and controls
123 lines (114 loc) · 3.23 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
include_once 'fbaccess.php';
if (!$user) {
require_once 'logout.php';
}
else {
$maxMaps = 5;
$mapsRetrieved = 0;
$flash_success = NULL;
$flash_error = NULL;
$lastMap = NULL;
if (isset($_GET["lastProcessedMap"])) {
$lastMap = $_GET["lastProcessedMap"];
$lastMap = strtolower($lastMap);
$lastMap = trim($lastMap);
$lastMap = str_replace(" ", ".", $lastMap);
}
$query = NULL;
if (isset($_GET["query"])) {
$query = $_GET["query"];
$query = strtolower($query);
$query = trim($query);
$query = str_replace(" ", ".", $query);
}
$rangeConditions = NULL;
if ($query) {
$rangeConditions=array("ComparisonOperator" => AmazonDynamoDB::CONDITION_BEGINS_WITH,
"AttributeValueList" => array(array(AmazonDynamoDB::TYPE_STRING => $query)));
}
if ($lastMap) {
$rangeConditions = array("ComparisonOperator" => AmazonDynamoDB::CONDITION_GREATER_THAN,
"AttributeValueList" => array(array(AmazonDynamoDB::TYPE_STRING => $lastMap)));
}
if ($query) {
// ajax query with prefix = $query
$listUserMapsResponse = $dynamo->query(array(
"TableName" => "MapPlusPlusUserMaps",
"HashKeyValue" => array(
AmazonDynamoDB::TYPE_STRING => $user
),
"RangeKeyCondition" => $rangeConditions,
"Limit" => $maxMaps
));
if ($listUserMapsResponse->isOK()) {
$result = array();
$mapArray=array();
foreach ($listUserMapsResponse->body->Items as $item) {
$mapName = $item->originalName->{AmazonDynamoDB::TYPE_STRING};
$mapDescription = $item->mapDescription->{AmazonDynamoDB::TYPE_STRING};
if ($mapName) {
$mapArray[] = array("mapName" => $mapName,
"mapDescription" => $mapDescription);
}
}
if (count($mapArray)) {
$result=array("maps" => $mapArray, "maxMaps" => $maxMaps);
} else {
$result=array("error" => "No maps found");
}
echo json_encode($result);
} else {
print_r ($listUserMapsResponse);
echo json_encode(array("error" => "There was a problem creating map, try again later."));
}
} else {
if ($lastMap) {
$listUserMapsResponse = $dynamo->query(array(
"TableName" => "MapPlusPlusUserMaps",
"HashKeyValue" => array(
AmazonDynamoDB::TYPE_STRING => $user
),
"RangeKeyCondition" => $rangeConditions,
"Limit" => $maxMaps
));
} else {
$listUserMapsResponse = $dynamo->query(array(
"TableName" => "MapPlusPlusUserMaps",
"HashKeyValue" => array(
AmazonDynamoDB::TYPE_STRING => $user
),
"Limit" => $maxMaps
));
}
$result = array();
$mapArray=array();
if ($listUserMapsResponse->isOK()) {
$count = 0;
foreach ($listUserMapsResponse->body->Items as $item) {
$mapName = $item->originalName->{AmazonDynamoDB::TYPE_STRING};
$mapDescription = $item->mapDescription->{AmazonDynamoDB::TYPE_STRING};
$count++;
if ($mapName) {
$mapArray[] = array("mapName" => $mapName,
"mapDescription" => $mapDescription);
}
}
if ($count) {
$result=array("maps" => $mapArray, "maxMaps" => $maxMaps);
}
else {
$result=array(
"error" => "No maps found",
);
}
} else {
// log this.
$result=array(
"error" => "There was a problem while retrieving your maps, please try again later."
);
}
echo json_encode($result);
}
}
?>