Ajout ratings gchange

This commit is contained in:
Boris 2022-10-26 12:12:20 +02:00
parent 5917c74e4e
commit 7c87c4a371
3 changed files with 110 additions and 1 deletions

View File

@ -75,7 +75,7 @@ class DAO {
'duniter' => 2,
'cesiumplus' => 5,
'gchange' => 5,
'gchange' => 10,
];
private $nodeTimeoutIncrement = [

View File

@ -6,6 +6,7 @@
require_once('DAO.class.php');
require_once('GchangeUser.class.php');
require_once('GchangeRecord.class.php');
require_once('GchangeRating.class.php');
class Gchange {
@ -291,6 +292,70 @@ class Gchange {
return $users;
}
public function getRatingsSentBy ($issuer) {
$n = 20;
$queryParams = [
'size' => $n,
'query' => [
'bool' => [
'must' => [
'term' => ['kind' => 'STAR']
],
'filter' => [
'term' => ['issuer' => $issuer]
]
]
]
];
$json = $this->dao->fetchJson('/like/record/_search', 'gchange', $queryParams);
$result = json_decode($json);
$ratings = [];
foreach ($result->hits->hits as $hit) {
$ratings[] = new GchangeRating($hit);
}
return $ratings;
}
public function getRatingsReceivedBy ($receiver) {
$n = 20;
$queryParams = [
'size' => $n,
'query' => [
'bool' => [
'must' => [
'term' => ['kind' => 'STAR']
],
'filter' => [
'term' => ['id' => $receiver]
]
]
]
];
$json = $this->dao->fetchJson('/like/record/_search', 'gchange', $queryParams);
$result = json_decode($json);
$ratings = [];
foreach ($result->hits->hits as $hit) {
$ratings[] = new GchangeRating($hit);
}
return $ratings;
}
public function getNearbyPlacesJson ($lat, $lon, $maxDistance, $minDistance = NULL) {
$n = 20;

View File

@ -0,0 +1,44 @@
<?php
class GchangeRating {
private $senderPubkey;
private $receiverPubkey;
private $level;
private $time;
public function __construct ($gchangeObject) {
$this->senderPubkey = $gchangeObject->_source->issuer;
$this->receiverPubkey = $gchangeObject->_source->id;
$this->level = $gchangeObject->_source->level;
$this->time = $gchangeObject->_source->time;
}
public function getLevel () {
return $this->level;
}
public function getSenderPubkey () {
return $this->senderPubkey;
}
public function getReceiverPubkey () {
return $this->receiverPubkey;
}
public function getTime () {
return $this->time;
}
}