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

86 lines
2.1 KiB
PHP
Raw Normal View History

2024-04-22 15:38:22 +02:00
<?php
namespace WoWPress\Models;
use Wenprise\ORM\WP\User as WPUser;
2024-04-23 00:44:42 +02:00
class User extends WPUser
{
2024-04-22 15:38:22 +02:00
2024-04-23 00:44:42 +02:00
public function characters()
{
2024-04-22 15:38:22 +02:00
return $this->hasMany(Character::class)->orderBy('rank');
}
2024-04-23 00:44:42 +02:00
public function raiders()
{
return $this->hasMany(Character::class, 'user_id')->where('raidchar', true)->orderBy('rank');
}
public static function getAvatar($avatar, $user_object)
{
if(is_numeric($user_object)){
$user = User::find($user_object);
if(!empty($user->ID)){
return $user->getAvatarAttribute();
}
}
if(!empty($user_object->user_id)){
$user = User::find($user_object->user_id);
if(!empty($user->ID)){
return $user->getAvatarAttribute();
}
}
return $avatar;
}
public function getAvatarAttribute(){
$chars = $this->characters;
if (!empty($chars->first())) {
return $chars->first()->avatar;
}
return $this->avatar_url;
}
2024-04-22 15:38:22 +02:00
2024-04-23 00:44:42 +02:00
public static function getUsername($username, $user_object)
{
if(is_numeric($user_object)){
$user = User::find($user_object);
if(!empty($user->ID)){
return $user->getUsernameAttribute();
}
}
if (!empty($user_object->user_id)) {
$user = User::find($user_object->user_id);
return $user->getUsernameAttribute();
}
if (!empty($user_object->ID)) {
$user = User::find($user_object->ID);
return $user->getUsernameAttribute();
}
return $username;
}
public function getUsernameAttribute()
{
$chars = $this->characters;
if (!empty($chars->first())) {
return $chars->first()->name;
}
return $this->user_nickname ?: $this->login;
}
public function getColorAttribute()
{
$chars = $this->characters;
if (!empty($chars->first())) {
return $chars->first()->color;
}
return "priest";
}
}