forked from La_Bureautique/zeg1jeux
La fucking biourotique
parent
ffca895018
commit
8b0b245c34
|
@ -18,6 +18,8 @@ define('SONAR_DURATION', 5);
|
|||
define("LAT_ASTROPORT_ONE", 44.22484418236386);
|
||||
define("LON_ASTROPORT_ONE", 1.6395813014177014);
|
||||
|
||||
define('MAX_NEARBY_PLACES', 15);
|
||||
|
||||
class Player {
|
||||
|
||||
private $pubkey;
|
||||
|
|
|
@ -191,47 +191,12 @@ class Gchange {
|
|||
return $result->hits->hits;
|
||||
}
|
||||
|
||||
public function getPlacesNearUser ($user, $radius) {
|
||||
public function getPlacesNearUser ($user, $radius, $maxPlacesNb) {
|
||||
|
||||
return $this->getNearbyPlaces($user->getLat(), $user->getLon(), $radius);
|
||||
return $this->getNearbyPlaces($user->getLat(), $user->getLon(), $radius, null, $maxPlacesNb);
|
||||
}
|
||||
|
||||
public function getPlaceDetails ($placeId) {
|
||||
|
||||
$placeDetailsCacheDir = 'place/details/';
|
||||
$placeDetailsCacheFile = $placeId . '.json';
|
||||
|
||||
try {
|
||||
|
||||
$json = $this->getJsonFromCache($placeDetailsCacheDir, $placeDetailsCacheFile, $this->cacheLongevity['placeDetails']);
|
||||
|
||||
} catch (Exception $errorMsgs) {
|
||||
|
||||
try {
|
||||
|
||||
$json = $this->fetchJson('/page/record/' + $placeId);
|
||||
|
||||
$this->cacheJson($placeDetailsCacheDir, $placeDetailsCacheFile, $json);
|
||||
|
||||
} catch (Exception $errorMsgs) {
|
||||
|
||||
try {
|
||||
|
||||
$json = $this->getJsonFromCache($placeDetailsCacheDir, $placeDetailsCacheFile, null);
|
||||
|
||||
} catch (Exception $errorMsgs) {
|
||||
|
||||
throw new Exception('Pas pu trouver les détails pour la page ' . $placeId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return json_decode($json);
|
||||
|
||||
}
|
||||
|
||||
public function getNearbyPlaces ($lat, $lon, $maxDistance, $minDistance = NULL) {
|
||||
public function getNearbyPlaces ($lat, $lon, $maxDistance, $minDistance = NULL, $maxPlacesNb) {
|
||||
|
||||
$placesCacheDir = 'places-nearby/geopoint/' . $maxDistance . 'km/';
|
||||
$placesCacheFile = $lat . ',' . $lon . '.json';
|
||||
|
@ -263,11 +228,10 @@ class Gchange {
|
|||
|
||||
try {
|
||||
|
||||
$n = 50;
|
||||
$n = (string) $maxPlacesNb;
|
||||
|
||||
$queryParams = [
|
||||
'size' => $n,
|
||||
// 'fields' => ['_id'],
|
||||
'query' => [
|
||||
'bool' => [
|
||||
'filter' => [
|
||||
|
@ -287,14 +251,19 @@ class Gchange {
|
|||
];
|
||||
|
||||
$json = $this->fetchJson('/page/record/_search', $queryParams);
|
||||
|
||||
// cache nearby places index
|
||||
$this->cacheJson($placesCacheDir, $placesCacheFile, $json);
|
||||
|
||||
// cache each nearby place details
|
||||
|
||||
$result = json_decode($json);
|
||||
|
||||
$resultClone = $this->filterIds($result);
|
||||
|
||||
// cache nearby places index
|
||||
$this->cacheJson($placesCacheDir, $placesCacheFile, json_encode($resultClone));
|
||||
|
||||
// cache each nearby place details
|
||||
|
||||
// ob_get_clean();
|
||||
// echo '<pre>'; print_r($resultClone); echo '</pre>';
|
||||
// echo '<pre>'; print_r($result); echo '</pre>';
|
||||
foreach ($result->hits->hits as $place) {
|
||||
|
||||
$nearbyPlaces[] = $place;
|
||||
|
@ -333,6 +302,80 @@ class Gchange {
|
|||
|
||||
return $nearbyPlaces;
|
||||
}
|
||||
|
||||
private function filterIds ($r) {
|
||||
|
||||
// $result = clone $r;
|
||||
|
||||
$result = new stdClass;
|
||||
|
||||
$result->took = $r->took;
|
||||
$result->timed_out = $r->timed_out;
|
||||
$result->_shards = new stdClass;
|
||||
$result->_shards->total = $r->_shards->total;
|
||||
$result->_shards->successful = $r->_shards->successful;
|
||||
$result->_shards->failed = $r->_shards->failed;
|
||||
$result->hits = new stdClass;
|
||||
$result->hits->total = $r->hits->total;
|
||||
$result->hits->max_score = $r->hits->max_score;
|
||||
$result->hits->hits = array();
|
||||
|
||||
$rHitsNb = count($r->hits->hits);
|
||||
|
||||
for ($i = 0; $i < $rHitsNb; $i++) {
|
||||
|
||||
$result->hits->hits[$i] = new stdClass;
|
||||
|
||||
$result->hits->hits[$i]->_id = $r->hits->hits[$i]->_id;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/*
|
||||
private function filterIds (&$item) {
|
||||
|
||||
$itemId = $item->_id;
|
||||
$item = new stdClass;
|
||||
$item->_id = $itemId;
|
||||
}
|
||||
*/
|
||||
|
||||
public function getPlaceDetails ($placeId) {
|
||||
|
||||
$placeDetailsCacheDir = 'place/details/';
|
||||
$placeDetailsCacheFile = $placeId . '.json';
|
||||
|
||||
try {
|
||||
|
||||
$json = $this->getJsonFromCache($placeDetailsCacheDir, $placeDetailsCacheFile, $this->cacheLongevity['placeDetails']);
|
||||
|
||||
} catch (Exception $errorMsgs) {
|
||||
|
||||
try {
|
||||
|
||||
$json = $this->fetchJson('/page/record/' + $placeId);
|
||||
|
||||
$this->cacheJson($placeDetailsCacheDir, $placeDetailsCacheFile, $json);
|
||||
|
||||
} catch (Exception $errorMsgs) {
|
||||
|
||||
try {
|
||||
|
||||
$json = $this->getJsonFromCache($placeDetailsCacheDir, $placeDetailsCacheFile, null);
|
||||
|
||||
} catch (Exception $errorMsgs) {
|
||||
|
||||
throw new Exception('Pas pu trouver les détails pour la page ' . $placeId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return json_decode($json);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
public function getNearbyRecords ($lat, $lon, $maxDistance, $minDistance = NULL) {
|
||||
|
|
Loading…
Reference in New Issue