master
Seph 2024-05-02 23:31:44 +02:00
parent 7e556ff7a5
commit aa8c0de3f9
8 changed files with 79 additions and 1 deletions

View File

@ -4,7 +4,7 @@ Theme URI: https://nebelkrieger.de
Author: Yorndar Author: Yorndar
Author URI: https://nebelkrieger.de Author URI: https://nebelkrieger.de
Description: The next gen NK-Theme Description: The next gen NK-Theme
Version: 0.2.1 Version: 0.3.0
Tested up to: 6.2 Tested up to: 6.2
Requires PHP: 8.0 Requires PHP: 8.0
License: GNU General Public License v2 or later License: GNU General Public License v2 or later

View File

@ -2,6 +2,7 @@
use WoWPress\Database\CreateCacheTable; use WoWPress\Database\CreateCacheTable;
use WoWPress\Database\CreateCharacterTable; use WoWPress\Database\CreateCharacterTable;
use WoWPress\Database\CreateLogTable;
use WoWPress\Database\CreateRaidTable; use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable; use WoWPress\Database\CreateSignupTable;
use WoWPress\Database\CreateSKSTable; use WoWPress\Database\CreateSKSTable;
@ -155,6 +156,7 @@ if (!function_exists('wowpress_database')) :
CreateRaidTable::sql(), CreateRaidTable::sql(),
CreateSignupTable::sql(), CreateSignupTable::sql(),
CreateSKSTable::sql(), CreateSKSTable::sql(),
CreateLogTable::sql(),
]); ]);
} }

View File

@ -1,5 +1,6 @@
<?php <?php
use WoWPress\Models\Log;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
use WoWPress\Models\SKS; use WoWPress\Models\SKS;
use WoWPress\Models\User; use WoWPress\Models\User;
@ -13,6 +14,8 @@ add_filter('generate_rewrite_rules', function ($wp_rewrite) {
['request/?$' => 'index.php?wowpress_page=form_request'], ['request/?$' => 'index.php?wowpress_page=form_request'],
['sks/?$' => 'index.php?wowpress_page=sks'], ['sks/?$' => 'index.php?wowpress_page=sks'],
['sks/([A-Za-z-0-9 ]+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'], ['sks/([A-Za-z-0-9 ]+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'],
['logs/?$' => 'index.php?wowpress_page=logs'],
$wp_rewrite->rules $wp_rewrite->rules
); );
}); });
@ -48,6 +51,25 @@ add_action('template_redirect', function () {
include plugin_dir_path(__FILE__) . '../pages/sks.php'; include plugin_dir_path(__FILE__) . '../pages/sks.php';
die; die;
break; break;
case 'logs':
isAllowed('wowpress_edit_raids');
$GLOBALS['wowpress']['page_title'] = "Logs";
echo "<div style='display:flex;flex-direction:column;gap:2em;'>";
echo '<hr style="width:100%">';
foreach(Log::all() as $log){
?>
<div style="display:flex;flex-direction:column;gap:1em;">
<div>Message: <?=$log->message?></div>
<div>Action: <?=$log->action?></div>
<div>Logged: <?=format_date($log->created_at,"dd.mm.YY HH:MM")?></div>
</div>
<hr style="width:100%">
<?php
}
echo "<div>";
die;
break;
case 'raids': case 'raids':
# isAllowed('wowpress_view_raids'); # isAllowed('wowpress_view_raids');
$GLOBALS['wowpress']['page_title'] = "Raids"; $GLOBALS['wowpress']['page_title'] = "Raids";

View File

@ -3,9 +3,11 @@
use Wenprise\Eloquent\Database; use Wenprise\Eloquent\Database;
use Wenprise\Eloquent\Facades\DB; use Wenprise\Eloquent\Facades\DB;
use WoWPress\Frontend\Icon; use WoWPress\Frontend\Icon;
use WoWPress\Models\Log;
use WoWPress\Models\SKS; use WoWPress\Models\SKS;
set_sidebar_status('top', false); set_sidebar_status('top', false);
$liste = $GLOBALS['wowpress']['liste']; $liste = $GLOBALS['wowpress']['liste'];

View File

@ -3,7 +3,9 @@
namespace WoWPress\Api; namespace WoWPress\Api;
use WoWPress\Models\Character; use WoWPress\Models\Character;
use WoWPress\Models\Log;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
use WoWPress\Models\User;
class WoWAudit extends Api{ class WoWAudit extends Api{
@ -40,6 +42,7 @@ class WoWAudit extends Api{
$url = "raids/".$raid->id_wowaudit; $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); return $this->put($url,$body);

View File

@ -0,0 +1,16 @@
<?php
namespace WoWPress\Database;
class CreateLogTable extends CreateTable
{
public static $table_name = "log";
public static $fields = [
'message' => 'json NOT NULL',
'action' => 'longtext NOT NULL',
'created_at' => 'timestamp NOT NULL',
'updated_at' => 'timestamp NOT NULL',
];
}

View File

@ -0,0 +1,28 @@
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
use WoWPress\Api\BattleNet;
class Log extends Model
{
protected $table = "wowpress_log";
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
const LOG_DEFAULT = "log.default";
const LOG_LOOT = "log.sks.loot";
const LOG_ROLL = "log.sks.roll";
const LOG_SIGNUP = "log.raid.signup";
public static function write(string $message,string $action = Log::LOG_DEFAULT){
$log = new Log();
$log->message = $message;
$log->action = $action;
$log->save();
}
}

View File

@ -84,6 +84,7 @@ class SKS extends Model
$list = SKS::where('list_name', $this->list_name)->get(); $list = SKS::where('list_name', $this->list_name)->get();
$ranks = range(1, count($list)); $ranks = range(1, count($list));
shuffle($ranks); shuffle($ranks);
Log::write(json_encode($list->map->only(['rank','char_name','realm_name'])->values()),Log::LOG_ROLL);
foreach ($list as $key => $sk) { foreach ($list as $key => $sk) {
$sk->rank = $ranks[$key]; $sk->rank = $ranks[$key];
$sk->save(); $sk->save();
@ -93,6 +94,7 @@ class SKS extends Model
public function loot() public function loot()
{ {
$after = $this->getAfter(); $after = $this->getAfter();
$rank = $this->rank;
$last_rank = $this->last_rank; $last_rank = $this->last_rank;
foreach ($after as $id => &$sk) { foreach ($after as $id => &$sk) {
/** /**
@ -116,6 +118,9 @@ class SKS extends Model
$this->rank = $last_rank; $this->rank = $last_rank;
$this->save(); $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) { foreach ($after as $sk) {
$sk->save(); $sk->save();
} }