Repository navigation
Expand file tree
/
Copy pathusers.php
More file actions
106 lines (94 loc) · 2.66 KB
/
Copy pathusers.php
File metadata and controls
106 lines (94 loc) · 2.66 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
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
<?php
class Users extends Database
{
public function checkUsername($username){
$res = parent::fetchContentById(0, 'user_username', $username, 'users');
$row = mysqli_num_rows($res);
if($row>0){
return false;
} else {
return true;
}
}
public function checkEmail($email){
$res = parent::fetchContentById(0, 'user_email', $email, 'users');
$row = mysqli_num_rows($res);
if($row>0){
return false;
} else {
return true;
}
}
public function loginUser($username, $password){
// The password must be encrypted beforehand
$db = new Database();
$query = "SELECT * FROM users WHERE user_username = '".$username."' AND user_pass = '".$password."'";
$res = $db::executeQuery($query);
$row = mysqli_fetch_array($res);
return $row;
}
public function getUserDetails($id){
$db = new Database();
return $db->fetchContentById(0, 'user_id', $id, 'users');
}
public function getUserLevel($xp){
$lower_lim = 0;
$upper_lim = 100;
for($lvl=2; ; $lvl++){
if(($xp<=100) && ($xp>=0)){
return 1;
} else if(($xp<=$upper_lim) && ($xp>=$lower_lim)){
// This is the user level !
return $lvl-1;
} else {
$lower_lim = $upper_lim;
$upper_lim = $upper_lim * 2;
}
}
}
public function getRemainingXp($xp){
$lvl = $this->getUserLevel($xp);
$upper_lim = pow(2, $lvl-1)*100;
$remaining_xp = $upper_lim - $xp;
return $remaining_xp;
}
public function getXpPercent($xp){
$lvl = $this->getUserLevel($xp);
$lower_lim = pow(2, $lvl-2)*100;
$upper_lim = pow(2, $lvl-1)*100;
$lower_xp = ($xp-$lower_lim);
$rem_xp_per = ($lower_xp/($upper_lim-$lower_lim))*100;
return $rem_xp_per;
}
public function getUserXp($user_id){
$user_details = $this->getUserDetails($user_id);
$user_arr = mysqli_fetch_array($user_details);
return $user_arr['user_xp'];
}
public function increaseUserXp($user_id, $increment_factor){
$db = new Database();
$current_xp = $this->getUserXp($user_id);
$inc_xp = $current_xp + $increment_factor;
$res = $db->updateContent(1, 'users', 'user_id', $user_id, 'user_xp', $inc_xp);
if($res){
// Xp increased successfully
return true;
} else {
// There was an error
return false;
}
}
public function pushNotification($user_id, $message) {
$db = new Database();
$time = time();
$res = $db->addContent(3, 'notifications', 'user_id', $user_id, 'notification_content', $message, 'timestamp', $time);
if($res){
// Notification pushed successfully
return true;
} else {
// Notification push failed
return false;
}
}
}
?>