Ejemplo n.º 1
1
 /**
  * Insert callback query request into database
  *
  * @param Entities\CallbackQuery &$callback_query
  *
  * @return bool If the insert was successful
  * @throws TelegramException
  */
 public static function insertCallbackQueryRequest(CallbackQuery &$callback_query)
 {
     if (!self::isDbConnected()) {
         return false;
     }
     try {
         $mysql_query = 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
             (
             `id`, `user_id`, `chat_id`, `message_id`, `inline_message_id`, `data`, `created_at`
             )
             VALUES (
             :callback_query_id, :user_id, :chat_id, :message_id, :inline_message_id, :data, :created_at
             )';
         $sth_insert_callback_query = self::$pdo->prepare($mysql_query);
         $date = self::getTimestamp(time());
         $callback_query_id = $callback_query->getId();
         $from = $callback_query->getFrom();
         $user_id = null;
         if (is_object($from)) {
             $user_id = $from->getId();
             self::insertUser($from, $date);
         }
         $message = $callback_query->getMessage();
         $chat_id = null;
         $message_id = null;
         if ($message) {
             $chat_id = $message->getChat()->getId();
             $message_id = $message->getMessageId();
             $sth = self::$pdo->prepare('SELECT * FROM `' . TB_MESSAGE . '`
                 WHERE `id` = ' . $message_id . ' AND `chat_id` = ' . $chat_id . ' LIMIT 1');
             $sth->execute();
             if ($sth->rowCount() > 0) {
                 self::insertEditedMessageRequest($message);
             } else {
                 self::insertMessageRequest($message);
             }
         }
         $inline_message_id = $callback_query->getInlineMessageId();
         $data = $callback_query->getData();
         $sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT);
         $sth_insert_callback_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
         $sth_insert_callback_query->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT);
         $sth_insert_callback_query->bindParam(':message_id', $message_id, \PDO::PARAM_INT);
         $sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
         $sth_insert_callback_query->bindParam(':data', $data, \PDO::PARAM_STR);
         $sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR);
         return $sth_insert_callback_query->execute();
     } catch (\PDOException $e) {
         throw new TelegramException($e->getMessage());
     }
 }
Ejemplo n.º 2
0
 /**
  * Insert callback query request into database
  *
  * @todo No return value at the end. Just return true?
  *
  * @param Entities\CallbackQuery &$callback_query
  *
  * @return bool
  */
 public static function insertCallbackQueryRequest(CallbackQuery &$callback_query)
 {
     if (!self::isDbConnected()) {
         return false;
     }
     try {
         //Callback query Table
         $mysql_query = 'INSERT IGNORE INTO `' . TB_CALLBACK_QUERY . '`
             (
             `id`, `user_id`, `message`, `inline_message_id`, `data`, `created_at`
             )
             VALUES (
             :callback_query_id, :user_id, :message, :inline_message_id, :data, :created_at
             )';
         $sth_insert_callback_query = self::$pdo->prepare($mysql_query);
         $date = self::getTimestamp(time());
         $callback_query_id = (int) $callback_query->getId();
         $from = $callback_query->getFrom();
         $user_id = null;
         if (is_object($from)) {
             $user_id = $from->getId();
             self::insertUser($from, $date);
         }
         $message = $callback_query->getMessage();
         $inline_message_id = $callback_query->getInlineMessageId();
         $data = $callback_query->getData();
         $sth_insert_callback_query->bindParam(':callback_query_id', $callback_query_id, \PDO::PARAM_INT);
         $sth_insert_callback_query->bindParam(':user_id', $user_id, \PDO::PARAM_INT);
         $sth_insert_callback_query->bindParam(':message', $message, \PDO::PARAM_STR);
         $sth_insert_callback_query->bindParam(':inline_message_id', $inline_message_id, \PDO::PARAM_STR);
         $sth_insert_callback_query->bindParam(':data', $data, \PDO::PARAM_STR);
         $sth_insert_callback_query->bindParam(':created_at', $date, \PDO::PARAM_STR);
         $status = $sth_insert_callback_query->execute();
     } catch (PDOException $e) {
         throw new TelegramException($e->getMessage());
     }
 }