Refractor SKS

master
Seph 2024-09-20 20:02:10 +02:00
parent f03651b83c
commit b1f5904b91
11 changed files with 715 additions and 207 deletions

View File

@ -9,6 +9,7 @@ use WoWPress\Database\CreateLogTable;
use WoWPress\Database\CreateNotificationTable;
use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable;
use WoWPress\Database\CreateSKSHistoryTable;
use WoWPress\Database\CreateSKSTable;
use WoWPress\Frontend\Widgets\Birthdays;
use WoWPress\Frontend\Widgets\BossKills;
@ -167,6 +168,8 @@ if (!function_exists('wowpress_database')) :
CreateNotificationTable::sql(),
CreateCharListsTable::sql(),
CreateCharListItemTable::sql(),
CreateSKSHistoryTable::sql(),
]);
}

View File

@ -5,6 +5,7 @@ use WoWPress\Models\CharacterList;
use WoWPress\Models\Log;
use WoWPress\Models\Raid;
use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
use WoWPress\Models\User;
add_filter('generate_rewrite_rules', function ($wp_rewrite) {
@ -76,39 +77,28 @@ add_action('template_redirect', function () {
include plugin_dir_path(__FILE__) . '../pages/roster.php';
die;
break;
case 'import_sks':
isAllowed('wowpress_edit_site');
echo "<pre>";
foreach(SKS::getLists() as $list){
$list_there = SKSHistory::where('list_name',$list->list_name)->first();
if(empty($list_there)){
$export = $list->export();
$sks = SKSHistory::createList($list->list_name,$export);
$sks->save();
}
}
die;
break;
case 'sks':
isAllowed('wowpress_view_raids');
$GLOBALS['wowpress']['page_title'] = "SKS-Liste";
$GLOBALS['wowpress']['liste'] = get_query_var('list_name', null);
include plugin_dir_path(__FILE__) . '../pages/sks.php';
die;
break;
case 'logs':
# $cl = new CharacterList();
# $cl->list_name = "Strike-Liste TWW Season 1";
# $cl->border_color = "red";
# $cl->max_count = 6;
# $cl->notify = true;
# $cl->save();
#$cl = CharacterList::find(14);
#$char = Character::first();
#$char = Character::find(8);
#$cl->addItem($char,'Richtig Dumm','2024-09-26');
#dd($cl->characters);
#exit;
isAllowed('wowpress_edit_raids');
$GLOBALS['wowpress']['page_title'] = "Logs";
echo "<div style='display:flex;flex-direction:column;gap:2em;'>";

View File

@ -0,0 +1,38 @@
<?php
// Optionen-Seite erstellen
use WoWPress\Models\SKSHistory;
function wowpress_misc_options_page()
{
global $select_options, $radio_options;
if (! isset($_REQUEST['settings-updated']))
$_REQUEST['settings-updated'] = false; ?>
<div class="wrap">
<h2>Allgemeine Optionen für <?php bloginfo('name'); ?></h2>
<?php if (false !== $_REQUEST['settings-updated']) : ?>
<div class="updated fade">
<p><strong>Einstellungen gespeichert!</strong></p>
</div>
<?php endif; ?>
<h3>SKS-Liste neu Würfeln</h3>
<form method="post" action="/request" enctype="multipart/form-data">
<input type="hidden" name="action" value="rollSKS">
<?php wp_nonce_field('rollSKS', 'rollSKS_nonce'); ?>
<?php foreach (SKSHistory::groupBy('list_name')->get() as $list): ?>
<p class="submit"><input type="submit" name="list_name" class="button-primary" value="<?= $list->list_name ?>" /></p>
<?php endforeach; ?>
</form>
<h3>Neue SKS-Liste</h3>
<form method="post" action="/request" enctype="multipart/form-data">
<input type="hidden" name="action" value="createSKS">
<?php wp_nonce_field('createSKS', 'createSKS_nonce'); ?>
<input type="text" name="list_name" value="" placeholder="Listen-Name">
<p class="submit"><input type="submit" class="button-primary" value="Liste erstellen" /></p>
</form>
</div>
<?php }

View File

@ -2,6 +2,7 @@
require_once('api.php');
require_once('style.php');
require_once('misc.php');
add_action('admin_init', 'theme_options_init');
add_action('admin_menu', 'theme_options_add_page');
@ -18,6 +19,7 @@ function theme_options_init()
{
register_setting('wowpress_options', 'wowpress_api', 'kb_validate_options');
register_setting('wowpress_options', 'wowpress_style', 'kb_validate_options');
register_setting('wowpress_options', 'wowpress_misc', 'kb_validate_options');
}
@ -44,6 +46,16 @@ function theme_options_add_page()
'dashicons-format-image',
26
);
add_menu_page(
'Verschiedenes',
'Verschiedenes',
'wowpress_edit_site',
'wowpress_misc_options',
'wowpress_misc_options_page',
'dashicons-admin-customizer',
26
);
}

View File

@ -5,52 +5,66 @@ use Wenprise\Eloquent\Facades\DB;
use WoWPress\Frontend\Icon;
use WoWPress\Models\Log;
use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
set_sidebar_status('top', false);
get_header();
$liste = $GLOBALS['wowpress']['liste'];
if (!empty($liste)) {
$liste = SKS::where('list_name', $liste)->first();
if (empty($liste->list_name)) {
$liste = SKS::first();
}
}
if (empty($liste->list_name)) {
$listen = SKS::getLists();
get_header();
if (empty($GLOBALS['wowpress']['liste'])):
$listen = SKSHistory::groupBy('list_name')->get();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?>n
<?= $GLOBALS['wowpress']['page_title'] ?>
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto">
<div class="bg-glass shadow p-auto flex flex-col gap-3">
<?php foreach ($listen as $list) : ?>
<a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a>
<?php endforeach; ?>
</div>
</main>
</section>
<?php
} else {
get_header();
<?php else:
$liste = SKSHistory::getLatestList($GLOBALS['wowpress']['liste']);
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="top-title flex flex-col gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?> "<?= $liste->list_name ?>"
SKS-Liste "<?= $liste->list_name ?>"
</div>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<div class="flex flex-row justify-center gap-2">
<?php
if ($prevList = $liste->getPreviousList()):
?>
<form action="/request" method="POST" class="hidden" id="undoSKS">
<?php wp_nonce_field('undoSKS', 'undoSKS_nonce'); ?>
<input type="hidden" name="action" value="undoSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
</form>
<button type="submit" form="undoSKS" class="btn btn-outline btn-deepblue text-white hover:text-alliance">
Rückgängig (Stand vom <?= format_date($prevList->created_at, "dd.MM.yyyy HH:mm") ?>)
</button>
<?php endif;
if ($nextList = $liste->getNextList()):
?>
<form action="/request" method="POST" class="hidden" id="redoSKS">
<?php wp_nonce_field('redoSKS', 'redoSKS_nonce'); ?>
<input type="hidden" name="action" value="redoSKS">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
</form>
<button type="submit" form="redoSKS" class="btn btn-outline btn-deepblue text-white hover:text-alliance">
Wiederherstellen (Stand vom <?= format_date($nextList->created_at, "dd.MM.yyyy HH:mm") ?>)
</button>
<?php endif; ?>
</div>
<? endif; ?>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto">
<div class="bg-glass shadow p-auto flex flex-col gap-2">
<table class="table-auto w-full">
<thead>
<tr class="bg-glass">
@ -64,60 +78,55 @@ if (empty($liste->list_name)) {
<?php endif; ?>
</tr>
</thead>
<tbody class="bg-black">
<?php
foreach (SKS::getList($liste->list_name) as $sk) :
<?php foreach ($liste->list_array as $list_item) :
switch ($list_item['rank']) {
case 1:
$rank_color = "text-[#bfac1d]";
break;
case 2:
$rank_color = "text-[#9c9b9a]";
break;
case 3:
$rank_color = "text-[#9e4f00]";
break;
default:
$rank_color = "text-white";
}
$char = $liste->getCharData($list_item['char']);
?>
<tr class="text-<?= $sk->active ? $sk->character->color : "slate-500" ?> odd:bg-slate-900">
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center">
<form action="/request" method="POST">
<div class="flex flex-row">
<input type="text" class="bg-glass w-full text-center border-0 border-b border-<?= $sk->character->color ?>" name="rank" value="<?= $sk->rank ?>">
<button class="btn btn-outline btn-alliance" title="Manueller Eingriff">
<?= Icon::get('o-wrench') ?>
</button>
<tr class="text-<?= $list_item['active'] ? $char->color : "slate-500" ?> odd:bg-slate-900">
<?php wp_nonce_field('fixSKS', 'fixSKS_nonce'); ?>
<input type="hidden" name="action" value="fixSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
</div>
</form>
</td>
<?php else : ?>
<td class="p-auto text-center"><?= $sk->rank ?></td>
<?php endif; ?>
<td class="p-auto text-center" style="font-size:1.3em"><?= $sk->character->name ?></td>
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $sk->character->realm ?></td>
<td class="p-auto text-center <?= $rank_color ?>"><?= $list_item['rank'] ?></td>
<td class="p-auto text-center" style="font-size:1.3em"><?= $char->name ?></td>
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $char->realm ?></td>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleSKS', 'toggleSKS_nonce'); ?>
<input type="hidden" name="action" value="toggleSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $sk->active ? $sk->character->color : "slate" ?>"><?= $sk->active ? "Aktiv" : "Inaktiv" ?></button>
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="rank" value="<?= $list_item['rank'] ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $list_item['active'] ? $char->color : "slate" ?>"><?= $list_item['active'] ? "Aktiv" : "Inaktiv" ?></button>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($sk->active) : ?>
<?php if ($list_item['active']) : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $sk->character->color ?>"><?= Icon::get('o-sparkles') ?></button>
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $char->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form>
<?php else : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<input type="hidden" name="list_name" value="<?= $liste['list_name'] ?>">
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
<button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form>
<? endif; ?>
@ -127,20 +136,15 @@ if (empty($liste->list_name)) {
</td>
<?php endif; ?>
</tr>
</div>
<?php
endforeach;
?>
</tbody>
</table>
<?php endforeach; ?>
</table>
</div>
</main>
</section>
<?php
}
if (current_user_can('wowpress_edit_raids')) : ?>
<?php
if (current_user_can('wowpress_edit_raids')) : ?>
<div x-data>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
@ -149,38 +153,20 @@ if (current_user_can('wowpress_edit_raids')) : ?>
<div class="flex flex-col gap-2">
<?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?>
<input type="hidden" name="action" value="addSKS">
<input type="hidden" name="list_name" value="<?=$liste->list_name?>">
<input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black">
<input type="text" name="list_name" placeholder="Listenname" value="<?= !empty($liste->list_name) ? $liste->list_name : "" ?>" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</template>
<?php if (!empty($liste->list_name)) : ?>
<template x-teleport="#sidebar_right">
<!--div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Liste neu Würfeln</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('rollSKS', 'rollSKS_nonce'); ?>
<input type="hidden" name="action" value="rollSKS">
<input type="hidden" name="list_name" value="<?= $liste->list_name ?>">
<button type="submit" class="btn btn-outline btn-orange"><?= Icon::get('o-arrow-path') ?> Würfeln</a>
</div>
</form>
</div-->
</template>
<?php endif; ?>
</div>
<?php
endif;
endif;
get_footer();
?>

View File

@ -0,0 +1,186 @@
<?php
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'];
if (!empty($liste)) {
$liste = SKS::where('list_name', $liste)->first();
if (empty($liste->list_name)) {
$liste = SKS::first();
}
}
if (empty($liste->list_name)) {
$listen = SKS::getLists();
get_header();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?>n
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto">
<?php foreach ($listen as $list) : ?>
<a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a>
<?php endforeach; ?>
</div>
</main>
</section>
<?php
} else {
get_header();
?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?> "<?= $liste->list_name ?>"
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto">
<table class="table-auto w-full">
<thead>
<tr class="bg-glass">
<th class="p-auto w-40">Rang</th>
<th class="p-auto">Charakter</th>
<th class="p-auto hidden lg:table-cell">Server</th>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<th class="p-auto hidden lg:table-cell">Status</th>
<th class="p-auto w-0">Aktion</th>
<?php endif; ?>
</tr>
</thead>
<tbody class="bg-black">
<?php
foreach (SKS::getList($liste->list_name) as $sk) :
?>
<tr class="text-<?= $sk->active ? $sk->character->color : "slate-500" ?> odd:bg-slate-900">
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center">
<form action="/request" method="POST">
<div class="flex flex-row">
<input type="text" class="bg-glass w-full text-center border-0 border-b border-<?= $sk->character->color ?>" name="rank" value="<?= $sk->rank ?>">
<button class="btn btn-outline btn-alliance" title="Manueller Eingriff">
<?= Icon::get('o-wrench') ?>
</button>
<?php wp_nonce_field('fixSKS', 'fixSKS_nonce'); ?>
<input type="hidden" name="action" value="fixSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
</div>
</form>
</td>
<?php else : ?>
<td class="p-auto text-center"><?= $sk->rank ?></td>
<?php endif; ?>
<td class="p-auto text-center" style="font-size:1.3em"><?= $sk->character->name ?></td>
<td class="p-auto text-center hidden lg:table-cell" style="font-size:1.3em"><?= $sk->character->realm ?></td>
<?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleSKS', 'toggleSKS_nonce'); ?>
<input type="hidden" name="action" value="toggleSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" class="btn w-full btn-outline btn-<?= $sk->active ? $sk->character->color : "slate" ?>"><?= $sk->active ? "Aktiv" : "Inaktiv" ?></button>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($sk->active) : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Looten" class="btn btn-outline btn-<?= $sk->character->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form>
<?php else : ?>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form>
<? endif; ?>
</div>
</td>
<?php endif; ?>
</tr>
</div>
<?php
endforeach;
?>
</tbody>
</table>
</div>
</main>
</section>
<?php
}
if (current_user_can('wowpress_edit_raids')) : ?>
<div x-data>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Charakter Hinzufügen</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?>
<input type="hidden" name="action" value="addSKS">
<input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black">
<input type="text" name="list_name" placeholder="Listenname" value="<?= !empty($liste->list_name) ? $liste->list_name : "" ?>" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</template>
<?php if (!empty($liste->list_name)) : ?>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
<h4 class="text-xl font-bold text-center mb-2">Liste neu Würfeln</h4>
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('rollSKS', 'rollSKS_nonce'); ?>
<input type="hidden" name="action" value="rollSKS">
<input type="hidden" name="list_name" value="<?= $liste->list_name ?>">
<button type="submit" class="btn btn-outline btn-orange"><?= Icon::get('o-arrow-path') ?> Würfeln</a>
</div>
</form>
</div>
</template>
<?php endif; ?>
</div>
<?php
endif;
get_footer();
?>

View File

@ -14,6 +14,7 @@ use WoWPress\Models\Notification;
use WoWPress\Models\Raid;
use WoWPress\Models\Signup;
use WoWPress\Models\SKS;
use WoWPress\Models\SKSHistory;
use WoWPress\Models\User;
if (empty($_POST['action'])) {
@ -151,40 +152,37 @@ switch ($_POST['action']) {
}
}
break;
case 'createSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['createSKS_nonce']) && wp_verify_nonce($_POST['createSKS_nonce'], 'createSKS')) {
if(isset($_POST['list_name'])){
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
break;
}
$list = new SKSHistory();
$list->list_name = $_POST['list_name'];
$list->active = true;
$list->fillWithRaiders();
$list->save();
}
}
break;
case 'addSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['addSKS_nonce']) && wp_verify_nonce($_POST['addSKS_nonce'], 'addSKS')) {
if (isset($_POST['name']) && isset($_POST['realm']) && isset($_POST['list_name'])) {
$char = Character::whereName($_POST['name'])->whereRealm($_POST['realm'])->first();
if (empty($char->ID)) {
$char = new Character();
$char->name = $_POST['name'];
$char->realm = $_POST['realm'];
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->addChar($_POST['name'],$_POST['realm']);
}
$sks = new SKS();
$sks->char_name = $char->name;
$sks->realm_name = $char->realm;
$sks->list_name = $_POST['list_name'];
$sks->active = true;
$sks_last = SKS::where('list_name', $sks->list_name)->orderBy('rank', 'desc')->first();
$sks->rank = !empty($sks_last->rank) ? $sks_last->rank + 1 : 1;
$sks->save();
}
}
break;
case 'toggleSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['toggleSKS_nonce']) && wp_verify_nonce($_POST['toggleSKS_nonce'], 'toggleSKS')) {
if (isset($_POST['sks_id'])) {
$sks = SKS::find($_POST['sks_id']);
if ($sks->ID) {
$sks->active = !$sks->active;
$sks->save();
if (isset($_POST['list_name']) && isset($_POST['rank'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->toggleActive($_POST['rank']);
}
}
}
@ -192,16 +190,9 @@ switch ($_POST['action']) {
case 'deleteSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['deleteSKS_nonce']) && wp_verify_nonce($_POST['deleteSKS_nonce'], 'deleteSKS')) {
if (isset($_POST['sks_id'])) {
$sks = SKS::find($_POST['sks_id']);
if ($sks->ID) {
$after = $sks->getAfter(false);
foreach ($after as $sk) {
$sk->rank = $sk->rank - 1;
$sk->save();
}
$sks->delete();
if (isset($_POST['list_name']) && isset($_POST['char'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->removeChar($_POST['char']);
}
}
}
@ -209,10 +200,29 @@ switch ($_POST['action']) {
case 'lootSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['lootSKS_nonce']) && wp_verify_nonce($_POST['lootSKS_nonce'], 'lootSKS')) {
if (isset($_POST['sks_id'])) {
$sks = SKS::find($_POST['sks_id']);
if ($sks->ID) {
$sks->loot();
if (isset($_POST['list_name']) && isset($_POST['char'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->loot($_POST['char']);
}
}
}
break;
case 'undoSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['undoSKS_nonce']) && wp_verify_nonce($_POST['undoSKS_nonce'], 'undoSKS')) {
if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->undo();
}
}
}
break;
case 'redoSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['redoSKS_nonce']) && wp_verify_nonce($_POST['redoSKS_nonce'], 'redoSKS')) {
if (isset($_POST['list_name'])) {
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->redo();
}
}
}
@ -221,22 +231,8 @@ switch ($_POST['action']) {
isAllowed('wowpress_edit_raids');
if (isset($_POST['rollSKS_nonce']) && wp_verify_nonce($_POST['rollSKS_nonce'], 'rollSKS')) {
if (isset($_POST['list_name'])) {
$sks = SKS::where('list_name', $_POST['list_name'])->first();
if (!empty($sks->ID)) {
# $sks->roll();
}
}
}
break;
case 'fixSKS':
isAllowed('wowpress_edit_raids');
if (isset($_POST['fixSKS_nonce']) && wp_verify_nonce($_POST['fixSKS_nonce'], 'fixSKS')) {
if (isset($_POST['sks_id']) && isset($_POST['rank'])) {
$sks = SKS::find($_POST['sks_id']);
if ($sks->ID) {
$sks->rank = intval($_POST['rank']);
$sks->save();
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
$list->shuffle();
}
}
}
@ -359,8 +355,8 @@ switch ($_POST['action']) {
}
case 'addList':
isAllowed('wowpress_edit_raids');
if(checkNonce('addList')){
if(isset($_POST['list_name'],$_POST['border_color'])){
if (checkNonce('addList')) {
if (isset($_POST['list_name'], $_POST['border_color'])) {
$list = new CharacterList();
$list->list_name = $_POST['list_name'];
$list->border_color = $_POST['border_color'];
@ -373,31 +369,30 @@ switch ($_POST['action']) {
isAllowed('wowpress_edit_raids');
if (isset($_POST['addCharToList_nonce']) && wp_verify_nonce($_POST['addCharToList_nonce'], 'addCharToList')) {
if(isset($_POST['character_ID']) && isset($_POST['list_id'])){
if (isset($_POST['character_ID']) && isset($_POST['list_id'])) {
$list = CharacterList::find($_POST['list_id']);
$char = Character::find($_POST['character_ID']);
if($char && $list){
if ($char && $list) {
$comment = "";
$date = date('Y-m-d');
if(!empty($_POST['comment'])){
if (!empty($_POST['comment'])) {
$comment = $_POST['comment'];
}
if(!empty($_POST['date'])){
if (!empty($_POST['date'])) {
$date = $_POST['date'];
}
$list->addItem($char,$comment,$date);
$list->addItem($char, $comment, $date);
}
}
}
break;
case 'removeListItem':
isAllowed('wowpress_edit_raids');
if(checkNonce('removeListItem')){
if(isset($_POST['item_id'])){
if (checkNonce('removeListItem')) {
if (isset($_POST['item_id'])) {
$item_id = intval($_POST['item_id']);
$item = CharacterListItem::find($item_id);
if($item){
if ($item) {
$item->delete();
#CharacterListItem::deleteOrphans();
}
@ -405,8 +400,8 @@ switch ($_POST['action']) {
}
break;
case 'cron':
if(isset($_POST['cron'])){
switch($_POST['cron']){
if (isset($_POST['cron'])) {
switch ($_POST['cron']) {
case 'update_applications':
break;

View File

@ -0,0 +1,18 @@
<?php
namespace WoWPress\Database;
class CreateSKSHistoryTable extends CreateTable
{
public static $table_name = "sks_history";
public static $fields = [
'list_name' => 'text NOT NULL',
'list_json' => 'json NOT NULL',
'active' => 'boolean',
'created_at' => 'timestamp NOT NULL',
'updated_at' => 'timestamp NOT NULL',
];
}

View File

@ -27,7 +27,7 @@ class Raid extends Model
{
parent::__construct($attrs);
$options = get_option('wowpress_api');
if (isset($options['bnet'])) {
if (isset($options['wowaudit'])) {
$key = get_option('wowpress_api')['wowaudit']['key'];
} else {
return false;

View File

@ -126,5 +126,19 @@ class SKS extends Model
}
}
public function export(){
$list = $this->getList($this->list_name);
foreach($list as &$list_item){
$list_item['char'] = $list_item['char_name']."-".$list_item['realm_name'];
unset($list_item['list_name']);
unset($list_item['char_name']);
unset($list_item['realm_name']);
unset($list_item['ID']);
}
$list->sort(fn($a,$b) => $a['rank'] - $b['rank']);
return json_encode($list);
}
}

View File

@ -0,0 +1,266 @@
<?php
namespace WoWPress\Models;
use Illuminate\Support\Collection;
use Wenprise\Eloquent\Model;
use WoWPress\Api\BattleNet;
use WoWPress\Api\WoWAudit;
class SKSHistory extends Model
{
protected $table = "wowpress_sks_history";
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public function getLatest()
{
return self::where('list_name', $this->list_name)->where('active', true)->latest('created_at')->first();
}
public static function getLatestList($list_name)
{
return static::where('list_name', $list_name)->where('active', true)->latest('created_at')->first();
}
private function setList($list_array)
{
$this->list_json = json_encode($list_array);
}
public static function createList(string $list_name, $list_json)
{
$sks = new static();
$sks->list_name = $list_name;
if (is_array($list_json)) {
$list_json = json_encode($list_json);
}
$sks->list_json = $list_json;
$sks->active = true;
$sks->fixOrder();
return $sks;
}
public function fillWithRaiders()
{
$options = get_option('wowpress_api');
if (isset($options['wowaudit'])) {
$key = get_option('wowpress_api')['wowaudit']['key'];
} else {
return false;
}
$api = new WoWAudit(null, $key);
$roster = $api->getRoster();
$list = [];
foreach ($roster as $id => $character) {
if (!empty($character['name'])) {
$list[] = [
'char' => $character['name'] . "-" . $character['realm'],
'rank' => $id + 1,
'active' => true,
];
}
}
$this->list_json = json_encode($list);
}
public function getListArrayAttribute()
{
return json_decode($this->list_json, true);
}
public function shuffle()
{
$ranks = range(1, count($this->list_array));
shuffle($ranks);
$list = $this->list_array;
foreach ($list as $id => &$list_item) {
$list_item['rank'] = array_pop($ranks);
}
$this->saveList($list);
}
private function getChar($char)
{
foreach ($this->list_array as $list_item) {
if ($list_item['char'] == $char) {
return $list_item;
}
}
return false;
}
private function sort($list)
{
usort($list, fn($a, $b) => $a['rank'] - $b['rank']);
return $list;
}
public function fixOrder()
{
$data = $this->list_array;
// Separate active and inactive items
$activeItems = [];
$inactiveItems = [];
foreach ($data as $item) {
if ($item["active"]) {
$activeItems[] = $item;
} else {
$inactiveItems[] = $item;
}
}
// Sort the active items by rank
usort($activeItems, function ($a, $b) {
return $a["rank"] - $b["rank"];
});
// Reassign ranks starting from 1 for active items
$rankCounter = 0;
foreach ($activeItems as $key => $item) {
$rankCounter += 1;
foreach ($inactiveItems as $inactive_item) {
if ($inactive_item['rank'] == $rankCounter) {
$rankCounter += 1;
}
}
$item["rank"] = $rankCounter;
$activeItems[$key] = $item;
}
// Merge active and inactive items back
$data = array_merge($inactiveItems, $activeItems);
$data = $this->sort($data);
$this->setList($data);
}
public function loot($char)
{
if ($looter = $this->getChar($char)) {
if ($looter['active']) {
$list = $this->list_array;
foreach ($list as $id => &$list_item) {
if ($list_item['rank'] == $looter['rank']) {
$list[$id]['rank'] = PHP_INT_MAX; //Ans Ende der Liste mit dem Looter
break;
}
}
return $this->saveList($list);
}
}
return false;
}
public function saveList($list_array)
{
$this->active = false;
$this->save();
$new = self::createList($this->list_name, $list_array);
$new->save();
return $new;
}
public function toggleActive($rank)
{
$list = $this->list_array;
foreach ($list as &$list_item) {
if ($rank == $list_item['rank']) {
$list_item['active'] = !$list_item['active'];
return $this->saveList($list);
}
}
return false;
}
public function getList()
{
return $this->list_array;
}
public function getCharData($char)
{
list($name, $realm) = explode("-", $char);
$character = Character::whereName($name)->whereRealm($realm)->first();
if (empty($character)) {
$character = new Character();
$character->name = $name;
$character->realm = $realm;
$character->class = "priest";
}
return $character;
}
public function getPreviousList()
{
return SKSHistory::where('list_name', $this->list_name)->whereNot('active')->where('created_at', '<', $this->created_at)->latest()->first();
}
public function getNextList()
{
return SKSHistory::where('list_name', $this->list_name)->whereNot('active')->where('created_at', '>', $this->created_at)->first();
}
public function undo()
{
$lastItem = $this->getPreviousList();
$lastItem->active = true;
$lastItem->save();
$this->active = false;
$this->save();
}
public function redo()
{
$nextItem = $this->getNextList();
$nextItem->active = true;
$nextItem->save();
$this->active = false;
$this->save();
}
public function removeChar($char, $realm = "")
{
if ($realm) {
$char = $char . "-" . $realm;
}
$list = $this->list_array;
foreach ($list as $id => $list_item) {
if (!$list_item['active'] && $list_item['char'] == $char) {
unset($list[$id]);
}
}
$this->saveList($list);
}
public function addChar($char, $realm = "")
{
if ($realm) {
$char = $char . "-" . $realm;
}
$list = $this->list_array;
foreach ($list as $list_item) {
if ($list_item['char'] == $char) {
return false;
}
}
$list[] = [
'rank' => PHP_INT_MAX,
'active' => true,
'char' => $char
];
$this->saveList($list);
}
}