WowPress-Tailwind/theme/wowpress/Models/Signup.php

184 lines
5.0 KiB
PHP
Raw Normal View History

2024-04-22 15:38:22 +02:00
<?php
namespace WoWPress\Models;
use Wenprise\Eloquent\Model;
2024-04-23 00:44:42 +02:00
use WoWPress\Api\WoWAudit;
2024-04-22 15:38:22 +02:00
class Signup extends Model
{
2024-04-23 00:44:42 +02:00
protected $table = "wowpress_signups";
2024-04-22 15:38:22 +02:00
protected $primaryKey = 'ID';
protected $guarded = ['ID'];
protected $statusList = [];
2024-04-23 00:44:42 +02:00
private $api;
2024-04-22 15:38:22 +02:00
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',
],
];
2024-04-23 00:44:42 +02:00
$options = get_option('wowpress_api');
if (isset($options['bnet'])) {
$key = get_option('wowpress_api')['wowaudit']['key'];
} else {
return false;
}
$this->api = new WoWAudit(null, $key);
2024-04-22 15:38:22 +02:00
}
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;
}
2024-04-23 00:44:42 +02:00
public function updateAPI(Character $second_char = null){
if($second_char->ID){
return $this->api->changeSignup($this->raid,$this->character,$this->status,$this->role,$this->comment,$second_char);
}else{
return $this->api->changeSignup($this->raid,$this->character,$this->status,$this->role,$this->comment);
}
}
2024-04-22 15:38:22 +02:00
}