From 7c87c4a37130119e49839a4a654c81058ce4eb20 Mon Sep 17 00:00:00 2001 From: Boris Date: Wed, 26 Oct 2022 12:12:20 +0200 Subject: [PATCH] Ajout ratings gchange --- lib/DAO.class.php | 2 +- lib/Gchange.class.php | 65 +++++++++++++++++++++++++++++++++++++ lib/GchangeRating.class.php | 44 +++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 lib/GchangeRating.class.php diff --git a/lib/DAO.class.php b/lib/DAO.class.php index 65c7dec..5f17890 100644 --- a/lib/DAO.class.php +++ b/lib/DAO.class.php @@ -75,7 +75,7 @@ class DAO { 'duniter' => 2, 'cesiumplus' => 5, - 'gchange' => 5, + 'gchange' => 10, ]; private $nodeTimeoutIncrement = [ diff --git a/lib/Gchange.class.php b/lib/Gchange.class.php index 5222d30..3ff3f30 100644 --- a/lib/Gchange.class.php +++ b/lib/Gchange.class.php @@ -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; diff --git a/lib/GchangeRating.class.php b/lib/GchangeRating.class.php new file mode 100644 index 0000000..8f63ebf --- /dev/null +++ b/lib/GchangeRating.class.php @@ -0,0 +1,44 @@ +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; + } +} \ No newline at end of file