-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.php
More file actions
158 lines (124 loc) · 4.44 KB
/
user.php
File metadata and controls
158 lines (124 loc) · 4.44 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
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
<?php
class User {
private $connection;
private $user ;
public function __construct($connection, $user)
{
$this->connection = $connection;
$user_details = mysqli_query($connection,"SELECT * FROM users WHERE username = '$user'");
$this->user = mysqli_fetch_array($user_details);
}
public function getFirstAndLastName(){
$username = $this->user['username'];
$query = mysqli_query($this->connection,"SELECT first_name, last_name FROM users WHERE username = '$username'");
$row = mysqli_fetch_array($query);
return $row['first_name'] . " " . $row['last_name'];
}
public function getFirstName(){
$username = $this->user['username'];
$query = mysqli_query($this->connection,"SELECT first_name FROM users WHERE username = '$username'");
$row = mysqli_fetch_array($query);
return $row['first_name'] ;
}
public function getUsername()
{
$username = $this->user['username'];
return $username;
}
public function getProfilePic()
{
$propic = $this->user['profile_pic'];
return $propic;
}
//public function getFriendArray()
//{
// $fa = $this->user['friend_array'];
// return $fa;
//}
public function getNumPosts()
{
$username = $this->user['username'];
$query = mysqli_query($this->connection, "SELECT num_posts FROM users WHERE username = '$username'");
$row = mysqli_fetch_array($query);
return $row['num_posts'];
}
public function isClosed()
{
$username = $this->user['username'];
$query = mysqli_query($this->connection, "SELECT user_closed FROM users WHERE username='$username'");
$row = mysqli_fetch_array($query);
if($row['user_closed'] == 'yes')
return true;
else
return false;
}
public function isFriend($friend_check)
{
//$usernameComma = "," . $friend_check . ",";
//if((strstr($this->user['friend_array'], $usernameComma) || $friend_check == $this->user['username']))
//{
// return true;
// }
// return false ;
$friendOf = $this->user['username'];
$query = mysqli_query($this->connection ,"SELECT * FROM friends WHERE (user_from = '$friendOf' AND user_to = '$friend_check' ) OR (user_from = '$friend_check' AND user_to = '$friendOf') ");
if(mysqli_num_rows($query) >0)
return true;
else
return false;
}
public function receive_request($userFrom)
{
$userTo = $this->user['username'];
$check_request = mysqli_query($this->connection, "SELECT * FROM friend_request WHERE user_to = '$userTo' AND user_from='$userFrom'");
if(mysqli_num_rows($check_request) >0)
{
return true;
}
return false;
}
public function sent_request($userTo)
{
$userFrom = $this->user['username'];
$check_request = mysqli_query($this->connection, "SELECT * FROM friend_request WHERE user_to = '$userTo' AND user_from='$userFrom'");
if(mysqli_num_rows($check_request) >0)
{
return true;
}
return false;
}
public function remove_friend($user_remove)
{
$friendOf = $this->user['username'];
/*$query = mysqli_query($this->connection , "SELECT friend_array FROM users WHERE username = '$user_to_be_remove'");
$row = mysqli_fetch_array($query);
$friend_array_of_username = $row['friend_array'];
$new_friend_array = str_replace($user_to_be_removed . ",", "", $this->user['friend_array']);
$remove = mysqli_query($this->connection , "UPDATE users SET friend_array = '$new_friend_array' WHERE username = $logged_in" );
$new_friend_array = str_replace($user_to_be_removed . ",", "", $friend_array_of_username);
$remove = mysqli_query($this->connection , "UPDATE users SET friend_array = '$new_friend_array' WHERE username = $friend_array_of_username" );*/
$query = mysqli_query($this->connection , "DELETE FROM friends WHERE (user_from = '$friendOf' AND user_to = '$user_remove' ) OR (user_from = '$user_remove' AND user_to = '$friendOf') ");
}
public function send_request($user_to)
{
$user_from = $this->user['username'];
$query = mysqli_query($this->connection , "INSERT INTO friend_request VALUES ('','$user_to','$user_from')");
}
public function getMutualFriends($user_to_check)
{
/*$mutualFriends = 0;
$user_array = $this->user['friend_array'];
$other_user_obj = new User($this->connection, $user_to_check);
$other_user_array = $other_user_obj->getFriendArray();
$user_array_explode = explode(",", $user_array);
$other_user_array_explode = explode("," ,$other_user_array );
foreach ($user_array_explode as $i ) {
foreach ($other_user_array_explode as $j ) {
if($i == $j && $i!="")
$mutualFriends++;
}
}
return $mutualFriends;*/
}
}
?>