forked from featherbb/featherbb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserlist.php
More file actions
125 lines (98 loc) · 4.69 KB
/
Copy pathUserlist.php
File metadata and controls
125 lines (98 loc) · 4.69 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
<?php
/**
* Copyright (C) 2015-2016 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Model;
use FeatherBB\Core\Database as DB;
use FeatherBB\Core\Utils;
class Userlist
{
// Counts the number of user for a specific query
public function fetch_user_count($username, $show_group)
{
// Fetch user count
$num_users = DB::for_table('users')->table_alias('u')
->where_gt('u.id', 1)
->where_not_equal('u.group_id', ForumEnv::get('FEATHER_UNVERIFIED'));
if ($username != '') {
$num_users = $num_users->where_like('u.username', str_replace('*', '%', $username));
}
if ($show_group > -1) {
$num_users = $num_users->where('u.group_id', $show_group);
}
$num_users = $num_users->count('id');
$num_users = Container::get('hooks')->fire('model.userlist.fetch_user_count', $num_users);
return $num_users;
}
// Generates the dropdown menu containing groups
public function generate_dropdown_menu($show_group)
{
$show_group = Container::get('hooks')->fire('model.userlist.generate_dropdown_menu_start', $show_group);
$dropdown_menu = '';
$result['select'] = array('g_id', 'g_title');
$result = DB::for_table('groups')
->select_many($result['select'])
->where_not_equal('g_id', ForumEnv::get('FEATHER_GUEST'))
->order_by('g_id');
$result = Container::get('hooks')->fireDB('model.userlist.generate_dropdown_menu_query', $result);
$result = $result->find_many();
foreach($result as $cur_group) {
if ($cur_group['g_id'] == $show_group) {
$dropdown_menu .= "\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'" selected="selected">'.Utils::escape($cur_group['g_title']).'</option>'."\n";
} else {
$dropdown_menu .= "\t\t\t\t\t\t\t".'<option value="'.$cur_group['g_id'].'">'.Utils::escape($cur_group['g_title']).'</option>'."\n";
}
}
$dropdown_menu = Container::get('hooks')->fire('model.userlist.generate_dropdown_menu', $dropdown_menu);
return $dropdown_menu;
}
// Prints the users
public function print_users($username, $start_from, $sort_by, $sort_dir, $show_group)
{
$userlist_data = array();
$username = Container::get('hooks')->fire('model.userlist.print_users_start', $username, $start_from, $sort_by, $sort_dir, $show_group);
// Retrieve a list of user IDs, LIMIT is (really) expensive so we only fetch the IDs here then later fetch the remaining data
$result = DB::for_table('users')
->select('u.id')
->table_alias('u')
->where_gt('u.id', 1)
->where_not_equal('u.group_id', ForumEnv::get('FEATHER_UNVERIFIED'));
if ($username != '') {
$result = $result->where_like('u.username', str_replace('*', '%', $username));
}
if ($show_group > -1) {
$result = $result->where('u.group_id', $show_group);
}
$result = $result->order_by($sort_by, $sort_dir)
->order_by_asc('u.id')
->limit(50)
->offset($start_from);
$result = Container::get('hooks')->fireDB('model.userlist.print_users_query', $result);
$result = $result->find_many();
if ($result) {
$user_ids = array();
foreach ($result as $cur_user_id) {
$user_ids[] = $cur_user_id['id'];
}
// Grab the users
$result['select'] = array('u.id', 'u.username', 'u.title', 'u.num_posts', 'u.registered', 'g.g_id', 'g.g_user_title');
$result = DB::for_table('users')
->table_alias('u')
->select_many($result['select'])
->left_outer_join('groups' ,array('g.g_id', '=', 'u.group_id'), 'g')
->where_in('u.id', $user_ids)
->order_by($sort_by, $sort_dir)
->order_by_asc('u.id');
$result = Container::get('hooks')->fireDB('model.userlist.print_users_grab_query', $result);
$result = $result->find_many();
foreach($result as $user_data) {
$userlist_data[] = $user_data;
}
}
$userlist_data = Container::get('hooks')->fire('model.userlist.print_users', $userlist_data);
return $userlist_data;
}
}