From aa8c0de3f9ebda2ed5a0ee9f4b4dde332a233845 Mon Sep 17 00:00:00 2001 From: Seph Date: Thu, 2 May 2024 23:31:44 +0200 Subject: [PATCH] Logs --- tailwind/custom/file-header.css | 2 +- theme/functions.php | 2 ++ theme/inc/config-routing.php | 22 +++++++++++++++++ theme/pages/sks.php | 2 ++ theme/wowpress/Api/WoWAudit.php | 3 +++ theme/wowpress/Database/CreateLogTable.php | 16 +++++++++++++ theme/wowpress/Models/Log.php | 28 ++++++++++++++++++++++ theme/wowpress/Models/SKS.php | 5 ++++ 8 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 theme/wowpress/Database/CreateLogTable.php create mode 100644 theme/wowpress/Models/Log.php diff --git a/tailwind/custom/file-header.css b/tailwind/custom/file-header.css index bbd2902..70e33c0 100644 --- a/tailwind/custom/file-header.css +++ b/tailwind/custom/file-header.css @@ -4,7 +4,7 @@ Theme URI: https://nebelkrieger.de Author: Yorndar Author URI: https://nebelkrieger.de Description: The next gen NK-Theme -Version: 0.2.1 +Version: 0.3.0 Tested up to: 6.2 Requires PHP: 8.0 License: GNU General Public License v2 or later diff --git a/theme/functions.php b/theme/functions.php index ba8e1af..f8e24c8 100644 --- a/theme/functions.php +++ b/theme/functions.php @@ -2,6 +2,7 @@ use WoWPress\Database\CreateCacheTable; use WoWPress\Database\CreateCharacterTable; +use WoWPress\Database\CreateLogTable; use WoWPress\Database\CreateRaidTable; use WoWPress\Database\CreateSignupTable; use WoWPress\Database\CreateSKSTable; @@ -155,6 +156,7 @@ if (!function_exists('wowpress_database')) : CreateRaidTable::sql(), CreateSignupTable::sql(), CreateSKSTable::sql(), + CreateLogTable::sql(), ]); } diff --git a/theme/inc/config-routing.php b/theme/inc/config-routing.php index 7f3a660..441005f 100644 --- a/theme/inc/config-routing.php +++ b/theme/inc/config-routing.php @@ -1,5 +1,6 @@ 'index.php?wowpress_page=form_request'], ['sks/?$' => 'index.php?wowpress_page=sks'], ['sks/([A-Za-z-0-9 ]+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'], + ['logs/?$' => 'index.php?wowpress_page=logs'], + $wp_rewrite->rules ); }); @@ -48,6 +51,25 @@ add_action('template_redirect', function () { include plugin_dir_path(__FILE__) . '../pages/sks.php'; die; break; + case 'logs': + + isAllowed('wowpress_edit_raids'); + $GLOBALS['wowpress']['page_title'] = "Logs"; + echo "
"; + echo '
'; + foreach(Log::all() as $log){ + ?> +
+
Message: message?>
+
Action: action?>
+
Logged: created_at,"dd.mm.YY HH:MM")?>
+
+
+ "; + die; + break; case 'raids': # isAllowed('wowpress_view_raids'); $GLOBALS['wowpress']['page_title'] = "Raids"; diff --git a/theme/pages/sks.php b/theme/pages/sks.php index 465cf23..c60fb69 100644 --- a/theme/pages/sks.php +++ b/theme/pages/sks.php @@ -3,9 +3,11 @@ use Wenprise\Eloquent\Database; use Wenprise\Eloquent\Facades\DB; use WoWPress\Frontend\Icon; +use WoWPress\Models\Log; use WoWPress\Models\SKS; + set_sidebar_status('top', false); $liste = $GLOBALS['wowpress']['liste']; diff --git a/theme/wowpress/Api/WoWAudit.php b/theme/wowpress/Api/WoWAudit.php index 3b74f1c..58c7585 100644 --- a/theme/wowpress/Api/WoWAudit.php +++ b/theme/wowpress/Api/WoWAudit.php @@ -3,7 +3,9 @@ namespace WoWPress\Api; use WoWPress\Models\Character; +use WoWPress\Models\Log; use WoWPress\Models\Raid; +use WoWPress\Models\User; class WoWAudit extends Api{ @@ -40,6 +42,7 @@ class WoWAudit extends Api{ $url = "raids/".$raid->id_wowaudit; + Log::write(json_encode(['char' => $character->name."-".$character->realm,'status' => $status,"role" => $role,'user' => User::find(get_current_user_id())->user_login]),Log::LOG_SIGNUP); return $this->put($url,$body); diff --git a/theme/wowpress/Database/CreateLogTable.php b/theme/wowpress/Database/CreateLogTable.php new file mode 100644 index 0000000..73a27be --- /dev/null +++ b/theme/wowpress/Database/CreateLogTable.php @@ -0,0 +1,16 @@ + 'json NOT NULL', + 'action' => 'longtext NOT NULL', + 'created_at' => 'timestamp NOT NULL', + 'updated_at' => 'timestamp NOT NULL', + ]; + +} diff --git a/theme/wowpress/Models/Log.php b/theme/wowpress/Models/Log.php new file mode 100644 index 0000000..d267380 --- /dev/null +++ b/theme/wowpress/Models/Log.php @@ -0,0 +1,28 @@ +message = $message; + $log->action = $action; + $log->save(); + } + +} \ No newline at end of file diff --git a/theme/wowpress/Models/SKS.php b/theme/wowpress/Models/SKS.php index 6c01bbd..8eccb21 100644 --- a/theme/wowpress/Models/SKS.php +++ b/theme/wowpress/Models/SKS.php @@ -84,6 +84,7 @@ class SKS extends Model $list = SKS::where('list_name', $this->list_name)->get(); $ranks = range(1, count($list)); shuffle($ranks); + Log::write(json_encode($list->map->only(['rank','char_name','realm_name'])->values()),Log::LOG_ROLL); foreach ($list as $key => $sk) { $sk->rank = $ranks[$key]; $sk->save(); @@ -93,6 +94,7 @@ class SKS extends Model public function loot() { $after = $this->getAfter(); + $rank = $this->rank; $last_rank = $this->last_rank; foreach ($after as $id => &$sk) { /** @@ -116,6 +118,9 @@ class SKS extends Model $this->rank = $last_rank; $this->save(); + Log::write(json_encode(['char' => $this->char_name."-".$this->realm_name,'rank' => $this->rank,'previous' => $rank,'list' => $this->list_name]),Log::LOG_LOOT); + + foreach ($after as $sk) { $sk->save(); }