Commit 7bd31911 authored by Jack'lul's avatar Jack'lul

fixed DB::selectChats(), small text update in whoiscommand

parent 28bd0f91
...@@ -143,7 +143,7 @@ class WhoisCommand extends AdminCommand ...@@ -143,7 +143,7 @@ class WhoisCommand extends AdminCommand
$text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: '.$old_id.')' : ''). "\n"; $text = 'Chat ID: ' . $user_id . (!empty($old_id) ? ' (previously: '.$old_id.')' : ''). "\n";
$text .= 'Type: ' . ucfirst($chat->getType()) . "\n"; $text .= 'Type: ' . ucfirst($chat->getType()) . "\n";
$text .= 'Title: ' . $chat->getTitle() . "\n"; $text .= 'Title: ' . $chat->getTitle() . "\n";
$text .= 'Bot added to group: ' . $created_at . "\n"; $text .= 'First time added to group: ' . $created_at . "\n";
$text .= 'Last activity: ' . $updated_at . "\n"; $text .= 'Last activity: ' . $updated_at . "\n";
} }
} elseif (is_array($results) && count($results) > 1) { } elseif (is_array($results) && count($results) > 1) {
......
...@@ -691,8 +691,6 @@ class DB ...@@ -691,8 +691,6 @@ class DB
/** /**
* Select Group and single Chats * Select Group and single Chats
* *
* @todo Seems to not return anything when $select_users = false
*
* @param bool $select_groups * @param bool $select_groups
* @param bool $select_super_groups * @param bool $select_super_groups
* @param bool $select_users * @param bool $select_users
...@@ -722,26 +720,39 @@ class DB ...@@ -722,26 +720,39 @@ class DB
$query = 'SELECT * , $query = 'SELECT * ,
' . TB_CHAT . '.`id` AS `chat_id`, ' . TB_CHAT . '.`id` AS `chat_id`,
' . TB_CHAT . '.`created_at` AS `chat_created_at`, ' . TB_CHAT . '.`created_at` AS `chat_created_at`,
' . TB_CHAT . '.`updated_at` AS `chat_updated_at`, ' . TB_CHAT . '.`updated_at` AS `chat_updated_at`
' . TB_USER . '.`id` AS `user_id` ' .
FROM `' . TB_CHAT . '` LEFT JOIN `' . TB_USER . '` (($select_users) ? ', ' . TB_USER . '.`id` AS `user_id` FROM `' . TB_CHAT . '` LEFT JOIN `' . TB_USER . '`
ON ' . TB_CHAT . '.`id`=' . TB_USER . '.`id`'; ON ' . TB_CHAT . '.`id`=' . TB_USER . '.`id`' : 'FROM `' . TB_CHAT . '`');
//Building parts of query //Building parts of query
$chat_or_user = '';
$where = []; $where = [];
$tokens = []; $tokens = [];
if (!$select_groups || !$select_users || !$select_super_groups) { if (!$select_groups || !$select_users || !$select_super_groups) {
$chat_or_user = '';
if ($select_groups) { if ($select_groups) {
$where[] = TB_CHAT . '.`type` = "group"'; $chat_or_user .= TB_CHAT . '.`type` = "group"';
} }
if ($select_super_groups) { if ($select_super_groups) {
$where[] = TB_CHAT . '.`type` = "supergroup"'; if (!empty($chat_or_user)) {
$chat_or_user .= ' OR ';
}
$chat_or_user .= TB_CHAT . '.`type` = "supergroup"';
} }
if ($select_users) { if ($select_users) {
$where[] = TB_CHAT . '.`type` = "private"'; if (!empty($chat_or_user)) {
$chat_or_user .= ' OR ';
}
$chat_or_user .= TB_CHAT . '.`type` = "private"';
} }
$where[] = '(' . $chat_or_user . ')';
} }
if (! is_null($date_from)) { if (! is_null($date_from)) {
...@@ -760,7 +771,12 @@ class DB ...@@ -760,7 +771,12 @@ class DB
} }
if (! is_null($text)) { if (! is_null($text)) {
$where[] = '(LOWER('.TB_CHAT . '.`title`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`last_name`) LIKE :text OR LOWER(' . TB_USER . '.`username`) LIKE :text)'; if ($select_users) {
$where[] = '(LOWER('.TB_CHAT . '.`title`) LIKE :text OR LOWER(' . TB_USER . '.`first_name`) LIKE :text OR LOWER(' . TB_USER . '.`last_name`) LIKE :text OR LOWER(' . TB_USER . '.`username`) LIKE :text)';
} else {
$where[] = 'LOWER('.TB_CHAT . '.`title`) LIKE :text';
}
$tokens[':text'] = '%'.strtolower($text).'%'; $tokens[':text'] = '%'.strtolower($text).'%';
} }
...@@ -788,3 +804,4 @@ class DB ...@@ -788,3 +804,4 @@ class DB
return $result; return $result;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment