1 | <?php |
||
5 | trait User { |
||
6 | |||
7 | abstract function getChat($chat_id); |
||
8 | |||
9 | abstract function setChatID($chat_id); |
||
10 | |||
11 | /** |
||
12 | * \addtogroup Bot Bot |
||
13 | * @{ |
||
14 | */ |
||
15 | |||
16 | /** |
||
17 | * \addtogroup Users-handle Users handling |
||
18 | * \brief Handle bot users on the database. |
||
19 | * @{ |
||
20 | */ |
||
21 | |||
22 | /** Pdo connection to the database. */ |
||
23 | public $pdo; |
||
24 | |||
25 | /** \brief Table contaning bot users data in the sql database. */ |
||
26 | public $user_table = '"User"'; |
||
27 | |||
28 | /** \brief Name of the column that represents the user id in the sql database */ |
||
29 | public $id_column = 'chat_id'; |
||
30 | |||
31 | /** \brief Add a user to the database. |
||
32 | * \details Add a user to the database in Bot::$user_table table and Bot::$id_column column using Bot::$pdo connection. |
||
33 | * @param int $chat_id chat_id of the user to add. |
||
34 | * @return bool True on success. |
||
35 | */ |
||
36 | public function addUser($chat_id) : bool { |
||
74 | |||
75 | /** |
||
76 | * \brief Broadcast a message to all user registred on the database. |
||
77 | * \details Send a message to all users subscribed, change Bot::$user_table and Bot::$id_column to match your database structure is. |
||
78 | * This method requires Bot::$pdo connection set. |
||
79 | * All parameters are the same as CoreBot::sendMessage. |
||
80 | * Because a limitation of Telegram Bot API the bot will have a delay after 20 messages sent in different chats. |
||
81 | * @see CoreBot::sendMessage |
||
82 | */ |
||
83 | public function broadcastMessage(string $text, string $reply_markup = null, string $parse_mode = 'HTML', bool $disable_web_preview = true, bool $disable_notification = false) { |
||
128 | |||
129 | /** @} */ |
||
130 | |||
131 | /** @} */ |
||
132 | |||
133 | } |
||
134 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.