PHP Class Longman\TelegramBot\DB

Datei anzeigen Open project: akalongman/php-telegram-bot Class Usage Examples

Protected Properties

Property Type Description
$mysql_credentials array MySQL credentials
$pdo PD\PDO PDO object
$table_prefix string Table prefix
$telegram Telegram Telegram class object

Public Methods

Method Description
entitiesArrayToJson ( array | null $entities, mixed $default = null ) : mixed Convert array of Entity items to a JSON array
externalInitialize ( PD\PDO $external_pdo_connection, Telegram $telegram, string $table_prefix = null ) : PD\PDO External Initialize
initialize ( array $credentials, Telegram $telegram, string $table_prefix = null, string $encoding = 'utf8mb4' ) : PD\PDO Initialize
insertCallbackQueryRequest ( CallbackQuery $callback_query ) : boolean Insert callback query request into database
insertChat ( Chat $chat, string $date, integer $migrate_to_chat_id = null ) : boolean Insert chat
insertChosenInlineResultRequest ( ChosenInlineResult $chosen_inline_result ) : boolean Insert chosen inline result request into database
insertEditedMessageRequest ( Message $edited_message ) : boolean Insert Edited Message request in db
insertInlineQueryRequest ( InlineQuery $inline_query ) : boolean Insert inline query request into database
insertMessageRequest ( Message $message ) : boolean Insert Message request in db
insertRequest ( Update $update ) : boolean Insert request into database
insertTelegramUpdate ( integer $id, integer $chat_id, integer $message_id, integer $inline_query_id, integer $chosen_inline_result_id, integer $callback_query_id, integer $edited_message_id ) : boolean Insert entry to telegram_update table
insertUser ( Longman\TelegramBot\Entities\User $user, string $date, Chat $chat = null ) : boolean Insert users and save their connection to chats
isDbConnected ( ) : boolean Check if database connection has been created
selectChats ( boolean $select_groups = true, boolean $select_super_groups = true, boolean $select_users = true, string $date_from = null, string $date_to = null, integer $chat_id = null, string $text = null ) : array | boolean Select Group and/or single Chats
selectMessages ( integer $limit = null ) : array | boolean Fetch message(s) from DB
selectTelegramUpdate ( integer $limit = null ) : array | boolean Fetch update(s) from DB

Protected Methods

Method Description
defineTables ( ) Define all the tables with the proper prefix
getTimestamp ( integer $time = null ) : string Convert from unix timestamp to timestamp

Method Details

defineTables() protected static method

Define all the tables with the proper prefix
protected static defineTables ( )

entitiesArrayToJson() public static method

Convert array of Entity items to a JSON array
public static entitiesArrayToJson ( array | null $entities, mixed $default = null ) : mixed
$entities array | null
$default mixed
return mixed

externalInitialize() public static method

Let you use the class with an external already existing Pdo Mysql connection.
public static externalInitialize ( PD\PDO $external_pdo_connection, Telegram $telegram, string $table_prefix = null ) : PD\PDO
$external_pdo_connection PD\PDO PDO database object
$telegram Telegram Telegram object to connect with this object
$table_prefix string Table prefix
return PD\PDO PDO database object

getTimestamp() protected static method

Convert from unix timestamp to timestamp
protected static getTimestamp ( integer $time = null ) : string
$time integer Unix timestamp (if null, current timestamp is used)
return string

initialize() public static method

Initialize
public static initialize ( array $credentials, Telegram $telegram, string $table_prefix = null, string $encoding = 'utf8mb4' ) : PD\PDO
$credentials array Database connection details
$telegram Telegram Telegram object to connect with this object
$table_prefix string Table prefix
$encoding string Database character encoding
return PD\PDO PDO database object

insertCallbackQueryRequest() public static method

Insert callback query request into database
public static insertCallbackQueryRequest ( CallbackQuery $callback_query ) : boolean
$callback_query Longman\TelegramBot\Entities\CallbackQuery
return boolean If the insert was successful

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

insertChosenInlineResultRequest() public static method

Insert chosen inline result request into database
public static insertChosenInlineResultRequest ( ChosenInlineResult $chosen_inline_result ) : boolean
$chosen_inline_result Longman\TelegramBot\Entities\ChosenInlineResult
return boolean If the insert was successful

insertEditedMessageRequest() public static method

Insert Edited Message request in db
public static insertEditedMessageRequest ( Message $edited_message ) : boolean
$edited_message Longman\TelegramBot\Entities\Message
return boolean If the insert was successful

insertInlineQueryRequest() public static method

Insert inline query request into database
public static insertInlineQueryRequest ( InlineQuery $inline_query ) : boolean
$inline_query Longman\TelegramBot\Entities\InlineQuery
return boolean If the insert was successful

insertMessageRequest() public static method

Insert Message request in db
public static insertMessageRequest ( Message $message ) : boolean
$message Longman\TelegramBot\Entities\Message
return boolean If the insert was successful

insertRequest() public static method

Insert request into database
public static insertRequest ( Update $update ) : boolean
$update Longman\TelegramBot\Entities\Update
return boolean

insertTelegramUpdate() public static method

Insert entry to telegram_update table
public static insertTelegramUpdate ( integer $id, integer $chat_id, integer $message_id, integer $inline_query_id, integer $chosen_inline_result_id, integer $callback_query_id, integer $edited_message_id ) : boolean
$id integer
$chat_id integer
$message_id integer
$inline_query_id integer
$chosen_inline_result_id integer
$callback_query_id integer
$edited_message_id integer
return boolean If the insert was successful

insertUser() public static method

Insert users and save their connection to chats
public static insertUser ( Longman\TelegramBot\Entities\User $user, string $date, Chat $chat = null ) : boolean
$user Longman\TelegramBot\Entities\User
$date string
$chat Longman\TelegramBot\Entities\Chat
return boolean If the insert was successful

isDbConnected() public static method

Check if database connection has been created
public static isDbConnected ( ) : boolean
return boolean

selectChats() public static method

Select Group and/or single Chats
public static selectChats ( boolean $select_groups = true, boolean $select_super_groups = true, boolean $select_users = true, string $date_from = null, string $date_to = null, integer $chat_id = null, string $text = null ) : array | boolean
$select_groups boolean
$select_super_groups boolean
$select_users boolean
$date_from string
$date_to string
$chat_id integer
$text string
return array | boolean (Selected chats or false if invalid arguments)

selectMessages() public static method

Fetch message(s) from DB
public static selectMessages ( integer $limit = null ) : array | boolean
$limit integer Limit the number of messages to fetch
return array | boolean Fetched data or false if not connected

selectTelegramUpdate() public static method

Fetch update(s) from DB
public static selectTelegramUpdate ( integer $limit = null ) : array | boolean
$limit integer Limit the number of updates to fetch
return array | boolean Fetched data or false if not connected

Property Details

$mysql_credentials protected_oe static_oe property

MySQL credentials
protected static array $mysql_credentials
return array

$pdo protected_oe static_oe property

PDO object
protected static PDO,PD $pdo
return PD\PDO

$table_prefix protected_oe static_oe property

Table prefix
protected static string $table_prefix
return string

$telegram protected_oe static_oe property

Telegram class object
protected static Telegram,Longman\TelegramBot $telegram
return Telegram