Skip to content

Commit 0c97f93

Browse files
committed
rename chosen_inline_query to chosen_inline_result
1 parent e5b6d41 commit 0c97f93

File tree

2 files changed

+71
-58
lines changed

2 files changed

+71
-58
lines changed

src/DB.php

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111

1212
namespace Longman\TelegramBot;
1313

14+
use Longman\TelegramBot\Entities\CallbackQuery;
1415
use Longman\TelegramBot\Entities\Chat;
16+
use Longman\TelegramBot\Entities\ChosenInlineResult;
1517
use Longman\TelegramBot\Entities\InlineQuery;
16-
use Longman\TelegramBot\Entities\CallbackQuery;
1718
use Longman\TelegramBot\Entities\Message;
1819
use Longman\TelegramBot\Entities\Update;
1920
use Longman\TelegramBot\Entities\User;
@@ -135,12 +136,12 @@ protected static function defineTable()
135136
if (!defined('TB_INLINE_QUERY')) {
136137
define('TB_INLINE_QUERY', self::$table_prefix.'inline_query');
137138
}
139+
if (!defined('TB_CHOSEN_INLINE_RESULT')) {
140+
define('TB_CHOSEN_INLINE_RESULT', self::$table_prefix.'chosen_inline_result');
141+
}
138142
if (!defined('TB_CALLBACK_QUERY')) {
139143
define('TB_CALLBACK_QUERY', self::$table_prefix.'callback_query');
140144
}
141-
if (!defined('TB_CHOSEN_INLINE_QUERY')) {
142-
define('TB_CHOSEN_INLINE_QUERY', self::$table_prefix.'chosen_inline_query');
143-
}
144145
if (!defined('TB_USER')) {
145146
define('TB_USER', self::$table_prefix.'user');
146147
}
@@ -256,14 +257,14 @@ protected static function getTimestamp($time = null)
256257
* @param int $chat_id
257258
* @param int $message_id
258259
* @param int $inline_query_id
259-
* @param int $chosen_inline_query_id
260+
* @param int $chosen_inline_result_id
260261
* @param int $callback_query_id
261262
*
262263
* @return bool|null
263264
*/
264-
public static function insertTelegramUpdate($id, $chat_id, $message_id, $inline_query_id, $chosen_inline_query_id, $callback_query_id)
265+
public static function insertTelegramUpdate($id, $chat_id, $message_id, $inline_query_id, $chosen_inline_result_id, $callback_query_id)
265266
{
266-
if (is_null($message_id) && is_null($inline_query_id) && is_null($chosen_inline_query_id) && is_null($callback_query_id)) {
267+
if (is_null($message_id) && is_null($inline_query_id) && is_null($chosen_inline_result_id) && is_null($callback_query_id)) {
267268
throw new TelegramException('Error both query_id and message_id are null');
268269
}
269270

@@ -275,18 +276,18 @@ public static function insertTelegramUpdate($id, $chat_id, $message_id, $inline_
275276
//telegram_update table
276277
$sth_insert_telegram_update = self::$pdo->prepare('INSERT IGNORE INTO `' . TB_TELEGRAM_UPDATE . '`
277278
(
278-
`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_query_id`, `callback_query_id`
279+
`id`, `chat_id`, `message_id`, `inline_query_id`, `chosen_inline_result_id`, `callback_query_id`
279280
)
280281
VALUES (
281-
:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_query_id, :callback_query_id
282+
:id, :chat_id, :message_id, :inline_query_id, :chosen_inline_result_id, :callback_query_id
282283
)
283284
');
284285

285286
$sth_insert_telegram_update->bindParam(':id', $id, \PDO::PARAM_INT);
286287
$sth_insert_telegram_update->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
287288
$sth_insert_telegram_update->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
288289
$sth_insert_telegram_update->bindParam(':inline_query_id', $inline_query_id, \PDO::PARAM_INT);
289-
$sth_insert_telegram_update->bindParam(':chosen_inline_query_id', $chosen_inline_query_id, \PDO::PARAM_INT);
290+
$sth_insert_telegram_update->bindParam(':chosen_inline_result_id', $chosen_inline_result_id, \PDO::PARAM_INT);
290291
$sth_insert_telegram_update->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT);
291292

292293
$status = $sth_insert_telegram_update->execute();
@@ -436,50 +437,10 @@ public static function insertRequest(Update &$update)
436437
self::insertInlineQueryRequest($inline_query);
437438
return self::insertTelegramUpdate($update_id, null, null, $inline_query_id, null, null);
438439
} elseif ($update->getUpdateType() == 'chosen_inline_result') {
439-
$chosen_inline_query = $update->getChosenInlineResult();
440-
441-
if (!self::isDbConnected()) {
442-
return false;
443-
}
444-
try {
445-
//Inline query Table
446-
$mysql_query = 'INSERT INTO `' . TB_CHOSEN_INLINE_QUERY . '`
447-
(
448-
`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`
449-
)
450-
VALUES (
451-
:result_id, :user_id, :location, :inline_message_id, :query, :created_at
452-
)';
453-
454-
$sth_insert_chosen_inline_query = self::$pdo->prepare($mysql_query);
455-
456-
$date = self::getTimestamp(time());
457-
$result_id = $chosen_inline_query->getResultId();
458-
$from = $chosen_inline_query->getFrom();
459-
$user_id = null;
460-
if (is_object($from)) {
461-
$user_id = $from->getId();
462-
self::insertUser($from, $date);
463-
}
464-
465-
$location = $chosen_inline_query->getLocation();
466-
$inline_message_id = $chosen_inline_query->getInlineMessageId();
467-
$query = $chosen_inline_query->getQuery();
468-
469-
$sth_insert_chosen_inline_query->bindParam(':result_id', $result_id, \PDO::PARAM_STR);
470-
$sth_insert_chosen_inline_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
471-
$sth_insert_chosen_inline_query->bindParam(':location', $location, \PDO::PARAM_INT);
472-
$sth_insert_chosen_inline_query->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_INT);
473-
$sth_insert_chosen_inline_query->bindParam(':query', $query, \PDO::PARAM_STR);
474-
$sth_insert_chosen_inline_query->bindParam(':created_at', $date, \PDO::PARAM_STR);
475-
476-
$status = $sth_insert_chosen_inline_query->execute();
477-
$chosen_inline_query_local_id = self::$pdo->lastInsertId();
478-
} catch (PDOException $e) {
479-
throw new TelegramException($e->getMessage());
480-
}
481-
482-
return self::insertTelegramUpdate($update_id, null, null, null, $chosen_inline_query_local_id, null);
440+
$chosen_inline_result = $update->getChosenInlineResult();
441+
self::insertChosenInlineResultRequest($chosen_inline_result);
442+
$chosen_inline_result_local_id = self::$pdo->lastInsertId();
443+
return self::insertTelegramUpdate($update_id, null, null, null, $chosen_inline_result_local_id, null);
483444
} elseif ($update->getUpdateType() == 'callback_query') {
484445
$callback_query = $update->getCallbackQuery();
485446
$callback_query_id = $callback_query->getId();
@@ -540,6 +501,57 @@ public static function insertInlineQueryRequest(InlineQuery &$inline_query)
540501
}
541502
}
542503

504+
/**
505+
* Insert chosen inline result request into database
506+
*
507+
* @param Entities\ChosenInlineResult &$chosen_inline_result
508+
*
509+
* @return bool
510+
*/
511+
public static function insertChosenInlineResultRequest(ChosenInlineResult &$chosen_inline_result)
512+
{
513+
if (!self::isDbConnected()) {
514+
return false;
515+
}
516+
try {
517+
//Chosen inline result Table
518+
$mysql_query = 'INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '`
519+
(
520+
`result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at`
521+
)
522+
VALUES (
523+
:result_id, :user_id, :location, :inline_message_id, :query, :created_at
524+
)';
525+
526+
$sth_insert_chosen_inline_result = self::$pdo->prepare($mysql_query);
527+
528+
$date = self::getTimestamp(time());
529+
$result_id = $chosen_inline_result->getResultId();
530+
$from = $chosen_inline_result->getFrom();
531+
$user_id = null;
532+
if (is_object($from)) {
533+
$user_id = $from->getId();
534+
self::insertUser($from, $date);
535+
}
536+
537+
$location = $chosen_inline_result->getLocation();
538+
$inline_message_id = $chosen_inline_result->getInlineMessageId();
539+
$query = $chosen_inline_result->getQuery();
540+
541+
$sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, \PDO::PARAM_STR);
542+
$sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
543+
$sth_insert_chosen_inline_result->bindParam(':location', $location, \PDO::PARAM_INT);
544+
$sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_INT);
545+
$sth_insert_chosen_inline_result->bindParam(':query', $query, \PDO::PARAM_STR);
546+
$sth_insert_chosen_inline_result->bindParam(':created_at', $date, \PDO::PARAM_STR);
547+
548+
$status = $sth_insert_chosen_inline_result->execute();
549+
} catch (PDOException $e) {
550+
throw new TelegramException($e->getMessage());
551+
}
552+
}
553+
554+
543555
/**
544556
* Insert callback query request into database
545557
*
@@ -711,6 +723,7 @@ public static function insertMessageRequest(Message &$message)
711723
$sth->bindParam(':forward_from', $forward_from, \PDO::PARAM_INT);
712724
$sth->bindParam(':forward_from_chat', $forward_from_chat, \PDO::PARAM_INT);
713725
$sth->bindParam(':forward_date', $forward_date, \PDO::PARAM_STR);
726+
714727
$reply_chat_id = null;
715728
if ($reply_to_message_id) {
716729
$reply_chat_id = $chat_id;

structure.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CREATE TABLE IF NOT EXISTS `inline_query` (
4545

4646
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
4747

48-
CREATE TABLE IF NOT EXISTS `chosen_inline_query` (
48+
CREATE TABLE IF NOT EXISTS `chosen_inline_result` (
4949
`id` bigint UNSIGNED AUTO_INCREMENT COMMENT 'Unique identifier for chosen query.',
5050
`result_id` CHAR(255) NOT NULL DEFAULT '' COMMENT 'Id of the chosen result',
5151
`user_id` bigint NULL COMMENT 'Sender',
@@ -136,18 +136,18 @@ CREATE TABLE IF NOT EXISTS `telegram_update` (
136136
`chat_id` bigint NULL DEFAULT NULL COMMENT 'Chat identifier.',
137137
`message_id` bigint UNSIGNED DEFAULT NULL COMMENT 'Unique message identifier',
138138
`inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The inline query unique identifier.',
139-
`chosen_inline_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The chosen query unique identifier.',
139+
`chosen_inline_result_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The chosen query unique identifier.',
140140
`callback_query_id` bigint UNSIGNED DEFAULT NULL COMMENT 'The callback query unique identifier.',
141141

142142
PRIMARY KEY (`id`),
143143
KEY `message_id` (`chat_id`, `message_id`),
144144
KEY `inline_query_id` (`inline_query_id`),
145-
KEY `chosen_inline_query_id` (`chosen_inline_query_id`),
145+
KEY `chosen_inline_result_id` (`chosen_inline_result_id`),
146146
KEY `callback_query_id` (`callback_query_id`),
147147

148148
FOREIGN KEY (`chat_id`, `message_id`) REFERENCES `message` (`chat_id`,`id`),
149149
FOREIGN KEY (`inline_query_id`) REFERENCES `inline_query` (`id`),
150-
FOREIGN KEY (`chosen_inline_query_id`) REFERENCES `chosen_inline_query` (`id`),
150+
FOREIGN KEY (`chosen_inline_result_id`) REFERENCES `chosen_inline_result` (`id`),
151151
FOREIGN KEY (`callback_query_id`) REFERENCES `callback_query` (`id`)
152152
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
153153

0 commit comments

Comments
 (0)