11
11
12
12
namespace Longman \TelegramBot ;
13
13
14
+ use Longman \TelegramBot \Entities \CallbackQuery ;
14
15
use Longman \TelegramBot \Entities \Chat ;
16
+ use Longman \TelegramBot \Entities \ChosenInlineResult ;
15
17
use Longman \TelegramBot \Entities \InlineQuery ;
16
- use Longman \TelegramBot \Entities \CallbackQuery ;
17
18
use Longman \TelegramBot \Entities \Message ;
18
19
use Longman \TelegramBot \Entities \Update ;
19
20
use Longman \TelegramBot \Entities \User ;
@@ -135,12 +136,12 @@ protected static function defineTable()
135
136
if (!defined ('TB_INLINE_QUERY ' )) {
136
137
define ('TB_INLINE_QUERY ' , self ::$ table_prefix .'inline_query ' );
137
138
}
139
+ if (!defined ('TB_CHOSEN_INLINE_RESULT ' )) {
140
+ define ('TB_CHOSEN_INLINE_RESULT ' , self ::$ table_prefix .'chosen_inline_result ' );
141
+ }
138
142
if (!defined ('TB_CALLBACK_QUERY ' )) {
139
143
define ('TB_CALLBACK_QUERY ' , self ::$ table_prefix .'callback_query ' );
140
144
}
141
- if (!defined ('TB_CHOSEN_INLINE_QUERY ' )) {
142
- define ('TB_CHOSEN_INLINE_QUERY ' , self ::$ table_prefix .'chosen_inline_query ' );
143
- }
144
145
if (!defined ('TB_USER ' )) {
145
146
define ('TB_USER ' , self ::$ table_prefix .'user ' );
146
147
}
@@ -256,14 +257,14 @@ protected static function getTimestamp($time = null)
256
257
* @param int $chat_id
257
258
* @param int $message_id
258
259
* @param int $inline_query_id
259
- * @param int $chosen_inline_query_id
260
+ * @param int $chosen_inline_result_id
260
261
* @param int $callback_query_id
261
262
*
262
263
* @return bool|null
263
264
*/
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 )
265
266
{
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 )) {
267
268
throw new TelegramException ('Error both query_id and message_id are null ' );
268
269
}
269
270
@@ -275,18 +276,18 @@ public static function insertTelegramUpdate($id, $chat_id, $message_id, $inline_
275
276
//telegram_update table
276
277
$ sth_insert_telegram_update = self ::$ pdo ->prepare ('INSERT IGNORE INTO ` ' . TB_TELEGRAM_UPDATE . '`
277
278
(
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`
279
280
)
280
281
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
282
283
)
283
284
' );
284
285
285
286
$ sth_insert_telegram_update ->bindParam (':id ' , $ id , \PDO ::PARAM_INT );
286
287
$ sth_insert_telegram_update ->bindParam (':chat_id ' , $ chat_id , \PDO ::PARAM_INT );
287
288
$ sth_insert_telegram_update ->bindParam (':message_id ' , $ message_id , \PDO ::PARAM_INT );
288
289
$ 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 );
290
291
$ sth_insert_telegram_update ->bindParam (':callback_query_id ' , $ callback_query_id , \PDO ::PARAM_INT );
291
292
292
293
$ status = $ sth_insert_telegram_update ->execute ();
@@ -436,50 +437,10 @@ public static function insertRequest(Update &$update)
436
437
self ::insertInlineQueryRequest ($ inline_query );
437
438
return self ::insertTelegramUpdate ($ update_id , null , null , $ inline_query_id , null , null );
438
439
} 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 );
483
444
} elseif ($ update ->getUpdateType () == 'callback_query ' ) {
484
445
$ callback_query = $ update ->getCallbackQuery ();
485
446
$ callback_query_id = $ callback_query ->getId ();
@@ -540,6 +501,57 @@ public static function insertInlineQueryRequest(InlineQuery &$inline_query)
540
501
}
541
502
}
542
503
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
+
543
555
/**
544
556
* Insert callback query request into database
545
557
*
@@ -711,6 +723,7 @@ public static function insertMessageRequest(Message &$message)
711
723
$ sth ->bindParam (':forward_from ' , $ forward_from , \PDO ::PARAM_INT );
712
724
$ sth ->bindParam (':forward_from_chat ' , $ forward_from_chat , \PDO ::PARAM_INT );
713
725
$ sth ->bindParam (':forward_date ' , $ forward_date , \PDO ::PARAM_STR );
726
+
714
727
$ reply_chat_id = null ;
715
728
if ($ reply_to_message_id ) {
716
729
$ reply_chat_id = $ chat_id ;
0 commit comments