-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuser.php
196 lines (140 loc) · 4.55 KB
/
user.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
declare(strict_types = 1);
defined('INSIDE') OR exit('No direct script access allowed');
/**
* This class maps the 'user'-table to an php object and is also responsible of keeping it up-to-date.
*
*/
class D_User {
private $userID;
private $username;
private $email;
private $onlineTime;
private $currentPlanet;
private $planetList = [];
private $points;
private $current_rank;
private $old_rank;
/**
* D_User constructor.
* @param int $uID
* @param string $uname
* @param string $email
* @param int $otime
* @param int $currPlanet
* @param int $points
* @param int $cRank
* @param int $oRank
*/
public function __construct(int $uID, string $uname, string $email, int $otime, int $currPlanet, int $points,
int $cRank, int $oRank) {
$this->userID = $uID;
$this->username = $uname;
$this->email = $email;
$this->onlineTime = $otime;
$this->currentPlanet = $currPlanet;
$this->points = $points;
$this->current_rank = $cRank;
$this->old_rank = $oRank;
}
/**
* @codeCoverageIgnore
*/
public function print() : void {
echo '<pre>';
print_r($this);
echo '</pre>';
}
public function getUserID() : int {
return $this->userID;
}
public function setUserID($userID) : void {
$this->userID = $userID;
}
public function getUsername() : string {
return $this->username;
}
public function setUsername($username) : void {
$this->username = $username;
}
public function getEmail() : string {
return $this->email;
}
public function setEmail($email) : void {
$this->email = $email;
}
public function getOnlineTime() : int {
return $this->onlineTime;
}
public function setOnlineTime($onlineTime) : void {
$this->onlineTime = $onlineTime;
}
public function getCurrentPlanet() : int {
return $this->currentPlanet;
}
public function setCurrentPlanet(int $cp) : void {
if (intval($cp) == $this->currentPlanet) {
return;
}
// TODO: relocate this code
// check if the user really owns the planet
for ($i = 0; $i < sizeof($this->planetList); $i++) {
if ($this->planetList[$i]->getPlanetID() == $cp) {
// update the database
$query = 'UPDATE users SET currentplanet = :cp WHERE userID = :userID;';
$dbConnection = new Database();
$stmt = $dbConnection->prepare($query);
$stmt->bindParam(':cp', $cp);
$stmt->bindParam(':userID', $this->userID);
$stmt->execute();
$this->currentPlanet = intval($cp);
// need to reload all the data, so refresh the page
//header("Refresh:0");
// TODO: return value to caller who then will refresh the page
break;
}
}
}
public function getPlanetList() : array {
return $this->planetList;
}
public function setPlanetList(array $pList) : void {
$this->planetList = $pList;
}
/**
* @return mixed
*/
public function getPoints() {
return $this->points;
}
/**
* @param mixed $points
*/
public function setPoints($points) : void {
$this->points = $points;
}
/**
* @return mixed
*/
public function getCurrentRank() {
return $this->current_rank;
}
/**
* @param mixed $current_rank
*/
public function setCurrentRank($current_rank) : void {
$this->current_rank = $current_rank;
}
/**
* @return mixed
*/
public function getOldRank() {
return $this->old_rank;
}
/**
* @param mixed $old_rank
*/
public function setOldRank($old_rank) : void {
$this->old_rank = $old_rank;
}
}