mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/9687] Separate querie for ban options of users
PHPBB3-9687
This commit is contained in:
parent
9b8b34e8f3
commit
f9a0e4d606
2 changed files with 29 additions and 12 deletions
|
@ -50,6 +50,7 @@ abstract class base implements type_interface
|
|||
public function __construct(driver_interface $db, string $bans_table, string $users_table, string $sessions_table, string $sessions_keys_table)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->bans_table = $bans_table;
|
||||
$this->users_table = $users_table;
|
||||
$this->sessions_table = $sessions_table;
|
||||
$this->sessions_keys_table = $sessions_keys_table;
|
||||
|
@ -109,9 +110,8 @@ abstract class base implements type_interface
|
|||
*/
|
||||
public function get_ban_options(): array
|
||||
{
|
||||
// @todo replace table constant by string
|
||||
$sql = 'SELECT *
|
||||
FROM ' . BANS_TABLE . '
|
||||
FROM ' . $this->bans_table . '
|
||||
WHERE (ban_end >= ' . time() . "
|
||||
OR ban_end = 0)
|
||||
AND ban_mode = '{$this->get_type()}'
|
||||
|
|
|
@ -73,23 +73,40 @@ class user extends base
|
|||
public function get_ban_options(): array
|
||||
{
|
||||
$ban_options = [];
|
||||
$ban_data = [];
|
||||
$user_ids = [];
|
||||
|
||||
// @todo replace table constant by string
|
||||
$sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
|
||||
FROM ' . BANS_TABLE . ' b, ' . $this->users_table . ' u
|
||||
$sql = 'SELECT b.*
|
||||
FROM ' . $this->bans_table . ' b
|
||||
WHERE (b.ban_end >= ' . time() . "
|
||||
OR b.ban_end = 0)
|
||||
AND b.ban_mode = '{$this->get_type()}'
|
||||
AND u.user_id = b.ban_item
|
||||
ORDER BY u.username_clean ASC";
|
||||
AND b.ban_mode = '{$this->get_type()}'";
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$row['ban_item'] = $row['username'] ?: $row['ban_item'];
|
||||
$ban_options[] = $row;
|
||||
$user_ids[] = $row['ban_item'];
|
||||
$ban_data[$row['ban_item']] = $row;
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
if (count($user_ids))
|
||||
{
|
||||
// Grab usernames for banned user IDs
|
||||
$sql = 'SELECT user_id, username, username_clean
|
||||
FROM ' . $this->users_table . '
|
||||
WHERE ' . $this->db->sql_in_set('user_id', $user_ids) . '
|
||||
ORDER BY username_clean';
|
||||
$result = $this->db->sql_query($sql);
|
||||
while ($row = $this->db->sql_fetchrow($result))
|
||||
{
|
||||
$ban_options[] = array_merge(
|
||||
$ban_data[$row['user_id']],
|
||||
$row
|
||||
);
|
||||
}
|
||||
$this->db->sql_freeresult($result);
|
||||
}
|
||||
|
||||
return $ban_options;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue