-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetMapFeatures.php
65 lines (56 loc) · 2.33 KB
/
getMapFeatures.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
<?php
/**
* @author James Baster <[email protected]>
* @copyright City of Edinburgh Council & James Baster
* @license Open Source under the 3-clause BSD License
* @url https://github.com/City-Outdoors/City-Outdoors-Web
*/
require 'includes/src/global.php';
$currentUser = getCurrentUser();
$featureSearch = new FeatureSearch();
$featureSearch->withinBounds($_GET['left'], $_GET['right'], $_GET['top'], $_GET['bottom']);
$featureSearch->visibleToUser($currentUser);
$featureSearch->userCheckedinInformation($currentUser);
$hiddenCollection = Collection::loadBySlug($CONFIG->HIDDEN_COLLECTION_SLUG);
if (isset($_GET['collections'])) {
// Sometimes the IDS for all possible collections are passed back.
// In this case, we want to do no filtering so features with content only are included.
// If the use has selected some collections only (ie deselected some) then we do want to filter.
$collectionIDs = explode(",", $_GET['collections']);
$collectionSearch = new CollectionSearch();
$anyCollectionNotSelected = false;
$collectionsToAdd = array();
while($collection = $collectionSearch->nextResult()) {
if (in_array($collection->getId(), $collectionIDs)) {
$collectionsToAdd[] = $collection;
} else {
$anyCollectionNotSelected = true;
}
}
if ($anyCollectionNotSelected) {
if ($collectionsToAdd) {
foreach($collectionsToAdd as $collection) $featureSearch->withinCollection ($collection);
} else {
// special case; user appears to have selected no collections. Well, ok ...
header('Content-type: application/json');
print json_encode(array('data'=>array(),'result'=>true));
die();
}
}
}
$data = array('data'=>array(),'result'=>true, 'userID'=>($currentUser?$currentUser->getId():null));
while($feature = $featureSearch->nextResult()) {
$inHiddenCollection = $hiddenCollection && in_array($hiddenCollection->getId(), $feature->getCollectionIDS());
$data['data'][] = array(
'id'=>$feature->getId(),
'lat'=>$feature->getPointLat(),
'lng'=>$feature->getPointLng(),
'collectionIDS'=>$feature->getCollectionIDS(),
'title'=>$feature->getTitle(),
'thumbnailURL'=>$feature->getThumbnailURL(),
'inHiddenCollection'=>$inHiddenCollection,
'answeredAllQuestions'=>($currentUser ? $feature->getHasUserAnsweredAllQuestions() : true),
);
}
header('Content-type: application/json');
print json_encode($data);