SKS und Widgets

master
Seph 2024-04-23 22:43:54 +02:00
parent b116f4f090
commit 775966f0dd
18 changed files with 588 additions and 241 deletions

View File

@ -16,6 +16,7 @@ if (empty($chars) || empty($chars->first())) {
$chars = [$this->character]; $chars = [$this->character];
} }
?> ?>
<div class="flex <?= $vertical ? "flex-col" : "flex-row" ?> border border-<?= $this->character->color ?> shadow" x-data="{open : false}"> <div class="flex <?= $vertical ? "flex-col" : "flex-row" ?> border border-<?= $this->character->color ?> shadow" x-data="{open : false}">
@ -42,7 +43,7 @@ if (empty($chars) || empty($chars->first())) {
<form id="<?= $id ?>" action="/request" method="POST"> <form id="<?= $id ?>" action="/request" method="POST">
<?php wp_nonce_field('signupRaid', 'signupRaid_nonce'); ?> <?php wp_nonce_field('signupRaid', 'signupRaid_nonce'); ?>
<input type="hidden" name="action" value="signupRaid"> <input type="hidden" name="action" value="signupRaid">
<input type="hidden" name="raid_id" value="<?= $this->raid_ID ?>"> <input type="hidden" name="raid_id" value="<?= $this->raid->ID ?>">
<div class="grid p-auto gap-auto"> <div class="grid p-auto gap-auto">

View File

@ -5,6 +5,8 @@ use WoWPress\Database\CreateCharacterTable;
use WoWPress\Database\CreateRaidTable; use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable; use WoWPress\Database\CreateSignupTable;
use WoWPress\Database\CreateSKSTable; use WoWPress\Database\CreateSKSTable;
use WoWPress\Frontend\Widgets\BossKills;
use WoWPress\Frontend\Widgets\CharacterSearch;
use WoWPress\Frontend\Widgets\RaidSignup; use WoWPress\Frontend\Widgets\RaidSignup;
use WoWPress\Models\Character; use WoWPress\Models\Character;
@ -461,6 +463,8 @@ function wowpress_add_category_meta($taxonomy)
/** Widgets */ /** Widgets */
$widget_raid_signup = new RaidSignup(); $widget_raid_signup = new RaidSignup();
$widget_boss_kills = new BossKills();
$widget_char_search = new CharacterSearch();

View File

@ -35,9 +35,9 @@ global $user;
<template x-data x-teleport="#sidebar_left"> <template x-data x-teleport="#sidebar_left">
<div class="bg-glass shadow p-auto order-1"> <div class="bg-glass shadow p-auto order-1">
<div class="flex flex-row justify-between"> <div class="flex flex-row justify-between">
<div>Hallo <?= $user->login ?></div> <div>Hallo <?= $user->username ?></div>
<?php if (!$user->ID) : ?> <?php if (!$user->ID) : ?>
<div>Bitte <a href="/wp-login.php" class="text-alliance underline">einloggen</a>:)</div> <div>Bitte <a href="/wp-login.php" class="text-alliance underline">einloggen</a> :)</div>
<?php else : ?> <?php else : ?>
<div><a href="/wp-login.php?action=logout" class="text-alliance underline"><?= Icon::get('o-power') ?></a></div> <div><a href="/wp-login.php?action=logout" class="text-alliance underline"><?= Icon::get('o-power') ?></a></div>

View File

@ -11,7 +11,7 @@ add_filter('generate_rewrite_rules', function ($wp_rewrite) {
['raid/(\d+)/?$' => 'index.php?wowpress_page=raid&raid_id=$matches[1]'], ['raid/(\d+)/?$' => 'index.php?wowpress_page=raid&raid_id=$matches[1]'],
['request/?$' => 'index.php?wowpress_page=form_request'], ['request/?$' => 'index.php?wowpress_page=form_request'],
['sks/?$' => 'index.php?wowpress_page=sks'], ['sks/?$' => 'index.php?wowpress_page=sks'],
['sks/(\d+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'], ['sks/([A-Za-z-]+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'],
$wp_rewrite->rules $wp_rewrite->rules
); );
}); });

View File

@ -57,14 +57,13 @@ get_header();
} }
} }
?> ?>
<div class="bg-glass p-auto text-center <?php if (count($has_raid) > 0) { ?> glow shadow-<?= $has_raid[0]->color ?> <?php } ?> grid grid-cols-2 grid-rows-2"> <div class="bg-glass p-auto text-center aspect-[1/0.8] <?php if (count($has_raid) > 0) { ?> glow shadow-<?= $has_raid[0]->color ?> <?php } ?> grid grid-cols-2 grid-rows-2" <?php if (count($has_raid) > 0) { ?> style="background-position:center;background-size: cover;background-image:url('<?=$has_raid[0]->thumbnail?>')" <?php } ?>>
<div class="text-left"><?= date('d', strtotime("$year-$month-$i")) ?></div> <div class="text-left"><?= date('d', strtotime("$year-$month-$i")) ?></div>
<div class="text-right"><?= format_date("$year-$month-$i", 'E') ?></div> <div class="text-right"><?= format_date("$year-$month-$i", 'E') ?></div>
<?php <?php
foreach ($has_raid as $raid) { foreach ($has_raid as $raid) {
?> ?>
<a href="<?= $raid->link ?>" class="group" style="grid-area: 2 / 1 / 3 / 3;"> <a href="<?= $raid->link ?>" class="group" style="grid-area: 2 / 1 / 3 / 3;">
<div class="group-hover:text-<?= $raid->color ?> bg-<?= $raid->color ?>-200"><?= $raid->title ?></div> <div class="group-hover:text-<?= $raid->color ?> bg-<?= $raid->color ?>-200"><?= $raid->title ?></div>
<?php if ($raid->difficulty) : ?><div class="text-sm text-slate-500">(<?= $raid->difficulty ?>)</div><?php endif; ?> <?php if ($raid->difficulty) : ?><div class="text-sm text-slate-500">(<?= $raid->difficulty ?>)</div><?php endif; ?>
@ -85,7 +84,7 @@ get_header();
<?php foreach ($raids as $raid) : ?> <?php foreach ($raids as $raid) : ?>
<a href="<?= $raid->link ?>" class="group text-center p-2 border border-<?= $raid->color ?>"> <a href="<?= $raid->link ?>" class="group text-center p-2 border border-<?= $raid->color ?>">
<div class="group-hover:text-<?= $raid->color ?> bg-<?= $raid->color ?>-200"><?= $raid->title ?></div> <div class="group-hover:text-<?= $raid->color ?> bg-<?= $raid->color ?>-200"><?= $raid->title ?></div>
<div><?=format_date($raid->start,'dd.MM.yyyy HH:mm')?></div> <div><?= format_date($raid->start, 'dd.MM.yyyy HH:mm') ?></div>
<?php if ($raid->difficulty) : ?><div class="text-sm text-slate-500">(<?= $raid->difficulty ?>)</div><?php endif; ?> <?php if ($raid->difficulty) : ?><div class="text-sm text-slate-500">(<?= $raid->difficulty ?>)</div><?php endif; ?>
</a> </a>
@ -99,15 +98,16 @@ get_header();
<template x-teleport="#sidebar_right"> <template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1 hidden lg:block"> <div class="bg-glass shadow p-auto order-1 hidden lg:block">
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<h4 class="text-xl font-bold text-center mb-2">Raid importieren</h4> <h4 class="text-xl font-bold text-center mb-2">Raid importieren</h4>
<form action="/request" method="POST"> <form action="/request" method="POST">
<div class="flex flex-col gap-2"> <div class="flex flex-col gap-2">
<?php wp_nonce_field('importRaid', 'importRaid_nonce'); ?> <?php wp_nonce_field('importRaid', 'importRaid_nonce'); ?>
<input type="hidden" name="action" value="importRaid"> <input type="hidden" name="action" value="importRaid">
<input type="text" name="id_wowaudit" placeholder="WoW-Audit ID" class="text-black"> <input type="text" name="id_wowaudit" placeholder="WoW-Audit ID" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Importieren</a> <button type="submit" class="btn btn-outline btn-hunter">Importieren</a>
</div> </div>
</form> </form>
<!--
<div class="text-sm text-center">- oder -</div> <div class="text-sm text-center">- oder -</div>
<h4 class="text-xl font-bold text-center mb-2 mt-2">Termin erstellen</h4> <h4 class="text-xl font-bold text-center mb-2 mt-2">Termin erstellen</h4>
<form action="/request" method="POST"> <form action="/request" method="POST">
@ -128,7 +128,8 @@ get_header();
</div> </div>
</form> </form>
</div> </div>
</div> -->
</div>
</template> </template>
</div> </div>

View File

@ -1,125 +1,125 @@
<?php <?php
use WoWPress\Frontend\Icon; use WoWPress\Frontend\Icon;
use WoWPress\Frontend\ToggleButton; use WoWPress\Frontend\ToggleButton;
use WoWPress\Models\Character; use WoWPress\Models\Character;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
$raid = $GLOBALS['wowpress']['raid']; $raid = $GLOBALS['wowpress']['raid'];
set_sidebar_status('top', false); set_sidebar_status('top', false);
set_sidebar_status('left', false); set_sidebar_status('left', false);
set_sidebar_status('right', false); set_sidebar_status('right', false);
global $user; global $user;
if($raid->id_wowaudit){ if ($raid->id_wowaudit) {
$raid->sync(true); $raid->sync(true);
$raid->save(); $raid->save();
} }
$unknowns = [];
get_header(); $unknowns = [];
?>
<div class="top-title flex flex-col lg:flex-row gap-auto" style="margin-top:calc(-1 * var(--wowp-gap))"> get_header();
<?php if ($raid->previous) : ?> ?>
<a href="<?= $raid->previous->link ?>" class="btn btn-outline hidden lg:flex">Vorheriger</a> <div class="top-title flex flex-col lg:flex-row gap-auto" style="margin-top:calc(-1 * var(--wowp-gap))">
<?php endif; ?> <?php if ($raid->previous) : ?>
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full"> <a href="<?= $raid->previous->link ?>" class="btn btn-outline hidden lg:flex">Vorheriger</a>
<?= $raid->title ?> <?php endif; ?>
</div> <div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?php if ($raid->next) : ?> <?= $raid->title ?>
<a href="<?= $raid->next->link ?>" class="btn btn-outline hidden lg:flex">Nächster</a>
<?php endif; ?>
</div> </div>
<section id="primary"> <?php if ($raid->next) : ?>
<main id="main"> <a href="<?= $raid->next->link ?>" class="btn btn-outline hidden lg:flex">Nächster</a>
<div class="flex flex-col lg:flex-row gap-auto" x-data="{encounter:<?= $raid->encounters[0]['id'] ?>}"> <?php endif; ?>
<div class="bg-glass shadow p-auto w-full lg:w-1/5 order-2 lg:order-1"> </div>
<h3 class="text-xl font-bold text-center">Bosse</h3> <section id="primary">
<div class="grid gap-auto"> <main id="main">
<?php foreach ($raid->encounters as $encounter) : ?> <div class="flex flex-col lg:flex-row gap-auto" x-data="{encounter:<?= $raid->encounters[0]['id'] ?>}">
<button <?= $encounter['enabled'] ? "" : "disabled" ?> x-on:click="encounter=<?= $encounter['id'] ?>" class="btn btn-outline <?= $encounter['enabled'] ? "btn-green" : "btn-slate" ?>" :class="{'current-menu-item' : encounter==<?=$encounter['id']?> }"><?= $encounter['name'] ?></button> <div class="bg-glass shadow p-auto w-full lg:w-1/5 order-2 lg:order-1">
<?php endforeach; ?> <h3 class="text-xl font-bold text-center">Bosse</h3>
</div> <div class="grid gap-auto">
</div> <?php foreach ($raid->encounters as $encounter) : ?>
<div class="w-full flex flex-col gap-auto order-3 lg:order-2"> <button <?= $encounter['enabled'] ? "" : "disabled" ?> x-on:click="encounter=<?= $encounter['id'] ?>" class="btn btn-outline <?= $encounter['enabled'] ? "btn-green" : "btn-slate" ?>" :class="{'current-menu-item' : encounter==<?= $encounter['id'] ?> }"><?= $encounter['name'] ?></button>
<div class="flex flex-col lg:flex-row gap-auto">
<div class="bg-glass shadow p-auto w-full lg:w-1/5">
<div class="grid text-center gap-1">
<div class="bg-<?= $raid->color ?> text-black text-2xl "><?= format_date($raid->start, "EEEE") ?></div>
<div class="border border-<?= $raid->color ?>">
<div class="text-3xl p-auto "><?= format_date($raid->start, "dd. MMMM") ?></div>
</div>
<div class="border border-<?= $raid->color ?> p-2">Start: <?= format_date($raid->start, "HH:mm") ?></div>
<div class="border border-<?= $raid->color ?> p-2">Ende: <?= format_date($raid->end, "HH:mm") ?></div>
<?php if ($raid->difficulty) : ?>
<div class="border border-<?= $raid->color ?> p-2"><?= $raid->difficulty ?></div>
<?php endif; ?>
</div>
</div>
<div class="bg-glass shadow p-auto w-full">
<?php foreach ($raid->encounters as $encounter) : ?>
<div x-cloak x-show="encounter==<?= $encounter['id'] ?>">
<h3 class="text-xl font-bold">Informationen für : <?= $encounter['name'] ?></h3>
<div>
<?=$encounter['notes']?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="flex flex-col lg:flex-row gap-auto">
<?php foreach ($raid->encounters as $encounter) : ?>
<div x-cloak x-show="encounter==<?= $encounter['id'] ?>" class="w-full">
<div class="w-full grid grid-cols-1 lg:grid-cols-4 gap-auto">
<?php
foreach ($encounter['selections']->groupBy('role') as $role => $signups) :
if ($role != "Unknown") :
?>
<div class="bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center"><?= $role ?></h3>
<?php foreach ($signups as $signup) : ?>
<?= $signup->showForm(false, true,false,$encounter['id'] == 0) ?>
<?php endforeach; ?>
</div>
<?php
else : if ($encounter['id'] == 0) : $unknowns = $signups;
endif;
endif;
endforeach;
?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="flex flex-col gap-auto w-full lg:w-1/5 order-1 lg:order-3">
<div class="bg-glass shadow p-auto">
<div class="flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Status</h3>
<?= $raid->showSignup($user->characters->first(), true, true, true) ?>
</div>
</div>
</div>
</div>
<div class="w-full order-4 bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Keine Rückmeldung</h3>
<div class="grid grid-cols-1 lg:grid-cols-5 flex-wrap gap-auto">
<?php foreach ($unknowns as $signup) : ?>
<?= $signup->showForm() ?>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
</main> <div class="w-full flex flex-col gap-auto order-3 lg:order-2">
</section> <div class="flex flex-col lg:flex-row gap-auto">
<?php <div class="bg-glass shadow p-auto w-full lg:w-1/5">
get_footer(); <div class="grid text-center gap-1">
<div class="bg-<?= $raid->color ?> text-black text-2xl "><?= format_date($raid->start, "EEEE") ?></div>
<div class="border border-<?= $raid->color ?>">
<div class="text-3xl p-auto "><?= format_date($raid->start, "dd. MMMM") ?></div>
</div>
<div class="border border-<?= $raid->color ?> p-2">Start: <?= format_date($raid->start, "HH:mm") ?></div>
<div class="border border-<?= $raid->color ?> p-2">Ende: <?= format_date($raid->end, "HH:mm") ?></div>
<?php if ($raid->difficulty) : ?>
<div class="border border-<?= $raid->color ?> p-2"><?= $raid->difficulty ?></div>
<?php endif; ?>
</div>
</div>
<div class="bg-glass shadow p-auto w-full">
<?php foreach ($raid->encounters as $encounter) : ?>
<div x-cloak x-show="encounter==<?= $encounter['id'] ?>">
<h3 class="text-xl font-bold">Informationen für : <?= $encounter['name'] ?></h3>
<div>
<?= $encounter['notes'] ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="flex flex-col lg:flex-row gap-auto">
<?php foreach ($raid->encounters as $encounter) : ?>
<div x-cloak x-show="encounter==<?= $encounter['id'] ?>" class="w-full">
<div class="w-full grid grid-cols-1 lg:grid-cols-4 gap-auto">
<?php
foreach ($encounter['selections']->groupBy('role') as $role => $signups) :
if ($role != "Unknown") :
?>
<div class="bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center"><?= $role ?></h3>
<?php foreach ($signups as $signup) : ?>
<?= $signup->showForm(false, true, false, $encounter['id'] == 0) ?>
<?php endforeach; ?>
</div>
<?php
else : if ($encounter['id'] == 0) : $unknowns = $signups;
endif;
endif;
endforeach;
?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="flex flex-col gap-auto w-full lg:w-1/5 order-1 lg:order-3">
<div class="bg-glass shadow p-auto">
<div class="flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Status</h3>
<?= $raid->showSignup($user->characters->first(), true, true, true) ?>
</div>
</div>
</div>
</div>
<div class="w-full order-4 bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Keine Rückmeldung</h3>
<div class="grid grid-cols-1 lg:grid-cols-5 flex-wrap gap-auto">
<?php foreach ($unknowns as $signup) : ?>
<?= $signup->showForm() ?>
<?php endforeach; ?>
</div>
</div>
</main>
</section>
<?php
get_footer();

View File

@ -9,17 +9,15 @@ use WoWPress\Models\SKS;
set_sidebar_status('top', false); set_sidebar_status('top', false);
$liste = $GLOBALS['wowpress']['liste']; $liste = $GLOBALS['wowpress']['liste'];
if(!empty($liste)){
#$sks = new SKS(); $liste = SKS::where('list_name',$liste)->first();
#$sks->list_name = "Normal"; if(empty($liste->list_name)){
#$sks->char_name = "Gasti"; $liste = SKS::first();
#$sks->realm_name = "McGaston"; }
#$sks->rank = 4; }
#$sks->active = true;
#$sks->save();
if (!$liste) { if (empty($liste->list_name)) {
$listen = SKS::getLists(); $listen = SKS::getLists();
@ -34,19 +32,13 @@ if (!$liste) {
<main id="main"> <main id="main">
<div class="bg-glass shadow p-auto"> <div class="bg-glass shadow p-auto">
<?php foreach ($listen as $list) : ?> <?php foreach ($listen as $list) : ?>
<a class="btn btn-outline" href="/sks/<?= $list->ID ?>"><?= $list->list_name ?></a> <a class="btn btn-outline" href="/sks/<?= $list->list_name ?>"><?= $list->list_name ?></a>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</main> </main>
</section> </section>
<?php <?php
get_footer();
exit;
} else { } else {
$liste = SKS::find($liste);
get_header(); get_header();
?> ?>
<div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))"> <div class="top-title flex flex-row gap-2" style="margin-top:calc(-1 * var(--wowp-gap))">
@ -63,8 +55,9 @@ if (!$liste) {
<th class="p-auto w-40">Rang</th> <th class="p-auto w-40">Rang</th>
<th class="p-auto">Charakter</th> <th class="p-auto">Charakter</th>
<th class="p-auto hidden lg:table-cell">Server</th> <th class="p-auto hidden lg:table-cell">Server</th>
<th class="p-auto hidden lg:table-cell">Status</th>
<?php if (current_user_can('wowpress_edit_raids')) : ?> <?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> <th class="p-auto w-0">Aktion</th>
<?php endif; ?> <?php endif; ?>
</tr> </tr>
@ -76,12 +69,22 @@ if (!$liste) {
<tr class="text-<?= $sk->active ? $sk->character->color : "slate-500" ?> odd:bg-slate-900"> <tr class="text-<?= $sk->active ? $sk->character->color : "slate-500" ?> odd:bg-slate-900">
<?php if (current_user_can('wowpress_edit_raids')) : ?> <?php if (current_user_can('wowpress_edit_raids')) : ?>
<td class="p-auto text-center"> <td class="p-auto text-center">
<div class="flex flex-row"> <form action="/request" method="POST">
<input type="text" class="bg-glass w-full text-center border-0 border-b border-<?= $sk->character->color ?>" name="rank" value="<?= $sk->rank ?>"> <div class="flex flex-row">
<button class="btn btn-outline btn-alliance" title="Manueller Eingriff">
<?= Icon::get('o-wrench') ?> <input type="text" class="bg-glass w-full text-center border-0 border-b border-<?= $sk->character->color ?>" name="rank" value="<?= $sk->rank ?>">
</button> <button class="btn btn-outline btn-alliance" title="Manueller Eingriff">
</div> <?= 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> </td>
<?php else : ?> <?php else : ?>
@ -89,25 +92,31 @@ if (!$liste) {
<?php endif; ?> <?php endif; ?>
<td class="p-auto text-center"><?= $sk->character->name ?></td> <td class="p-auto text-center"><?= $sk->character->name ?></td>
<td class="p-auto text-center hidden lg:table-cell"><?= $sk->character->realm ?></td> <td class="p-auto text-center hidden lg:table-cell"><?= $sk->character->realm ?></td>
<td class="p-auto text-center hidden lg:table-cell">
<button class="btn w-full btn-outline btn-<?= $sk->active ? $sk->character->color : "slate" ?>"><?= $sk->active ? "Aktiv" : "Inaktiv" ?></button>
</td>
<?php if (current_user_can('wowpress_edit_raids')) : ?> <?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"> <td class="p-auto">
<div class="flex gap-2 flex-col lg:flex-row justify-end"> <div class="flex gap-2 flex-col lg:flex-row justify-end">
<?php if ($sk->active) : ?> <?php if ($sk->active) : ?>
<form action="/request" method="POST"> <form action="/request" method="POST">
<?php wp_nonce_field('lootSKS', 'lootSKSnonce'); ?> <?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS"> <input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="id" value="<?= $sk->ID ?>"> <input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" class="btn btn-outline btn-<?=$sk->character->color?>"><?= Icon::get('o-sparkles') ?></button> <button type="submit" title="Looten" class="btn btn-outline btn-<?= $sk->character->color ?>"><?= Icon::get('o-sparkles') ?></button>
</form> </form>
<?php else : ?> <?php else : ?>
<form action="/request" method="POST"> <form action="/request" method="POST">
<?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?> <?php wp_nonce_field('deleteSKS', 'deleteSKS_nonce'); ?>
<input type="hidden" name="action" value="deleteSKS"> <input type="hidden" name="action" value="deleteSKS">
<input type="hidden" name="id" value="<?= $sk->ID ?>"> <input type="hidden" name="sks_id" value="<?= $sk->ID ?>">
<button type="submit" class="btn btn-outline btn-gray"><?= Icon::get('o-trash') ?></button> <button type="submit" title="Löschen" class="btn btn-outline btn-red"><?= Icon::get('o-trash') ?></button>
</form> </form>
<? endif; ?> <? endif; ?>
@ -126,27 +135,34 @@ if (!$liste) {
</div> </div>
</main> </main>
</section> </section>
<?php if (current_user_can('wowpress_edit_characters')) : ?> <?php
<div x-data> }
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1"> if (current_user_can('wowpress_edit_characters')) : ?>
<h4 class="text-xl font-bold text-center mb-2">Charakter Hinzufügen</h4> <div x-data>
<form action="/request" method="POST"> <template x-teleport="#sidebar_right">
<div class="flex flex-col gap-2"> <div class="bg-glass shadow p-auto order-1">
<?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?> <h4 class="text-xl font-bold text-center mb-2">Charakter Hinzufügen</h4>
<input type="hidden" name="action" value="addSKS"> <form action="/request" method="POST">
<input type="text" name="name" placeholder="Name" class="text-black"> <div class="flex flex-col gap-2">
<input type="text" name="realm" placeholder="Server" class="text-black"> <?php wp_nonce_field('addSKS', 'addSKS_nonce'); ?>
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a> <input type="hidden" name="action" value="addSKS">
</div> <input type="text" name="name" placeholder="Name" class="text-black">
</form> <input type="text" name="realm" placeholder="Server" class="text-black">
</div> <input type="text" name="list_name" placeholder="Listenname" value="<?= !empty($liste->list_name) ? $liste->list_name : "" ?>" class="text-black">
</template>
</div> <button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</template>
</div>
<?php <?php
endif; endif;
get_footer();
get_footer();
}
?> ?>

View File

@ -7,8 +7,8 @@ class WoWPressNavWalker extends \Walker_Nav_Menu
function start_lvl(&$output, $depth=0, $args=null) { function start_lvl(&$output, $depth=0, $args=null) {
$output .= ' $output .= '
<div x-show="open" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="block xl:absolute right-0 w-full mt-2 origin-top-right rounded-md shadow-lg xl:w-48"> <div x-cloak x-show="open" x-transition:enter="transition ease-out duration-100" x-transition:enter-start="transform opacity-0 scale-95" x-transition:enter-end="transform opacity-100 scale-100" x-transition:leave="transition ease-in duration-75" x-transition:leave-start="transform opacity-100 scale-100" x-transition:leave-end="transform opacity-0 scale-95" class="block xl:absolute right-0 w-full mt-2 origin-top-right rounded-md shadow-lg xl:w-48">
<div class="px-2 py-2 bg-glass shadow dark-mode:bg-gray-800 w-full flex flex-col gap-2"> <div x-cloak class="px-2 py-2 bg-glass shadow dark-mode:bg-gray-800 w-full flex flex-col gap-2">
'; ';
} }
function end_lvl(&$output, $depth= 0, $args=null) { function end_lvl(&$output, $depth= 0, $args=null) {
@ -30,7 +30,7 @@ class WoWPressNavWalker extends \Walker_Nav_Menu
if($args->walker->has_children){ if($args->walker->has_children){
$output .= '<div @click.away="open = false" class="relative" x-data="{ open: false }">'; $output .= '<div x-cloak @click.away="open = false" class="relative" x-data="{ open: false }">';
$output .= '<button @click="open = !open" class="w-full nav-btn ' . implode(" ", $item->classes) . '">'; $output .= '<button @click="open = !open" class="w-full nav-btn ' . implode(" ", $item->classes) . '">';
} }
elseif ($item->url && $item->url != '#') { elseif ($item->url && $item->url != '#') {

View File

@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Redirect;
use WoWPress\Models\Character; use WoWPress\Models\Character;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
use WoWPress\Models\Signup; use WoWPress\Models\Signup;
use WoWPress\Models\SKS;
use WoWPress\Models\User; use WoWPress\Models\User;
if (empty($_POST['action'])) { if (empty($_POST['action'])) {
@ -90,15 +91,15 @@ switch ($_POST['action']) {
if (isset($_POST['importRaid_nonce']) && wp_verify_nonce($_POST['importRaid_nonce'], 'importRaid')) { if (isset($_POST['importRaid_nonce']) && wp_verify_nonce($_POST['importRaid_nonce'], 'importRaid')) {
if (isset($_POST['id_wowaudit'])) { if (isset($_POST['id_wowaudit'])) {
if(!empty(Raid::where('id_wowaudit',$_POST['id_wowaudit'])->first())){ if (!empty(Raid::where('id_wowaudit', $_POST['id_wowaudit'])->first())) {
break; break;
} }
$raid = new Raid(); $raid = new Raid();
$raid->id_wowaudit = $_POST['id_wowaudit']; $raid->id_wowaudit = $_POST['id_wowaudit'];
$raid->sync(); $raid->sync();
if(!empty($raid->title)){ if (!empty($raid->title)) {
$raid->save(); $raid->save();
} }
} }
@ -142,6 +143,86 @@ switch ($_POST['action']) {
} }
} }
break; 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'];
}
$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();
}
}
}
break;
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();
}
}
}
break;
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();
}
}
}
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();
}
}
}
break;
} }
header('Location: ' . $_SERVER['HTTP_REFERER']); header('Location: ' . $_SERVER['HTTP_REFERER']);

View File

@ -0,0 +1,20 @@
<?php
?>
<div class="bg-glass shadow p-auto order-last flex flex-col gap-2">
<h3 class="text-xl font-bold text-center"><?= $this->title ?></h3>
<h4 class="text-lg font-bold text-center"><?=$instance['raid_name']?></h4>
<?php
foreach ($instance['bosses'] as $boss) {
if (!empty($boss['name'])) :
?>
<div class="flex flex-row gap-2 justify-around">
<div><?= $boss['name'] ?></div>
<div><?= $boss['date']?format_date($boss['date']):"Nicht besiegt" ?></div>
</div>
<?php
endif;
}
?>
</div>

View File

@ -0,0 +1,5 @@
<?php
?>
<div class="bg-glass shadow p-auto order-last">
</div>

View File

@ -18,7 +18,7 @@ $character = $user->raiders->first();
<?php foreach ($raids as $raid) : ?> <?php foreach ($raids as $raid) : ?>
<?php <?php
?> ?>
<div class="border shadow p-auto flex flex-col gap-2"> <div class="border shadow p-auto flex flex-col gap-2" style="background-position:center;background-size: cover;background-image:url('<?=$raid->thumbnail?>')">
<h1 class="text-xl font-bold text-center"><?= $raid->title ?></h1> <h1 class="text-xl font-bold text-center"><?= $raid->title ?></h1>
<div class="text-center text-<?= $raid->color ?>"><?= $raid->difficulty ?></div> <div class="text-center text-<?= $raid->color ?>"><?= $raid->difficulty ?></div>

View File

@ -12,6 +12,7 @@ class CreateRaidTable extends CreateTable
'difficulty' => 'text NOT NULL', 'difficulty' => 'text NOT NULL',
'start' => 'datetime NOT NULL', 'start' => 'datetime NOT NULL',
'end' => 'datetime NOT NULL', 'end' => 'datetime NOT NULL',
'status' => 'text',
]; ];
} }

View File

@ -0,0 +1,52 @@
<?php
namespace WoWPress\Frontend\Widgets;
class BossKills extends Widget
{
protected $template_path = "boss_kills.php";
protected $title = "Boss-Kills";
protected $base_id = "wowpress_boss_kills";
public $name = "Boss-Kills";
protected $restricted = false;
public function form($instance)
{
$raid_name = !empty($instance['raid_name']) ? $instance['raid_name'] : ""; ?>
<p>
<label for="<?php echo esc_attr($this->get_field_id("raid_name")); ?>"><?php echo esc_html__('Raid-Name', 'wowpress'); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id("raid_name")); ?>" name="<?php echo esc_attr($this->get_field_name("raid_name")); ?>" value="<?php echo esc_attr($raid_name); ?>">
</p>
<?php
for ($i = 0; $i <= 15; $i++) {
$boss_name = !empty($instance['bosses'][$i]['name']) ? $instance['bosses'][$i]['name'] : "";
$boss_kill = !empty($instance['bosses'][$i]['date']) ? $instance['bosses'][$i]['date'] : "";
?>
<p>
<label for="<?php echo esc_attr($this->get_field_id("bosses[$i][name]")); ?>"><?php echo esc_html__('Boss-Name', 'wowpress'); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id("bosses[$i][name]")); ?>" name="<?php echo esc_attr($this->get_field_name("bosses[$i][name]")); ?>" value="<?php echo esc_attr($boss_name); ?>">
</p>
<p>
<label for="<?php echo esc_attr($this->get_field_id("bosses[$i][date]")); ?>"><?php echo esc_html__('Firstkill', 'wowpress'); ?></label>
<input type="date" class="widefat" id="<?php echo esc_attr($this->get_field_id("bosses[$i][date]")); ?>" name="<?php echo esc_attr($this->get_field_name("bosses[$i][date]")); ?>" value="<?php echo esc_attr($boss_kill); ?>">
</p>
<?php
}
}
public function update($new_instance, $old_instance)
{
$instance = array();
$instance['raid_name'] = (!empty($new_instance['raid_name'])) ? strip_tags($new_instance['raid_name']) : '';
for ($i = 0; $i <= 15; $i++) {
$instance['bosses'][$i]['name'] = (!empty($new_instance['bosses'][$i]['name'])) ? strip_tags($new_instance['bosses'][$i]['name']) : '';
$instance['bosses'][$i]['date'] = (!empty($new_instance['bosses'][$i]['date'])) ? strip_tags($new_instance['bosses'][$i]['date']) : '';
}
return $instance;
}
}

View File

@ -0,0 +1,60 @@
<?php
namespace WoWPress\Frontend\Widgets;
class CharacterSearch extends Widget
{
protected $template_path = "char_search.php";
protected $title = "Charaktersuche";
protected $base_id = "wowpress_char_search";
public $name = "Charaktersuche";
protected $restricted = false;
protected $classes = [
'Death Knight' => [
'Frost',
'Unholy',
'Blood'
],
'Demon Hunter' => [
'Havoc',
'Vengeance',
],
'Druid' => [
'Feral',
'Balance',
'Guardian',
'Restoration',
]
];
public function form($instance)
{
foreach ($this->classes as $class => $specs) {
foreach ($specs as $spec) {
?>
<p>
<label for="<?php echo esc_attr($this->get_field_id("classes[$class][$spec]")); ?>"><?php echo esc_html__("$spec - $class", 'wowpress'); ?></label>
<input type="text" class="widefat" id="<?php echo esc_attr($this->get_field_id("classes[$class][$spec]")); ?>" name="<?php echo esc_attr($this->get_field_name("classes[$class][$spec]]")); ?>" value="<?php echo esc_attr($instance['classes'][$class][$spec]); ?>">
</p>
<?php
}
}
}
public function update($new_instance, $old_instance)
{
$instance = array();
foreach ($this->classes as $class => $specs) {
foreach ($specs as $spec) {
$instance['classes'][$class][$spec] = (!empty($new_instance['classes'][$class][$spec])) ? strip_tags($new_instance['classes'][$class][$spec]) : '';
}
}
return $instance;
}
}

View File

@ -21,7 +21,6 @@ class Raid extends Model
public $notes; public $notes;
public $encounters; public $encounters;
public $status;
public $partial; public $partial;
public function __construct($attrs = []) public function __construct($attrs = [])
@ -124,7 +123,7 @@ class Raid extends Model
$sup[$character->id_wowaudit] = $signup['status']; $sup[$character->id_wowaudit] = $signup['status'];
$s = new Signup(); $s = new Signup();
$s->character_id = $character->ID; $s->character_id = $character->ID;
$s->raid_ID = $this->ID; $s->raid_id = $this->ID;
if ($this->partial) { if ($this->partial) {
foreach ($encounters as $encounter) { foreach ($encounters as $encounter) {
if ($signup['selected']) break; if ($signup['selected']) break;
@ -154,7 +153,7 @@ class Raid extends Model
$s = new Signup(); $s = new Signup();
$s->character_id = $character->ID; $s->character_id = $character->ID;
$s->raid_ID = $this->ID; $s->raid_id = $this->ID;
$s->boss_id = $encounter['id']; $s->boss_id = $encounter['id'];
$s->status = $selection['selected'] ? "Selected" : $selection['status']; $s->status = $selection['selected'] ? "Selected" : $selection['status'];
$s->role = $selection['role']; $s->role = $selection['role'];
@ -212,27 +211,26 @@ class Raid extends Model
public function getPreviousAttribute() public function getPreviousAttribute()
{ {
$id = $this->ID;
while ($id) { $previous = Raid::where('start','<',$this->start)->orderBy('start','DESC')->first();
$raid = Raid::find(--$id); return $previous;
if (!empty($raid->ID)) { }
return $raid;
} public function getThumbnailAttribute(){
}
return false; $clean_name = str_replace([" ","'"],"-",$this->title);
$clean_name = preg_replace('/[^a-zA-Z0-9_-]/', '', $clean_name);
$clean_name = strtolower($clean_name);
return "https://data.wowaudit.com/img/$clean_name-small.jpeg";
} }
public function getNextAttribute() public function getNextAttribute()
{ {
$id = $this->ID; $next = Raid::where('start','>',$this->start)->orderBy('start','ASC')->first();
while ($id <= Raid::max('ID')) { return $next;
$raid = Raid::find(++$id);
if (!empty($raid->ID)) {
return $raid;
}
}
return false;
} }
public function showSignup($character, $showRole = false, $showStatus = false, $vertical = false) public function showSignup($character, $showRole = false, $showStatus = false, $vertical = false)

View File

@ -15,17 +15,22 @@ class SKS extends Model
public static function getList($name){ public static function getList($name)
return static::where('list_name',$name)->orderBy('rank')->get(); {
return static::where('list_name', $name)->orderBy('rank')->get();
} }
public static function getLists(){
return static::distinct('list_name')->get();
public static function getLists()
{
return static::groupBy('list_name')->get();
} }
public function getCharacterAttribute(){ public function getCharacterAttribute()
$char= Character::where('name',$this->char_name)->where('realm',$this->realm_name)->first(); {
if(!empty($char->ID)){ $char = Character::where('name', $this->char_name)->where('realm', $this->realm_name)->first();
if (!empty($char->ID)) {
return $char; return $char;
} }
@ -37,6 +42,84 @@ class SKS extends Model
return $char; return $char;
} }
} public function getAfter($active = true)
{
$list = static::where('list_name', $this->list_name)->where('rank', ">", $this->rank);
if ($active) {
$list = $list->where('active', true);
}
return $list->orderBy('rank')->get();
}
public function getPrevious($active = true)
{
$prev = SKS::where('list_name', $this->list_name)->where('rank', '<', $this->rank);
if ($active) {
$prev = $prev->where('active', true);
}
$prev = $prev->orderBy('rank', 'DESC')->first();
if (!empty($prev->ID)) {
return $prev->rank;
} else {
return $this->rank;
}
}
public function getLastRankAttribute()
{
$lastSK = SKS::where('list_name', $this->list_name)
->where('active', true)
->orderBy('rank', 'DESC')->get()->first();
if (!empty($lastSK->ID)) {
return $lastSK->rank;
}
return false;
}
public function roll()
{
$list = SKS::where('list_name', $this->list_name)->get();
$ranks = range(1, count($list));
shuffle($ranks);
foreach ($list as $key => $sk) {
$sk->rank = $ranks[$key];
$sk->save();
}
}
public function loot()
{
$after = $this->getAfter();
$last_rank = $this->last_rank;
foreach ($after as $id => &$sk) {
/**
* Ignoriere inaktive Charaktere & Charaktere
* die auf einem höheren Rang als der Looter sind
* und überspringe die restlichen Anweisungen
*/
if (!$sk->active || $sk->rank < $this->rank) {
continue;
}
/**
* Setze den Rang des Charakters auf den Rang des vorherigen aktiven
*/
$after[$id]->rank = $sk->getPrevious(true);
}
/**
* Setze den Rang des Looters auf den letzen aktiven Rang
*/
$this->rank = $last_rank;
$this->save();
foreach ($after as $sk) {
$sk->save();
}
}
}

View File

@ -59,6 +59,12 @@ class Signup extends Model
'icon' => 's-star', 'icon' => 's-star',
'color' => 'paladin', 'color' => 'paladin',
], ],
'Too Late' => (object)[
'selectable' => false,
'name' => 'Anmeldung Vergessen',
'icon' => 'o-face-frown',
'color' => 'deathknight',
],
]; ];
$this->roleList = [ $this->roleList = [
@ -104,38 +110,52 @@ class Signup extends Model
$this->api = new WoWAudit(null, $key); $this->api = new WoWAudit(null, $key);
} }
public function character(){ public function character()
{
return $this->belongsTo(Character::class); return $this->belongsTo(Character::class);
} }
public function raid(){ public function raid()
{
return $this->belongsTo(Raid::class); return $this->belongsTo(Raid::class);
} }
public function showForm($showRole = false, $showStatus = false,$vertical = false,$doSignup = true){ public function showForm($showRole = false, $showStatus = false, $vertical = false, $doSignup = true)
require(get_template_directory()."/components/raid-signup.php"); {
$tooLate = $this->raid->status == "Locked";
$doSignup = $doSignup && !$tooLate;
if ($this->status == "Unknown" && $tooLate) {
$this->setStatus('Too Late');
$showStatus = true;
$showRole = false;
}
require(get_template_directory() . "/components/raid-signup.php");
} }
public function getStatusList($selectable = false){ public function getStatusList($selectable = false)
{
$out = []; $out = [];
foreach($this->statusList as $key => $status){ foreach ($this->statusList as $key => $status) {
if($selectable){ if ($selectable) {
if($status->selectable){ if ($status->selectable) {
$out[$key] = $status; $out[$key] = $status;
} }
}else{ } else {
$out[$key] = $status; $out[$key] = $status;
} }
} }
return $out; return $out;
} }
public function getRoleList(){ public function getRoleList()
{
$out = []; $out = [];
foreach($this->roleList as $key => $status){ foreach ($this->roleList as $key => $status) {
if($status->selectable){ if ($status->selectable) {
$out[$key] = $status; $out[$key] = $status;
} }
} }
@ -143,21 +163,24 @@ class Signup extends Model
} }
public function getStatus(){ public function getStatus()
{
if (key_exists($this->status, $this->statusList)) { if (key_exists($this->status, $this->statusList)) {
return $this->statusList[$this->status]; return $this->statusList[$this->status];
} }
return $this->statusList['Unknown']; return $this->statusList['Unknown'];
} }
public function getRole(){ public function getRole()
{
if (key_exists($this->role, $this->roleList)) { if (key_exists($this->role, $this->roleList)) {
return $this->roleList[$this->role]; return $this->roleList[$this->role];
} }
return $this->roleList['Unknown']; return $this->roleList['Unknown'];
} }
public function setStatus($status){ public function setStatus($status)
{
if (key_exists($status, $this->statusList)) { if (key_exists($status, $this->statusList)) {
$this->status = $status; $this->status = $status;
return true; return true;
@ -165,7 +188,8 @@ class Signup extends Model
return false; return false;
} }
public function setRole($role){ public function setRole($role)
{
if (key_exists($role, $this->roleList)) { if (key_exists($role, $this->roleList)) {
$this->role = $role; $this->role = $role;
return true; return true;
@ -173,11 +197,12 @@ class Signup extends Model
return false; return false;
} }
public function updateAPI(Character $second_char = null){ public function updateAPI(Character $second_char = null)
if($second_char->ID){ {
return $this->api->changeSignup($this->raid,$this->character,$this->status,$this->role,$this->comment,$second_char); if ($second_char->ID) {
}else{ return $this->api->changeSignup($this->raid, $this->character, $this->status, $this->role, $this->comment, $second_char);
return $this->api->changeSignup($this->raid,$this->character,$this->status,$this->role,$this->comment); } else {
return $this->api->changeSignup($this->raid, $this->character, $this->status, $this->role, $this->comment);
} }
} }
} }