Lists
parent
7d0771be23
commit
2a7f744634
|
@ -4,7 +4,7 @@ Theme URI: https://nebelkrieger.de
|
|||
Author: Yorndar
|
||||
Author URI: https://nebelkrieger.de
|
||||
Description: The next gen NK-Theme
|
||||
Version: 0.4.0
|
||||
Version: 0.4.2
|
||||
Tested up to: 6.2
|
||||
Requires PHP: 8.0
|
||||
License: GNU General Public License v2 or later
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
use WoWPress\Database\CreateCacheTable;
|
||||
use WoWPress\Database\CreateCharacterTable;
|
||||
use WoWPress\Database\CreateCharListItemTable;
|
||||
use WoWPress\Database\CreateCharListsTable;
|
||||
use WoWPress\Database\CreateComplaintTable;
|
||||
use WoWPress\Database\CreateLogTable;
|
||||
use WoWPress\Database\CreateNotificationTable;
|
||||
|
@ -163,6 +165,8 @@ if (!function_exists('wowpress_database')) :
|
|||
CreateLogTable::sql(),
|
||||
CreateComplaintTable::sql(),
|
||||
CreateNotificationTable::sql(),
|
||||
CreateCharListsTable::sql(),
|
||||
CreateCharListItemTable::sql(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -84,6 +84,10 @@ function isAllowed($capability)
|
|||
endif;
|
||||
}
|
||||
|
||||
function checkNonce($nonce){
|
||||
return isset($_POST[$nonce.'_nonce']) && wp_verify_nonce($_POST[$nonce.'_nonce'], $nonce);
|
||||
}
|
||||
|
||||
|
||||
function setGlobalUser(){
|
||||
global $user;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use WoWPress\Models\Character;
|
||||
use WoWPress\Models\CharacterList;
|
||||
use WoWPress\Models\Log;
|
||||
use WoWPress\Models\Raid;
|
||||
use WoWPress\Models\SKS;
|
||||
|
@ -18,6 +20,8 @@ add_filter('generate_rewrite_rules', function ($wp_rewrite) {
|
|||
['db/?$' => 'index.php?wowpress_page=db'],
|
||||
['kummerkasten/?$' => 'index.php?wowpress_page=complaints'],
|
||||
['kummerkasten/(\d+)/?$' => 'index.php?wowpress_page=complaints&complaint_id=$matches[1]'],
|
||||
['lists/?$' => 'index.php?wowpress_page=lists'],
|
||||
['list/(\d+)/?$' => 'index.php?wowpress_page=lists&list_id=$matches[1]'],
|
||||
|
||||
$wp_rewrite->rules
|
||||
);
|
||||
|
@ -29,6 +33,7 @@ add_filter('query_vars', function ($query_vars) {
|
|||
$query_vars[] = 'month';
|
||||
$query_vars[] = 'raid_id';
|
||||
$query_vars[] = 'list_name';
|
||||
$query_vars[] = 'list_id';
|
||||
$query_vars[] = 'complaint_id';
|
||||
|
||||
|
||||
|
@ -48,6 +53,18 @@ add_action('template_redirect', function () {
|
|||
header('Location: /');
|
||||
die;
|
||||
break;
|
||||
case 'lists':
|
||||
$list = get_query_var('list_id');
|
||||
$list = CharacterList::find($list);
|
||||
if ($list) {
|
||||
$GLOBALS['wowpress']['page_title'] = $list->list_name;
|
||||
include plugin_dir_path(__FILE__) . '../pages/single_charlist.php';
|
||||
} else {
|
||||
$GLOBALS['wowpress']['page_title'] = "Charakterlisten";
|
||||
include plugin_dir_path(__FILE__) . '../pages/charlists.php';
|
||||
}
|
||||
die;
|
||||
break;
|
||||
case 'complaints':
|
||||
isAllowed('wowpress_view_complaints');
|
||||
$GLOBALS['wowpress']['page_title'] = "Kummerkasten";
|
||||
|
@ -69,19 +86,42 @@ add_action('template_redirect', function () {
|
|||
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;'>";
|
||||
echo '<hr style="width:100%">';
|
||||
foreach(Log::all() as $log){
|
||||
?>
|
||||
foreach (Log::all() as $log) {
|
||||
?>
|
||||
<div style="display:flex;flex-direction:column;gap:1em;">
|
||||
<div>Message: <?=$log->message?></div>
|
||||
<div>Action: <?=$log->action?></div>
|
||||
<div>Logged: <?=format_date($log->created_at,"dd.MM.YY HH:mm")?></div>
|
||||
<div>Message: <?= $log->message ?></div>
|
||||
<div>Action: <?= $log->action ?></div>
|
||||
<div>Logged: <?= format_date($log->created_at, "dd.MM.YY HH:mm") ?></div>
|
||||
</div>
|
||||
<hr style="width:100%">
|
||||
<?php
|
||||
<?php
|
||||
}
|
||||
echo "<div>";
|
||||
die;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
|
||||
use WoWPress\Api\BattleNet;
|
||||
use WoWPress\Database\Cache;
|
||||
use WoWPress\Frontend\Icon;
|
||||
use WoWPress\Models\Character;
|
||||
use WoWPress\Models\CharacterList;
|
||||
|
||||
global $widget_area;
|
||||
set_sidebar_status('top', false);
|
||||
|
||||
$characters = Character::orderBy('rank')->get();
|
||||
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'] ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section id="primary" x-data="{char:null}">
|
||||
<main id="main" class="flex flex-row gap-2 flex-wrap">
|
||||
<?php foreach (CharacterList::all() as $list) : ?>
|
||||
<a class="bg-glass shadow p-auto text-center" href="/list/<?=$list->ID?>">
|
||||
<div class="text-2xl"><?= $list->list_name ?></div>
|
||||
<div class="text-small text-slate-700">(<?= $list->characters()->groupBy('ID')->get()->count() ?> Charaktere)</div>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</main><!-- #main -->
|
||||
<?php
|
||||
if (current_user_can('wowpress_edit_raids')) : ?>
|
||||
|
||||
<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 hinzufügen</h4>
|
||||
<form action="/request" method="POST">
|
||||
<div class="flex flex-col gap-2">
|
||||
<?php wp_nonce_field('addList', 'addList_nonce'); ?>
|
||||
<input type="hidden" name="action" value="addList">
|
||||
<input type="text" class="bg-white bg-opacity-0 border-alliance" placeholder="Listenname" name="list_name">
|
||||
<input type="text" class="bg-white bg-opacity-0 border-alliance" placeholder="CSS-Farbe der Einträge" name="border_color">
|
||||
<label for="notify" class="flex flex-row gap-1 items-center justify-between">Spieler bei Eintrag benachrichtigen? <input class="accent-orange-500" type="checkbox" name="notify" id="notify"></label>
|
||||
<button type="submit" class="btn btn-outline btn-orange"><?= Icon::get('o-plus') ?> Hinzufügen</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</section><!-- #primary -->
|
||||
|
||||
<?php
|
||||
get_footer();
|
|
@ -65,7 +65,7 @@ get_header();
|
|||
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>
|
||||
<div class="group-hover:text-<?= $raid->color ?> bg-<?= $raid->color ?> bg-opacity-50"><?= $raid->title ?></div>
|
||||
<?php if ($raid->difficulty) : ?><div class="text-sm text-slate-500">(<?= $raid->difficulty ?>)</div><?php endif; ?>
|
||||
</a>
|
||||
<?php
|
||||
|
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
|
||||
use WoWPress\Api\BattleNet;
|
||||
use WoWPress\Database\Cache;
|
||||
use WoWPress\Frontend\Icon;
|
||||
use WoWPress\Models\Character;
|
||||
use WoWPress\Models\CharacterList;
|
||||
|
||||
global $widget_area;
|
||||
set_sidebar_status('top', false);
|
||||
|
||||
$characters = Character::orderBy('rank')->get();
|
||||
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'] ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<section id="primary" x-data="{char:null}">
|
||||
<main id="main">
|
||||
<div class="flex flex-col gap-10">
|
||||
<?php foreach ($list->characters()->get()->groupBy('ID') as $character) : ?>
|
||||
<div class="flex flex-row gap-2 flex-wrap">
|
||||
<div class="bg-glass shadow p-auto text-center xl:w-1/4">
|
||||
<div class="text-2xl"><?php $character->first()->classButton ?></div>
|
||||
</div>
|
||||
<div class="bg-glass shadow p-auto flex-grow xl:flex-grow-0 text-2xl flex flex-col items-center justify-center">
|
||||
<?= $character->count() ?>x
|
||||
</div>
|
||||
<div class="hidden flex-grow xl:grid gap-2" style=" grid-template-columns: repeat(auto-fill, 24%);">
|
||||
<?php foreach ($character as $listItem) : ?>
|
||||
<?php if (current_user_can('wowpress_edit_raids')) : ?>
|
||||
<div class="bg-glass shadow p-auto flex-grow text-center border border-<?= $list->border_color ? $list->border_color . "-500" : 'white' ?>" x-data="{open:false}" @click="open=!open">
|
||||
<div><?= format_date($listItem->pivot->date) ?></div>
|
||||
<div><?= $listItem->pivot->comment ?></div>
|
||||
<template x-teleport="body">
|
||||
<div x-show="open" class="fixed inset-0 px-2 z-10 overflow-hidden flex items-center justify-center">
|
||||
<div x-show="open" x-on:click="open = false" x-transition:enter="transition-opacity ease-out duration-300" x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100" x-transition:leave="transition-opacity ease-in duration-300" x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0" class="absolute inset-0 bg-deepblue bg-opacity-75 transition-opacity"></div>
|
||||
<!-- Modal Content -->
|
||||
<div x-show="open" x-transition:enter="transition-transform ease-out duration-300" x-transition:enter-start="transform scale-75" x-transition:enter-end="transform scale-100" x-transition:leave="transition-transform ease-in duration-300" x-transition:leave-start="transform scale-100" x-transition:leave-end="transform scale-75" class="bg-glass border shadow overflow-hidden max-w-md w-full sm:w-96 md:w-1/2 lg:w-2/3 xl:w-1/3 z-50">
|
||||
<!-- Modal Body -->
|
||||
<div class="p-auto flex flex-col gap-2 items-center justify-center">
|
||||
<form id="removeListItem<?= $listItem->pivot->ID ?>" action="/request" method="POST" class="hidden">
|
||||
<?php wp_nonce_field('removeListItem', 'removeListItem_nonce'); ?>
|
||||
<input type="hidden" name="action" value="removeListItem">
|
||||
<input type="hidden" name="item_id" value="<?= $listItem->pivot->ID ?>">
|
||||
<!-- Modal Footer -->
|
||||
</form>
|
||||
<?php $listItem->classButton?>
|
||||
<div class="text-center w-full p-auto border border-white">Eintrag vom <?=format_date($listItem->pivot->date)?></div>
|
||||
<button type="submit" form="removeListItem<?= $listItem->pivot->ID ?>" class="btn btn-red w-full">Löschen</button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<?php else : ?>
|
||||
<div class="bg-glass shadow p-auto flex-grow text-center border border-<?= $list->border_color ? $list->border_color . "-500" : 'white' ?>">
|
||||
<div><?= format_date($listItem->pivot->date) ?></div>
|
||||
<div><?= $listItem->pivot->comment ?></div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endforeach ?>
|
||||
<?php
|
||||
if (current_user_can('wowpress_edit_raids')) :
|
||||
?>
|
||||
<button @click="char=<?= $listItem->ID ?>" class="btn btn-<?= $list->border_color ?>"><?= Icon::get('o-plus') ?></button>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</main><!-- #main -->
|
||||
<?php
|
||||
if (current_user_can('wowpress_edit_raids')) : ?>
|
||||
|
||||
<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('addCharToList', 'addCharToList_nonce'); ?>
|
||||
<input type="hidden" name="action" value="addCharToList">
|
||||
<input type="hidden" name="list_id" value="<?= $list->ID ?>">
|
||||
<select name="character_ID" id="" x-model="char" class="bg-white bg-opacity-0 border-alliance">
|
||||
<option value="null" selected disabled>Charakter auswählen</option>
|
||||
<?php
|
||||
foreach (Character::all() as $char) :
|
||||
?>
|
||||
<option value="<?= $char->ID ?>"><?= $char->name ?> - <?= $char->realm ?></option>
|
||||
<?php
|
||||
endforeach;
|
||||
?>
|
||||
</select>
|
||||
<input type="text" class="bg-white bg-opacity-0 border-alliance" placeholder="Kommentar" name="comment">
|
||||
<input type="date" name="date" id="" class="bg-white bg-opacity-0 border-alliance">
|
||||
<button type="submit" class="btn btn-outline btn-<?= $list->border_color ?>"><?= Icon::get('o-plus') ?> Hinzufügen</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</section><!-- #primary -->
|
||||
|
||||
<?php
|
||||
|
||||
get_footer();
|
|
@ -2,7 +2,12 @@
|
|||
require_once('vendor/autoload.php');
|
||||
|
||||
use Illuminate\Support\Facades\Redirect;
|
||||
use Wenprise\Eloquent\Database;
|
||||
use Wenprise\Eloquent\Facades\DB;
|
||||
use Wenprise\Eloquent\Model;
|
||||
use WoWPress\Models\Character;
|
||||
use WoWPress\Models\CharacterList;
|
||||
use WoWPress\Models\CharacterListItem;
|
||||
use WoWPress\Models\Complaint;
|
||||
use WoWPress\Models\Log;
|
||||
use WoWPress\Models\Notification;
|
||||
|
@ -245,6 +250,7 @@ switch ($_POST['action']) {
|
|||
$c->complaint = $_POST['complaint'];
|
||||
$c->anonymous = !empty($_POST['hide']);
|
||||
$c->save();
|
||||
Notification::addCapabilityNotification("wowpress_edit_complaints", "Neuer Eintrag im Kummerkasten!");
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -334,24 +340,79 @@ switch ($_POST['action']) {
|
|||
case 'updatePageBG':
|
||||
isAllowed('wowpress_edit_site');
|
||||
if (isset($_POST['updatePageBG_nonce']) && wp_verify_nonce($_POST['updatePageBG_nonce'], 'updatePageBG')) {
|
||||
if (isset($_FILES['bg']) && $_FILES['bg']['type'] == "image/jpeg" ) {
|
||||
$bg_path = ABSPATH."/wp-content/bg.jpg";
|
||||
rename($_FILES['bg']['tmp_name'],$bg_path);
|
||||
chmod(ABSPATH."/wp-content/bg.jpg",0644);
|
||||
if (isset($_FILES['bg']) && $_FILES['bg']['type'] == "image/jpeg") {
|
||||
$bg_path = ABSPATH . "/wp-content/bg.jpg";
|
||||
rename($_FILES['bg']['tmp_name'], $bg_path);
|
||||
chmod(ABSPATH . "/wp-content/bg.jpg", 0644);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'updateRaidTitle':
|
||||
isAllowed('wowpress_edit_raids');
|
||||
if (isset($_POST['updateRaidTitle_nonce']) && wp_verify_nonce($_POST['updateRaidTitle_nonce'], 'updateRaidTitle')) {
|
||||
if(isset($_POST['raid_id']) && isset($_POST['name'])){
|
||||
if (isset($_POST['raid_id']) && isset($_POST['name'])) {
|
||||
$raid = Raid::find($_POST['raid_id']);
|
||||
if($raid){
|
||||
if ($raid) {
|
||||
$raid->setTitle($_POST['name']);
|
||||
}
|
||||
}
|
||||
}
|
||||
case 'addList':
|
||||
isAllowed('wowpress_edit_raids');
|
||||
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'];
|
||||
$list->notify = !empty($_POST['notify']);
|
||||
$list->max_count = 18;
|
||||
$list->save();
|
||||
}
|
||||
}
|
||||
case 'addCharToList':
|
||||
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'])){
|
||||
$list = CharacterList::find($_POST['list_id']);
|
||||
$char = Character::find($_POST['character_ID']);
|
||||
if($char && $list){
|
||||
$comment = "";
|
||||
$date = date('Y-m-d');
|
||||
if(!empty($_POST['comment'])){
|
||||
$comment = $_POST['comment'];
|
||||
}
|
||||
if(!empty($_POST['date'])){
|
||||
$date = $_POST['date'];
|
||||
}
|
||||
$list->addItem($char,$comment,$date);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case 'removeListItem':
|
||||
isAllowed('wowpress_edit_raids');
|
||||
if(checkNonce('removeListItem')){
|
||||
if(isset($_POST['item_id'])){
|
||||
$item_id = intval($_POST['item_id']);
|
||||
$item = CharacterListItem::find($item_id);
|
||||
if($item){
|
||||
$item->delete();
|
||||
#CharacterListItem::deleteOrphans();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'cron':
|
||||
if(isset($_POST['cron'])){
|
||||
switch($_POST['cron']){
|
||||
case 'update_applications':
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
header('Location: ' . $_SERVER['HTTP_REFERER']);
|
||||
|
|
|
@ -136,14 +136,14 @@ if (is_user_logged_in()) {
|
|||
<div x-show="notification">
|
||||
<div class="p-2 flex flex-col mt-1 absolute gap-2 shadow" style="background-color:var(--color-deepblue)">
|
||||
<?php foreach ($notifications as $notification) : ?>
|
||||
<div class="p-2 border flex flex-row gap-1 justify-between">
|
||||
<div class="p-2 border border-alliance flex flex-row gap-1 justify-between">
|
||||
<form class="hidden" action="/request" method="POST" id="deleteNotification<?= $notification->ID ?>">
|
||||
<input type="hidden" name="action" value="notificationSeen">
|
||||
<input type="hidden" name="notification_id" value="<?= $notification->ID ?>">
|
||||
<?php wp_nonce_field('notificationSeen', 'notificationSeen_nonce'); ?>
|
||||
</form>
|
||||
<div><?= $notification->note ?></div>
|
||||
<button type="submit" class="cursor-pointer" form="deleteNotification<?= $notification->ID ?>"><?= Icon::get('o-x-circle') ?> </button>
|
||||
<div class="my-2 mx-3"><?= $notification->note ?></div>
|
||||
<button type="submit" class="cursor-pointer text-red-500" form="deleteNotification<?= $notification->ID ?>"><?= Icon::get('o-x-circle') ?> </button>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<?php
|
||||
|
||||
namespace WoWPress\Database;
|
||||
|
||||
class CreateCharListItemTable extends CreateTable
|
||||
{
|
||||
|
||||
public static $table_name = "charlists_item";
|
||||
public static $fields = [
|
||||
'character_id' => 'mediumint NOT NULL',
|
||||
'list_id' => 'mediumint NOT NULL',
|
||||
'date' => 'date NOT NULL',
|
||||
'count_multiplier' => 'tinyint NOT NULL',
|
||||
'comment' => 'text',
|
||||
];
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace WoWPress\Database;
|
||||
|
||||
class CreateCharListsTable extends CreateTable
|
||||
{
|
||||
|
||||
public static $table_name = "charlists";
|
||||
public static $fields = [
|
||||
'list_name' => 'text NOT NULL',
|
||||
'border_color' => 'text NOT NULL',
|
||||
'max_count' => 'mediumint NOT NULL',
|
||||
'notify' => 'boolean'
|
||||
];
|
||||
|
||||
}
|
|
@ -29,6 +29,10 @@ class Character extends Model
|
|||
$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 user(){
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
@ -53,15 +57,25 @@ class Character extends Model
|
|||
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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace WoWPress\Models;
|
||||
|
||||
use Wenprise\Eloquent\Model;
|
||||
|
||||
class CharacterList extends Model{
|
||||
|
||||
protected $table = "wowpress_charlists";
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'ID';
|
||||
protected $guarded = ['ID'];
|
||||
|
||||
public function characters(){
|
||||
return $this->belongsToMany(Character::class,'wowpress_charlists_item','character_id','list_id')->orderBy('character_id')->orderByPivot('date')->withPivot('comment','date','ID');
|
||||
}
|
||||
|
||||
public function addItem(Character $char, $comment = null, $date = null, $multiplier = 1){
|
||||
$this->characters()->attach($char->ID,[
|
||||
'comment' => $comment,
|
||||
'date' => $date?:date('Y-m-d'),
|
||||
'count_multiplier' => $multiplier
|
||||
]);
|
||||
if($this->notify){
|
||||
if($char->user){
|
||||
Notification::addNotification($char->user->ID,'Neuer Eintrag in Liste: '.$this->list_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function removeItem($id){
|
||||
$this->characters()->wherePivot('id',$id)->first()->detach();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace WoWPress\Models;
|
||||
|
||||
use LogicException;
|
||||
use Wenprise\Eloquent\Model;
|
||||
|
||||
class CharacterListItem extends Model{
|
||||
|
||||
protected $table = "wowpress_charlists_item";
|
||||
public $timestamps = false;
|
||||
protected $primaryKey = 'ID';
|
||||
protected $guarded = ['ID'];
|
||||
|
||||
|
||||
public function list(){
|
||||
$this->belongsTo(CharacterList::class,'list_id');
|
||||
}
|
||||
|
||||
public function character(){
|
||||
$this->belongsTo(Character::class,'character_id');
|
||||
}
|
||||
|
||||
public static function deleteOrphans(){
|
||||
$items = static::all();
|
||||
foreach($items as $item){
|
||||
try{
|
||||
$item->list;
|
||||
}catch(LogicException $e){
|
||||
$item->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -19,6 +19,15 @@ class Notification extends Model{
|
|||
$note->save();
|
||||
}
|
||||
|
||||
public static function addCapabilityNotification($capability,$note_text){
|
||||
$users = get_users(array(
|
||||
'capability' => $capability,
|
||||
));
|
||||
foreach($users as $user){
|
||||
Notification::addNotification($user->ID, $note_text);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getAll(){
|
||||
return Notification::where('user_id',get_current_user_id())->get();
|
||||
}
|
||||
|
|
|
@ -81,9 +81,9 @@ class Raid extends Model
|
|||
if (!empty($this->id_wowaudit)) {
|
||||
$raid = (object)$this->api->getRaid($this->id_wowaudit, $force);
|
||||
if (!empty($raid->id)) {
|
||||
if($this->title && $raid->instance == "Custom"){
|
||||
if ($this->title && $raid->instance == "Custom") {
|
||||
//Titel nur sezten wenn kein Custom Raid
|
||||
}else{
|
||||
} else {
|
||||
$this->title = $raid->instance;
|
||||
}
|
||||
$this->start = $raid->date . " " . $raid->start_time;
|
||||
|
@ -183,7 +183,7 @@ class Raid extends Model
|
|||
}
|
||||
|
||||
$this->encounters = collect($encounters);
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -192,7 +192,8 @@ class Raid extends Model
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function setTitle($title){
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->save();
|
||||
}
|
||||
|
@ -222,27 +223,28 @@ class Raid extends Model
|
|||
public function getPreviousAttribute()
|
||||
{
|
||||
|
||||
$previous = Raid::where('start','<',$this->start)->orderBy('start','DESC')->first();
|
||||
$previous = Raid::where('start', '<', $this->start)->orderBy('start', 'DESC')->first();
|
||||
return $previous;
|
||||
}
|
||||
|
||||
public function getThumbnailAttribute(){
|
||||
public function getThumbnailAttribute()
|
||||
{
|
||||
|
||||
$clean_name = str_replace([" ","'"],"-",$this->title);
|
||||
$clean_name = str_replace([" ", "'"], "-", $this->title);
|
||||
$clean_name = preg_replace('/[^a-zA-Z0-9_-]/', '', $clean_name);
|
||||
$clean_name = strtolower($clean_name);
|
||||
$url = "https://data.wowaudit.com/img/$clean_name-small.jpeg";
|
||||
if(file_exists($url)){
|
||||
return $url;
|
||||
}
|
||||
list($status) = get_headers($url);
|
||||
if (strpos($status, '404') !== FALSE) {
|
||||
return "https://data.wowaudit.com/img/custom-small.jpeg";
|
||||
|
||||
}
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
public function getNextAttribute()
|
||||
{
|
||||
$next = Raid::where('start','>',$this->start)->orderBy('start','ASC')->first();
|
||||
$next = Raid::where('start', '>', $this->start)->orderBy('start', 'ASC')->first();
|
||||
return $next;
|
||||
}
|
||||
|
||||
|
@ -254,7 +256,7 @@ class Raid extends Model
|
|||
} else {
|
||||
$chars = [$character];
|
||||
}
|
||||
if(!empty($this->id_wowaudit)) $this->sync();
|
||||
if (!empty($this->id_wowaudit)) $this->sync();
|
||||
if (!empty($character->ID) && !empty($this->signups)) {
|
||||
foreach ($this->signups as $signup) {
|
||||
foreach ($chars as $character) {
|
||||
|
@ -268,7 +270,6 @@ class Raid extends Model
|
|||
$s = new Signup();
|
||||
$s->raid_id = $this->ID;
|
||||
$s->character_id = $character->ID;
|
||||
return $s->showForm($showRole,$showStatus,$vertical);
|
||||
|
||||
return $s->showForm($showRole, $showStatus, $vertical);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue