La Bureautique tue tout

This commit is contained in:
Boris 2022-10-24 19:14:58 +02:00
parent a2e2d4583f
commit 5917c74e4e
6 changed files with 350 additions and 62 deletions

View File

@ -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');

View File

@ -484,7 +484,7 @@ class DAO {
if (isset($queryParams)) {
$out[] = _('Paramètres de la requête : ');
$out[] = print_r($queryParams, true);
$out[] = '<pre>'. print_r($queryParams, true) . '<pre>';
}
$this->decease($out);

View File

@ -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 () {

View File

@ -0,0 +1,57 @@
<?php
class GchangeRecord {
private $gchangeId;
private $title;
private $description;
private $type;
private $imgSrc = null;
public function __construct ($gchangeObject) {
$this->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;
}
}

71
map.php
View File

@ -61,7 +61,10 @@ echo '
data-radius="'. $_SESSION['radius'] .'"
>
<div id="map-deco"></div>
';
/*
echo '
<section class="player" style="left: calc(50% - '. DEMI_TAILLE_SPRITE . 'px); top: calc(50% - '. DEMI_TAILLE_SPRITE . 'px);">';
$avatarSrc = $player->getAvatarImgSrc();
@ -75,18 +78,13 @@ echo '
height="'. TAILLE_SPRITE .'" />
</section>
';
*/
$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 '
</article>
</section>';
if (isset($_GET['place']) and ($place->_id == $_GET['place'])) {
$selectedPlace = $place;
}
}
echo '
</div>
@ -189,8 +192,42 @@ if (isset($selectedPlace)) {
';
$visitors = $gchange->getUsersInDaPlace($place->_id);
$records_visitors = [];
$records = $gchange->getRecordsByIssuer($place->_source->issuer);
if (!empty($visitors)) {
echo '
<h4>Visiteurs</h4>
<ul class="visitors">';
foreach ($visitors as $visitor) {
$records_visitors = array_merge($records_visitors, $gchange->getRecordsByIssuer($visitor->getUserGchangeId()));
echo '
<li class="visitor">';
$avatarSrc = $visitor->getAvatarImgSrc();
$src = !empty($avatarSrc) ? $avatarSrc : $games[$_SESSION['gameId']]['default_avatar'];
echo '
<img src="'. $src . '"
alt="'. $visitor->getUserName() .'"
title="'. $visitor->getUserName() .'"
width="64"
height="64" />
</li>';
}
echo '
</ul>';
}
$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 '<ul>';
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 '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->_id . '/"'. $description .'>
' . $item->_source->title . '
<a href="https://www.gchange.fr/#/app/market/view/'. $item->getGchangeId() . '/"'. $description .'>
' . $item->getTitle() . '
</a>
</li>
@ -241,13 +278,13 @@ if (isset($selectedPlace)) {
echo '<ul>';
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 '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->_id . '/"'. $description .'>
' . $item->_source->title . '
<a href="https://www.gchange.fr/#/app/market/view/'. $item->getGchangeId() . '/"'. $description .'>
' . $item->getTitle() . '
</a>
</li>
@ -262,13 +299,13 @@ if (isset($selectedPlace)) {
echo '<ul>';
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 '
<li>
<a href="https://www.gchange.fr/#/app/market/view/'. $item->_id . '/"'. $description .'>
' . $item->_source->title . '
<a href="https://www.gchange.fr/#/app/market/view/'. $item->getGchangeId() . '/"'. $description .'>
' . $item->getTitle() . '
</a>
</li>

View File

@ -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;
}