System messages

This commit is contained in:
Daniel Brendel
2024-03-02 22:05:34 +01:00
parent 8ef5d1801e
commit 5de5d4d612
17 changed files with 201 additions and 33 deletions

View File

@@ -0,0 +1,52 @@
<?php
/**
* This class represents your module
*/
class TextBlockModule {
/**
* @param $name
* @param $url
* @return void
* @throws \Exception
*/
public static function newPlant($name, $url)
{
try {
$text = __('tb.added_new_plant', ['name' => $name, 'url' => $url]);
static::addToChat($text, 'x1fab4');
} catch (\Exception $e) {
throw $e;
}
}
/**
* @param $message
* @param $icon
* @return void
* @throws \Exception
*/
private static function addToChat($message, $icon)
{
try {
if (!app('chat_system')) {
return;
}
$user = UserModel::getAuthUser();
if (!$user) {
throw new \Exception('Invalid user');
}
$icon = html_entity_decode('&#' . $icon, ENT_COMPAT | ENT_QUOTES);
ChatMsgModel::raw('INSERT INTO `' . ChatMsgModel::tableName() . '` (userId, message, system, created_at) VALUES(?, ?, 1, CURRENT_TIMESTAMP)', [
$user->get('id'),
$icon . ' ' . $message
]);
} catch (\Exception $e) {
throw $e;
}
}
}