Longman\TelegramBot\DB::insertChat PHP Method

insertChat() public static method

Insert chat
public static insertChat ( Chat $chat, string $date, integer $migrate_to_chat_id = null ) : boolean
$chat Longman\TelegramBot\Entities\Chat
$date string
$migrate_to_chat_id integer
return boolean If the insert was successful
    public static function insertChat(Chat $chat, $date, $migrate_to_chat_id = null)
    {
        if (!self::isDbConnected()) {
            return false;
        }
        $chat_id = $chat->getId();
        $chat_title = $chat->getTitle();
        $chat_type = $chat->getType();
        try {
            $sth = self::$pdo->prepare('
                INSERT INTO `' . TB_CHAT . '`
                (`id`, `type`, `title`, `created_at` ,`updated_at`, `old_id`)
                VALUES
                (:id, :type, :title, :date, :date, :oldid)
                ON DUPLICATE KEY UPDATE
                    `type`       = :type,
                    `title`      = :title,
                    `updated_at` = :date
            ');
            if ($migrate_to_chat_id) {
                $chat_type = 'supergroup';
                $sth->bindParam(':id', $migrate_to_chat_id, PDO::PARAM_INT);
                $sth->bindParam(':oldid', $chat_id, PDO::PARAM_INT);
            } else {
                $sth->bindParam(':id', $chat_id, PDO::PARAM_INT);
                $sth->bindParam(':oldid', $migrate_to_chat_id, PDO::PARAM_INT);
            }
            $sth->bindParam(':type', $chat_type, PDO::PARAM_INT);
            $sth->bindParam(':title', $chat_title, PDO::PARAM_STR, 255);
            $sth->bindParam(':date', $date, PDO::PARAM_STR);
            return $sth->execute();
        } catch (PDOException $e) {
            throw new TelegramException($e->getMessage());
        }
    }