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
|
<?php /* Copyright (c) 2024 Freya Murphy */
class People_model extends Model {
private $request_model;
function __construct($load) {
parent::__construct($load);
$this->request_model = $this->load->model('request');
}
/**
* @param mixed $select
*/
private function get_filted_query($select): DatabaseQuery {
$filter_type = $this->request_model->get_str('filter', FALSE);
$filter_uid = $this->request_model->get_int('uid', FALSE);
$max = $this->request_model->get_int('max', FALSE);
$query = $this->db
->select($select)
->from('api.user u');
if ($filter_type && $filter_uid) {
switch ($filter_type) {
case 'follower': {
$query = $query
->join('xssbook.follow f', 'f.follower_id = u.id AND f.followee_id', 'INNER')
->eq($filter_uid)
->where('f.value = TRUE');
} break;
case 'followee': {
$query = $query
->join('xssbook.follow f', 'f.followee_id = u.id AND f.follower_id', 'INNER')
->eq($filter_uid)
->where('f.value = TRUE');
} break;
}
}
if ($max) {
$query = $query
->where('u.id')
->le($max);
}
return $query;
}
/**
* @return array<string,mixed>
*/
public function get_users(): array {
$page = $this->request_model->get_int('page', 0);
$page_size = 24;
$offset = $page_size * $page;
$users = $this->get_filted_query('u.*')
->order_by('u.id', 'DESC')
->offset($offset)
->limit($page_size)
->rows();
$count = $this->get_filted_query('COUNT(u.id) AS count')
->row()['count'];
$max = 0;
foreach ($users as $user) {
$max = max($max, $user['id']);
}
$filter_type = $this->request_model->get_str('filter', FALSE);
$filter_uid = $this->request_model->get_int('uid', FALSE);
return array(
'users' => $users,
'count' => $count,
'page_size' => $page_size,
'max_id' => $max,
'filter_type' => $filter_type || '',
'filter_uid' => $filter_uid || ''
);
}
public function get_data(): ?array {
$data = parent::get_data();
$data['title'] = ucfirst(lang('title'));
return $data;
}
}
|