Repository navigation
Expand file tree
/
Copy pathposts.php
More file actions
65 lines (56 loc) · 1.89 KB
/
Copy pathposts.php
File metadata and controls
65 lines (56 loc) · 1.89 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
<?php
class Posts extends Database
{
// Get all the threads started by a user
public function getAllUserPosts($user_id){
$db = new Database();
$query = "SELECT * FROM threads WHERE user_id={$user_id} ORDER BY posted_at DESC";
$res = $db::executeQuery($query);
return $res;
}
// Get a particular thread by a particular user
public function getUserPostById($post_id){
$db = new Database();
$res = $db->fetchContentById(0, 'thread_id', $post_id, 'threads');
return $res;
}
// Get all the posts by all the users
public function getAllPosts($language=NULL){
$db = new Database();
if($language=='')
$query = "SELECT * FROM threads ORDER BY thread_id DESC";
else
$query = "SELECT * FROM threads WHERE thread_language_id = {$language} ORDER BY thread_id DESC";
$res = $db::executeQuery($query);
return $res;
}
// Get the recent post by the user
public function getRecentUserPost($user_id){
$db = new Database();
$query = "SELECT * FROM threads WHERE user_id={$user_id} ORDER BY thread_id DESC";
$res = $db::executeQuery($query);
return $res;
}
// Get all the comments posted by a user
public function getAllUserComments($user_id){
$db = new Database();
$query = "SELECT * FROM answers WHERE user_id={$user_id} ORDER BY answer_id DESC";
$res = $db::executeQuery($query);
return $res;
}
public function getAllThreadComments($thread_id){
$db = new Database();
$query = "SELECT * FROM answers WHERE thread_id={$thread_id}";
$res = $db::executeQuery($query);
return $res;
}
public function increaseViews($post_id){
$db = new Database();
$post_res = self::getUserPostById($post_id);
$post_arr = mysqli_fetch_array($post_res);
$views = $post_arr['thread_views'];
$views++;
$res = $db->updateContent(1, 'threads', 'thread_id', $post_id, 'thread_views', $views);
}
}
?>