-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery.php
More file actions
69 lines (61 loc) · 2.1 KB
/
query.php
File metadata and controls
69 lines (61 loc) · 2.1 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
<?php
//TODO вынести $liker куда нибудь
function getUser(int $user_id): User | null{
if($user_id <= 0){
return null;
}
$data = DataBaseGetLine("SELECT * FROM v_user WHERE id = {$user_id} LIMIT 1;");
if(isset($data) && is_array($data)){
return new User($data);
}
return null;
}
function getPostUser(int $user_id, int $list): array{
$ret = [];
if($user_id <= 0 || $list <= 0){
return $ret;
}
$from = ($list - 1) * COUNT_LIST;
$liker = "(liker = ".SESSION_ID." OR liker IS NULL) ORDER BY id DESC";
$arr = DataBaseGetArray("SELECT * FROM v_post_2 WHERE user = {$user_id} AND {$liker} LIMIT {$from}, ".COUNT_LIST);
for($i = 0; $i < count($arr); $i++){
$ret[] = new Post($arr[$i]);
}
return $ret;
}
function getPost(int $post_id, int $child_list): Post | null{
if($post_id <= 0 || $child_list <= 0){
return null;
}
$liker = "(liker = ".SESSION_ID." OR liker IS NULL) ORDER BY id DESC";
$data = DataBaseGetLine("SELECT * FROM v_post_2 WHERE id = {$post_id} AND {$liker} LIMIT 1;");
if(isset($data) && is_array($data)){
return new Post($data, true, $child_list);
}
return null;
}
function getPostFather(int $post_id): Post | null{
if($post_id <= 0){
return null;
}
$liker = "(liker = ".SESSION_ID." OR liker IS NULL) ORDER BY id DESC";
$data = DataBaseGetLine("SELECT * FROM v_post_2 WHERE id = {$post_id} AND {$liker} LIMIT 1;");
if(isset($data) && is_array($data)){
return new Post($data);
}
return null;
}
function getPostChild(int $post_id, int $list = 1): array{
$ret = [];
if($list <= 0 || $post_id <= 0){
return $ret;
}
$from = ($list - 1) * COUNT_LIST;
$liker = "(liker = ".SESSION_ID." OR liker IS NULL) ORDER BY id DESC";
$arr = DataBaseGetArray("SELECT * FROM v_post_2 WHERE answer = {$post_id} AND {$liker} LIMIT {$from}, ".COUNT_LIST);
for($i = 0; $i < count($arr); $i++){
$ret[] = new Post($arr[$i]);
}
return $ret;
}
?>