@@ 493-534 (lines=42) @@ | ||
490 | * @return bool If the insert was successful |
|
491 | * @throws \Longman\TelegramBot\Exception\TelegramException |
|
492 | */ |
|
493 | public static function insertInlineQueryRequest(InlineQuery $inline_query) |
|
494 | { |
|
495 | if (!self::isDbConnected()) { |
|
496 | return false; |
|
497 | } |
|
498 | ||
499 | try { |
|
500 | $mysql_query = 'INSERT IGNORE INTO `' . TB_INLINE_QUERY . '` |
|
501 | ( |
|
502 | `id`, `user_id`, `location`, `query`, `offset`, `created_at` |
|
503 | ) |
|
504 | VALUES ( |
|
505 | :inline_query_id, :user_id, :location, :query, :param_offset, :created_at |
|
506 | )'; |
|
507 | ||
508 | $sth_insert_inline_query = self::$pdo->prepare($mysql_query); |
|
509 | ||
510 | $date = self::getTimestamp(time()); |
|
511 | $inline_query_id = $inline_query->getId(); |
|
512 | $from = $inline_query->getFrom(); |
|
513 | $user_id = null; |
|
514 | if (is_object($from)) { |
|
515 | $user_id = $from->getId(); |
|
516 | self::insertUser($from, $date); |
|
517 | } |
|
518 | ||
519 | $location = $inline_query->getLocation(); |
|
520 | $query = $inline_query->getQuery(); |
|
521 | $offset = $inline_query->getOffset(); |
|
522 | ||
523 | $sth_insert_inline_query->bindParam(':inline_query_id', $inline_query_id, PDO::PARAM_INT); |
|
524 | $sth_insert_inline_query->bindParam(':user_id', $user_id, PDO::PARAM_INT); |
|
525 | $sth_insert_inline_query->bindParam(':location', $location, PDO::PARAM_STR); |
|
526 | $sth_insert_inline_query->bindParam(':query', $query, PDO::PARAM_STR); |
|
527 | $sth_insert_inline_query->bindParam(':param_offset', $offset, PDO::PARAM_STR); |
|
528 | $sth_insert_inline_query->bindParam(':created_at', $date, PDO::PARAM_STR); |
|
529 | ||
530 | return $sth_insert_inline_query->execute(); |
|
531 | } catch (PDOException $e) { |
|
532 | throw new TelegramException($e->getMessage()); |
|
533 | } |
|
534 | } |
|
535 | ||
536 | /** |
|
537 | * Insert chosen inline result request into database |
|
@@ 544-585 (lines=42) @@ | ||
541 | * @return bool If the insert was successful |
|
542 | * @throws \Longman\TelegramBot\Exception\TelegramException |
|
543 | */ |
|
544 | public static function insertChosenInlineResultRequest(ChosenInlineResult $chosen_inline_result) |
|
545 | { |
|
546 | if (!self::isDbConnected()) { |
|
547 | return false; |
|
548 | } |
|
549 | ||
550 | try { |
|
551 | $mysql_query = 'INSERT INTO `' . TB_CHOSEN_INLINE_RESULT . '` |
|
552 | ( |
|
553 | `result_id`, `user_id`, `location`, `inline_message_id`, `query`, `created_at` |
|
554 | ) |
|
555 | VALUES ( |
|
556 | :result_id, :user_id, :location, :inline_message_id, :query, :created_at |
|
557 | )'; |
|
558 | ||
559 | $sth_insert_chosen_inline_result = self::$pdo->prepare($mysql_query); |
|
560 | ||
561 | $date = self::getTimestamp(time()); |
|
562 | $result_id = $chosen_inline_result->getResultId(); |
|
563 | $from = $chosen_inline_result->getFrom(); |
|
564 | $user_id = null; |
|
565 | if (is_object($from)) { |
|
566 | $user_id = $from->getId(); |
|
567 | self::insertUser($from, $date); |
|
568 | } |
|
569 | ||
570 | $location = $chosen_inline_result->getLocation(); |
|
571 | $inline_message_id = $chosen_inline_result->getInlineMessageId(); |
|
572 | $query = $chosen_inline_result->getQuery(); |
|
573 | ||
574 | $sth_insert_chosen_inline_result->bindParam(':result_id', $result_id, PDO::PARAM_STR); |
|
575 | $sth_insert_chosen_inline_result->bindParam(':user_id', $user_id, PDO::PARAM_INT); |
|
576 | $sth_insert_chosen_inline_result->bindParam(':location', $location, PDO::PARAM_INT); |
|
577 | $sth_insert_chosen_inline_result->bindParam(':inline_message_id', $inline_message_id, PDO::PARAM_STR); |
|
578 | $sth_insert_chosen_inline_result->bindParam(':query', $query, PDO::PARAM_STR); |
|
579 | $sth_insert_chosen_inline_result->bindParam(':created_at', $date, PDO::PARAM_STR); |
|
580 | ||
581 | return $sth_insert_chosen_inline_result->execute(); |
|
582 | } catch (PDOException $e) { |
|
583 | throw new TelegramException($e->getMessage()); |
|
584 | } |
|
585 | } |
|
586 | ||
587 | /** |
|
588 | * Insert callback query request into database |