/** * Insert Edited Message request in db * * @param Entities\Message &$edited_message * * @return bool If the insert was successful * @throws TelegramException */ public static function insertEditedMessageRequest(Message &$edited_message) { if (!self::isDbConnected()) { return false; } $from = $edited_message->getFrom(); $chat = $edited_message->getChat(); $chat_id = $chat->getId(); $edit_date = self::getTimestamp($edited_message->getEditDate()); $entities = $edited_message->getEntities(); //Insert chat self::insertChat($chat, $edit_date); //Insert user and the relation with the chat self::insertUser($from, $edit_date, $chat); try { $sth = self::$pdo->prepare('INSERT INTO `' . TB_EDITED_MESSAGE . '` ( `chat_id`, `message_id`, `user_id`, `edit_date`, `text`, `entities`, `caption` ) VALUES ( :chat_id, :message_id, :user_id, :date, :text, :entities, :caption )'); $message_id = $edited_message->getMessageId(); $from_id = $from->getId(); $text = $edited_message->getText(); $caption = $edited_message->getCaption(); $sth->bindParam(':chat_id', $chat_id, \PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, \PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, \PDO::PARAM_INT); $sth->bindParam(':date', $edit_date, \PDO::PARAM_STR); $var = []; if (is_array($entities)) { foreach ($entities as $elm) { $var[] = json_decode($elm, true); } $entities = json_encode($var); } else { $entities = null; } $sth->bindParam(':text', $text, \PDO::PARAM_STR); $sth->bindParam(':entities', $entities, \PDO::PARAM_STR); $sth->bindParam(':caption', $caption, \PDO::PARAM_STR); return $sth->execute(); } catch (\PDOException $e) { throw new TelegramException($e->getMessage()); } }
/** * Insert Edited Message request in db * * @param \Longman\TelegramBot\Entities\Message $edited_message * * @return bool If the insert was successful * @throws \Longman\TelegramBot\Exception\TelegramException */ public static function insertEditedMessageRequest(Message $edited_message) { if (!self::isDbConnected()) { return false; } $from = $edited_message->getFrom(); $chat = $edited_message->getChat(); $chat_id = $chat->getId(); $edit_date = self::getTimestamp($edited_message->getEditDate()); $entities = self::entitiesArrayToJson($edited_message->getEntities(), null); //Insert chat self::insertChat($chat, $edit_date); //Insert user and the relation with the chat if (is_object($from)) { self::insertUser($from, $edit_date, $chat); } try { $sth = self::$pdo->prepare(' INSERT IGNORE INTO `' . TB_EDITED_MESSAGE . '` (`chat_id`, `message_id`, `user_id`, `edit_date`, `text`, `entities`, `caption`) VALUES (:chat_id, :message_id, :user_id, :date, :text, :entities, :caption) '); $message_id = $edited_message->getMessageId(); if (is_object($from)) { $from_id = $from->getId(); } else { $from_id = null; } $text = $edited_message->getText(); $caption = $edited_message->getCaption(); $sth->bindParam(':chat_id', $chat_id, PDO::PARAM_INT); $sth->bindParam(':message_id', $message_id, PDO::PARAM_INT); $sth->bindParam(':user_id', $from_id, PDO::PARAM_INT); $sth->bindParam(':date', $edit_date, PDO::PARAM_STR); $sth->bindParam(':text', $text, PDO::PARAM_STR); $sth->bindParam(':entities', $entities, PDO::PARAM_STR); $sth->bindParam(':caption', $caption, PDO::PARAM_STR); return $sth->execute(); } catch (PDOException $e) { throw new TelegramException($e->getMessage()); } }