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];
}
?>
<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">
<?php wp_nonce_field('signupRaid', 'signupRaid_nonce'); ?>
<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">

View File

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

View File

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

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]'],
['request/?$' => 'index.php?wowpress_page=form_request'],
['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
);
});

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-right"><?= format_date("$year-$month-$i", 'E') ?></div>
<?php
foreach ($has_raid as $raid) {
?>
<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>
<?php if ($raid->difficulty) : ?><div class="text-sm text-slate-500">(<?= $raid->difficulty ?>)</div><?php endif; ?>
@ -108,6 +107,7 @@ get_header();
<button type="submit" class="btn btn-outline btn-hunter">Importieren</a>
</div>
</form>
<!--
<div class="text-sm text-center">- oder -</div>
<h4 class="text-xl font-bold text-center mb-2 mt-2">Termin erstellen</h4>
<form action="/request" method="POST">
@ -128,6 +128,7 @@ get_header();
</div>
</form>
</div>
-->
</div>
</template>
</div>

View File

@ -9,17 +9,15 @@ use WoWPress\Models\SKS;
set_sidebar_status('top', false);
$liste = $GLOBALS['wowpress']['liste'];
#$sks = new SKS();
#$sks->list_name = "Normal";
#$sks->char_name = "Gasti";
#$sks->realm_name = "McGaston";
#$sks->rank = 4;
#$sks->active = true;
#$sks->save();
if(!empty($liste)){
$liste = SKS::where('list_name',$liste)->first();
if(empty($liste->list_name)){
$liste = SKS::first();
}
}
if (!$liste) {
if (empty($liste->list_name)) {
$listen = SKS::getLists();
@ -34,19 +32,13 @@ if (!$liste) {
<main id="main">
<div class="bg-glass shadow p-auto">
<?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; ?>
</div>
</main>
</section>
<?php
get_footer();
exit;
} else {
$liste = SKS::find($liste);
get_header();
?>
<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">Charakter</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')) : ?>
<th class="p-auto hidden lg:table-cell">Status</th>
<th class="p-auto w-0">Aktion</th>
<?php endif; ?>
</tr>
@ -76,38 +69,54 @@ if (!$liste) {
<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"><?= $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">
<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')) : ?>
<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', 'lootSKSnonce'); ?>
<?php wp_nonce_field('lootSKS', 'lootSKS_nonce'); ?>
<input type="hidden" name="action" value="lootSKS">
<input type="hidden" name="id" value="<?= $sk->ID ?>">
<button type="submit" class="btn btn-outline btn-<?=$sk->character->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="id" value="<?= $sk->ID ?>">
<button type="submit" class="btn btn-outline btn-gray"><?= Icon::get('o-trash') ?></button>
<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; ?>
@ -126,7 +135,10 @@ if (!$liste) {
</div>
</main>
</section>
<?php if (current_user_can('wowpress_edit_characters')) : ?>
<?php
}
if (current_user_can('wowpress_edit_characters')) : ?>
<div x-data>
<template x-teleport="#sidebar_right">
<div class="bg-glass shadow p-auto order-1">
@ -137,6 +149,8 @@ if (!$liste) {
<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>
@ -148,5 +162,7 @@ if (!$liste) {
endif;
get_footer();
}
?>

View File

@ -7,8 +7,8 @@ class WoWPressNavWalker extends \Walker_Nav_Menu
function start_lvl(&$output, $depth=0, $args=null) {
$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 class="px-2 py-2 bg-glass shadow dark-mode:bg-gray-800 w-full flex flex-col gap-2">
<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 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) {
@ -30,7 +30,7 @@ class WoWPressNavWalker extends \Walker_Nav_Menu
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) . '">';
}
elseif ($item->url && $item->url != '#') {

View File

@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Redirect;
use WoWPress\Models\Character;
use WoWPress\Models\Raid;
use WoWPress\Models\Signup;
use WoWPress\Models\SKS;
use WoWPress\Models\User;
if (empty($_POST['action'])) {
@ -142,6 +143,86 @@ switch ($_POST['action']) {
}
}
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']);

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
?>
<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>
<div class="text-center text-<?= $raid->color ?>"><?= $raid->difficulty ?></div>

View File

@ -12,6 +12,7 @@ class CreateRaidTable extends CreateTable
'difficulty' => 'text NOT NULL',
'start' => '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 $encounters;
public $status;
public $partial;
public function __construct($attrs = [])
@ -124,7 +123,7 @@ class Raid extends Model
$sup[$character->id_wowaudit] = $signup['status'];
$s = new Signup();
$s->character_id = $character->ID;
$s->raid_ID = $this->ID;
$s->raid_id = $this->ID;
if ($this->partial) {
foreach ($encounters as $encounter) {
if ($signup['selected']) break;
@ -154,7 +153,7 @@ class Raid extends Model
$s = new Signup();
$s->character_id = $character->ID;
$s->raid_ID = $this->ID;
$s->raid_id = $this->ID;
$s->boss_id = $encounter['id'];
$s->status = $selection['selected'] ? "Selected" : $selection['status'];
$s->role = $selection['role'];
@ -212,27 +211,26 @@ class Raid extends Model
public function getPreviousAttribute()
{
$id = $this->ID;
while ($id) {
$raid = Raid::find(--$id);
if (!empty($raid->ID)) {
return $raid;
$previous = Raid::where('start','<',$this->start)->orderBy('start','DESC')->first();
return $previous;
}
}
return false;
public function getThumbnailAttribute(){
$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()
{
$id = $this->ID;
while ($id <= Raid::max('ID')) {
$raid = Raid::find(++$id);
if (!empty($raid->ID)) {
return $raid;
}
}
return false;
$next = Raid::where('start','>',$this->start)->orderBy('start','ASC')->first();
return $next;
}
public function showSignup($character, $showRole = false, $showStatus = false, $vertical = false)

View File

@ -15,15 +15,20 @@ class SKS extends Model
public static function getList($name){
public static function getList($name)
{
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)) {
return $char;
@ -38,5 +43,83 @@ class SKS extends Model
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',
'color' => 'paladin',
],
'Too Late' => (object)[
'selectable' => false,
'name' => 'Anmeldung Vergessen',
'icon' => 'o-face-frown',
'color' => 'deathknight',
],
];
$this->roleList = [
@ -104,19 +110,32 @@ class Signup extends Model
$this->api = new WoWAudit(null, $key);
}
public function character(){
public function character()
{
return $this->belongsTo(Character::class);
}
public function raid(){
public function raid()
{
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)
{
$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 = [];
foreach ($this->statusList as $key => $status) {
if ($selectable) {
@ -131,7 +150,8 @@ class Signup extends Model
return $out;
}
public function getRoleList(){
public function getRoleList()
{
$out = [];
foreach ($this->roleList as $key => $status) {
if ($status->selectable) {
@ -143,21 +163,24 @@ class Signup extends Model
}
public function getStatus(){
public function getStatus()
{
if (key_exists($this->status, $this->statusList)) {
return $this->statusList[$this->status];
}
return $this->statusList['Unknown'];
}
public function getRole(){
public function getRole()
{
if (key_exists($this->role, $this->roleList)) {
return $this->roleList[$this->role];
}
return $this->roleList['Unknown'];
}
public function setStatus($status){
public function setStatus($status)
{
if (key_exists($status, $this->statusList)) {
$this->status = $status;
return true;
@ -165,7 +188,8 @@ class Signup extends Model
return false;
}
public function setRole($role){
public function setRole($role)
{
if (key_exists($role, $this->roleList)) {
$this->role = $role;
return true;
@ -173,7 +197,8 @@ class Signup extends Model
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);
} else {