Compare commits
No commits in common. "b9d1865186ebc457f4d354c0c41f81f4cfceeeb0" and "f03651b83c203af54efe28496da39541128b5196" have entirely different histories.
b9d1865186
...
f03651b83c
|
@ -57,7 +57,7 @@
|
|||
--color-deepblue: #000032;
|
||||
--color-alliance: #f7941e;
|
||||
--color-background: var(--color-deepblue);
|
||||
--color-glass: color-mix(in lch, transparent 42%, var(--color-background));
|
||||
--color-glass: color-mix(in lch, transparent 75%, var(--color-background));
|
||||
}
|
||||
|
||||
.p-auto {
|
||||
|
|
|
@ -9,7 +9,6 @@ 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;
|
||||
|
@ -168,8 +167,6 @@ if (!function_exists('wowpress_database')) :
|
|||
CreateNotificationTable::sql(),
|
||||
CreateCharListsTable::sql(),
|
||||
CreateCharListItemTable::sql(),
|
||||
CreateSKSHistoryTable::sql(),
|
||||
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ 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) {
|
||||
|
@ -77,28 +76,39 @@ 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;'>";
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
<?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 }
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
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');
|
||||
|
@ -19,7 +18,6 @@ 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');
|
||||
|
||||
}
|
||||
|
||||
|
@ -46,16 +44,6 @@ 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use WoWPress\Models\User;
|
|||
global $widget_area;
|
||||
set_sidebar_status('top', false);
|
||||
|
||||
$characters = Character::orderBy('name')->get();
|
||||
$characters = Character::orderBy('rank')->get();
|
||||
get_header();
|
||||
|
||||
?>
|
||||
|
@ -28,6 +28,7 @@ get_header();
|
|||
<tr>
|
||||
<td class="p-auto">Name</td>
|
||||
<td class="p-auto hidden lg:table-cell">Klasse</td>
|
||||
<td class="p-auto hidden lg:table-cell">Rang</td>
|
||||
<td class="p-auto hidden lg:table-cell">Server</td>
|
||||
<td class="p-auto hidden lg:table-cell">Gilde</td>
|
||||
|
||||
|
@ -58,6 +59,7 @@ get_header();
|
|||
<?= translate_string($char->spec) ?></span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="p-auto hidden lg:table-cell"><?= $char->rank ?></td>
|
||||
<td class="p-auto hidden lg:table-cell"><?= $char->realm ?></td>
|
||||
<td class="p-auto hidden lg:table-cell"><?= $char->guild ?></td>
|
||||
|
||||
|
|
|
@ -5,66 +5,52 @@ 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();
|
||||
|
||||
if (empty($GLOBALS['wowpress']['liste'])):
|
||||
$listen = SKSHistory::groupBy('list_name')->get();
|
||||
$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'] ?>
|
||||
<?= $GLOBALS['wowpress']['page_title'] ?>n
|
||||
</div>
|
||||
</div>
|
||||
<section id="primary">
|
||||
<main id="main">
|
||||
<div class="bg-glass shadow p-auto flex flex-col gap-3">
|
||||
<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:
|
||||
$liste = SKSHistory::getLatestList($GLOBALS['wowpress']['liste']);
|
||||
?>
|
||||
<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">
|
||||
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()):
|
||||
} else {
|
||||
get_header();
|
||||
?>
|
||||
<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 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>
|
||||
<? endif; ?>
|
||||
</div>
|
||||
<section id="primary">
|
||||
<main id="main">
|
||||
<div class="bg-glass shadow p-auto flex flex-col gap-2">
|
||||
<div class="bg-glass shadow p-auto">
|
||||
<table class="table-auto w-full">
|
||||
<thead>
|
||||
<tr class="bg-glass">
|
||||
|
@ -78,55 +64,60 @@ if (empty($GLOBALS['wowpress']['liste'])):
|
|||
<?php endif; ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<?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']);
|
||||
<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">
|
||||
|
||||
<tr class="text-<?= $list_item['active'] ? $char->color : "slate-500" ?> odd:bg-slate-900">
|
||||
<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>
|
||||
|
||||
<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 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="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>
|
||||
<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 ($list_item['active']) : ?>
|
||||
<?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="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>
|
||||
<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="list_name" value="<?= $liste['list_name'] ?>">
|
||||
<input type="hidden" name="char" value="<?= $list_item['char'] ?>">
|
||||
<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; ?>
|
||||
|
@ -136,14 +127,19 @@ if (empty($GLOBALS['wowpress']['liste'])):
|
|||
</td>
|
||||
<?php endif; ?>
|
||||
</tr>
|
||||
|
||||
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
</div>
|
||||
</main>
|
||||
</section>
|
||||
<?php
|
||||
}
|
||||
|
||||
if (current_user_can('wowpress_edit_raids')) : ?>
|
||||
<div x-data>
|
||||
<template x-teleport="#sidebar_right">
|
||||
|
@ -153,20 +149,38 @@ if (empty($GLOBALS['wowpress']['liste'])):
|
|||
<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();
|
||||
|
||||
|
||||
|
||||
?>
|
|
@ -1,186 +0,0 @@
|
|||
<?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();
|
||||
|
||||
|
||||
|
||||
?>
|
|
@ -14,7 +14,6 @@ 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'])) {
|
||||
|
@ -37,7 +36,6 @@ switch ($_POST['action']) {
|
|||
$char = new Character();
|
||||
$char->name = $_POST['name'];
|
||||
$char->realm = $_POST['realm'];
|
||||
$char->save();
|
||||
$char->updateFromAPI();
|
||||
$char->updateMedia();
|
||||
}
|
||||
|
@ -153,37 +151,40 @@ 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'])) {
|
||||
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
|
||||
$list->addChar($_POST['name'],$_POST['realm']);
|
||||
$char = Character::whereName($_POST['name'])->whereRealm($_POST['realm'])->first();
|
||||
if (empty($char->ID)) {
|
||||
$char = new Character();
|
||||
$char->name = $_POST['name'];
|
||||
$char->realm = $_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['list_name']) && isset($_POST['rank'])) {
|
||||
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
|
||||
$list->toggleActive($_POST['rank']);
|
||||
if (isset($_POST['sks_id'])) {
|
||||
$sks = SKS::find($_POST['sks_id']);
|
||||
if ($sks->ID) {
|
||||
$sks->active = !$sks->active;
|
||||
$sks->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -191,9 +192,16 @@ switch ($_POST['action']) {
|
|||
case 'deleteSKS':
|
||||
isAllowed('wowpress_edit_raids');
|
||||
if (isset($_POST['deleteSKS_nonce']) && wp_verify_nonce($_POST['deleteSKS_nonce'], 'deleteSKS')) {
|
||||
if (isset($_POST['list_name']) && isset($_POST['char'])) {
|
||||
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
|
||||
$list->removeChar($_POST['char']);
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -201,29 +209,10 @@ switch ($_POST['action']) {
|
|||
case 'lootSKS':
|
||||
isAllowed('wowpress_edit_raids');
|
||||
if (isset($_POST['lootSKS_nonce']) && wp_verify_nonce($_POST['lootSKS_nonce'], 'lootSKS')) {
|
||||
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();
|
||||
if (isset($_POST['sks_id'])) {
|
||||
$sks = SKS::find($_POST['sks_id']);
|
||||
if ($sks->ID) {
|
||||
$sks->loot();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -232,8 +221,22 @@ switch ($_POST['action']) {
|
|||
isAllowed('wowpress_edit_raids');
|
||||
if (isset($_POST['rollSKS_nonce']) && wp_verify_nonce($_POST['rollSKS_nonce'], 'rollSKS')) {
|
||||
if (isset($_POST['list_name'])) {
|
||||
if ($list = SKSHistory::getLatestList($_POST['list_name'])) {
|
||||
$list->shuffle();
|
||||
$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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -385,6 +388,7 @@ switch ($_POST['action']) {
|
|||
$list->addItem($char,$comment,$date);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 'removeListItem':
|
||||
|
|
|
@ -103,12 +103,8 @@ abstract class Api
|
|||
$headers = array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json));
|
||||
$headers[] = 'Accept: application/json';
|
||||
if ($headerauth) {
|
||||
if (!is_bool($headerauth)) {
|
||||
$headers[] = 'Authorization: Bearer ' . $headerauth;
|
||||
} else {
|
||||
$headers[] = 'Authorization: ' . $this->api_key;
|
||||
}
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
|
||||
|
@ -150,6 +146,7 @@ abstract class Api
|
|||
|
||||
$cache = Cache::where('p_key', $cache_key)->get()->last();
|
||||
|
||||
|
||||
if(empty($cache->ID) || $cache->isExpired($expiration)){
|
||||
$ch = curl_init();
|
||||
if (!empty($parameter)) {
|
||||
|
@ -166,12 +163,8 @@ abstract class Api
|
|||
$headers = array();
|
||||
$headers[] = 'Accept: application/json';
|
||||
if ($headerauth) {
|
||||
if (!is_bool($headerauth)) {
|
||||
$headers[] = 'Authorization: Bearer ' . $headerauth;
|
||||
} else {
|
||||
$headers[] = 'Authorization: ' . $this->api_key;
|
||||
}
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
@ -187,8 +180,6 @@ abstract class Api
|
|||
$from_cache = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (!is_array($cache->value)) {
|
||||
return ['error' => true];
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ class BattleNet extends Api{
|
|||
$data = $this->get("/profile/wow/character/$realm/$name", [
|
||||
'namespace' => 'profile-eu',
|
||||
'locale' => 'en_US',
|
||||
# 'access_token' => $this->bearer()
|
||||
], $this->bearer(), $timeout);
|
||||
'access_token' => $this->bearer()
|
||||
], false, $timeout);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -35,13 +35,13 @@ class BattleNet extends Api{
|
|||
$data = $this->get($guild, [
|
||||
'namespace' => 'profile-eu',
|
||||
'locale' => 'en_US',
|
||||
#'access_token' => $this->bearer()
|
||||
], $this->bearer(), -1);
|
||||
'access_token' => $this->bearer()
|
||||
], false, -1);
|
||||
$data = $this->get($data['roster']['href'], [
|
||||
'namespace' => 'profile-eu',
|
||||
'locale' => 'en_US',
|
||||
#'access_token' => $this->bearer()
|
||||
], $this->bearer(), -1);
|
||||
'access_token' => $this->bearer()
|
||||
], false, -1);
|
||||
foreach($data['members'] as $member){
|
||||
if($member['character']['name'] == $name && $member['character']['realm']['slug'] == $char['realm']['slug']){
|
||||
$guild = $char['guild']['name'];
|
||||
|
@ -62,8 +62,8 @@ class BattleNet extends Api{
|
|||
$data = $this->get("/profile/wow/character/$realm/$name/character-media", [
|
||||
'namespace' => 'profile-eu',
|
||||
'locale' => 'en_US',
|
||||
# 'access_token' => $this->bearer()
|
||||
], $this->bearer(), $timeout);
|
||||
'access_token' => $this->bearer()
|
||||
], false, $timeout);
|
||||
|
||||
if(!empty($data['code']) && $data['code'] == 403){
|
||||
# var_dump($data);
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
<?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',
|
||||
];
|
||||
|
||||
}
|
|
@ -29,18 +29,15 @@ class Character extends Model
|
|||
$this->api = new BattleNet($id,$key);
|
||||
}
|
||||
|
||||
public function lists()
|
||||
{
|
||||
public function lists(){
|
||||
return $this->belongsToMany(CharacterList::class,'wowpress_charlists_item','list_id','character_id')->withPivot('comment','date','id');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
public function user(){
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function getCanEditAttribute()
|
||||
{
|
||||
public function getCanEditAttribute(){
|
||||
if(empty($this->user->ID)){
|
||||
return current_user_can('wowpress_edit_raids');
|
||||
}
|
||||
|
@ -57,41 +54,29 @@ class Character extends Model
|
|||
return $string;
|
||||
}
|
||||
|
||||
public function getRankAttribute($rank)
|
||||
{
|
||||
public function getRankAttribute($rank){
|
||||
switch($rank){
|
||||
case 0:
|
||||
return "Gildenmeister";
|
||||
case 0: return "Gildenmeister";
|
||||
break;
|
||||
case 1:
|
||||
return "Offizier";
|
||||
case 1: return "Offizier";
|
||||
break;
|
||||
case 2:
|
||||
return "Offi-Twink";
|
||||
case 2: return "Offi-Twink";
|
||||
break;
|
||||
case 3:
|
||||
return "Raidlead";
|
||||
case 3: return "Raidlead";
|
||||
break;
|
||||
case 4:
|
||||
return "Ehrenmitglied";
|
||||
case 4: return "Ehrenmitglied";
|
||||
break;
|
||||
case 5:
|
||||
return "Raider";
|
||||
case 5: return "Raider";
|
||||
break;
|
||||
case 6:
|
||||
return "Raider-Twink";
|
||||
case 6: return "Raider-Twink";
|
||||
break;
|
||||
case 7:
|
||||
return "F&F";
|
||||
case 7: return "F&F";
|
||||
break;
|
||||
case 8:
|
||||
return "Novize";
|
||||
case 8: return "Novize";
|
||||
break;
|
||||
case 9:
|
||||
return "Sleeper";
|
||||
case 9: return "Sleeper";
|
||||
break;
|
||||
default:
|
||||
return "Gast";
|
||||
default: return "Gast";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,8 +91,7 @@ class Character extends Model
|
|||
return get_template_directory_uri() . "/icons/class/$classname/$classname.png";
|
||||
}
|
||||
|
||||
public static function classIconLink($class)
|
||||
{
|
||||
public static function classIconLink($class){
|
||||
$classname = (new self())->sanitize($class);
|
||||
return get_template_directory_uri() . "/icons/class/$classname/$classname.png";
|
||||
}
|
||||
|
@ -119,8 +103,7 @@ class Character extends Model
|
|||
return get_template_directory_uri() . "/icons/class/$classname/$specname.png";
|
||||
}
|
||||
|
||||
public static function specIconLink($class, $spec)
|
||||
{
|
||||
public static function specIconLink($class,$spec){
|
||||
$classname = (new self())->sanitize($class);
|
||||
$specname = (new self())->sanitize($spec);
|
||||
return get_template_directory_uri() . "/icons/class/$classname/$specname.png";
|
||||
|
@ -147,8 +130,7 @@ class Character extends Model
|
|||
return $char_from_api;
|
||||
}
|
||||
|
||||
public function updateMedia($force = false)
|
||||
{
|
||||
public function updateMedia($force = false){
|
||||
if(empty($this->id_blizz)){
|
||||
return false;
|
||||
}
|
||||
|
@ -160,19 +142,11 @@ class Character extends Model
|
|||
$id = $this->id_blizz;
|
||||
$mod = $id % 256;
|
||||
$realm = $this->sanitize($this->realm,'-');
|
||||
$data = $this->api->getMedia($this->name, $this->realm, 0);
|
||||
if (key_exists("assets", $data)) {
|
||||
foreach ($data['assets'] as $asset) {
|
||||
if ($asset['key'] == 'avatar') {
|
||||
file_put_contents($character_dir . "avatar.jpg", file_get_contents($asset['value']));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$img_url = "https://render.worldofwarcraft.com/eu/character/$realm/$mod/$id-avatar.jpg";
|
||||
file_put_contents($character_dir."avatar.jpg",file_get_contents($img_url));
|
||||
}
|
||||
|
||||
public function getAvatarAttribute()
|
||||
{
|
||||
public function getAvatarAttribute(){
|
||||
$character_dir = wp_upload_dir()['basedir']."/characters/".$this->ID."/avatar.jpg";
|
||||
$character_dir_uri = wp_upload_dir()['baseurl']."/characters/".$this->ID."/avatar.jpg";
|
||||
if(file_exists($character_dir)){
|
||||
|
@ -180,11 +154,11 @@ class Character extends Model
|
|||
}else{
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function getClassButtonAttribute()
|
||||
{
|
||||
public function getClassButtonAttribute(){
|
||||
require(get_template_directory()."/template-parts/components/class-button.php");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ class Raid extends Model
|
|||
{
|
||||
parent::__construct($attrs);
|
||||
$options = get_option('wowpress_api');
|
||||
if (isset($options['wowaudit'])) {
|
||||
if (isset($options['bnet'])) {
|
||||
$key = get_option('wowpress_api')['wowaudit']['key'];
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -126,19 +126,5 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,266 +0,0 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue