Compare commits

...

2 Commits

Author SHA1 Message Date
Seph b9d1865186 API-Fixes 2024-11-02 20:27:01 +01:00
Seph b1f5904b91 Refractor SKS 2024-09-20 20:02:10 +02:00
16 changed files with 861 additions and 319 deletions

View File

@ -57,7 +57,7 @@
--color-deepblue: #000032;
--color-alliance: #f7941e;
--color-background: var(--color-deepblue);
--color-glass: color-mix(in lch, transparent 75%, var(--color-background));
--color-glass: color-mix(in lch, transparent 42%, var(--color-background));
}
.p-auto {

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

@ -10,7 +10,7 @@ use WoWPress\Models\User;
global $widget_area;
set_sidebar_status('top', false);
$characters = Character::orderBy('rank')->get();
$characters = Character::orderBy('name')->get();
get_header();
?>
@ -28,7 +28,6 @@ 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>
@ -59,22 +58,21 @@ 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>
<?php if (current_user_can('wowpress_edit_characters')) : ?>
<td class="p-auto hidden lg:table-cell">
<form action="/request" method="POST">
<?php wp_nonce_field('toggleRaidchar', 'toggleRaidchar_nonce'); ?>
<input type="hidden" name="action" value="toggleRaidchar">
<input type="hidden" name="id" value="<?= $char->ID ?>">
<?php if ($char->raidchar) : ?>
<button type="submit" class="btn btn-<?=$char->color?>"><?=Icon::get('o-check-circle')?> Ja</button>
<?php else : ?>
<button type="submit" class="btn btn-gray"><?=Icon::get('o-no-symbol')?> Nein</button>
<?php endif; ?>
</form>
<form action="/request" method="POST">
<?php wp_nonce_field('toggleRaidchar', 'toggleRaidchar_nonce'); ?>
<input type="hidden" name="action" value="toggleRaidchar">
<input type="hidden" name="id" value="<?= $char->ID ?>">
<?php if ($char->raidchar) : ?>
<button type="submit" class="btn btn-<?= $char->color ?>"><?= Icon::get('o-check-circle') ?> Ja</button>
<?php else : ?>
<button type="submit" class="btn btn-gray"><?= Icon::get('o-no-symbol') ?> Nein</button>
<?php endif; ?>
</form>
</td>
<td class="p-auto hidden lg:table-cell">

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,83 +78,73 @@ if (empty($liste->list_name)) {
<?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">
<?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']);
?>
<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 ?>">
<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>
</div>
<?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>
</form>
</td>
<td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end">
<?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="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="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; ?>
</form>
</div>
</td>
<?php endif; ?>
</tr>
</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>
<?php endforeach; ?>
</table>
</div>
<?php
endforeach;
?>
</tbody>
</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'])) {
@ -36,6 +37,7 @@ switch ($_POST['action']) {
$char = new Character();
$char->name = $_POST['name'];
$char->realm = $_POST['realm'];
$char->save();
$char->updateFromAPI();
$char->updateMedia();
}
@ -151,40 +153,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 +191,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 +201,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 +232,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 +356,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,40 +370,39 @@ 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();
#CharacterListItem::deleteOrphans();
}
}
}
}
break;
case 'cron':
if(isset($_POST['cron'])){
switch($_POST['cron']){
if (isset($_POST['cron'])) {
switch ($_POST['cron']) {
case 'update_applications':
break;

View File

@ -71,7 +71,7 @@ abstract class Api
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
@ -103,7 +103,11 @@ abstract class Api
$headers = array('Content-Type: application/json', 'Content-Length: ' . strlen($data_json));
$headers[] = 'Accept: application/json';
if ($headerauth) {
$headers[] = 'Authorization: ' . $this->api_key;
if (!is_bool($headerauth)) {
$headers[] = 'Authorization: Bearer ' . $headerauth;
} else {
$headers[] = 'Authorization: ' . $this->api_key;
}
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
@ -130,10 +134,10 @@ abstract class Api
$result = "{}";
if (!str_contains($url, "https:/")) {
$url = $this->api_url . $url;
}else{
} else {
$parts = parse_url($url);
parse_str($parts['query'], $query);
$parameter = array_merge($parameter,$query);
$parameter = array_merge($parameter, $query);
$url = strtok($url, '?');
}
@ -146,39 +150,44 @@ 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)) {
$parameter = http_build_query($parameter);
curl_setopt($ch, CURLOPT_URL, $url . "?" . $parameter);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
if (empty($cache->ID) || $cache->isExpired($expiration)) {
$ch = curl_init();
if (!empty($parameter)) {
$parameter = http_build_query($parameter);
curl_setopt($ch, CURLOPT_URL, $url . "?" . $parameter);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
$headers = array();
$headers[] = 'Accept: application/json';
if ($headerauth) {
$headers[] = 'Authorization: ' . $this->api_key;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$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);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$result = substr($response, $header_size);
if (curl_errno($ch)) {
error_log('Error:' . curl_error($ch));
return false;
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$result = substr($response, $header_size);
if (curl_errno($ch)) {
error_log('Error:' . curl_error($ch));
return false;
}
$cache = Cache::upsert($cache_key, $result);
$from_cache = false;
}
$cache = Cache::upsert($cache_key, $result);
$from_cache = false;
}
if (!is_array($cache->value)) {
return ['error' => true];

View File

@ -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()
], false, $timeout);
# 'access_token' => $this->bearer()
], $this->bearer(), $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()
], false, -1);
#'access_token' => $this->bearer()
], $this->bearer(), -1);
$data = $this->get($data['roster']['href'], [
'namespace' => 'profile-eu',
'locale' => 'en_US',
'access_token' => $this->bearer()
], false, -1);
#'access_token' => $this->bearer()
], $this->bearer(), -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()
], false, $timeout);
# 'access_token' => $this->bearer()
], $this->bearer(), $timeout);
if(!empty($data['code']) && $data['code'] == 403){
# var_dump($data);

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

@ -19,26 +19,29 @@ class Character extends Model
{
parent::__construct($attrs);
$options = get_option('wowpress_api');
if(isset($options['bnet'])){
if (isset($options['bnet'])) {
$key = get_option('wowpress_api')['bnet']['key'];
$id = get_option('wowpress_api')['bnet']['id'];
}else{
} else {
return false;
}
$this->api = new BattleNet($id,$key);
$this->api = new BattleNet($id, $key);
}
public function lists(){
return $this->belongsToMany(CharacterList::class,'wowpress_charlists_item','list_id','character_id')->withPivot('comment','date','id');
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(){
if(empty($this->user->ID)){
public function getCanEditAttribute()
{
if (empty($this->user->ID)) {
return current_user_can('wowpress_edit_raids');
}
return current_user_can('wowpress_edit_raids') || (get_current_user_id() == $this->user->ID);
@ -46,7 +49,7 @@ class Character extends Model
public function sanitize($string,$delimiter_space="")
public function sanitize($string, $delimiter_space = "")
{
$string = strtolower(str_replace(" ", $delimiter_space, $string));
$string = strtolower(str_replace("'", "", $string));
@ -54,29 +57,41 @@ class Character extends Model
return $string;
}
public function getRankAttribute($rank){
switch($rank){
case 0: return "Gildenmeister";
break;
case 1: return "Offizier";
break;
case 2: return "Offi-Twink";
break;
case 3: return "Raidlead";
break;
case 4: return "Ehrenmitglied";
break;
case 5: return "Raider";
break;
case 6: return "Raider-Twink";
break;
case 7: return "F&F";
break;
case 8: return "Novize";
break;
case 9: return "Sleeper";
break;
default: return "Gast";
public function getRankAttribute($rank)
{
switch ($rank) {
case 0:
return "Gildenmeister";
break;
case 1:
return "Offizier";
break;
case 2:
return "Offi-Twink";
break;
case 3:
return "Raidlead";
break;
case 4:
return "Ehrenmitglied";
break;
case 5:
return "Raider";
break;
case 6:
return "Raider-Twink";
break;
case 7:
return "F&F";
break;
case 8:
return "Novize";
break;
case 9:
return "Sleeper";
break;
default:
return "Gast";
}
}
@ -91,7 +106,8 @@ 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";
}
@ -103,7 +119,8 @@ 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";
@ -111,54 +128,63 @@ class Character extends Model
public function updateFromAPI()
{
$realm = $this->sanitize($this->realm,"-");
$char_from_api = $this->api->getCharacter($this->name,$realm);
if(!array_key_exists('character_class',$char_from_api)){
$realm = $this->sanitize($this->realm, "-");
$char_from_api = $this->api->getCharacter($this->name, $realm);
if (!array_key_exists('character_class', $char_from_api)) {
return false;
}
$this->class = $char_from_api['character_class']['name'];
$this->spec = $char_from_api['active_spec']['name'];
$this->id_blizz = $char_from_api['id'];
$guild_data = $this->api->getGuildRank($this->name,$realm);
if(!empty($guild_data['rank'])){
$this->guild = $guild_data['guild'];
$this->rank = $guild_data['rank'];
}else{
$guild_data = $this->api->getGuildRank($this->name, $realm);
if (!empty($guild_data['rank'])) {
$this->guild = $guild_data['guild'];
$this->rank = $guild_data['rank'];
} else {
$this->rank = 99;
}
$this->save();
return $char_from_api;
}
public function updateMedia($force = false){
if(empty($this->id_blizz)){
public function updateMedia($force = false)
{
if (empty($this->id_blizz)) {
return false;
}
$character_dir = wp_upload_dir()['basedir']."/characters/".$this->ID."/";
if(!is_dir($character_dir)){
mkdir($character_dir,0777,true);
$character_dir = wp_upload_dir()['basedir'] . "/characters/" . $this->ID . "/";
if (!is_dir($character_dir)) {
mkdir($character_dir, 0777, true);
}
$id = $this->id_blizz;
$mod = $id % 256;
$realm = $this->sanitize($this->realm,'-');
$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));
$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;
}
}
}
}
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)){
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)) {
return $character_dir_uri;
}else{
} else {
return "";
}
}
public function getClassButtonAttribute(){
require(get_template_directory()."/template-parts/components/class-button.php");
public function getClassButtonAttribute()
{
require(get_template_directory() . "/template-parts/components/class-button.php");
}
}

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);
}
}