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',
|
|
|
|
],
|
2024-04-23 22:43:54 +02:00
|
|
|
'Too Late' => (object)[
|
|
|
|
'selectable' => false,
|
|
|
|
'name' => 'Anmeldung Vergessen',
|
|
|
|
'icon' => 'o-face-frown',
|
|
|
|
'color' => 'deathknight',
|
|
|
|
],
|
2024-04-22 15:38:22 +02:00
|
|
|
];
|
|
|
|
|
|
|
|
$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
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function character()
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
return $this->belongsTo(Character::class);
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function raid()
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
return $this->belongsTo(Raid::class);
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function showForm($showRole = false, $showStatus = false, $vertical = false, $doSignup = true)
|
|
|
|
{
|
|
|
|
$tooLate = $this->raid->status == "Locked";
|
|
|
|
$doSignup = $doSignup && !$tooLate;
|
|
|
|
|
|
|
|
if ($this->status == "Unknown" && $tooLate) {
|
|
|
|
$this->setStatus('Too Late');
|
|
|
|
$showStatus = true;
|
|
|
|
$showRole = false;
|
|
|
|
}
|
|
|
|
|
2024-04-26 17:47:19 +02:00
|
|
|
require(get_template_directory() . "/template-parts/components/raid-signup.php");
|
2024-04-22 15:38:22 +02:00
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function getStatusList($selectable = false)
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
$out = [];
|
2024-04-23 22:43:54 +02:00
|
|
|
foreach ($this->statusList as $key => $status) {
|
|
|
|
if ($selectable) {
|
|
|
|
if ($status->selectable) {
|
|
|
|
$out[$key] = $status;
|
2024-04-22 15:38:22 +02:00
|
|
|
}
|
2024-04-23 22:43:54 +02:00
|
|
|
} else {
|
|
|
|
$out[$key] = $status;
|
2024-04-22 15:38:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function getRoleList()
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
$out = [];
|
2024-04-23 22:43:54 +02:00
|
|
|
foreach ($this->roleList as $key => $status) {
|
|
|
|
if ($status->selectable) {
|
|
|
|
$out[$key] = $status;
|
2024-04-22 15:38:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function getStatus()
|
|
|
|
{
|
2024-04-26 17:47:19 +02:00
|
|
|
$tooLate = $this->raid->status == "Locked";
|
|
|
|
if($tooLate && $this->status == "Unknown"){
|
|
|
|
$this->setStatus('Too Late');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-22 15:38:22 +02:00
|
|
|
if (key_exists($this->status, $this->statusList)) {
|
|
|
|
return $this->statusList[$this->status];
|
|
|
|
}
|
|
|
|
return $this->statusList['Unknown'];
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function getRole()
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
if (key_exists($this->role, $this->roleList)) {
|
|
|
|
return $this->roleList[$this->role];
|
|
|
|
}
|
|
|
|
return $this->roleList['Unknown'];
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function setStatus($status)
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
if (key_exists($status, $this->statusList)) {
|
|
|
|
$this->status = $status;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-04-23 22:43:54 +02:00
|
|
|
public function setRole($role)
|
|
|
|
{
|
2024-04-22 15:38:22 +02:00
|
|
|
if (key_exists($role, $this->roleList)) {
|
|
|
|
$this->role = $role;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2024-04-23 00:44:42 +02:00
|
|
|
|
2024-04-23 22:43:54 +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-23 00:44:42 +02:00
|
|
|
}
|
|
|
|
}
|
2024-04-22 15:38:22 +02:00
|
|
|
}
|