diff --git a/config.php b/config.php index da1df59..b19d45e 100644 --- a/config.php +++ b/config.php @@ -8,7 +8,7 @@ error_reporting(E_ALL); session_start(); -define('DEFAULT_RADIUS', 100); +define('DEFAULT_RADIUS', 50); define('TAILLE_SPRITE', 32); define('DEMI_TAILLE_SPRITE', (TAILLE_SPRITE/2)); @@ -85,7 +85,7 @@ $games = [ ] ]; -$radiuses = [5, 10, 20, 50, 100]; +$radiuses = [5, 10, 20, 50]; define('DEFAULT_GAME', 'spationaute'); diff --git a/lib/DAO.class.php b/lib/DAO.class.php index dac8dac..65c7dec 100644 --- a/lib/DAO.class.php +++ b/lib/DAO.class.php @@ -484,7 +484,7 @@ class DAO { if (isset($queryParams)) { $out[] = _('Paramètres de la requête : '); - $out[] = print_r($queryParams, true); + $out[] = '
'. print_r($queryParams, true) . ''; } $this->decease($out); diff --git a/lib/Gchange.class.php b/lib/Gchange.class.php index 07c8169..5222d30 100644 --- a/lib/Gchange.class.php +++ b/lib/Gchange.class.php @@ -5,6 +5,7 @@ require_once('DAO.class.php'); require_once('GchangeUser.class.php'); +require_once('GchangeRecord.class.php'); class Gchange { @@ -16,6 +17,7 @@ class Gchange { private $cacheLongevity = array( 'placesNearby' => 604800, // 3 jours + 'usersNearby' => 43200, // 12 heures 'users' => 43200, // 12 heures 'records' => 900 // 15 min ); @@ -40,15 +42,29 @@ class Gchange { $queryParams = [ 'size' => $n, 'query' => [ - 'bool' =>[ - 'must' => [ + 'bool' => [ + 'filter' => [ 'term' => [ 'issuer' => $issuer ] - ], - 'must_not' => [ + + /* + , 'range' => [ + 'stock' => [ + 'gte' => 1 + ] + ] + */ + ] + /* + , 'filter' => [ + ] + */ + + , 'must_not' => [ [ "term" => ["stock" => 0] ] ] + ] ], 'sort' => [ @@ -63,7 +79,15 @@ class Gchange { $result = json_decode($json); - return $result->hits->hits; + + $records = []; + + foreach ($result->hits->hits as $hit) { + + $records[] = new GchangeRecord($hit); + } + + return $records; } @@ -127,6 +151,9 @@ class Gchange { public function getPlacesNearUser ($user, $radius) { + return $this->getNearbyPlaces($user->getLat(), $user->getLon(), $radius); + + /* $placesCacheDir = 'places-nearby/user/'; $placesCacheFile = $user->getUserGchangeId() . '.json'; @@ -143,27 +170,136 @@ class Gchange { $result = json_decode($json); return $result->hits->hits; + + */ } public function getNearbyPlaces ($lat, $lon, $maxDistance, $minDistance = NULL) { - $json = $this->getNearbyPlacesJson($lat, $lon, $maxDistance, $minDistance); + $placesCacheDir = 'places-nearby/geopoint/'; + $placesCacheFile = $lat . ',' . $lon . '.json'; + + $json = $this->getJsonFromCache($placesCacheDir, $placesCacheFile, $this->cacheLongevity['placesNearby']); + + if (empty($json)) { + + $json = $this->getNearbyPlacesJson($lat, $lon, $maxDistance, $minDistance); + + $this->cacheJson($placesCacheDir, $placesCacheFile, $json); + + } $result = json_decode($json); return $result->hits->hits; } + public function getNearbyUsers ($lat, $lon, $maxDistance, $minDistance = NULL) { + + $placesCacheDir = 'users-nearby/geopoint/'; + $placesCacheFile = $lat . ',' . $lon . '.json'; - public function getNearbyPlacesJson ($lat, $lon, $maxDistance, $minDistance = NULL) { + $json = $this->getJsonFromCache($placesCacheDir, $placesCacheFile, $this->cacheLongevity['usersNearby']); + + if (empty($json)) { + + $json = $this->getNearbyPlacesJson($lat, $lon, $maxDistance, $minDistance); + + $this->cacheJson($placesCacheDir, $placesCacheFile, $json); + + } + + $result = json_decode($json); + + return $result->hits->hits; + } + + public function getImmaterialRecords () { $n = 20; + $queryParams = [ + 'size' => $n, + 'query' => [ + 'nested' => [ + 'path' => 'category', + 'query' => [ + 'bool' => [ + 'should' => [ + [ 'term' => [ 'category.parent' => 'cat31' ] ], + [ 'term' => [ 'category.id' => 'cat31' ] ], + [ 'term' => [ 'category.parent' => 'cat74' ] ], + [ 'term' => [ 'category.id' => 'cat74' ] ] + ], + 'must_not' => [ + [ "term" => ["category.id" => "cat65"] ] + ] + ] + ] + ] + ] + ]; + + $json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams); + $result = json_decode($json); + + + $records = []; + + foreach ($result->hits->hits as $hit) { + + $records[] = new GchangeRecord($hit); + } + + return $records; + } + + public function getUsersInDaPlace ($placeId) { + + $n = 20; + + $queryParams = [ + 'size' => $n, + 'query' => [ + 'nested' => [ + 'path' => 'socials', + 'query' => [ + 'bool' => [ + 'filter' => [ + 'term' => [ + 'socials.url' => 'https://www.gchange.fr/#/app/page/view/'. $placeId .'/' + ] + ] + ] + ] + ] + ] + ]; + + $json = $this->dao->fetchJson('/user/profile/_search', 'gchange', $queryParams); + + $result = json_decode($json); + + + $users = []; + + foreach ($result->hits->hits as $hit) { + + $users[] = new GchangeUser($hit); + } + + return $users; + } + + public function getNearbyPlacesJson ($lat, $lon, $maxDistance, $minDistance = NULL) { + + $n = 20; + $queryParams = [ 'size' => $n, 'query' => [ 'bool' => [ - 'must' => [ + 'filter' => [ [ 'geo_distance' => [ @@ -217,39 +353,15 @@ class Gchange { $json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams); $result = json_decode($json); - return $result->hits->hits; - } - - public function getImmaterialRecords () { - $n = 20; - - $queryParams = [ - 'size' => $n, - 'query' => [ - 'nested' => [ - 'path' => 'category', - 'query' => [ - 'bool' => [ - 'should' => [ - [ 'term' => [ 'category.parent' => 'cat31' ] ], - [ 'term' => [ 'category.id' => 'cat31' ] ], - [ 'term' => [ 'category.parent' => 'cat74' ] ], - [ 'term' => [ 'category.id' => 'cat74' ] ] - ], - 'must_not' => [ - [ "term" => ["category.id" => "cat65"] ] - ] - ] - ] - ] - ] - ]; - - $json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams); - $result = json_decode($json); - - return $result->hits->hits; + $records = []; + + foreach ($result->hits->hits as $hit) { + + $records[] = new GchangeRecord($hit); + } + + return $records; } public function getShippable () { @@ -268,7 +380,15 @@ class Gchange { $json = $this->dao->fetchJson('/market/record/_search?pretty', 'gchange', $queryParams); $result = json_decode($json); - return $result->hits->hits; + + $records = []; + + foreach ($result->hits->hits as $hit) { + + $records[] = new GchangeRecord($hit); + } + + return $records; } public function getHousingOffers () { diff --git a/lib/GchangeRecord.class.php b/lib/GchangeRecord.class.php new file mode 100644 index 0000000..f0a14a3 --- /dev/null +++ b/lib/GchangeRecord.class.php @@ -0,0 +1,57 @@ +title = $gchangeObject->_id; + + $this->type = $gchangeObject->_source->type; + + $this->title = $gchangeObject->_source->title; + + $this->description = $gchangeObject->_source->description; + + if (isset($gchangeObject->_source->avatar->_content) and + !empty($gchangeObject->_source->avatar->_content)) { + + $this->imgSrc = 'data:'. $gchangeObject->_source->avatar->_content_type .';base64,' . $gchangeObject->_source->avatar->_content; + } + } + + public function getGchangeId () { + + return $this->gchangeId; + } + + public function getType () { + + return $this->type; + } + + public function getTitle () { + + return $this->title; + } + + public function getDescription () { + + return $this->description; + } + + public function getImgSrc () { + + return $this->imgSrc; + } +} \ No newline at end of file diff --git a/map.php b/map.php index 1f3261a..d899760 100644 --- a/map.php +++ b/map.php @@ -61,7 +61,10 @@ echo ' data-radius="'. $_SESSION['radius'] .'" > + '; + /* + echo ''; $avatarSrc = $player->getAvatarImgSrc(); @@ -75,18 +78,13 @@ echo ' height="'. TAILLE_SPRITE .'" /> '; - + */ $places = $gchange->getPlacesNearUser($player, $_SESSION['radius']); $selectedPlace = NULL; foreach ($places as $place) { - - if (isset($_GET['place']) and ($place->_id == $_GET['place'])) { - - $selectedPlace = $place; - } $placeLat = $place->_source->geoPoint->lat; $placeLon = $place->_source->geoPoint->lon; @@ -129,6 +127,11 @@ echo ' '; + + if (isset($_GET['place']) and ($place->_id == $_GET['place'])) { + + $selectedPlace = $place; + } } echo ' @@ -189,8 +192,42 @@ if (isset($selectedPlace)) { '; + $visitors = $gchange->getUsersInDaPlace($place->_id); + $records_visitors = []; - $records = $gchange->getRecordsByIssuer($place->_source->issuer); + if (!empty($visitors)) { + + echo ' +Visiteurs
+ +