getEntities() публичный Метод

This method overrides the default getEntities method and returns a nice array of MessageEntity objects.
public getEntities ( ) : null | MessageEntity[]
Результат null | MessageEntity[]
Пример #1
0
 /**
  * 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());
     }
 }
Пример #2
0
 /**
  * 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());
     }
 }
Пример #3
0
 /**
  * Insert Message request in db
  *
  * @param Entities\Message &$message
  *
  * @return bool If the insert was successful
  */
 public static function insertMessageRequest(Message &$message)
 {
     if (!self::isDbConnected()) {
         return false;
     }
     $from = $message->getFrom();
     $chat = $message->getChat();
     $chat_id = $chat->getId();
     $date = self::getTimestamp($message->getDate());
     $forward_from = $message->getForwardFrom();
     $forward_from_chat = $message->getForwardFromChat();
     $photo = $message->getPhoto();
     $entities = $message->getEntities();
     $new_chat_member = $message->getNewChatMember();
     $new_chat_photo = $message->getNewChatPhoto();
     $left_chat_member = $message->getLeftChatMember();
     $migrate_from_chat_id = $message->getMigrateFromChatId();
     $migrate_to_chat_id = $message->getMigrateToChatId();
     self::insertChat($chat, $date, $migrate_to_chat_id);
     //Insert user and the relation with the chat
     self::insertUser($from, $date, $chat);
     //Forwarded object
     if ($forward_from || $forward_from_chat) {
         $forward_date = self::getTimestamp($message->getForwardDate());
     }
     //Insert the forwarded message user in users table
     if (is_object($forward_from)) {
         self::insertUser($forward_from, $forward_date);
         $forward_from = $forward_from->getId();
     }
     if (is_object($forward_from_chat)) {
         self::insertChat($forward_from_chat, $forward_date);
         $forward_from_chat = $forward_from_chat->getId();
     }
     //New and left chat member
     if ($new_chat_member) {
         //Insert the new chat user
         self::insertUser($new_chat_member, $date, $chat);
         $new_chat_member = $new_chat_member->getId();
     } elseif ($left_chat_member) {
         //Insert the left chat user
         self::insertUser($left_chat_member, $date, $chat);
         $left_chat_member = $left_chat_member->getId();
     }
     try {
         //message Table
         $sth = self::$pdo->prepare('INSERT IGNORE INTO `' . TB_MESSAGE . '`
             (
             `id`, `user_id`, `date`, `chat_id`, `forward_from`, `forward_from_chat`,
             `forward_date`, `reply_to_chat`, `reply_to_message`, `text`, `entities`, `audio`, `document`,
             `photo`, `sticker`, `video`, `voice`, `caption`, `contact`,
             `location`, `venue`, `new_chat_member`, `left_chat_member`,
             `new_chat_title`,`new_chat_photo`, `delete_chat_photo`, `group_chat_created`,
             `supergroup_chat_created`, `channel_chat_created`,
             `migrate_from_chat_id`, `migrate_to_chat_id`, `pinned_message`
             )
             VALUES (
             :message_id, :user_id, :date, :chat_id, :forward_from, :forward_from_chat,
             :forward_date, :reply_to_chat, :reply_to_message, :text, :entities, :audio, :document,
             :photo, :sticker, :video, :voice, :caption, :contact,
             :location, :venue, :new_chat_member, :left_chat_member,
             :new_chat_title, :new_chat_photo, :delete_chat_photo, :group_chat_created,
             :supergroup_chat_created, :channel_chat_created,
             :migrate_from_chat_id, :migrate_to_chat_id, :pinned_message
             )');
         $message_id = $message->getMessageId();
         $from_id = $from->getId();
         $reply_to_message = $message->getReplyToMessage();
         $reply_to_message_id = null;
         if (is_object($reply_to_message)) {
             $reply_to_message_id = $reply_to_message->getMessageId();
             // please notice that, as explaied in the documentation, reply_to_message don't contain other
             // reply_to_message field so recursion deep is 1
             self::insertMessageRequest($reply_to_message);
         }
         $text = $message->getText();
         $audio = $message->getAudio();
         $document = $message->getDocument();
         $sticker = $message->getSticker();
         $video = $message->getVideo();
         $voice = $message->getVoice();
         $caption = $message->getCaption();
         $contact = $message->getContact();
         $location = $message->getLocation();
         $venue = $message->getVenue();
         $new_chat_title = $message->getNewChatTitle();
         $delete_chat_photo = $message->getDeleteChatPhoto();
         $group_chat_created = $message->getGroupChatCreated();
         $supergroup_chat_created = $message->getSupergroupChatCreated();
         $channel_chat_created = $message->getChannelChatCreated();
         $migrate_from_chat_id = $message->getMigrateFromChatId();
         $migrate_to_chat_id = $message->getMigrateToChatId();
         $pinned_message = $message->getPinnedMessage();
         $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', $date, \PDO::PARAM_STR);
         $sth->bindParam(':forward_from', $forward_from, \PDO::PARAM_INT);
         $sth->bindParam(':forward_from_chat', $forward_from_chat, \PDO::PARAM_INT);
         $sth->bindParam(':forward_date', $forward_date, \PDO::PARAM_STR);
         $reply_chat_id = null;
         if ($reply_to_message_id) {
             $reply_chat_id = $chat_id;
         }
         $var = [];
         if (is_array($entities)) {
             foreach ($entities as $elm) {
                 $var[] = json_decode($elm, true);
             }
             $entities = json_encode($var);
         } else {
             $entities = null;
         }
         $sth->bindParam(':reply_to_chat', $reply_chat_id, \PDO::PARAM_INT);
         $sth->bindParam(':reply_to_message', $reply_to_message_id, \PDO::PARAM_INT);
         $sth->bindParam(':text', $text, \PDO::PARAM_STR);
         $sth->bindParam(':entities', $entities, \PDO::PARAM_STR);
         $sth->bindParam(':audio', $audio, \PDO::PARAM_STR);
         $sth->bindParam(':document', $document, \PDO::PARAM_STR);
         $var = [];
         if (is_array($photo)) {
             foreach ($photo as $elm) {
                 $var[] = json_decode($elm, true);
             }
             $photo = json_encode($var);
         } else {
             $photo = '';
         }
         $sth->bindParam(':photo', $photo, \PDO::PARAM_STR);
         $sth->bindParam(':sticker', $sticker, \PDO::PARAM_STR);
         $sth->bindParam(':video', $video, \PDO::PARAM_STR);
         $sth->bindParam(':voice', $voice, \PDO::PARAM_STR);
         $sth->bindParam(':caption', $caption, \PDO::PARAM_STR);
         $sth->bindParam(':contact', $contact, \PDO::PARAM_STR);
         $sth->bindParam(':location', $location, \PDO::PARAM_STR);
         $sth->bindParam(':venue', $venue, \PDO::PARAM_STR);
         $sth->bindParam(':new_chat_member', $new_chat_member, \PDO::PARAM_INT);
         $sth->bindParam(':left_chat_member', $left_chat_member, \PDO::PARAM_INT);
         $sth->bindParam(':new_chat_title', $new_chat_title, \PDO::PARAM_STR);
         //Array of Photosize
         $var = [];
         if (is_array($new_chat_photo)) {
             foreach ($new_chat_photo as $elm) {
                 $var[] = json_decode($elm, true);
             }
             $new_chat_photo = json_encode($var);
         } else {
             $new_chat_photo = '';
         }
         $sth->bindParam(':new_chat_photo', $new_chat_photo, \PDO::PARAM_STR);
         $sth->bindParam(':delete_chat_photo', $delete_chat_photo, \PDO::PARAM_STR);
         $sth->bindParam(':group_chat_created', $group_chat_created, \PDO::PARAM_STR);
         $sth->bindParam(':supergroup_chat_created', $supergroup_chat_created, \PDO::PARAM_INT);
         $sth->bindParam(':channel_chat_created', $channel_chat_created, \PDO::PARAM_INT);
         $sth->bindParam(':migrate_from_chat_id', $migrate_from_chat_id, \PDO::PARAM_INT);
         $sth->bindParam(':migrate_to_chat_id', $migrate_to_chat_id, \PDO::PARAM_INT);
         $sth->bindParam(':pinned_message', $pinned_message, \PDO::PARAM_INT);
         $status = $sth->execute();
     } catch (PDOException $e) {
         throw new TelegramException($e->getMessage());
     }
     return true;
 }