1 | <?php |
||
5 | trait DatabaseHandler { |
||
6 | |||
7 | /** |
||
8 | * \addtogroup Users-handle Users handling |
||
9 | * \brief Handle bot users on the database. |
||
10 | * @{ |
||
11 | */ |
||
12 | |||
13 | /** \brief Table contaning bot users data in the sql database. */ |
||
14 | public $user_table = '"User"'; |
||
15 | |||
16 | /** \brief Name of the column that represents the user id in the sql database */ |
||
17 | public $id_column = 'chat_id'; |
||
18 | |||
19 | /** \brief Add a user to the database. |
||
20 | * \details Add a user to the database in Bot::$user_table table and Bot::$id_column column using Bot::$pdo connection. |
||
21 | * @param $chat_id chat_id of the user to add. |
||
22 | * @return True on success. |
||
23 | */ |
||
24 | public function addUser($chat_id) : bool { |
||
62 | |||
63 | /** |
||
64 | * \brief Broadcast a message to all user registred on the database. |
||
65 | * \details Send a message to all users subscribed, change Bot::$user_table and Bot::$id_column to match your database structure is. |
||
66 | * This method requires Bot::$pdo connection set. |
||
67 | * All parameters are the same as CoreBot::sendMessage. |
||
68 | * Because a limitation of Telegram Bot API the bot will have a delay after 20 messages sent in different chats. |
||
69 | * @see CoreBot::sendMessage |
||
70 | */ |
||
71 | public function broadcastMessage($text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = true, bool $disable_notification = false) { |
||
116 | |||
117 | /** @} */ |
||
118 | |||
119 | } |
||
120 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: