This repository was archived by the owner on Oct 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrating.php
More file actions
74 lines (59 loc) · 2.16 KB
/
Copy pathrating.php
File metadata and controls
74 lines (59 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
require_once './vendor/autoload.php';
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
class Rating
{
protected $database;
protected $chatId;
public function __construct($chatId)
{
$this->chatId = $chatId;
$acc = ServiceAccount::fromJsonFile(__DIR__ . $_ENV['member_rating_bot_secretpath']);
$firebase = (new Factory)->withServiceAccount($acc)->create();
$this->database = $firebase->getDatabase();
if (!$this->database->getReference($this->chatId)->getValue('likeSymbol')) {
$this->database->getReference()->getChild($this->chatId)->getChild('likeSymbol')->set('+');
$this->database->getReference()->getChild($this->chatId)->getChild('dislikeSymbol')->set('-');
}
}
public function getStatistics()
{
return $this->database->getReference($this->chatId)->getValue();
}
public function get($userName = NULL)
{
if (empty($userName) || !isset($userName)) {
return FALSE;
}
if ($this->database->getReference($this->chatId)->getSnapshot()->hasChild($userName)) {
return $this->database->getReference($this->chatId)->getChild($userName)->getValue();
} else {
return FALSE;
}
}
public function changeSymbol($whatToChange, $newSymbol)
{
$this->database->getReference()->getChild($this->chatId)->getChild($whatToChange)->set($newSymbol);
}
public function insertBig(array $data, $userName)
{
if (empty($data) || !isset($data)) {
return FALSE;
}
foreach ($data as $key => $value) {
$this->database->getReference()->getChild($this->chatId)->getChild($userName)->getChild($key)->set($value);
}
return TRUE;
}
public function insertMessageInfo(array $data, $userName, $messageId)
{
if (empty($data) || !isset($data)) {
return FALSE;
}
foreach ($data as $key => $value) {
$this->database->getReference()->getChild($this->chatId)->getChild($userName)->getChild($messageId)->getChild($key)->set($value);
}
return TRUE;
}
}