Test Failed
Push — main ( d9df25...7cc2e0 )
by chief
07:27
created

user_helper::get_channel_views()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 10
1
<?php
2
3
/**
4
* @Auther: bhief
5
* @Version: 1.0
6
* @Added Base
7
*
8
* Use this class for getting user information
9
*
10
**/
11
class user_helper {
12
    public $__db;
13
14
	public function __construct($conn){
15
        $this->__db = $conn;
16
	}
17
18
    function fetch_pfp($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
19
        $stmt = $this->__db->prepare("SELECT pfp FROM users WHERE username = :username");
20
        $stmt->bindParam(":username", $username);
21
        $stmt->execute();
22
        while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
23
            $pfp = $row['pfp'];
24
        } // why the while statement? just remove it (i cant be bothered to)
25
26
        return (isset($pfp) ? $pfp : "default.png");
27
    }
28
29
    
30
    function fetch_unread_pms($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
31
        $stmt = $this->__db->prepare("SELECT * FROM pms WHERE touser = :user AND readed = 'n'");
32
        $stmt->bindParam(":user", $user);
33
        $stmt->execute();
34
    
35
        return $stmt->rowCount();
36
    }
37
38
    function if_blocked($user, $reciever) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
        $stmt = $this->__db->prepare("SELECT reciever FROM block WHERE sender = :user AND reciever = :reciever");
40
        $stmt->bindParam(":user", $user);
41
        $stmt->bindParam(":reciever", $reciever);
42
        $stmt->execute();
43
44
        return $stmt->rowCount() === 1;
45
    }    
46
47
    function if_cooldown($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
48
        $stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username AND cooldown_comment >= NOW() - INTERVAL 1 MINUTE");
49
        $stmt->bindParam(":username", $user);
50
        $stmt->execute();
51
        
52
        return $stmt->rowCount() === 1;
53
    }
54
55
    function if_upload_cooldown($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
56
        $stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username AND upload_cooldown >= NOW() - INTERVAL 10 MINUTE");
57
        $stmt->bindParam(":username", $user);
58
        $stmt->execute();
59
        
60
        return $stmt->rowCount() === 1;
61
    }
62
63
    function fetch_user_username($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
64
        $stmt = $this->__db->prepare("SELECT * FROM users WHERE username = :username");
65
        $stmt->bindParam(":username", $username);
66
        $stmt->execute();
67
68
        return ($stmt->rowCount() === 0 ? 0 : $stmt->fetch(PDO::FETCH_ASSOC));
69
    }
70
71
    function user_exists($user) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
72
        $stmt = $this->__db->prepare("SELECT username FROM users WHERE username = :username");
73
        $stmt->bindParam(":username", $user);
74
        $stmt->execute();
75
76
        return $stmt->rowCount() === 1;
77
    }
78
79
    function if_subscribed($user, $reciever) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
80
        $stmt = $this->__db->prepare("SELECT reciever FROM subscribers WHERE sender = :sender AND reciever = :reciever");
81
        $stmt->bindParam(":sender", $user);
82
        $stmt->bindParam(":reciever", $reciever);
83
        $stmt->execute();
84
85
        return $stmt->rowCount() === 1;
86
    }
87
88
    function fetch_subs_count($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
89
        $stmt = $this->__db->prepare("SELECT * FROM subscribers WHERE reciever = :username");
90
        $stmt->bindParam(":username", $username);
91
        $stmt->execute();
92
93
        return $stmt->rowCount();
94
    }
95
96
    function fetch_user_videos(string $id) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
97
        $stmt = $this->__db->prepare("SELECT rid FROM videos WHERE author = :id");
98
        $stmt->bindParam(":id", $id);
99
        $stmt->execute();
100
        
101
        return $stmt->rowCount();
102
    }
103
104
    function fetch_user_favorites(string $username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
105
        $stmt = $this->__db->prepare("SELECT reciever FROM favorite_video WHERE sender = :username");
106
        $stmt->bindParam(":username", $username);
107
        $stmt->execute(); 
108
    
109
        return $stmt->rowCount();
110
    }
111
112
    function fetch_subscriptions($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
113
        $stmt = $this->__db->prepare("SELECT * FROM subscribers WHERE sender = :username");
114
        $stmt->bindParam(":username", $username);
115
        $stmt->execute();
116
    
117
        return $stmt->rowCount();
118
    }
119
120
    function get_channel_views(string $rid) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
121
        $stmt = $this->__db->prepare("SELECT * FROM channel_views WHERE channel = :rid");
122
        $stmt->bindParam(":rid", $rid);
123
        $stmt->execute();
124
        
125
        return $stmt->rowCount();
126
    }
127
128
    function fetch_friends_accepted($username) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
129
        $stmt = $this->__db->prepare("SELECT * FROM friends WHERE reciever = :username AND status = 'a'");
130
        $stmt->bindParam(":username", $username);
131
        $stmt->execute();
132
    
133
        $friends = $stmt->rowCount();
134
135
        $stmt = $this->__db->prepare("SELECT * FROM friends WHERE sender = :username AND status = 'a'");
136
        $stmt->bindParam(":username", $username);
137
        $stmt->execute();
138
    
139
        return $friends + $stmt->rowCount();
140
    }
141
}
142
143
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...