From 5917c74e4e0e1d7164614081ecf8e0b29823f933 Mon Sep 17 00:00:00 2001 From: Boris Date: Mon, 24 Oct 2022 19:14:58 +0200 Subject: [PATCH] La Bureautique tue tout --- config.php | 4 +- lib/DAO.class.php | 2 +- lib/Gchange.class.php | 202 +++++++++++++++++++++++++++------- lib/GchangeRecord.class.php | 57 ++++++++++ map.php | 71 +++++++++--- themes/spationaute/layout.css | 76 ++++++++++++- 6 files changed, 350 insertions(+), 62 deletions(-) create mode 100644 lib/GchangeRecord.class.php 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

+ +
    '; + + foreach ($visitors as $visitor) { + + $records_visitors = array_merge($records_visitors, $gchange->getRecordsByIssuer($visitor->getUserGchangeId())); + + echo ' +
  • '; + + $avatarSrc = $visitor->getAvatarImgSrc(); + $src = !empty($avatarSrc) ? $avatarSrc : $games[$_SESSION['gameId']]['default_avatar']; + + echo ' + '. $visitor->getUserName() .' +
  • '; + } + echo ' +
'; + } + + + $records_placeCreator = $gchange->getRecordsByIssuer($place->_source->issuer); + + $records = array_merge($records_placeCreator, $records_visitors); $offers = []; $needs = []; @@ -198,7 +235,7 @@ if (isset($selectedPlace)) { foreach ($records as $record) { - switch ($record->_source->type) { + switch ($record->getType()) { case 'offer': $offers[] = $record; @@ -219,13 +256,13 @@ if (isset($selectedPlace)) { echo '
    '; foreach ($needs as $item) { - $description = isset($item->_source->description) ? ' title="'. substr($item->_source->description, 0, 30) . '"' : ''; + $description = !empty($item->getDescription()) ? ' title="'. substr($item->getDescription(), 0, 30) . '"' : ''; echo '
  • - - ' . $item->_source->title . ' + + ' . $item->getTitle() . '
  • @@ -241,13 +278,13 @@ if (isset($selectedPlace)) { echo '
      '; foreach ($offers as $item) { - $description = isset($item->_source->description) ? ' title="'. substr($item->_source->description, 0, 30) . '"' : ''; + $description = !empty($item->getDescription()) ? ' title="'. substr($item->getDescription(), 0, 30) . '"' : ''; echo '
    • - - ' . $item->_source->title . ' + + ' . $item->getTitle() . '
    • @@ -262,13 +299,13 @@ if (isset($selectedPlace)) { echo '
        '; foreach ($crowdfundings as $item) { - $description = isset($item->description) ? ' title="'. substr($item->_source->description, 0, 30) . '"' : ''; + $description = !empty($item->getDescription()) ? ' title="'. substr($item->getDescription(), 0, 30) . '"' : ''; echo '
      • - - ' . $item->_source->title . ' + + ' . $item->getTitle() . '
      • diff --git a/themes/spationaute/layout.css b/themes/spationaute/layout.css index fde963f..44b9f57 100644 --- a/themes/spationaute/layout.css +++ b/themes/spationaute/layout.css @@ -113,8 +113,37 @@ main { +#place-details ul.visitors { + margin: 0; + padding: 0; + list-style: none; +} +#place-details ul.visitors li { + + margin: 0; + padding: 0; +} + +#place-details .visitors { + + display: flex; + flex-direction: row; + flex-wrap: wrap; +} + +#place-details .visitors .visitor { + + margin-right: 1rem; + flex-basis: 64px; + text-align: center; +} + +#place-details .visitors .visitor img { + + display: block; +} #place-details { @@ -159,6 +188,30 @@ main { + + + + + + + + + + + + + + + + + + + + + + + + #messenger-page main { display: flex; @@ -277,6 +330,27 @@ main { } + + + + + + + + + + + + + + + + + + + + + #login-page input { border-radius: 0; @@ -309,6 +383,6 @@ main { } #login-page fieldset { - + border-width: 0; } \ No newline at end of file