From ac80cf04dd2d57413e031eab2f45ab16cd2cd3dd Mon Sep 17 00:00:00 2001 From: Daniel Brendel Date: Sun, 3 Mar 2024 02:35:02 +0100 Subject: [PATCH] #130 Further plant system messages --- app/lang/de/tb.php | 5 +++- app/lang/en/tb.php | 5 +++- app/models/PlantsModel.php | 3 ++ app/modules/TextBlockModule.php | 50 +++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/app/lang/de/tb.php b/app/lang/de/tb.php index 29919e3..7b2c9f8 100644 --- a/app/lang/de/tb.php +++ b/app/lang/de/tb.php @@ -1,5 +1,8 @@ 'Ich habe eine neue Pflanze hinzugefügt: {name}' + 'added_new_plant' => 'Ich habe eine neue Pflanze hinzugefügt: {name}', + 'moved_plant_to_history' => 'Ich habe {name} zu ' . app('history_name') . ' geschoben', + 'restored_plant_from_history' => 'Ich habe {name} von ' . app('history_name') . ' wiederhergestellt', + 'deleted_plant' => 'Ich habe {name} gelöscht' ]; \ No newline at end of file diff --git a/app/lang/en/tb.php b/app/lang/en/tb.php index cbdb9db..cdb3402 100644 --- a/app/lang/en/tb.php +++ b/app/lang/en/tb.php @@ -1,5 +1,8 @@ 'I added a new plant: {name}' + 'added_new_plant' => 'I added a new plant: {name}', + 'moved_plant_to_history' => 'I moved {name} to {history}', + 'restored_plant_from_history' => 'I restored {name} from {history}', + 'deleted_plant' => 'I deleted {name}' ]; \ No newline at end of file diff --git a/app/models/PlantsModel.php b/app/models/PlantsModel.php index b4ffe39..a2c43b0 100644 --- a/app/models/PlantsModel.php +++ b/app/models/PlantsModel.php @@ -474,6 +474,7 @@ static::raw('UPDATE `' . self::tableName() . '` SET history = 1, history_date = CURRENT_TIMESTAMP WHERE id = ?', [$plantId]); LogModel::addLog($user->get('id'), $plant->get('name'), 'mark_historical', '', url('/plants/history')); + TextBlockModule::plantToHistory($plant->get('name'), url('/plants/history')); } catch (\Exception $e) { throw $e; } @@ -497,6 +498,7 @@ static::raw('UPDATE `' . self::tableName() . '` SET history = 0, history_date = NULL WHERE id = ?', [$plantId]); LogModel::addLog($user->get('id'), $plant->get('name'), 'historical_restore', '', url('/plants/details/' . $plantId)); + TextBlockModule::plantFromHistory($plant->get('name'), url('/plants/details/' . $plantId)); } catch (\Exception $e) { throw $e; } @@ -526,6 +528,7 @@ static::raw('DELETE FROM `' . self::tableName() . '` WHERE id = ?', [$plantId]); LogModel::addLog($user->get('id'), $plant->get('name'), 'remove_plant', ''); + TextBlockModule::deletePlant($plant->get('name')); } catch (\Exception $e) { throw $e; } diff --git a/app/modules/TextBlockModule.php b/app/modules/TextBlockModule.php index 3f36b9f..458e617 100644 --- a/app/modules/TextBlockModule.php +++ b/app/modules/TextBlockModule.php @@ -21,6 +21,56 @@ class TextBlockModule { } } + /** + * @param $name + * @param $url + * @return void + * @throws \Exception + */ + public static function plantToHistory($name, $url) + { + try { + $text = __('tb.moved_plant_to_history', ['name' => $name, 'url' => $url, 'history' => app('history_name')]); + + static::addToChat($text, 'x1fab4'); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * @param $name + * @param $url + * @return void + * @throws \Exception + */ + public static function plantFromHistory($name, $url) + { + try { + $text = __('tb.restored_plant_from_history', ['name' => $name, 'url' => $url, 'history' => app('history_name')]); + + static::addToChat($text, 'x1fab4'); + } catch (\Exception $e) { + throw $e; + } + } + + /** + * @param $name + * @return void + * @throws \Exception + */ + public static function deletePlant($name) + { + try { + $text = __('tb.deleted_plant', ['name' => $name]); + + static::addToChat($text, 'x1fab4'); + } catch (\Exception $e) { + throw $e; + } + } + /** * @param $message * @param $icon