Raid anmeldung 2.0

master
sephger 2024-04-22 15:38:22 +02:00
parent d7328bb087
commit 6bb27671fd
57 changed files with 3173 additions and 341 deletions

View File

@ -2,100 +2,100 @@
use WoWPress\Frontend\Icon; use WoWPress\Frontend\Icon;
use WoWPress\Frontend\ToggleButton; use WoWPress\Frontend\ToggleButton;
use WoWPress\Models\Signup;
$id = "raidSignup_" . uniqid();
global $user;
if(!empty($this->character->user->ID)){
$chars = $this->character->user->characters;
}else{
$chars = [$this->character];
}
?> ?>
<div class="flex flex-row" x-data="{open : false}"> <div class="flex <?= $vertical ? "flex-col" : "flex-row" ?> border border-<?= $this->character->color ?> shadow" x-data="{open : false}">
<button x-on:click="open = true" class="btn btn-<?= $character->color ?> w-full"><img src="<?= $character->classIcon ?>" class="h-8"><?= $character->name ?></button> <button <?=($doSignup && $this->character->can_edit)?'x-on:click="open = true"':''?> class="btn btn-outline btn-<?= $this->character->color ?> w-full">
<div class="border border-<?= $character->color ?> flex flex-row text-slate-500 items-center justify-center p-auto border-s-0"><?= Icon::get('o-minus-circle') ?></div> <img src="<?= $this->character->classIcon ?>" class="h-8"><?= $this->character->name ?></button>
<div class="border border-<?= $character->color ?> flex flex-row text-slate-500 items-center justify-center p-auto border-s-0"><?= Icon::get('o-minus-circle') ?></div> <?php if ($showStatus) : ?>
<div class="border border-<?= $this->character->color ?> bg-<?=$this->getStatus()->color?> bg-opacity-25 flex flex-row text-<?= $this->getStatus()->color ?> items-center justify-center p-auto gap-1"><?= Icon::get($this->getStatus()->icon) ?>
<?= $vertical ? $this->getStatus()->name : "" ?>
</div>
<?php endif; ?>
<?php if ($showRole) : ?>
<div class="border border-<?= $this->character->color ?> bg-<?=$this->getRole()->color?> bg-opacity-25 flex flex-row text-<?= $this->getRole()->color ?> items-center justify-center p-auto gap-1"><?= Icon::get($this->getRole()->icon) ?>
<?=$vertical?$this->getRole()->name:""?>
</div>
<?php endif; ?>
<?php if($doSignup && $this->character->can_edit): ?>
<template x-teleport="body"> <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" 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> <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 --> <!-- 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 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"> <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 --> <!-- Modal Body -->
<form action=""> <form id="<?= $id ?>">
<div class="grid grid-cols-2 gap-auto p-auto"> <div class="grid p-auto gap-auto">
<button class="col-span-2 btn btn-<?= $character->color ?> w-full"><img src="<?= $character->classIcon ?>" class="h-8"><?= $character->name ?></button> <?php foreach($chars as $key => $character):
<div class="col-span-2 text-center">Anwesenheit</div>
<?= (new ToggleButton([ (new ToggleButton([
'type' => 'radio', 'type' => 'radio',
'name' => 'raid_status', 'name' => 'rad_character',
'text' => 'Anwesend', 'text' => $character->name,
'color' => 'monk', 'color' => $character->color,
'icon_yes' => 'o-check-circle', 'icon_yes' => 'o-check',
'checked' => true, 'checked' => $character->ID == $this->character->ID,
'row' => false, 'row' => false,
]))->render() ?> ]))->render();
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_status', endforeach; ?>
'text' => 'Abwesend',
'color' => 'deathknight',
'icon_yes' => 'o-x-circle',
'row' => false,
]))->render() ?>
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_status',
'text' => 'Ersatzbank',
'color' => 'druid',
'icon_yes' => 'o-question-mark-circle',
'row' => false,
]))->render() ?>
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_status',
'text' => 'Verspätet',
'color' => 'demonhunter',
'icon_yes' => 'o-clock',
'row' => false,
]))->render() ?>
<div class="col-span-2 text-center">Rolle</div>
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_role',
'text' => 'Tank',
'color' => 'priest',
'icon_yes' => 'o-shield-exclamation',
'row' => false,
]))->render() ?>
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_role',
'text' => 'Heal',
'color' => 'priest',
'icon_yes' => 'o-heart',
'row' => false,
]))->render() ?>
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_role',
'text' => 'Ranged',
'color' => 'priest',
'icon_yes' => 'o-bolt',
'checked' => true,
'row' => false,
]))->render() ?>
<?= (new ToggleButton([
'type' => 'radio',
'name' => 'raid_role',
'text' => 'Melee',
'color' => 'priest',
'icon_yes' => 'o-hand-raised',
'row' => false,
]))->render() ?>
</div>
<!-- Modal Footer -->
<div class="border-t p-auto">
<button x-on:click="open = false" class="btn btn-outline btn-monk w-full">
<?= Icon::get('o-paper-airplane') ?>
<span>Status Speichern</span>
</button>
</div> </div>
<div class="grid grid-cols-2 gap-auto p-auto">
<div class="col-span-2 text-center">Anwesenheit</div>
<?php
foreach ($this->getStatusList(true) as $key => $status) {
(new ToggleButton([
'type' => 'radio',
'name' => 'raid_status',
'text' => $status->name,
'color' => $status->color,
'icon_yes' => $status->icon,
'checked' => $key == $this->status,
'row' => false,
]))->render();
}
?>
<div class="col-span-2 text-center">Rolle</div>
<?php
foreach ($this->getRoleList() as $key => $role) {
(new ToggleButton([
'type' => 'radio',
'name' => 'raid_role',
'text' => $role->name,
'color' => $role->color,
'icon_yes' => $role->icon,
'checked' => $key == $this->role,
'row' => false,
]))->render();
}
?>
<div class="col-span-2 text-center">Kommentar</div>
<div class="flex flex-col gap-auto col-span-2">
<input type="text" class="w-full bg-glass text-white border border-white" placeholder="Kommentar eingeben...">
<button x-on:click="open = false" class="btn btn-outline btn-monk">
<?= Icon::get('o-paper-airplane') ?>
Speichern
</button>
</div>
</div>
<!-- Modal Footer -->
</form> </form>
</div> </div>
</div> </div>
</template> </template>
<?php endif; ?>
</div> </div>

View File

@ -1,7 +1,8 @@
{ {
"require": { "require": {
"wenprise/eloquent": "^9.0", "wenprise/eloquent": "^9.0",
"blade-ui-kit/blade-heroicons": "^2.3" "blade-ui-kit/blade-heroicons": "^2.3",
"wenprise/wp-orm": "dev-main"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {

55
theme/composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "5625e5e811b04817d86fbc8aa09b2525", "content-hash": "d60cf4fa524106e881f804fded28561e",
"packages": [ "packages": [
{ {
"name": "blade-ui-kit/blade-heroicons", "name": "blade-ui-kit/blade-heroicons",
@ -2427,12 +2427,63 @@
"source": "https://github.com/iwillhappy1314/wenprise-eloquent/tree/9.0.1" "source": "https://github.com/iwillhappy1314/wenprise-eloquent/tree/9.0.1"
}, },
"time": "2023-11-17T07:30:03+00:00" "time": "2023-11-17T07:30:03+00:00"
},
{
"name": "wenprise/wp-orm",
"version": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/iwillhappy1314/wenprise-wp-orm.git",
"reference": "6171efa42a6d5b07c13867acd4cd0ff4616fde1b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/iwillhappy1314/wenprise-wp-orm/zipball/6171efa42a6d5b07c13867acd4cd0ff4616fde1b",
"reference": "6171efa42a6d5b07c13867acd4cd0ff4616fde1b",
"shasum": ""
},
"require": {
"wenprise/eloquent": "^9.0"
},
"default-branch": true,
"type": "library",
"autoload": {
"psr-4": {
"Wenprise\\ORM\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Amos Lee",
"email": "iwillhappy1314@gmail.com"
}
],
"description": "Eloquent ORM for WordPress",
"homepage": "https://github.com/iwillhappy1314/wenprise-wp-orm",
"keywords": [
"eloquent",
"orm",
"plugin",
"sql",
"wordpress"
],
"support": {
"issues": "https://github.com/iwillhappy1314/wenprise-wp-orm/issues",
"source": "https://github.com/iwillhappy1314/wenprise-wp-orm/tree/main"
},
"time": "2023-11-16T16:46:17+00:00"
} }
], ],
"packages-dev": [], "packages-dev": [],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": [], "stability-flags": {
"wenprise/wp-orm": 20
},
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": [], "platform": [],

View File

@ -14,7 +14,7 @@
</div><!-- #content --> </div><!-- #content -->
<?php if (is_active_sidebar('right-widgets') && get_sidebar_status('right')) : ?> <?php if (is_active_sidebar('right-widgets') && get_sidebar_status('right')) : ?>
<div class="widget-wrapper right-widgets"> <div class="widget-wrapper right-widgets" id="sidebar_right">
<?php dynamic_sidebar('right-widgets'); ?> <?php dynamic_sidebar('right-widgets'); ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
@ -23,7 +23,7 @@
<div class="sticky top-[100vh]"> <div class="sticky top-[100vh]">
<?php if (is_active_sidebar('bottom-widgets') && get_sidebar_status('bottom')) : ?> <?php if (is_active_sidebar('bottom-widgets') && get_sidebar_status('bottom')) : ?>
<div class="widget-wrapper bottom-widgets"> <div class="widget-wrapper bottom-widgets" id="sidebar_bottom">
<?php dynamic_sidebar('bottom-widgets'); ?> <?php dynamic_sidebar('bottom-widgets'); ?>
</div> </div>
<?php endif; ?> <?php endif; ?>

View File

@ -3,11 +3,16 @@
use WoWPress\Database\CreateCacheTable; use WoWPress\Database\CreateCacheTable;
use WoWPress\Database\CreateCharacterTable; use WoWPress\Database\CreateCharacterTable;
use WoWPress\Database\CreateRaidTable; use WoWPress\Database\CreateRaidTable;
use WoWPress\Database\CreateSignupTable;
use WoWPress\Database\CreateSKSTable;
use WoWPress\Models\Character; use WoWPress\Models\Character;
ini_set('display_errors', 1); ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); ini_set('display_startup_errors', 1);
error_reporting(E_ALL); error_reporting(E_ALL);
global $user;
setlocale(LC_TIME, 'de_DE.UTF8'); setlocale(LC_TIME, 'de_DE.UTF8');
require_once('vendor/autoload.php'); require_once('vendor/autoload.php');
@ -145,6 +150,8 @@ if (!function_exists('wowpress_database')) :
CreateCharacterTable::sql(), CreateCharacterTable::sql(),
CreateCacheTable::sql(), CreateCacheTable::sql(),
CreateRaidTable::sql(), CreateRaidTable::sql(),
CreateSignupTable::sql(),
CreateSKSTable::sql(),
]); ]);
} }
@ -164,7 +171,7 @@ function wowpress_widgets_init()
'name' => __('Header', 'wowpress'), 'name' => __('Header', 'wowpress'),
'id' => 'top-widgets', 'id' => 'top-widgets',
'description' => __('Add widgets here to appear on the header.', 'wowpress'), 'description' => __('Add widgets here to appear on the header.', 'wowpress'),
'before_widget' => '<section id="%1$s" class="widget %2$s">', 'before_widget' => '<section id="%1$s" class="widget %2$s order-last">',
'after_widget' => '</section>', 'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">', 'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>', 'after_title' => '</h2>',
@ -175,7 +182,7 @@ function wowpress_widgets_init()
'name' => __('Linke Seite', 'wowpress'), 'name' => __('Linke Seite', 'wowpress'),
'id' => 'left-widgets', 'id' => 'left-widgets',
'description' => __('Add widgets here to appear on the left side.', 'wowpress'), 'description' => __('Add widgets here to appear on the left side.', 'wowpress'),
'before_widget' => '<section id="%1$s" class="widget %2$s">', 'before_widget' => '<section id="%1$s" class="widget %2$s order-last">',
'after_widget' => '</section>', 'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">', 'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>', 'after_title' => '</h2>',
@ -186,7 +193,7 @@ function wowpress_widgets_init()
'name' => __('Rechte Seite', 'wowpress'), 'name' => __('Rechte Seite', 'wowpress'),
'id' => 'right-widgets', 'id' => 'right-widgets',
'description' => __('Add widgets here to appear on the right side.', 'wowpress'), 'description' => __('Add widgets here to appear on the right side.', 'wowpress'),
'before_widget' => '<section id="%1$s" class="widget %2$s">', 'before_widget' => '<section id="%1$s" class="widget %2$s order-last">',
'after_widget' => '</section>', 'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">', 'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>', 'after_title' => '</h2>',
@ -197,7 +204,7 @@ function wowpress_widgets_init()
'name' => __('Footer', 'wowpress'), 'name' => __('Footer', 'wowpress'),
'id' => 'bottom-widgets', 'id' => 'bottom-widgets',
'description' => __('Add widgets here to appear in your footer.', 'wowpress'), 'description' => __('Add widgets here to appear in your footer.', 'wowpress'),
'before_widget' => '<section id="%1$s" class="widget %2$s">', 'before_widget' => '<section id="%1$s" class="widget %2$s order-last">',
'after_widget' => '</section>', 'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">', 'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>', 'after_title' => '</h2>',
@ -447,6 +454,6 @@ function wowpress_add_category_meta($taxonomy)
} }
return false; return false;
} }
/** Roles */ /** Roles */
set_roles(); set_roles();
setGlobalUser();

View File

@ -11,6 +11,9 @@
* @package WowPress * @package WowPress
*/ */
use WoWPress\Frontend\Icon;
global $user;
?> ?>
<!doctype html> <!doctype html>
<html <?php language_attributes(); ?>> <html <?php language_attributes(); ?>>
@ -19,16 +22,51 @@
<meta charset="<?php bloginfo('charset'); ?>"> <meta charset="<?php bloginfo('charset'); ?>">
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="profile" href="https://gmpg.org/xfn/11"> <link rel="profile" href="https://gmpg.org/xfn/11">
<script src="<?= get_template_directory_uri() ?>/plugins/alpine.min.js" defer></script>
<?php wp_head(); ?> <?php wp_head(); ?>
<style> <style>
:root{ :root {
--color-background: var(--color-deepblue); --color-background: var(--color-deepblue);
} }
</style> </style>
</head> </head>
<body <?php body_class('dark'); ?>> <body <?php body_class('dark'); ?>>
<?php if (get_sidebar_status('left')) : ?>
<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>
<?php if (!$user->ID) : ?>
<div>Bitte <a href="/wp-login.php" class="text-alliance underline">einloggen</a>:)</div>
<?php else : ?>
<div><a href="/wp-login.php?action=logout" class="text-alliance underline"><?= Icon::get('o-power') ?></a></div>
<?php endif; ?>
</div>
<?php if ($user->ID) : ?>
<div>
<h5 class="text-center text-lg font-bold">Charakter-Liste</h5>
<div class="flex flex-col gap-2">
<?php
$chars = $user->characters;
if (!empty($chars)) {
foreach ($chars as $character) : ?>
<button class="btn btn-outline btn-<?= $character->color ?> w-full cursor-default">
<img src="<?= $character->classIcon ?>" class="h-8"><?= $character->name ?></button>
<?php endforeach;
} else {
?>
Keine Chataktere zugewiesen.
<?php
}
?>
</div>
</div>
<?php endif; ?>
</div>
</template>
<?php endif; ?>
<?php wp_body_open(); ?> <?php wp_body_open(); ?>
@ -37,13 +75,13 @@
<?php get_template_part('template-parts/layout/header', 'content'); ?> <?php get_template_part('template-parts/layout/header', 'content'); ?>
<div class="content-wrapper"> <div class="content-wrapper">
<?php if (is_active_sidebar('top-widgets') && get_sidebar_status('top') ) : ?> <?php if (is_active_sidebar('top-widgets') && get_sidebar_status('top')) : ?>
<div class="widget-wrapper top-widgets"> <div class="widget-wrapper top-widgets" id="sidebar_top">
<?php dynamic_sidebar('top-widgets'); ?> <?php dynamic_sidebar('top-widgets'); ?>
</div> </div>
<?php endif; ?> <?php endif; ?>
<?php if (is_active_sidebar('left-widgets') && get_sidebar_status('left')) : ?> <?php if (is_active_sidebar('left-widgets') && get_sidebar_status('left')) : ?>
<div class="widget-wrapper left-widgets"> <div class="widget-wrapper left-widgets" id="sidebar_left">
<?php dynamic_sidebar('left-widgets'); ?> <?php dynamic_sidebar('left-widgets'); ?>
</div> </div>
<?php endif; ?> <?php endif; ?>

View File

@ -1,5 +1,7 @@
<?php <?php
use WoWPress\Models\User;
function set_roles() function set_roles()
{ {
remove_role('editor'); remove_role('editor');
@ -34,7 +36,7 @@ function set_roles()
$admin->add_cap('wowpress_edit_site', true); $admin->add_cap('wowpress_edit_site', true);
$admin->add_cap('wowpress_edit_raids', true); $admin->add_cap('wowpress_edit_raids', true);
$admin->add_cap('wowpress_edit_characters', true); $admin->add_cap('wowpress_edit_characters', true);
$admin->add_cap('wowpress_view_raids');
foreach (get_role('administrator')->capabilities as $cap => $status) { foreach (get_role('administrator')->capabilities as $cap => $status) {
$gm->add_cap($cap, $status); $gm->add_cap($cap, $status);
@ -44,4 +46,29 @@ function set_roles()
$rl->add_cap('wowpress_edit_raids', true); $rl->add_cap('wowpress_edit_raids', true);
$rl->add_cap('wowpress_edit_characters', true); $rl->add_cap('wowpress_edit_characters', true);
$rl->add_cap('wowpress_view_raids');
$raider->add_cap('wowpress_view_raids');
$novize->add_cap('wowpress_view_raids');
}
function isAllowed($capability)
{
if (!current_user_can($capability)) :
include plugin_dir_path(__FILE__) . '../pages/404.php';
die;
endif;
}
function setGlobalUser(){
global $user;
$user = get_current_user_id();
if ($user) {
$user = User::find($user);
} else {
$user = new User();
$user->ID = 0;
$user->login = "Gast";
}
} }

View File

@ -1,14 +1,17 @@
<?php <?php
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
use WoWPress\Models\User;
add_filter('generate_rewrite_rules', function ($wp_rewrite) { add_filter('generate_rewrite_rules', function ($wp_rewrite) {
$wp_rewrite->rules = array_merge( $wp_rewrite->rules = array_merge(
['roster/?$' => 'index.php?wowpress_page=roster'], ['roster/?$' => 'index.php?wowpress_page=roster'],
['raids/?$' => 'index.php?wowpress_page=raids&year='.date('Y')."&month=".date('m')], ['raids/?$' => 'index.php?wowpress_page=raids&year=' . date('Y') . "&month=" . date('m')],
['raids/(\d+)/(\d+)?$' => 'index.php?wowpress_page=raids&year=$matches[1]&month=$matches[2]'], ['raids/(\d+)/(\d+)?$' => 'index.php?wowpress_page=raids&year=$matches[1]&month=$matches[2]'],
['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/(\d+)?$' => 'index.php?wowpress_page=sks&list_name=$matches[1]'],
$wp_rewrite->rules $wp_rewrite->rules
); );
}); });
@ -18,31 +21,34 @@ add_filter('query_vars', function ($query_vars) {
$query_vars[] = 'year'; $query_vars[] = 'year';
$query_vars[] = 'month'; $query_vars[] = 'month';
$query_vars[] = 'raid_id'; $query_vars[] = 'raid_id';
$query_vars[] = 'list_name';
return $query_vars; return $query_vars;
}); });
add_action('template_redirect', function () { add_action('template_redirect', function () {
$page = get_query_var('wowpress_page'); $page = get_query_var('wowpress_page');
setGlobalUser();
switch ($page) { switch ($page) {
case 'roster': case 'roster':
$GLOBALS['wowpress']['widget_area'] = [
'left' => false,
'right' => false,
'top' => false,
'bottom' => true,
];
$GLOBALS['wowpress']['page_title'] = "Gildenverzeichnis"; $GLOBALS['wowpress']['page_title'] = "Gildenverzeichnis";
include plugin_dir_path(__FILE__) . '../pages/roster.php'; include plugin_dir_path(__FILE__) . '../pages/roster.php';
die; die;
break; 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 'raids': case 'raids':
$GLOBALS['wowpress']['widget_area'] = [ # isAllowed('wowpress_view_raids');
'left' => true,
'right' => true,
'top' => false,
'bottom' => true,
];
$GLOBALS['wowpress']['page_title'] = "Raids"; $GLOBALS['wowpress']['page_title'] = "Raids";
$GLOBALS['wowpress']['raids']['year'] = get_query_var('year'); $GLOBALS['wowpress']['raids']['year'] = get_query_var('year');
$GLOBALS['wowpress']['raids']['month'] = get_query_var('month'); $GLOBALS['wowpress']['raids']['month'] = get_query_var('month');
@ -51,13 +57,7 @@ add_action('template_redirect', function () {
die; die;
break; break;
case 'raid': case 'raid':
$GLOBALS['wowpress']['widget_area'] = [ isAllowed('wowpress_view_raids');
'left' => true,
'right' => true,
'top' => false,
'bottom' => true,
];
$raid = Raid::find(get_query_var('raid_id')); $raid = Raid::find(get_query_var('raid_id'));
$GLOBALS['wowpress']['raid'] = $raid; $GLOBALS['wowpress']['raid'] = $raid;
$GLOBALS['wowpress']['page_title'] = $raid->title; $GLOBALS['wowpress']['page_title'] = $raid->title;

View File

@ -0,0 +1,34 @@
<?php
use WoWPress\Api\BattleNet;
use WoWPress\Database\Cache;
use WoWPress\Frontend\Icon;
use WoWPress\Models\Character;
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">
Keine Berechtigung
</div>
</div>
<section id="primary">
<main id="main">
<div class="bg-glass shadow p-auto text-2xl font-bold flex flex-col items-center gap-2">
<?= Icon::get('o-face-frown', '3em') ?>
<span>Leider darfst du hier nicht sein.</span>
<span>Wenn du denkst, das ist ein Fehler, melde dich doch bei deinem lieblings Homepage-Offi und gib ihm Bescheid!</span>
<span>Ansonsten sieh zu, dass du dich hier wieder wegbewegst, zum Beispiel auf die <a class="text-alliance underline" href="/">Hauptseite</a></span>
</div>
</main><!-- #main -->
</section><!-- #primary -->
<?php
get_footer();

View File

@ -1,5 +1,6 @@
<?php <?php
use WoWPress\Frontend\Icon;
use WoWPress\Models\Raid; use WoWPress\Models\Raid;
global $widget_area; global $widget_area;
@ -8,22 +9,44 @@ global $year;
global $month; global $month;
set_sidebar_status('top', false); set_sidebar_status('top', false);
switch ($month) {
case "01":
$prev_month = 12;
$prev_year = $year - 1;
$next_month = $month + 1;
$next_year = $year;
break;
case "12":
$prev_month = $month - 1;
$prev_year = $year;
$next_month = "01";
$next_year = $year + 1;
break;
default:
$prev_month = $month - 1;
$prev_year = $year;
$next_month = $month + 1;
$next_year = $year;
break;
}
$raids = Raid::where("start", ">", "$year-$month-01 00:00:00")->where("start", "<", "$year-$next_month-01 00:00:00")->orderBy('start')->get();
$raids = Raid::where("start", ">", "$year-$month-01 00:00:00")->get();
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))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full"> <a href="/raids/<?= $prev_year ?>/<?= $prev_month ?>" class="bg-glass shadow p-3 flex flex-col items-center justify-center"><?= Icon::get('o-chevron-double-left') ?></a>
<?= $GLOBALS['wowpress']['page_title'] ?> <div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
</div> Raids
</div>
<a href="/raids/<?= $next_year ?>/<?= $next_month ?>" class="bg-glass shadow p-3 flex flex-col items-center justify-center"><?= Icon::get('o-chevron-double-right') ?></a>
</div> </div>
<section id="primary"> <section id="primary">
<main id="main"> <main id="main">
<div class="bg-glass shadow p-auto"> <div class="bg-glass shadow p-auto hidden lg:block">
<div class="text-xl font-bold bg-glass text-white text-center"><?= format_date("$year-$month-1", 'MMMM') ?></div> <div class="text-xl font-bold bg-glass text-white text-center"><?= format_date("$year-$month-1", 'MMMM yyyy') ?></div>
<div class="grid grid-cols-7 gap-1 pt-1" style="grid-auto-rows: 1fr"> <div class="grid grid-cols-7 gap-1 pt-1" style="grid-auto-rows: 1fr">
<?php <?php
for ($i = 1; $i <= date("t", strtotime("$year-$month-01")); $i++) { for ($i = 1; $i <= date("t", strtotime("$year-$month-01")); $i++) {
@ -34,20 +57,20 @@ 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 <?php if (count($has_raid) > 0) { ?> glow shadow-<?= $has_raid[0]->color ?> <?php } ?> grid grid-cols-2 grid-rows-2">
<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; ?>
</a> </a>
<?php <?php
} }
?> ?>
</div> </div>
@ -56,6 +79,19 @@ get_header();
?> ?>
</div> </div>
</div> </div>
<div class="bg-glass shadow p-auto block lg:hidden">
<div class="text-xl font-bold bg-glass text-white text-center"><?= format_date("$year-$month-1", 'MMMM yyyy') ?></div>
<div class="flex flex-col gap-2">
<?php foreach ($raids as $raid) : ?>
<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><?=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; ?>
</a>
<?php endforeach; ?>
</div>
</div>
</main> </main>
</section> </section>

View File

@ -5,6 +5,7 @@ use WoWPress\Api\BattleNet;
use WoWPress\Database\Cache; use WoWPress\Database\Cache;
use WoWPress\Frontend\Icon; use WoWPress\Frontend\Icon;
use WoWPress\Models\Character; use WoWPress\Models\Character;
use WoWPress\Models\User;
global $widget_area; global $widget_area;
set_sidebar_status('top', false); set_sidebar_status('top', false);
@ -14,9 +15,9 @@ 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))">
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full"> <div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $GLOBALS['wowpress']['page_title'] ?> <?= $GLOBALS['wowpress']['page_title'] ?>
</div> </div>
</div> </div>
<section id="primary"> <section id="primary">
@ -30,7 +31,12 @@ get_header();
<td class="p-auto hidden lg:table-cell">Rang</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">Server</td>
<td class="p-auto hidden lg:table-cell">Gilde</td> <td class="p-auto hidden lg:table-cell">Gilde</td>
<td class="p-auto">Aktionen</td> <?php if (current_user_can('wowpress_edit_characters')) : ?>
<td class="p-auto hidden lg:table-cell">
User
</td>
<td class="p-auto">Aktionen</td>
<?php endif; ?>
</tr> </tr>
</thead> </thead>
<tbody class="bg-slate-900"> <tbody class="bg-slate-900">
@ -53,42 +59,81 @@ get_header();
<td class="p-auto hidden lg:table-cell"><?= $char->rank ?></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->realm ?></td>
<td class="p-auto hidden lg:table-cell"><?= $char->guild ?></td> <td class="p-auto hidden lg:table-cell"><?= $char->guild ?></td>
<?php if (current_user_can('wowpress_edit_characters')) : ?>
<td class="p-auto"> <td class="p-auto hidden lg:table-cell">
<div class="flex flex-row justify-end gap-2">
<form action="/request" method="POST">
<?php wp_nonce_field('updateCharacter', 'updateCharacter_nonce'); ?>
<input type="hidden" name="action" value="updateCharacter">
<input type="hidden" name="id" value="<?=$char->ID?>">
<button type="submit" class="btn btn-outline button-green"><?= Icon::get('o-arrow-path') ?></button>
</form>
<form action="/request" method="POST"> <form action="/request" method="POST">
<?php wp_nonce_field('deleteCharacter', 'deleteCharacter_nonce'); ?> <input type="hidden" name="char_id" value="<?= $char->ID ?>">
<input type="hidden" name="action" value="deleteCharacter"> <?php wp_nonce_field('changeUser', 'changeUser_nonce'); ?>
<input type="hidden" name="id" value="<?=$char->ID?>"> <input type="hidden" name="action" value="changeUser">
<button type="submit" class="btn btn-outline button-red"><?= Icon::get('o-trash') ?></button> <div class="flex flex-row">
<div x-data="{ open: false, uid: '<?= $char->user ? $char->user->ID : "0" ?>' , selected: '<?= $char->user ? $char->user->login : "" ?>' }" @click.away="open = false" class="relative">
<input type="hidden" name="uid" x-model="uid">
<!-- Button -->
<button type="button" @click="open = !open" class="min-w-[180px] max-w-[180px] h-full px-4 py-2 border-e-0 border border-<?= $char->color ?> flex items-center justify-between" :class="{'text-<?= $char->color ?>': selected !== '', 'text-gray-500': selected === ''}">
<span class="max-w-[120px] overflow-hidden" x-text="selected === '' ? 'Kein User' : selected"></span>
<svg class="ml-2 w-4 h-4" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
</svg>
</button>
<!-- Dropdown Menu -->
<div x-show="open" class="absolute mt-2 bg-glass border border-<?= $char->color ?> w-full z-10" x-cloak>
<ul class="max-h-[240px] overflow-auto [&>li]:text-slate-200 [&>li]:px-4 [&>li]:py-2 hover:[&>li]:bg-slate-600 [&>li]:cursor-pointer">
<li @click="selected = ''; uid='0'; open = false;" value="0">Kein User</li>
<?php foreach (User::all() as $user) : ?>
<li @click="selected = '<?= $user->login ?>'; uid = '<?= $user->ID ?>'; open = false;" value="<?= $user->ID ?>"><?= $user->login ?></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<button type="submit" class="btn btn-<?= $char->color ?>"><?= Icon::get('o-user-plus') ?></button>
</div>
</form> </form>
</div> </td>
</td> <td class="p-auto">
<div class="flex flex-row justify-end gap-2">
<form action="/request" method="POST">
<?php wp_nonce_field('updateCharacter', 'updateCharacter_nonce'); ?>
<input type="hidden" name="action" value="updateCharacter">
<input type="hidden" name="id" value="<?= $char->ID ?>">
<button type="submit" class="btn btn-outline button-green"><?= Icon::get('o-arrow-path') ?></button>
</form>
<form action="/request" method="POST">
<?php wp_nonce_field('deleteCharacter', 'deleteCharacter_nonce'); ?>
<input type="hidden" name="action" value="deleteCharacter">
<input type="hidden" name="id" value="<?= $char->ID ?>">
<button type="submit" class="btn btn-outline button-red"><?= Icon::get('o-trash') ?></button>
</form>
</div>
</td>
<?php endif; ?>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="bg-glass shadow p-auto m-auto lg:w-1/4">
<form action="/request" method="POST">
<div class="flex flex-col gap-2">
<?php wp_nonce_field('addCharacter', 'addCharacter_nonce'); ?>
<input type="hidden" name="action" value="addCharacter">
<input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</main><!-- #main --> </main><!-- #main -->
</section><!-- #primary --> </section><!-- #primary -->
<?php if (current_user_can('wowpress_edit_characters')) : ?>
<div x-data="{addChar:true}">
<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('addCharacter', 'addCharacter_nonce'); ?>
<input type="hidden" name="action" value="addCharacter">
<input type="text" name="name" placeholder="Name" class="text-black">
<input type="text" name="realm" placeholder="Server" class="text-black">
<button type="submit" class="btn btn-outline btn-hunter">Hinzufügen</a>
</div>
</form>
</div>
</template>
</div>
<?php <?php
endif;
get_footer(); get_footer();

View File

@ -1,114 +1,123 @@
<?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);
get_header(); global $user;
?>
<div class="top-title flex flex-col lg:flex-row gap-auto" style="margin-top:calc(-1 * var(--wowp-gap))"> if($raid->id_wowaudit){
<?php if ($raid->previous) : ?> $raid->sync(true);
<a href="<?= $raid->previous->link ?>" class="btn btn-outline hidden lg:flex">Vorheriger</a> $raid->save();
<?php endif; ?> }
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full"> $unkowns = [];
<?= $GLOBALS['wowpress']['page_title'] ?>
get_header();
?>
<div class="top-title flex flex-col lg:flex-row gap-auto" style="margin-top:calc(-1 * var(--wowp-gap))">
<?php if ($raid->previous) : ?>
<a href="<?= $raid->previous->link ?>" class="btn btn-outline hidden lg:flex">Vorheriger</a>
<?php endif; ?>
<div class="text-3xl font-bold bg-glass shadow p-3 text-center w-full">
<?= $raid->title ?>
</div>
<?php if ($raid->next) : ?>
<a href="<?= $raid->next->link ?>" class="btn btn-outline hidden lg:flex">Nächster</a>
<?php endif; ?>
</div> </div>
<?php if ($raid->next) : ?> <section id="primary">
<a href="<?= $raid->next->link ?>" class="btn btn-outline hidden lg:flex">Nächster</a> <main id="main">
<?php endif; ?> <div class="flex flex-col lg:flex-row gap-auto" x-data="{encounter:<?= $raid->encounters[0]['id'] ?>}">
</div> <div class="bg-glass shadow p-auto w-full lg:w-1/5 order-2 lg:order-1">
<section id="primary"> <h3 class="text-xl font-bold text-center">Bosse</h3>
<main id="main"> <div class="grid gap-auto">
<div class="flex flex-col lg:flex-row gap-auto"> <?php foreach ($raid->encounters as $encounter) : ?>
<div class="bg-glass shadow p-auto w-full lg:w-1/5 order-2 lg:order-1"> <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>
<h3 class="text-xl font-bold text-center">Bosse</h3> <?php endforeach; ?>
<div class="grid gap-auto"> </div>
<button class="btn btn-outline btn-alliance">Alle</button>
<button class="btn btn-outline btn-priest">Fahrs'tuhl der Raidzerstörer</button>
<button class="btn btn-outline btn-priest">Hogger</button>
<button class="btn btn-outline btn-priest">Sylvanas linker Zeh</button>
<button class="btn btn-outline btn-priest">RC Loot Council (Endboss)</button>
</div> </div>
</div> <div class="w-full flex flex-col gap-auto order-3 lg:order-2">
<div class="w-full flex flex-col gap-auto order-3 lg:order-2"> <div class="flex flex-col lg:flex-row gap-auto">
<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="bg-glass shadow p-auto w-full lg:w-1/5"> <div class="grid text-center gap-1">
<div class="grid text-center gap-1"> <div class="bg-<?= $raid->color ?> text-black text-2xl "><?= format_date($raid->start, "EEEE") ?></div>
<div class="bg-<?= $raid->color ?> text-black text-2xl "><?= format_date($raid->start, "EEEE") ?></div> <div class="border border-<?= $raid->color ?>">
<div class="border border-<?= $raid->color ?>"> <div class="text-3xl p-auto "><?= format_date($raid->start, "dd. MMMM") ?></div>
<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="border border-<?= $raid->color ?> p-2">Start: <?= format_date($raid->start, "HH:mm") ?></div> </div>
<div class="border border-<?= $raid->color ?> p-2">Ende: <?= format_date($raid->end, "HH:mm") ?></div> <div class="bg-glass shadow p-auto w-full">
<?php if ($raid->difficulty) : ?> <?php foreach ($raid->encounters as $encounter) : ?>
<div class="border border-<?= $raid->color ?> p-2"><?= $raid->difficulty ?></div> <div x-cloak x-show="encounter==<?= $encounter['id'] ?>">
<?php endif; ?> <h3 class="text-xl font-bold">Informationen für : <?= $encounter['name'] ?></h3>
<div>
<?=$encounter['notes']?>
</div>
</div>
<?php endforeach; ?>
</div> </div>
</div> </div>
<div class="bg-glass shadow p-auto w-full">
<h3 class="text-xl font-bold">Informationen:</h3>
<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> </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 lg:flex-row gap-auto"> <div class="flex flex-col gap-auto">
<div class="w-full grid grid-cols-1 lg:grid-cols-4 gap-auto"> <h3 class="text-xl font-bold text-center">Status</h3>
<div class="bg-glass shadow p-auto flex flex-col gap-auto"> <?= $raid->showSignup($user->characters->first(), true, true, true) ?>
<h3 class="text-xl font-bold text-center">Tank</h3>
</div>
<div class="bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Heal</h3>
<?= $raid->showSignup(Character::whereName('Pandacetamol')->first()) ?>
</div>
<div class="bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Range</h3>
<?= $raid->showSignup(Character::whereName('Bleihagel')->first()) ?>
</div>
<div class="bg-glass shadow p-auto flex flex-col gap-auto">
<h3 class="text-xl font-bold text-center">Melee</h3>
<?= $raid->showSignup(Character::whereName('Moodyblues')->first()) ?>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="flex flex-col gap-auto w-full lg:w-1/5 order-1 lg:order-3"> <div class="w-full order-4 bg-glass shadow p-auto flex flex-col gap-auto">
<div class="bg-glass shadow p-auto"> <h3 class="text-xl font-bold text-center">Keine Rückmeldung</h3>
<div class="flex flex-col gap-auto"> <div class="grid grid-cols-1 lg:grid-cols-5 flex-wrap gap-auto">
<h3 class="text-xl font-bold text-center">Status</h3> <?php foreach ($unknowns as $signup) : ?>
<?= $raid->showSignup(Character::first()) ?> <?= $signup->showForm() ?>
</div> <?php endforeach; ?>
</div> </div>
</div> </div>
</div> </main>
<div class="w-full order-4 bg-glass shadow p-auto flex flex-col gap-auto"> </section>
<h3 class="text-xl font-bold text-center">Keine Rückmeldung</h3> <?php
<div class="grid grid-cols-1 lg:grid-cols-12 gap-auto"> get_footer();
<button class="btn btn-outline btn-evoker">Yorndragon</button>
<button class="btn btn-outline btn-mage">Aye</button>
<button class="btn btn-outline btn-warrior">Stormranger</button>
<button class="btn btn-outline btn-druid">Kaldori</button>
<button class="btn btn-outline btn-shaman">Nokin</button>
</div>
</div>
</main>
</section>
<?php
get_footer();

View File

@ -0,0 +1,70 @@
<?php
use Wenprise\Eloquent\Database;
use Wenprise\Eloquent\Facades\DB;
use WoWPress\Models\SKS;
set_sidebar_status('top', false);
$liste = $GLOBALS['wowpress']['liste'];
if(!$liste){
$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->ID?>"><?=$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))">
<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">
<?php
foreach(SKS::getList($liste->list_name) as $sk):
?>
<div class="flex flex-row">
<button class="btn btn-outline"><?=$sk->char_name?></button>
<div class="border p-auto"><?=$sk->rank?></div>
<div class="border p-auto"><?=$sk->active?"Aktiv":"Inaktiv"?></div>
</div>
<?php
endforeach;
?>
</div>
</main>
</section>
<?php
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 md:w-48"> <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"> <div 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) {

View File

@ -3,6 +3,7 @@ require_once('vendor/autoload.php');
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use WoWPress\Models\Character; use WoWPress\Models\Character;
use WoWPress\Models\User;
if (empty($_POST['action'])) { if (empty($_POST['action'])) {
exit(404); exit(404);
@ -16,47 +17,56 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/wp-load.php')) {
switch ($_POST['action']) { switch ($_POST['action']) {
case 'addCharacter': case 'addCharacter':
if (current_user_can('wowpress_edit_characters')) { isAllowed('wowpress_edit_characters');
if (isset($_POST['addCharacter_nonce']) && wp_verify_nonce($_POST['addCharacter_nonce'], 'addCharacter')) { if (isset($_POST['addCharacter_nonce']) && wp_verify_nonce($_POST['addCharacter_nonce'], 'addCharacter')) {
if (isset($_POST['name']) && isset($_POST['realm'])) { if (isset($_POST['name']) && isset($_POST['realm'])) {
$char = Character::whereName($_POST['name'])->whereRealm($_POST['realm'])->first(); $char = Character::whereName($_POST['name'])->whereRealm($_POST['realm'])->first();
if (empty($char->ID)) { if (empty($char->ID)) {
$char = new Character(); $char = new Character();
$char->name = $_POST['name']; $char->name = $_POST['name'];
$char->realm = $_POST['realm']; $char->realm = $_POST['realm'];
$char->updateFromAPI(); $char->updateFromAPI();
$char->updateMedia(); $char->updateMedia();
}
} }
} else {
echo "NO";
} }
} else {
echo "NO BUT IN BLACK";
} }
break; break;
case 'deleteCharacter': case 'deleteCharacter':
if (current_user_can('wowpress_edit_characters')) { isAllowed('wowpress_edit_characters');
if (isset($_POST['deleteCharacter_nonce']) && wp_verify_nonce($_POST['deleteCharacter_nonce'], 'deleteCharacter')) { if (isset($_POST['deleteCharacter_nonce']) && wp_verify_nonce($_POST['deleteCharacter_nonce'], 'deleteCharacter')) {
if (isset($_POST['id'])) { if (isset($_POST['id'])) {
$char = Character::find($_POST['id']); $char = Character::find($_POST['id']);
if ($char->ID) { if ($char->ID) {
$char->delete(); $char->delete();
}
} }
} }
} }
break; break;
case 'updateCharacter': case 'updateCharacter':
if (current_user_can('wowpress_edit_characters')) { isAllowed('wowpress_edit_characters');
if (isset($_POST['updateCharacter_nonce']) && wp_verify_nonce($_POST['updateCharacter_nonce'], 'updateCharacter')) { if (isset($_POST['updateCharacter_nonce']) && wp_verify_nonce($_POST['updateCharacter_nonce'], 'updateCharacter')) {
if (isset($_POST['id'])) { if (isset($_POST['id'])) {
$char = Character::find($_POST['id']); $char = Character::find($_POST['id']);
if ($char->ID) { if ($char->ID) {
$char->updateFromAPI(); $char->updateFromAPI();
$char->updateMedia(); $char->updateMedia();
} }
}
}
break;
case 'changeUser':
isAllowed('wowpress_edit_characters');
if (isset($_POST['changeUser_nonce']) && wp_verify_nonce($_POST['changeUser_nonce'], 'changeUser')) {
if (isset($_POST['char_id']) && isset($_POST['uid'])) {
$char = Character::find($_POST['char_id']);
$user = User::find($_POST['uid']);
if (!empty($char->ID)) {
if (empty($user->ID)) {
$char->user_id = null;
$char->save();
} else
$char->user_id = $user->ID;
$char->save();
} }
} }
} }

View File

@ -6,12 +6,12 @@
* *
* @package WowPress * @package WowPress
*/ */
?> ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <div class="bg-glass shadow p-auto text-center">
<header class="entry-header">
<header class="entry-header">
<?php <?php
if ( ! is_front_page() ) { if ( ! is_front_page() ) {
the_title( '<h1 class="entry-title">', '</h1>' ); the_title( '<h1 class="entry-title">', '</h1>' );
@ -20,10 +20,16 @@
} }
?> ?>
</header><!-- .entry-header --> </header><!-- .entry-header -->
</div>
<article class="p-auto" id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php wowpress_post_thumbnail(); ?> <?php wowpress_post_thumbnail(); ?>
<div <?php wowpress_content_class( 'entry-content' ); ?>> <div class="" <?php wowpress_content_class( 'entry-content' ); ?>>
<?php <?php
the_content(); the_content();

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Template part for displaying posts * Template part for displaying posts
* *
@ -7,28 +8,34 @@
* @package WowPress * @package WowPress
*/ */
use WoWPress\Models\User;
$author = User::find(get_the_author_meta('ID'));
?> ?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div class="post-wrapper" style="--author-class:var(--color-deathknight)"> <div class="post-wrapper" style="--author-class:var(--color-deathknight)">
<div class="post-title"><h1><?php the_title()?></h1></div> <div class="post-title">
<h1><?php the_title() ?></h1>
</div>
<div class="post-content"><?php the_content() ?></div> <div class="post-content"><?php the_content() ?></div>
<div class="post-day"><?=get_the_date('d')?></div> <div class="post-day"><?= get_the_date('d') ?></div>
<div class="post-month"><?=get_the_date('F')?></div> <div class="post-month"><?= get_the_date('F') ?></div>
<?php <?php
$category = get_the_category(); $category = get_the_category();
$category = array_pop($category); $category = array_pop($category);
$color = get_term_meta( $category->term_id, 'color', true ); $color = get_term_meta($category->term_id, 'color', true);
?> ?>
<div class="post-category ribbon" style="--color-ribbon:#<?= ctype_xdigit($color)?$color:'fff'?>"><span><?=$category->name?></span></div> <div class="post-category ribbon" style="--color-ribbon:#<?= ctype_xdigit($color) ? $color : 'fff' ?>"><span><?= $category->name ?></span></div>
<div class="post-avatar"><img src="<?=get_avatar_url( get_the_author_meta( 'ID' ));?>"></div> <div class="post-avatar"><img src="<?= get_avatar_url(get_the_author_meta('ID')); ?>"></div>
<div class="post-author"> <div class="post-author">
<?php if(current_user_can('edit_post',$post->ID)): ?> <?php if (current_user_can('edit_post', $post->ID)) : ?>
<a href="<?=get_edit_post_link($post->ID)?>"> <a href="<?= get_edit_post_link($post->ID) ?>">
<?=get_the_author()?> <?= $author->display_name ?>
</a> </a>
<?php else: ?> <?php else : ?>
<?=get_the_author()?> <?= $author->display_name ?>
<?php endif; ?> <?php endif; ?>
</div> </div>
</article><!-- #post-${ID} --> </article><!-- #post-${ID} -->

View File

@ -8,6 +8,7 @@ $baseDir = dirname($vendorDir);
return array( return array(
'voku\\' => array($vendorDir . '/voku/portable-ascii/src/voku'), 'voku\\' => array($vendorDir . '/voku/portable-ascii/src/voku'),
'WoWPress\\' => array($baseDir . '/wowpress'), 'WoWPress\\' => array($baseDir . '/wowpress'),
'Wenprise\\ORM\\' => array($vendorDir . '/wenprise/wp-orm/src'),
'Wenprise\\' => array($vendorDir . '/wenprise/eloquent/src'), 'Wenprise\\' => array($vendorDir . '/wenprise/eloquent/src'),
'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'), 'Symfony\\Polyfill\\Php80\\' => array($vendorDir . '/symfony/polyfill-php80'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'), 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),

View File

@ -29,6 +29,7 @@ class ComposerStaticInit13829b6fd5f7bfdfd80b0a9c5c2c90b4
'W' => 'W' =>
array ( array (
'WoWPress\\' => 9, 'WoWPress\\' => 9,
'Wenprise\\ORM\\' => 13,
'Wenprise\\' => 9, 'Wenprise\\' => 9,
), ),
'S' => 'S' =>
@ -90,6 +91,10 @@ class ComposerStaticInit13829b6fd5f7bfdfd80b0a9c5c2c90b4
array ( array (
0 => __DIR__ . '/../..' . '/wowpress', 0 => __DIR__ . '/../..' . '/wowpress',
), ),
'Wenprise\\ORM\\' =>
array (
0 => __DIR__ . '/..' . '/wenprise/wp-orm/src',
),
'Wenprise\\' => 'Wenprise\\' =>
array ( array (
0 => __DIR__ . '/..' . '/wenprise/eloquent/src', 0 => __DIR__ . '/..' . '/wenprise/eloquent/src',

View File

@ -2529,6 +2529,58 @@
"source": "https://github.com/iwillhappy1314/wenprise-eloquent/tree/9.0.1" "source": "https://github.com/iwillhappy1314/wenprise-eloquent/tree/9.0.1"
}, },
"install-path": "../wenprise/eloquent" "install-path": "../wenprise/eloquent"
},
{
"name": "wenprise/wp-orm",
"version": "dev-main",
"version_normalized": "dev-main",
"source": {
"type": "git",
"url": "https://github.com/iwillhappy1314/wenprise-wp-orm.git",
"reference": "6171efa42a6d5b07c13867acd4cd0ff4616fde1b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/iwillhappy1314/wenprise-wp-orm/zipball/6171efa42a6d5b07c13867acd4cd0ff4616fde1b",
"reference": "6171efa42a6d5b07c13867acd4cd0ff4616fde1b",
"shasum": ""
},
"require": {
"wenprise/eloquent": "^9.0"
},
"time": "2023-11-16T16:46:17+00:00",
"default-branch": true,
"type": "library",
"installation-source": "dist",
"autoload": {
"psr-4": {
"Wenprise\\ORM\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Amos Lee",
"email": "iwillhappy1314@gmail.com"
}
],
"description": "Eloquent ORM for WordPress",
"homepage": "https://github.com/iwillhappy1314/wenprise-wp-orm",
"keywords": [
"eloquent",
"orm",
"plugin",
"sql",
"wordpress"
],
"support": {
"issues": "https://github.com/iwillhappy1314/wenprise-wp-orm/issues",
"source": "https://github.com/iwillhappy1314/wenprise-wp-orm/tree/main"
},
"install-path": "../wenprise/wp-orm"
} }
], ],
"dev": true, "dev": true,

View File

@ -3,7 +3,7 @@
'name' => '__root__', 'name' => '__root__',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '45e66ab3a0edfe4d53254637a653545e1b3d40bf', 'reference' => 'd7328bb0873bd5ff981d843717b3e140b56b049b',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -13,7 +13,7 @@
'__root__' => array( '__root__' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => '45e66ab3a0edfe4d53254637a653545e1b3d40bf', 'reference' => 'd7328bb0873bd5ff981d843717b3e140b56b049b',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -367,5 +367,16 @@
'aliases' => array(), 'aliases' => array(),
'dev_requirement' => false, 'dev_requirement' => false,
), ),
'wenprise/wp-orm' => array(
'pretty_version' => 'dev-main',
'version' => 'dev-main',
'reference' => '6171efa42a6d5b07c13867acd4cd0ff4616fde1b',
'type' => 'library',
'install_path' => __DIR__ . '/../wenprise/wp-orm',
'aliases' => array(
0 => '9999999-dev',
),
'dev_requirement' => false,
),
), ),
); );

View File

@ -0,0 +1 @@
/.idea

View File

@ -0,0 +1,27 @@
{
"name": "wenprise/wp-orm",
"description": "Eloquent ORM for WordPress",
"keywords": [
"wordpress",
"plugin",
"orm",
"eloquent",
"sql"
],
"homepage": "https://github.com/iwillhappy1314/wenprise-wp-orm",
"require": {
"wenprise/eloquent": "^9.0"
},
"license": "MIT",
"authors": [
{
"name": "Amos Lee",
"email": "iwillhappy1314@gmail.com"
}
],
"autoload": {
"psr-4": {
"Wenprise\\ORM\\": "src/"
}
}
}

View File

@ -0,0 +1,22 @@
<?php
namespace Wenprise\ORM\Builder;
use Illuminate\Database\Eloquent\Builder;
/**
* Class CommentBuilder
*
* @package Wenprise\ORM\Model\Builder
* @author Junior Grossi <juniorgro@gmail.com>
*/
class CommentBuilder extends Builder
{
/**
* @return CommentBuilder
*/
public function approved()
{
return $this->where('comment_approved', 1);
}
}

View File

@ -0,0 +1,113 @@
<?php
namespace Wenprise\ORM\Builder;
use Illuminate\Database\Eloquent\Builder;
/**
* Class PostBuilder
*
* @package Wenprise\ORM\Model\Builder
* @author Junior Grossi <juniorgro@gmail.com>
*/
class PostBuilder extends Builder
{
/**
* @param string $status
* @return PostBuilder
*/
public function status($status)
{
return $this->where('post_status', $status);
}
/**
* @return PostBuilder
*/
public function published()
{
return $this->status('publish');
}
/**
* @param string $type
* @return PostBuilder
*/
public function type($type)
{
return $this->where('post_type', $type);
}
/**
* @param array $types
* @return PostBuilder
*/
public function typeIn(array $types)
{
return $this->whereIn('post_type', $types);
}
/**
* @param string $slug
* @return PostBuilder
*/
public function slug($slug)
{
return $this->where('post_name', $slug);
}
/**
* @param string $postParentId
* @return PostBuilder
*/
public function parent($postParentId)
{
return $this->where('post_parent', $postParentId);
}
/**
* @param string $taxonomy
* @param mixed $terms
* @return PostBuilder
*/
public function taxonomy($taxonomy, $terms)
{
return $this->whereHas('taxonomies', function ($query) use ($taxonomy, $terms) {
$query->where('taxonomy', $taxonomy)
->whereHas('term', function ($query) use ($terms) {
$query->whereIn('slug', is_array($terms) ? $terms : [$terms]);
});
});
}
/**
* @param mixed $term
* @return PostBuilder
*/
public function search($term = false)
{
if (empty($term)) {
return $this;
}
$terms = is_string($term) ? explode(' ', $term) : $term;
$terms = collect($terms)->map(function ($term) {
return trim(str_replace('%', '', $term));
})->filter()->map(function ($term) {
return '%' . $term . '%';
});
if ($terms->isEmpty()) {
return $this;
}
return $this->where(function ($query) use ($terms) {
$terms->each(function ($term) use ($query) {
$query->orWhere('post_title', 'like', $term)
->orWhere('post_excerpt', 'like', $term)
->orWhere('post_content', 'like', $term);
});
});
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Wenprise\ORM\Builder;
use Illuminate\Database\Eloquent\Builder;
/**
* Class TaxonomyBuilder
*
* @package Corcel
* @author Junior Grossi <juniorgro@gmail.com>
* @author Yoram de Langen <yoramdelangen@gmail.com>
*/
class TaxonomyBuilder extends Builder
{
/**
* @return TaxonomyBuilder
*/
public function category()
{
return $this->where('taxonomy', 'category');
}
/**
* @return TaxonomyBuilder
*/
public function menu()
{
return $this->where('taxonomy', 'nav_menu');
}
/**
* @param string $name
* @return TaxonomyBuilder
*/
public function name($name)
{
return $this->where('taxonomy', $name);
}
/**
* @param string $slug
* @return TaxonomyBuilder
*/
public function slug($slug = null)
{
if (! is_null($slug) && ! empty($slug)) {
return $this->whereHas('term', function ($query) use ($slug) {
$query->where('slug', $slug);
});
}
return $this;
}
/**
* @param null $slug
* @return TaxonomyBuilder
*/
public function term($slug = null)
{
return $this->slug($slug);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Wenprise\ORM\Collection;
use Illuminate\Database\Eloquent\Collection;
/**
* Class MetaCollection
*
* @package Wenprise\ORM\Model\Collection
* @author Junior Grossi <juniorgro@gmail.com>
*/
class MetaCollection extends Collection
{
/**
* @param string $key
* @return mixed
*/
public function __get($key)
{
if (isset($this->items) && count($this->items)) {
$meta = $this->first(function ($meta) use ($key) {
return $meta->meta_key === $key;
});
return $meta ? $meta->meta_value : null;
}
return null;
}
/**
* @param string $name
* @return bool
*/
public function __isset($name)
{
return !is_null($this->__get($name));
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace Wenprise\ORM\Concerns;
use Illuminate\Support\Arr;
/**
* Trait AliasesTrait
*
* @package Corcel\Traits
* @author Junior Grossi <juniorgro@gmail.com>
*/
trait Aliases
{
/**
* @return array
*/
public static function getAliases()
{
if (isset(parent::$aliases) && count(parent::$aliases)) {
return array_merge(parent::$aliases, static::$aliases);
}
return static::$aliases;
}
/**
* @param string $new
* @param string $old
*/
public static function addAlias($new, $old)
{
static::$aliases[$new] = $old;
}
/**
* @param string $key
* @return mixed
*/
public function getAttribute($key)
{
$value = parent::getAttribute($key);
if ($value === null && count(static::getAliases())) {
if ($value = Arr::get(static::getAliases(), $key)) {
if (is_array($value)) {
$meta = Arr::get($value, 'meta');
return $meta ? $this->meta->$meta : null;
}
return parent::getAttribute($value);
}
}
return $value;
}
/**
* Get alias value from mutator or directly from attribute
*
* @param string $key
* @param mixed $value
* @return mixed
*/
public function mutateAttribute($key, $value)
{
if ($this->hasGetMutator($key)) {
return parent::mutateAttribute($key, $value);
}
return $this->getAttribute($key);
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Wenprise\ORM\Concerns;
/**
* Trait CustomTimestamps
*
* @package Corcel\Traits
* @author Junior Grossi <juniorgro@gmail.com>
*/
trait CustomTimestamps
{
/**
* @param mixed $value
* @return mixed
*/
public function setCreatedAt($value)
{
$field = static::CREATED_AT;
$this->{$field} = $value;
$field .= '_gmt';
$this->{$field} = $value;
return parent::setCreatedAt($value);
}
/**
* @param mixed $value
* @return mixed
*/
public function setUpdatedAt($value)
{
$field = static::UPDATED_AT;
$this->{$field} = $value;
$field .= '_gmt';
$this->{$field} = $value;
return parent::setUpdatedAt($value);
}
}

View File

@ -0,0 +1,205 @@
<?php
namespace Wenprise\ORM\Concerns;
use Illuminate\Database\Eloquent\Builder;
use UnexpectedValueException;
/**
* Trait HasMetaFields
*
* @package Corcel\Traits
* @author Junior Grossi <juniorgro@gmail.com>
*/
trait MetaFields
{
/**
* @var array
*/
protected $builtInClasses = [
\Wenprise\ORM\WP\Comment::class => \Wenprise\ORM\Meta\CommentMeta::class,
\Wenprise\ORM\WP\Post::class => \Wenprise\ORM\Meta\PostMeta::class,
\Wenprise\ORM\WP\Term::class => \Wenprise\ORM\Meta\TermMeta::class,
\Wenprise\ORM\WP\User::class => \Wenprise\ORM\Meta\UserMeta::class,
];
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function fields()
{
return $this->meta();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function meta()
{
return $this->hasMany($this->getMetaClass(), $this->getMetaForeignKey());
}
/**
* @return string
*
* @throws \UnexpectedValueException
*/
protected function getMetaClass()
{
foreach ($this->builtInClasses as $model => $meta) {
if ($this instanceof $model) {
return $meta;
}
}
throw new UnexpectedValueException(sprintf('%s must extends one of Corcel built-in models: Comment, Post, Term or User.', static::class));
}
/**
* @return string
*
* @throws \UnexpectedValueException
*/
protected function getMetaForeignKey()
{
foreach ($this->builtInClasses as $model => $meta) {
if ($this instanceof $model) {
$basename = class_basename($model);
return sprintf('%s_id', strtolower($basename));
}
}
throw new UnexpectedValueException(sprintf('%s must extends one of Corcel built-in models: Comment, Post, Term or User.', static::class));
}
/**
* @param Builder $query
* @param string $meta
* @param mixed $value
* @return Builder
*/
public function scopeHasMeta(Builder $query, $meta, $value = null)
{
if (! is_array($meta)) {
$meta = [$meta => $value];
}
foreach ($meta as $key => $value) {
$query->whereHas('meta', function ($query) use ($key, $value) {
if (is_string($key)) {
$query->where('meta_key', $key);
return is_null($value) ? $query : // 'foo' => null
$query->where('meta_value', $value); // 'foo' => 'bar'
}
return $query->where('meta_key', $value); // 0 => 'foo'
});
}
return $query;
}
/**
* @param string $key
* @param mixed $value
* @return bool
*/
public function saveField($key, $value)
{
return $this->saveMeta($key, $value);
}
/**
* @param string $key
* @param mixed $value
* @return bool
*/
public function saveMeta($key, $value = null)
{
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->saveOneMeta($k, $v);
}
$this->load('meta');
return true;
}
return $this->saveOneMeta($key, $value);
}
/**
* @param string $key
* @param mixed $value
* @return bool
*/
private function saveOneMeta($key, $value)
{
$meta = $this->meta()->where('meta_key', $key)->firstOrNew(['meta_key' => $key]);
$result = $meta->fill(['meta_value' => $value])->save();
$this->load('meta');
return $result;
}
/**
* @param string $key
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Model
*/
public function createField($key, $value)
{
return $this->createMeta($key, $value);
}
/**
* @param string $key
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Model|\Illuminate\Support\Collection
*/
public function createMeta($key, $value = null)
{
if (is_array($key)) {
return collect($key)->map(function ($value, $key) {
return $this->createOneMeta($key, $value);
});
}
return $this->createOneMeta($key, $value);
}
/**
* @param string $key
* @param mixed $value
* @return \Illuminate\Database\Eloquent\Model
*/
private function createOneMeta($key, $value)
{
$meta = $this->meta()->create([
'meta_key' => $key,
'meta_value' => $value,
]);
$this->load('meta');
return $meta;
}
/**
* @param string $attribute
* @return mixed|null
*/
public function getMeta($attribute)
{
if ($meta = $this->meta->{$attribute}) {
return $meta;
}
return null;
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Wenprise\ORM\Concerns;
use Illuminate\Database\Eloquent\Builder;
/**
* Trait OrderedTrait
*
* @package Corcel\Traits
* @author Junior Grossi <juniorgro@gmail.com>
*/
trait OrderScopes
{
/**
* @param Builder $query
* @return Builder
*/
public function scopeNewest(Builder $query)
{
return $query->orderBy(static::CREATED_AT, 'desc');
}
/**
* @param Builder $query
* @return Builder
*/
public function scopeOldest(Builder $query)
{
return $query->orderBy(static::CREATED_AT, 'asc');
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Wenprise\ORM\Meta;
use Wenprise\ORM\WP\Comment;
/**
* Class CommentMeta
*
* @package Wenprise\ORM\Model\Meta
* @author Junior Grossi <juniorgro@gmail.com>
*/
class CommentMeta extends Meta
{
/**
* @var string
*/
protected $table = 'commentmeta';
/**
* @var array
*/
protected $fillable = ['meta_key', 'meta_value', 'comment_id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function comment()
{
return $this->belongsTo(Comment::class);
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace Wenprise\ORM\Meta;
use Wenprise\Eloquent\Model;
use Wenprise\ORM\Collection\MetaCollection;
use Exception;
/**
* Class Meta
*
* @package Wenprise\ORM\Model\Meta
* @author Junior Grossi <juniorgro@gmail.com>
*/
abstract class Meta extends Model
{
/**
* @var string
*/
protected $primaryKey = 'meta_id';
/**
* @var bool
*/
public $timestamps = false;
/**
* @var array
*/
protected $appends = ['value'];
/**
* @return mixed
*/
public function getValueAttribute()
{
try {
$value = unserialize($this->meta_value);
return $value === false && $this->meta_value !== false ?
$this->meta_value :
$value;
} catch (Exception $ex) {
return $this->meta_value;
}
}
/**
* @param array $models
* @return MetaCollection
*/
public function newCollection(array $models = [])
{
return new MetaCollection($models);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Wenprise\ORM\Meta;
use Wenprise\ORM\WP\Post;
/**
* Class PostMeta
*
* @package Wenprise\ORM\Model\Meta
* @author Junior Grossi <juniorgro@gmail.com>
*/
class PostMeta extends Meta
{
protected $primaryKey = 'meta_id';
protected $table = 'postmeta';
/**
* @var array
*/
protected $fillable = ['meta_key', 'meta_value', 'post_id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function post()
{
return $this->belongsTo(Post::class);
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Wenprise\ORM\Meta;
use Wenprise\ORM\WP\Term;
/**
* Class TermMeta
*
* @package Wenprise\ORM\Model\Meta
* @author Junior Grossi <juniorgro@gmail.com>
*/
class TermMeta extends Meta
{
/**
* @var string
*/
protected $table = 'termmeta';
/**
* @var array
*/
protected $fillable = ['meta_key', 'meta_value', 'term_id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function term()
{
return $this->belongsTo(Term::class);
}
}

View File

@ -0,0 +1,66 @@
<?php
namespace Wenprise\ORM\Meta;
use Wenprise\ORM\WP\Attachment;
use Illuminate\Support\Arr;
/**
* Class ThumbnailMeta
*
* @package Wenprise\ORM\Model\Meta
* @author Junior Grossi <juniorgro@gmail.com>
*/
class ThumbnailMeta extends PostMeta
{
const SIZE_THUMBNAIL = 'thumbnail';
const SIZE_MEDIUM = 'medium';
const SIZE_LARGE = 'large';
const SIZE_FULL = 'full';
/**
* @var array
*/
protected $with = ['attachment'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function attachment()
{
return $this->belongsTo(Attachment::class, 'meta_value');
}
/**
* @param string $size
* @return array
* @throws \Exception
*/
public function size($size)
{
if ($size == self::SIZE_FULL) {
return $this->attachment->url;
}
$meta = unserialize($this->attachment->meta->_wp_attachment_metadata);
$sizes = Arr::get($meta, 'sizes');
if (!isset($sizes[$size])) {
return $this->attachment->url;
}
$data = Arr::get($sizes, $size);
return array_merge($data, [
'url' => dirname($this->attachment->url).'/'.$data['file'],
]);
}
/**
* @return string
*/
public function __toString()
{
return $this->attachment->guid;
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Wenprise\ORM\Meta;
use Wenprise\ORM\WP\User;
/**
* Class UserMeta
*
* @package Wenprise\ORM\Model\Meta
* @author Mickael Burguet <www.rundef.com>
* @author Junior Grossi <juniorgro@gmail.com>
*/
class UserMeta extends Meta
{
protected $primaryKey = 'umeta_id';
public $timestamps = false;
/**
* @var string
*/
protected $table = 'usermeta';
/**
* @var array
*/
protected $fillable = ['meta_key', 'meta_value', 'user_id'];
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}

View File

@ -0,0 +1,45 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\ORM\Concerns\Aliases;
/**
* Class Attachment
*
* @package Corcel\Model
* @author José CI <josec89@gmail.com>
* @author Junior Grossi <juniorgro@gmail.com>
*/
class Attachment extends Post {
use Aliases;
/**
* @var string
*/
protected $postType = 'attachment';
/**
* @var array
*/
protected $appends = [
'title',
'url',
'type',
'description',
'caption',
'alt',
];
/**
* @var array
*/
protected static $aliases = [
'title' => 'post_title',
'url' => 'guid',
'type' => 'post_mime_type',
'description' => 'post_content',
'caption' => 'post_excerpt',
'alt' => [ 'meta' => '_wp_attachment_image_alt' ],
];
}

View File

@ -0,0 +1,109 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\ORM\Builder\CommentBuilder;
use Wenprise\ORM\Concerns\CustomTimestamps;
use Wenprise\ORM\Concerns\MetaFields;
use Wenprise\Eloquent\Model;
class Comment extends Model
{
use MetaFields;
use CustomTimestamps;
const CREATED_AT = 'comment_date';
const UPDATED_AT = null;
protected $primaryKey = 'comment_ID';
/**
* @var array
*/
protected $dates = ['comment_date'];
/**
* Find a comment by post ID.
*
* @param int $postId
* @return Comment
*/
public static function findByPostId($postId)
{
return (new static())->where('comment_post_ID', $postId)->get();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function post()
{
return $this->belongsTo(Post::class, 'comment_post_ID');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->original();
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function original()
{
return $this->belongsTo(Comment::class, 'comment_parent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function replies()
{
return $this->hasMany(Comment::class, 'comment_parent');
}
/**
* @return bool
*/
public function isApproved()
{
return $this->attributes['comment_approved'] == 1;
}
/**
* @return bool
*/
public function isReply()
{
return $this->attributes['comment_parent'] > 0;
}
/**
* @return bool
*/
public function hasReplies()
{
return $this->replies->count() > 0;
}
/**
* @param \Illuminate\Database\Query\Builder $query
* @return CommentBuilder
*/
public function newEloquentBuilder($query)
{
return new CommentBuilder($query);
}
/**
* @param mixed $value
* @return void
*/
public function setUpdatedAt($value)
{
//
}
}

View File

@ -0,0 +1,121 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\Eloquent\Model;
use Exception;
/**
* Option class.
*
* @package Corcel\Model
* @author José CI <josec89@gmail.com>
* @author Junior Grossi <juniorgro@gmail.com>
*/
class Option extends Model
{
/**
* @var string
*/
protected $primaryKey = 'option_id';
/**
* @var bool
*/
public $timestamps = false;
/**
* @var array
*/
protected $fillable = [
'option_name',
'option_value',
'autoload',
];
/**
* @var array
*/
protected $appends = ['value'];
/**
* @return mixed
*/
public function getValueAttribute()
{
try {
$value = unserialize($this->option_value);
return $value === false && $this->option_value !== false ?
$this->option_value :
$value;
} catch (Exception $ex) {
return $this->option_value;
}
}
/**
* @param string $key
* @param mixed $value
* @return Option
*/
public static function add($key, $value)
{
return static::create([
'option_name' => $key,
'option_value' => is_array($value) ? serialize($value) : $value,
]);
}
/**
* @param string $name
* @return mixed
*/
public static function get($name)
{
if ($option = self::where('option_name', $name)->first()) {
return $option->value;
}
return null;
}
/**
* @return array
* @deprecated
*/
public static function getAll()
{
return static::asArray();
}
/**
* @param array $keys
* @return array
*/
public static function asArray($keys = [])
{
$query = static::query();
if (!empty($keys)) {
$query->whereIn('option_name', $keys);
}
return $query->get()
->pluck('value', 'option_name')
->toArray();
}
/**
* @return array
*/
public function toArray()
{
if ($this instanceof Option) {
return [$this->option_name => $this->value];
}
return parent::toArray();
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Wenprise\ORM\WP;
use Illuminate\Database\Eloquent\Builder;
/**
* Class Page
*
* @package Corcel\Model
* @author Junior Grossi <juniorgro@gmail.com>
*/
class Page extends Post
{
/**
* @var string
*/
protected $postType = 'page';
/**
* @param Builder $query
* @return mixed
*/
public function scopeHome(Builder $query)
{
return $query
->where('ID', '=', Option::get('page_on_front'))
->limit(1);
}
}

View File

@ -0,0 +1,390 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\ORM\Builder\PostBuilder;
use Wenprise\ORM\Concerns\Aliases;
use Wenprise\ORM\Concerns\CustomTimestamps;
use Wenprise\ORM\Concerns\MetaFields;
use Wenprise\ORM\Concerns\OrderScopes;
use Wenprise\Eloquent\Model;
use Wenprise\ORM\Meta\ThumbnailMeta;
class Post extends Model
{
use Aliases;
use MetaFields;
use OrderScopes;
use CustomTimestamps;
const CREATED_AT = 'post_date';
const UPDATED_AT = 'post_modified';
/**
* @var string
*/
protected $table = 'posts';
protected $post_type = null;
/**
* @var string
*/
protected $primaryKey = 'ID';
/**
* @var array
*/
protected $dates = ['post_date', 'post_date_gmt', 'post_modified', 'post_modified_gmt'];
/**
* @var array
*/
protected $with = ['meta'];
/**
* @var array
*/
protected static $postTypes = [];
/**
* @var array
*/
protected $fillable = [
'post_content',
'post_title',
'post_excerpt',
'post_type',
'to_ping',
'pinged',
'post_content_filtered',
];
/**
* @var array
*/
protected $appends = [
'title',
'slug',
'content',
'type',
'mime_type',
'url',
'author_id',
'parent_id',
'created_at',
'updated_at',
'excerpt',
'status',
'image',
'terms',
'main_category',
'keywords',
'keywords_str',
];
/**
* @var array
*/
protected static $aliases = [
'title' => 'post_title',
'content' => 'post_content',
'excerpt' => 'post_excerpt',
'slug' => 'post_name',
'type' => 'post_type',
'mime_type' => 'post_mime_type',
'url' => 'guid',
'author_id' => 'post_author',
'parent_id' => 'post_parent',
'created_at' => 'post_date',
'updated_at' => 'post_modified',
'status' => 'post_status',
];
/**
* @param \Illuminate\Database\Query\Builder $query
* @return PostBuilder
*/
public function newEloquentBuilder($query)
{
return new PostBuilder($query);
}
/**
* @return PostBuilder
*/
public function newQuery()
{
return $this->postType ? parent::newQuery()->type($this->postType) : parent::newQuery();
}
/**
* Filter by post type
*
* @param $query
* @param string $type
*
* @return mixed
*/
public function scopeType($query, $type = 'post')
{
return $query->where('post_type', '=', $type);
}
/**
* Filter by post status
*
* @param $query
* @param string $status
*
* @return mixed
*/
public function scopeStatus($query, $status = 'publish')
{
return $query->where('post_status', '=', $status);
}
/**
* Filter by post author
*
* @param $query
* @param null $author
*
* @return mixed
*/
public function scopeAuthor($query, $author = null)
{
if ($author) {
return $query->where('post_author', '=', $author);
}
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function thumbnail()
{
return $this->hasOne(ThumbnailMeta::class, 'post_id')->where('meta_key', '_thumbnail_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function taxonomies()
{
return $this->belongsToMany(Taxonomy::class, 'term_relationships', 'object_id', 'term_taxonomy_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
{
return $this->hasMany(Comment::class, 'comment_post_ID');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function author()
{
return $this->belongsTo(User::class, 'post_author');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->belongsTo(Post::class, 'post_parent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function children()
{
return $this->hasMany(Post::class, 'post_parent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function attachment()
{
return $this->hasMany(Post::class, 'post_parent')->where('post_type', 'attachment');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function revision()
{
return $this->hasMany(Post::class, 'post_parent')->where('post_type', 'revision');
}
/**
* Whether the post contains the term or not.
*
* @param string $taxonomy
* @param string $term
* @return bool
*/
public function hasTerm($taxonomy, $term)
{
return isset($this->terms[$taxonomy]) && isset($this->terms[$taxonomy][$term]);
}
/**
* @param string $postType
*/
public function setPostType($postType)
{
$this->postType = $postType;
}
/**
* @return string
*/
public function getPostType()
{
return $this->postType;
}
/**
* @return string
*/
public function getContentAttribute()
{
return do_shortcode($this->post_content);
}
/**
* @return string
*/
public function getExcerptAttribute()
{
return do_shortcode($this->post_excerpt);
}
/**
* Gets the featured image if any
* Looks in meta the _thumbnail_id field.
*
* @return string
*/
public function getImageAttribute()
{
if ($this->thumbnail and $this->thumbnail->attachment) {
return $this->thumbnail->attachment->guid;
}
}
/**
* Gets all the terms arranged taxonomy => terms[].
*
* @return array
*/
public function getTermsAttribute()
{
return $this->taxonomies->groupBy(function ($taxonomy) {
return $taxonomy->taxonomy == 'post_tag' ? 'tag' : $taxonomy->taxonomy;
})->map(function ($group) {
return $group->mapWithKeys(function ($item) {
return [$item->term->slug => $item->term->name];
});
})->toArray();
}
/**
* Gets the first term of the first taxonomy found.
*
* @return string
*/
public function getMainCategoryAttribute()
{
$mainCategory = 'Uncategorized';
if (! empty($this->terms)) {
$taxonomies = array_values($this->terms);
if (! empty($taxonomies[0])) {
$terms = array_values($taxonomies[0]);
$mainCategory = $terms[0];
}
}
return $mainCategory;
}
/**
* Gets the keywords as array.
*
* @return array
*/
public function getKeywordsAttribute()
{
return collect($this->terms)->map(function ($taxonomy) {
return collect($taxonomy)->values();
})->collapse()->toArray();
}
/**
* Gets the keywords as string.
*
* @return string
*/
public function getKeywordsStrAttribute()
{
return implode(',', (array) $this->keywords);
}
/**
* @param string $name The post type slug
* @param string $class The class to be instantiated
*/
public static function registerPostType($name, $class)
{
static::$postTypes[$name] = $class;
}
/**
* Clears any registered post types.
*/
public static function clearRegisteredPostTypes()
{
static::$postTypes = [];
}
/**
* Get the post format, like the WP get_post_format() function.
*
* @return bool|string
*/
public function getFormat()
{
$taxonomy = $this->taxonomies()->where('taxonomy', 'post_format')->first();
if ($taxonomy && $taxonomy->term) {
return str_replace('post-format-', '', $taxonomy->term->slug);
}
return false;
}
/**
* @param string $key
* @return mixed
*/
public function __get($key)
{
$value = parent::__get($key);
if ($value === null && ! property_exists($this, $key)) {
return $this->meta->$key;
}
return $value;
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace Wenprise\ORM\WP;
/**
* Tag class.
*
* @package Corcel\Model
* @author Mickael Burguet <www.rundef.com>
*/
class Tag extends Taxonomy
{
/**
* @var string
*/
protected $taxonomy = 'post_tag';
}

View File

@ -0,0 +1,104 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\ORM\Builder\TaxonomyBuilder;
use Wenprise\Eloquent\Model;
use Wenprise\ORM\Meta\TermMeta;
/**
* Class Taxonomy
*
* @package Corcel\Model
* @author Junior Grossi <juniorgro@gmail.com>
*/
class Taxonomy extends Model
{
/**
* @var string
*/
protected $table = 'term_taxonomy';
/**
* @var string
*/
protected $primaryKey = 'term_taxonomy_id';
/**
* @var array
*/
protected $with = ['term'];
/**
* @var bool
*/
public $timestamps = false;
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function meta()
{
return $this->hasMany(TermMeta::class, 'term_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function term()
{
return $this->belongsTo(Term::class, 'term_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function parent()
{
return $this->belongsTo(Taxonomy::class, 'parent');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function posts()
{
return $this->belongsToMany(Post::class, 'term_relationships', 'term_taxonomy_id', 'object_id');
}
/**
* @param \Illuminate\Database\Query\Builder $query
* @return TaxonomyBuilder
*/
public function newEloquentBuilder($query)
{
return new TaxonomyBuilder($query);
}
/**
* TaxonomyBuilder
*
* @return $this|\Illuminate\Database\Eloquent\Builder
*/
public function newQuery()
{
return isset($this->taxonomy) && $this->taxonomy ? parent::newQuery()->where('taxonomy', $this->taxonomy) : parent::newQuery();
}
/**
* Magic method to return the meta data like the post original fields.
*
* @param string $key
* @return string
*/
public function __get($key)
{
if (! isset($this->$key)) {
if (isset($this->term->$key)) {
return $this->term->$key;
}
}
return parent::__get($key);
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\ORM\Concerns\MetaFields;
use Wenprise\Eloquent\Model;
/**
* Class Term.
*
* @package Corcel\Model
* @author Junior Grossi <juniorgro@gmail.com>
*/
class Term extends Model
{
use MetaFields;
/**
* @var string
*/
protected $primaryKey = 'term_id';
/**
* @var bool
*/
public $timestamps = false;
/**
* @var string
*/
protected $table = 'terms';
/**
* @return \Illuminate\Database\Eloquent\Relations\HasOne
*/
public function taxonomy()
{
return $this->hasOne(Taxonomy::class, 'term_id');
}
}

View File

@ -0,0 +1,42 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\Eloquent\Model;
/**
* Class TermRelationship.
*
* @package Corcel\Model
* @author Junior Grossi <juniorgro@gmail.com>
*/
class TermRelationship extends Model
{
/**
* @var array
*/
protected $primaryKey = ['object_id', 'term_taxonomy_id'];
/**
* @var bool
*/
public $timestamps = false;
protected $table = 'term_relationships';
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function post()
{
return $this->belongsTo(Post::class, 'object_id');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function taxonomy()
{
return $this->belongsTo(Taxonomy::class, 'term_taxonomy_id');
}
}

View File

@ -0,0 +1,203 @@
<?php
namespace Wenprise\ORM\WP;
use Wenprise\ORM\Concerns\Aliases;
use Wenprise\ORM\Concerns\MetaFields;
use Wenprise\ORM\Concerns\OrderScopes;
use Wenprise\Eloquent\Model;
/**
* Class User
*
* @package Corcel\Model
* @author Ashwin Sureshkumar <ashwin.sureshkumar@gmail.com>
* @author Mickael Burguet <www.rundef.com>
* @author Junior Grossi <juniorgro@gmail.com>
*/
class User extends Model
{
const CREATED_AT = 'user_registered';
const UPDATED_AT = null;
use Aliases;
use MetaFields;
use OrderScopes;
/**
* @var string
*/
protected $primaryKey = 'ID';
/**
* @var array
*/
protected $hidden = ['user_pass'];
/**
* @var array
*/
protected $dates = ['user_registered'];
/**
* @var array
*/
protected $with = ['meta'];
/**
* @var array
*/
protected static $aliases = [
'login' => 'user_login',
'email' => 'user_email',
'slug' => 'user_nicename',
'url' => 'user_url',
'nickname' => ['meta' => 'nickname'],
'first_name' => ['meta' => 'first_name'],
'last_name' => ['meta' => 'last_name'],
'created_at' => 'user_registered',
];
/**
* The accessors to append to the model's array form.
*
* @var array
*/
protected $appends = [
'login',
'email',
'slug',
'url',
'nickname',
'first_name',
'last_name',
'avatar',
'created_at',
];
/**
* @param mixed $value
*/
public function setUpdatedAtAttribute($value)
{
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function posts()
{
return $this->hasMany(Post::class, 'post_author');
}
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function comments()
{
return $this->hasMany(Comment::class, 'user_id');
}
/**
* Get the name of the unique identifier for the user.
*
* @return string
*/
public function getAuthIdentifierName()
{
return $this->primaryKey;
}
/**
* Get the unique identifier for the user.
*
* @return mixed
*/
public function getAuthIdentifier()
{
return $this->attributes[$this->primaryKey];
}
/**
* Get the password for the user.
*
* @return string
*/
public function getAuthPassword()
{
return $this->user_pass;
}
/**
* Get the token value for the "remember me" session.
*
* @return string
*/
public function getRememberToken()
{
$tokenName = $this->getRememberTokenName();
return $this->meta->{$tokenName};
}
/**
* Set the token value for the "remember me" session.
*
* @param string $value
*/
public function setRememberToken($value)
{
$tokenName = $this->getRememberTokenName();
$this->meta->{$tokenName} = $value;
}
/**
* Get the column name for the "remember me" token.
*
* @return string
*/
public function getRememberTokenName()
{
return 'remember_token';
}
/**
* Get the e-mail address where password reset links are sent.
*
* @return string
*/
public function getEmailForPasswordReset()
{
return $this->user_email;
}
/**
* @param string $token
*/
public function sendPasswordResetNotification($token)
{
}
/**
* Get the avatar url from Gravatar
*
* @return string
*/
public function getAvatarAttribute()
{
$hash = ! empty($this->email) ? md5(strtolower(trim($this->email))) : '';
return sprintf('//secure.gravatar.com/avatar/%s?d=mm', $hash);
}
/**
* @param mixed $value
* @return void
*/
public function setUpdatedAt($value)
{
//
}
}

View File

@ -24,6 +24,7 @@ class BattleNet extends Api{
public function getGuildRank($name,$realm){ public function getGuildRank($name,$realm){
$char = $this->getCharacter($name,$realm); $char = $this->getCharacter($name,$realm);
$guild = $char['guild']['key']['href']; $guild = $char['guild']['key']['href'];
$rank = 99;
if($char['guild']['name'] != "Nebelkrieger" || $char['guild']['realm']['name'] != "Alexstrasza"){ if($char['guild']['name'] != "Nebelkrieger" || $char['guild']['realm']['name'] != "Alexstrasza"){
$guild = $char['guild']['name']; $guild = $char['guild']['name'];
@ -45,9 +46,12 @@ class BattleNet extends Api{
if($member['character']['name'] == $name && $member['character']['realm']['slug'] == $char['realm']['slug']){ if($member['character']['name'] == $name && $member['character']['realm']['slug'] == $char['realm']['slug']){
$guild = $char['guild']['name']; $guild = $char['guild']['name'];
$rank = intval($member['rank']); $rank = intval($member['rank']);
return compact('guild','rank');
} }
} }
$guild = "-";
return compact('guild','rank'); return compact('guild','rank');
} }

View File

@ -11,9 +11,9 @@ class WoWAudit extends Api{
return $this->get('raids', ['include_past' => $include_past?"true":"false"],true,5); return $this->get('raids', ['include_past' => $include_past?"true":"false"],true,5);
} }
public function getRaid($id) public function getRaid($id,$force)
{ {
return $this->get("raids/$id", [], true, 5); return $this->get("raids/$id", [], true, $force?-1:5);
} }
public function getRoster(){ public function getRoster(){

View File

@ -11,10 +11,11 @@ class CreateCharacterTable extends CreateTable
'realm' => 'text NOT NULL', 'realm' => 'text NOT NULL',
'class' => "text DEFAULT Adventurer", 'class' => "text DEFAULT Adventurer",
'spec' => "text DEFAULT Brave", 'spec' => "text DEFAULT Brave",
'id_blizz' => 'mediumint(9)', 'id_blizz' => 'mediumint',
'id_wowaudit' => 'mediumint',
'guild' => "text", 'guild' => "text",
'rank' => 'tinyint DEFAULT 99', 'rank' => 'tinyint DEFAULT 99',
'user_id' => 'mediumint(9)', 'user_id' => 'mediumint',
]; ];
} }

View File

@ -0,0 +1,18 @@
<?php
namespace WoWPress\Database;
class CreateSKSTable extends CreateTable
{
public static $table_name = "sks";
public static $fields = [
'list_name' => 'text NOT NULL',
'char_name' => 'text NOT NULL',
'realm_name' => 'text NOT NULL',
'rank' => 'tinyint NOT NULL',
'active' => 'boolean NOT NULL',
];
}

View File

@ -0,0 +1,19 @@
<?php
namespace WoWPress\Database;
class CreateSignupTable extends CreateTable
{
public static $table_name = "signups";
public static $fields = [
'character_id' => 'mediumint NOT NULL',
'raid_id' => 'mediumint NOT NULL',
'boss_id' => 'mediumint',
'status' => 'text NOT NULL',
'role' => 'text NOT NULL',
'created_at' => 'timestamp NOT NULL',
'updated_at' => 'timestamp NOT NULL',
];
}

View File

@ -29,6 +29,16 @@ class Character extends Model
$this->api = new BattleNet($id,$key); $this->api = new BattleNet($id,$key);
} }
public function user(){
return $this->belongsTo(User::class);
}
public function getCanEditAttribute(){
return current_user_can('wowpress_edit_raids') || (get_current_user_id() == $this->ID);
}
protected function sanitize($string,$delimiter_space="") protected function sanitize($string,$delimiter_space="")
{ {
$string = strtolower(str_replace(" ", $delimiter_space, $string)); $string = strtolower(str_replace(" ", $delimiter_space, $string));
@ -47,7 +57,8 @@ class Character extends Model
case 5: return "Raider"; case 5: return "Raider";
case 6: return "Raider-Twink"; case 6: return "Raider-Twink";
case 7: return "F&F"; case 7: return "F&F";
case 8: return "Sleeper"; case 8: return "Novize";
case 9: return "Sleeper";
default: return "Gast"; default: return "Gast";
} }
} }
@ -81,9 +92,12 @@ class Character extends Model
$this->spec = $char_from_api['active_spec']['name']; $this->spec = $char_from_api['active_spec']['name'];
$this->id_blizz = $char_from_api['id']; $this->id_blizz = $char_from_api['id'];
$guild_data = $this->api->getGuildRank($this->name,$realm); $guild_data = $this->api->getGuildRank($this->name,$realm);
if(!empty($guild_data['rank'])){
$this->guild = $guild_data['guild']; $this->guild = $guild_data['guild'];
$this->rank = $guild_data['rank']; $this->rank = $guild_data['rank'];
}else{
$this->rank = 99;
}
$this->save(); $this->save();
return $char_from_api; return $char_from_api;
} }

View File

@ -2,8 +2,10 @@
namespace WoWPress\Models; namespace WoWPress\Models;
use MO;
use Wenprise\Eloquent\Model; use Wenprise\Eloquent\Model;
use WoWPress\Api\BattleNet; use WoWPress\Api\BattleNet;
use WoWPress\Api\WoWAudit;
class Raid extends Model class Raid extends Model
{ {
@ -13,42 +15,201 @@ class Raid extends Model
protected $primaryKey = 'ID'; protected $primaryKey = 'ID';
protected $guarded = ['ID']; protected $guarded = ['ID'];
public $signups;
private $api; private $api;
public $notes;
public $encounters;
public $status;
public $partial;
public function __construct($attrs = []) public function __construct($attrs = [])
{ {
parent::__construct($attrs); parent::__construct($attrs);
$options = get_option('wowpress_api'); $options = get_option('wowpress_api');
if(isset($options['bnet'])){ if (isset($options['bnet'])) {
$key = get_option('wowpress_api')['wowaudit']['key']; $key = get_option('wowpress_api')['wowaudit']['key'];
}else{ } else {
return false; return false;
} }
$this->api = new BattleNet(null,$key); $this->api = new WoWAudit(null, $key);
} }
private function sortRoles($a, $b)
{
switch ($a->role) {
case 'Tank':
$asort = 0;
break;
case 'Heal':
$asort = 1;
break;
case 'Ranged':
$asort = 2;
break;
case 'Melee':
$asort = 3;
break;
default:
$asort = 4;
break;
}
switch ($b->role) {
case 'Tank':
$bsort = 0;
break;
case 'Heal':
$bsort = 1;
break;
case 'Ranged':
$bsort = 2;
break;
case 'Melee':
$bsort = 3;
break;
default:
$bsort = 4;
break;
}
return $asort - $bsort;
}
public function getColorAttribute($type=""){ public function sync($force = false)
switch($this->difficulty){ {
case 'Normal': return "shaman";
case 'Heroic': return "warlock"; if (!empty($this->id_wowaudit)) {
case 'Mythic': return "deathknight"; $raid = (object)$this->api->getRaid($this->id_wowaudit, $force);
case 'Teamspeak': return "hunter"; if (!empty($raid->id)) {
default: return "priest"; $this->title = $raid->instance;
$this->start = $raid->date . " " . $raid->start_time;
$this->end = $raid->date . " " . $raid->end_time;
$this->difficulty = $raid->difficulty;
$this->status = $raid->status;
$encounters = $raid->encounters;
$partial = false;
$signups = [];
$sup = [];
foreach ($encounters as $key => &$encounter) {
$partial = $encounter['enabled'] || $partial;
if (empty($encounter['selections'])) {
$encounter['selections'] = [];
}
$encounters[$key]['selections'] = collect($encounter['selections']);
}
$this->partial = $partial;
foreach ($raid->signups as $signup) {
$character = Character::whereName($signup['character']['name'])->whereRealm($signup['character']['realm'])->first();
if (empty($character)) {
$character = new Character();
$character->name = $signup['character']['name'];
$character->realm = $signup['character']['realm'];
$character->updateFromAPI();
}
if ($character->class != $signup['class']) {
if (!empty($character->user)) {
$newchar = $character->user->characters()->where('class', $signup['class'])->first();
if (!empty($newchar->ID)) {
$character = $newchar;
}
}
}
$character->id_wowaudit = $signup['character']['id'];
$character->save();
$sup[$character->id_wowaudit] = $signup['status'];
$s = new Signup();
$s->character_id = $character->ID;
$s->raid_ID = $this->ID;
if ($this->partial) {
foreach ($encounters as $encounter) {
if ($signup['selected']) break;
if (empty($encounter['selections'])) continue;
foreach ($encounter['selections'] as $selection) {
if ($selection['character_id'] == $signup['character']['id']) {
$signup['selected'] = $selection['selected'] || $signup['selected'];
if ($signup['selected']) {
break 2;
}
}
}
}
}
$s->status = $signup['selected'] ? "Selected" : $signup['status'];
$s->role = $signup['status'] == "Unknown" ? "Unknown" : $signup['role'];
$signups[] = $s;
}
$this->signups = collect($signups);
foreach ($encounters as $encounter) {
foreach ($encounter['selections'] as $key => &$selection) {
$character = Character::where('id_wowaudit', $selection['character_id'])->first();
$selection['status'] = $sup[$character->id_wowaudit];
$s = new Signup();
$s->character_id = $character->ID;
$s->raid_ID = $this->ID;
$s->boss_id = $encounter['id'];
$s->status = $selection['selected'] ? "Selected" : $selection['status'];
$s->role = $selection['role'];
$encounter['selections'][$key] = $s;
}
}
array_unshift($encounters, [
'name' => "Alle Bosse",
'id' => 0,
'enabled' => true,
'notes' => $raid->notes,
'selections' => $this->signups,
]);
foreach ($encounters as &$encounter) {
$encounter['selections'] = collect($encounter['selections'])->sortBy([fn ($a, $b) => $this->sortRoles($a, $b), 'character_id']);
}
$this->encounters = collect($encounters);
}
}
return false;
}
public function getColorAttribute($type = "")
{
switch ($this->difficulty) {
case 'Normal':
return "shaman";
case 'Heroic':
return "warlock";
case 'Mythic':
return "deathknight";
case 'Teamspeak':
return "hunter";
default:
return "priest";
} }
} }
public function getLinkAttribute(){ public function getLinkAttribute()
return "/raid/".$this->ID; {
return "/raid/" . $this->ID;
} }
public function getPreviousAttribute(){ public function getPreviousAttribute()
{
$id = $this->ID; $id = $this->ID;
while($id){ while ($id) {
$raid = Raid::find(--$id); $raid = Raid::find(--$id);
if(!empty($raid->ID)){ if (!empty($raid->ID)) {
return $raid; return $raid;
} }
} }
@ -56,19 +217,40 @@ class Raid extends Model
} }
public function getNextAttribute(){ public function getNextAttribute()
{
$id = $this->ID; $id = $this->ID;
while($id <= Raid::max('ID')){ while ($id <= Raid::max('ID')) {
$raid = Raid::find(++$id); $raid = Raid::find(++$id);
if(!empty($raid->ID)){ if (!empty($raid->ID)) {
return $raid; return $raid;
} }
} }
return false; return false;
} }
public function showSignup(Character $character){ public function showSignup($character, $showRole = false, $showStatus = false, $vertical = false)
require(get_template_directory()."/components/raid-signup.php"); {
} $u = $character->user;
if (!empty($u->ID)) {
$chars = $u->characters;
} else {
$chars = [$character];
}
if (!empty($character->ID) && !empty($this->signups)) {
foreach ($this->signups as $signup) {
foreach ($chars as $character) {
if ($signup->character->ID == $character->ID) {
return $signup->showForm($showRole, $showStatus, $vertical);
}
}
}
}
} $s = new Signup();
$s->raid_id = $this->ID;
$s->character_id = $character->ID;
return $s->showForm($showRole,$showStatus,$vertical);
}
}

View File

@ -0,0 +1,28 @@
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
use WoWPress\Api\BattleNet;
class SKS extends Model
{
protected $table = "wowpress_sks";
public $timestamps = false;
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
public static function getList($name){
return static::where('list_name',$name)->orderBy('rank')->get();
}
public static function getLists(){
return static::distinct('list_name')->get();
}
}

View File

@ -0,0 +1,163 @@
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
class Signup extends Model
{
protected $table = "wowpress_characters";
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
protected $statusList = [];
protected $roleList = [];
public $status = "Unknown";
public $role = "Unknown";
public function __construct()
{
$this->statusList = [
'Unknown' => (object)[
'selectable' => false,
'name' => 'Keine Rückmeldung',
'icon' => 'o-no-symbol',
'color' => 'slate-500',
],
'Present' => (object)[
'selectable' => true,
'name' => 'Anwesend',
'icon' => 'o-check-circle',
'color' => 'green-500',
],
'Absent' => (object)[
'selectable' => true,
'name' => 'Abwesend',
'icon' => 'o-x-circle',
'color' => 'red-500',
],
'Late' => (object)[
'selectable' => true,
'name' => 'Verspätet',
'icon' => 'o-clock',
'color' => 'orange-500',
],
'Tentative' => (object)[
'selectable' => true,
'name' => 'Ersatzbank',
'icon' => 'o-question-mark-circle',
'color' => 'yellow-500',
],
'Selected' => (object)[
'selectable' => false,
'name' => 'Bestätigt',
'icon' => 's-star',
'color' => 'paladin',
],
];
$this->roleList = [
'Unknown' => (object)[
'selectable' => false,
'name' => 'Keine Rolle',
'icon' => 'o-no-symbol',
'color' => 'slate-500',
],
'Tank' => (object)[
'selectable' => true,
'name' => 'Tank',
'icon' => 'o-shield-exclamation',
'color' => 'white',
],
'Heal' => (object)[
'selectable' => true,
'name' => 'Heilung',
'icon' => 'o-heart',
'color' => 'white',
],
'Ranged' => (object)[
'selectable' => true,
'name' => 'Ranged',
'icon' => 'o-bolt',
'color' => 'white',
],
'Melee' => (object)[
'selectable' => true,
'name' => 'Melee',
'icon' => 'o-hand-raised',
'color' => 'white',
],
];
}
public function character(){
return $this->belongsTo(Character::class);
}
public function raid(){
return $this->belongsTo(Raid::class);
}
public function showForm($showRole = false, $showStatus = false,$vertical = false,$doSignup = true){
require(get_template_directory()."/components/raid-signup.php");
}
public function getStatusList($selectable = false){
$out = [];
foreach($this->statusList as $key => $status){
if($selectable){
if($status->selectable){
$out[$key] = $status;
}
}else{
$out[$key] = $status;
}
}
return $out;
}
public function getRoleList(){
$out = [];
foreach($this->roleList as $key => $status){
if($status->selectable){
$out[$key] = $status;
}
}
return $out;
}
public function getStatus(){
if (key_exists($this->status, $this->statusList)) {
return $this->statusList[$this->status];
}
return $this->statusList['Unknown'];
}
public function getRole(){
if (key_exists($this->role, $this->roleList)) {
return $this->roleList[$this->role];
}
return $this->roleList['Unknown'];
}
public function setStatus($status){
if (key_exists($status, $this->statusList)) {
$this->status = $status;
return true;
}
return false;
}
public function setRole($role){
if (key_exists($role, $this->roleList)) {
$this->role = $role;
return true;
}
return false;
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace WoWPress\Models;
use Wenprise\ORM\WP\User as WPUser;
class User extends WPUser{
public function characters(){
return $this->hasMany(Character::class)->orderBy('rank');
}
}