View sourcecode

The following files exists in this folder. Click to view.

userdata.php

33 lines ASCII Unix (LF)
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
<?php
class UserData
{
    public static 
$storage "data.json";
    public 
$user;
    public 
$userindex;
    public 
$userinfo;
    public function 
__construct($username)
    {
        
$this->userinfo json_decode(file_get_contents(self::$storage), true);
        foreach (
$this->userinfo as $i=> $user) {
            if (
$user["username"] != $username)
                continue;
            
$this->user $user;
            
$this->userindex $i;
            break;
        }
    }
    public function 
saveUserData()
    {
        
$this->userinfo[$this->userindex] = $this->user;
        
file_put_contents(self::$storagejson_encode($this->userinfoJSON_PRETTY_PRINT));
    }

    public function 
getBalance(){
        
$balance 0;
        foreach(
$this->user["balance"] as $transaction){
            
$balance += $transaction;
        }
        return 
$balance;
    }
}
?>