-
Notifications
You must be signed in to change notification settings - Fork 0
/
guyclicker.class.php
43 lines (35 loc) · 1.19 KB
/
guyclicker.class.php
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
<?php
class GuyClicker
{
public $collection;
function __construct() {
include($_SERVER['DOCUMENT_ROOT'] . '/../vendor/autoload.php');
$client = new MongoDB\Client(
'mongodb+srv://chester:Rzzk4YIx5b9EGEOs@wyvernhole.2ydpn.mongodb.net/wyvernhole?retryWrites=true&w=majority'
);
$database = $client->guyclicker;
$this->collection = $database->savegames;
}
function saveGame($guys, $id = null, $museum = []) {
$inserts = [
'guys' => $guys,
'museum' => $museum
];
if ($id) {
$result = $this->collection->updateOne(
['_id' => $id],
['$set' => $inserts],
['upsert' => true]
);
} else {
$result = $this->collection->insertOne($inserts);
}
return $result;
}
function loadGame() {
if (isset($_COOKIE['saveid'])) {
$savedGame = $this->collection->findOne(['_id' => $_COOKIE['saveid']]);
return $savedGame;
}
}
}