You've already forked Epicnabbo-Catalogus-Updated-Daily
🆙 Added fixed cms
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Compositions\HasBadge;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Achievement extends Model implements HasBadge
|
||||
{
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function getBadgePath(): string
|
||||
{
|
||||
return sprintf('%sACH_%s.gif', setting('badges_path'), $this->getBadgeName());
|
||||
}
|
||||
|
||||
public function getBadgeName(): string
|
||||
{
|
||||
return sprintf('%s%s', $this->name, (string) $this->level);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\NotificationType;
|
||||
use App\Models\Article\ArticleComment;
|
||||
use App\Models\Article\ArticleReaction;
|
||||
use App\Models\Compositions\HasNotificationUrl;
|
||||
use Auth;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Str;
|
||||
|
||||
class Article extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use HasNotificationUrl;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $table = 'website_articles';
|
||||
|
||||
#[\Override]
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function (Article $article): void {
|
||||
$article->user_id = Auth::id();
|
||||
$article->slug = Str::slug($article->title);
|
||||
$article->predominant_color = getPredominantImageColor($article->image);
|
||||
});
|
||||
|
||||
static::updating(function (Article $article): void {
|
||||
$article->slug = Str::slug($article->title);
|
||||
|
||||
if ($article->isDirty('image')) {
|
||||
$article->predominant_color = getPredominantImageColor($article->image);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function syncPaginatedComments(): void
|
||||
{
|
||||
$this->setRelation('comments',
|
||||
$this->comments()->defaultRelationships()->paginate(10)->fragment('comments'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function fromIdAndSlug(string $id, string $slug, bool $withDefaultRelationships = true): Builder
|
||||
{
|
||||
return Article::valid()
|
||||
->when($withDefaultRelationships, fn ($query) => $query->defaultRelationships())
|
||||
->whereId($id)
|
||||
->whereSlug($slug);
|
||||
}
|
||||
|
||||
public static function getLatestValidArticle(bool $withDefaultRelationships = true): ?Article
|
||||
{
|
||||
$article = Article::valid()
|
||||
->when($withDefaultRelationships, fn ($query) => $query->defaultRelationships())
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if (! $article) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$article->syncPaginatedComments();
|
||||
|
||||
return $article;
|
||||
}
|
||||
|
||||
public static function forIndex(int $limit): Builder
|
||||
{
|
||||
return Article::valid()
|
||||
->with(['user:id,username,look,avatar_background'])
|
||||
->select(['id', 'user_id', 'title', 'slug', 'is_promotion', 'image', 'description', 'promotion_ends_at', 'created_at', 'fixed'])
|
||||
->limit($limit)
|
||||
->latest();
|
||||
}
|
||||
|
||||
#[\Illuminate\Database\Eloquent\Attributes\Scope]
|
||||
protected function valid(Builder $query): void
|
||||
{
|
||||
$query->whereVisible(true);
|
||||
}
|
||||
|
||||
#[\Illuminate\Database\Eloquent\Attributes\Scope]
|
||||
protected function defaultRelationships(Builder $query): void
|
||||
{
|
||||
$query->with([
|
||||
'user:id,username,look,gender',
|
||||
'tags',
|
||||
'reactions' => fn ($query) => $query->defaultRelationships(),
|
||||
'user.followers',
|
||||
]);
|
||||
}
|
||||
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArticleComment::class)->defaultBehavior();
|
||||
}
|
||||
|
||||
public function reactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(ArticleReaction::class)->defaultBehavior();
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
|
||||
protected function titleColor(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn () => isDarkColor($this->predominant_color) ? '#fff' : '#000',
|
||||
);
|
||||
}
|
||||
|
||||
public function createFollowersNotification(): void
|
||||
{
|
||||
$this->user->followers()
|
||||
->with('user:id,username')
|
||||
->each(fn (AuthorNotification $follower) => $follower->user->notify($this->user, NotificationType::ArticlePosted, $this->getNotificationUrl()),
|
||||
);
|
||||
}
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'visible' => 'boolean',
|
||||
'fixed' => 'boolean',
|
||||
'allow_comments' => 'boolean',
|
||||
'is_promotion' => 'boolean',
|
||||
'promotion_ends_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function websiteArticles()
|
||||
{
|
||||
return $this->morphedByMany(WebsiteArticle::class, 'taggable');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
|
||||
class WebsiteArticle extends Model
|
||||
{
|
||||
use HasSlug, SoftDeletes;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom('title')
|
||||
->saveSlugsTo('slug')
|
||||
->usingSeparator('-')->allowDuplicateSlugs();
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function reactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteArticleReaction::class, 'article_id')
|
||||
->whereActive(true);
|
||||
}
|
||||
|
||||
public function comments(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteArticleComment::class, 'article_id');
|
||||
}
|
||||
|
||||
public function userHasReachedArticleCommentLimit(): bool
|
||||
{
|
||||
return $this->comments()->where('user_id', '=', Auth::id())->count() >= (int) setting('max_comment_per_article');
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::saving(function ($model): void {
|
||||
if (empty($model->image)) {
|
||||
$model->image = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class WebsiteArticleComment extends Model
|
||||
{
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteArticle::class, 'article_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function canBeDeleted(): bool
|
||||
{
|
||||
return $this->user_id === Auth::id() || hasPermission('delete_article_comments');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteArticleReaction extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $hidden = [
|
||||
'user_id',
|
||||
'article_id',
|
||||
];
|
||||
|
||||
public static function getReaction(int $articleId, int $userId, string $reaction): ?self
|
||||
{
|
||||
return self::where('user_id', $userId)
|
||||
->where('article_id', $articleId)
|
||||
->where('reaction', $reaction)
|
||||
->first();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model): void {
|
||||
$model->user_id = auth()->id();
|
||||
});
|
||||
}
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteArticle::class, 'article_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ChatlogPrivate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'chatlogs_private';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function sender(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_from_id');
|
||||
}
|
||||
|
||||
public function receiver(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_to_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Game\Room;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ChatlogRoom extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'chatlogs_room';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'timestamp';
|
||||
|
||||
public function room()
|
||||
{
|
||||
return $this->belongsTo(Room::class);
|
||||
}
|
||||
|
||||
public function sender()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_from_id');
|
||||
}
|
||||
|
||||
public function receiver()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_to_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CommandLog extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'commandlogs';
|
||||
|
||||
protected $primaryKey = 'timestamp';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'timestamp' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\RareValue;
|
||||
|
||||
use App\Models\Game\Furniture\CatalogItem;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteRareValue extends Model
|
||||
{
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
protected function casts()
|
||||
{
|
||||
return [
|
||||
'currency_type' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteRareValueCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
public function item(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CatalogItem::class, 'item_id', 'item_ids');
|
||||
}
|
||||
|
||||
public function isLimitedEdition(): bool
|
||||
{
|
||||
if (is_null($this->item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->item->limited_stack > 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\RareValue;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteRareValueCategory extends Model
|
||||
{
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public function furniture(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteRareValue::class, 'category_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\Game\Permission;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteOpenPosition extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'website_open_positions';
|
||||
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'permission_id',
|
||||
'description',
|
||||
'apply_from',
|
||||
'apply_to',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
static::deleting(function ($openPosition): void {
|
||||
WebsiteStaffApplications::where('rank_id', $openPosition->permission_id)->delete();
|
||||
});
|
||||
}
|
||||
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'permission_id', 'id');
|
||||
}
|
||||
|
||||
public function applications()
|
||||
{
|
||||
return $this->hasMany(WebsiteStaffApplications::class, 'rank_id', 'permission_id');
|
||||
}
|
||||
|
||||
#[\Illuminate\Database\Eloquent\Attributes\Scope]
|
||||
protected function canApply($query)
|
||||
{
|
||||
return $query->where('apply_from', '<=', now())->where('apply_to', '>', now());
|
||||
}
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'apply_from' => 'datetime',
|
||||
'apply_to' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\Game\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteStaffApplications extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $table = 'website_staff_applications';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'rank_id',
|
||||
'content',
|
||||
];
|
||||
|
||||
public function rank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'rank_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteTeam extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'team_id', 'id');
|
||||
}
|
||||
|
||||
public function getBadgePath(): string
|
||||
{
|
||||
return sprintf('%s%s.gif', setting('badges_path'), $this->getBadgeName());
|
||||
}
|
||||
|
||||
public function getBadgeName(): string
|
||||
{
|
||||
return $this->badge ?: '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Compositions;
|
||||
|
||||
interface HasBadge
|
||||
{
|
||||
public function getBadgePath(): string;
|
||||
|
||||
public function getBadgeName(): string;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Compositions;
|
||||
|
||||
trait HasNotificationUrl
|
||||
{
|
||||
public function getNotificationUrl(): string
|
||||
{
|
||||
return route('articles.show', [$this->id, $this->slug]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EmulatorSetting extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
public $incrementing = false;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EmulatorText extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
public $incrementing = false;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CatalogItem extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function itemBase(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ItemBase::class, 'item_ids', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class CatalogPage extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function catalogItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(CatalogItem::class, 'page_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ItemBase extends Model
|
||||
{
|
||||
protected $table = 'items_base';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function icon(): string
|
||||
{
|
||||
return sprintf('%s/%s_icon.png', setting('furniture_icons_path'), $this->item_name);
|
||||
}
|
||||
|
||||
public function catalogItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(CatalogItem::class, 'item_ids', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Guild;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Guild extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function members(): HasMany
|
||||
{
|
||||
return $this->hasMany(GuildMember::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Guild;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class GuildMember extends Model
|
||||
{
|
||||
protected $table = 'guilds_members';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function guilds(): HasMany
|
||||
{
|
||||
return $this->hasMany(Guild::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game;
|
||||
|
||||
use App\Models\Compositions\HasBadge;
|
||||
use App\Models\StaffApplication;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Permission extends Model implements HasBadge
|
||||
{
|
||||
protected $table = 'permissions';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = ['id', 'rank_name'];
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'rank', 'id');
|
||||
}
|
||||
|
||||
public function roles(): HasMany
|
||||
{
|
||||
return $this->hasMany(PermissionRole::class);
|
||||
}
|
||||
|
||||
public function staffApplications(): HasMany
|
||||
{
|
||||
return $this->hasMany(StaffApplication::class, 'rank_id');
|
||||
}
|
||||
|
||||
public function getBadgePath(): string
|
||||
{
|
||||
return sprintf('%s%s.gif', setting('badges_path'), $this->getBadgeName());
|
||||
}
|
||||
|
||||
public function getBadgeName(): string
|
||||
{
|
||||
return $this->badge;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class MessengerFriendship extends Model
|
||||
{
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_two_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserBadge extends Model
|
||||
{
|
||||
protected $table = 'users_badges';
|
||||
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserCurrency extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected $table = 'users_currency';
|
||||
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserSetting extends Model
|
||||
{
|
||||
protected $table = 'users_settings';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserSubscription extends Model
|
||||
{
|
||||
protected $table = 'users_subscriptions';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game;
|
||||
|
||||
use App\Models\Game\Guild\Guild;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class Room extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function guild(): HasOne
|
||||
{
|
||||
return $this->hasOne(Guild::class, 'room_id');
|
||||
}
|
||||
|
||||
public function owner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHelpCenterCategory extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Stevebauman\Purify\Facades\Purify;
|
||||
|
||||
class WebsiteHelpCenterTicket extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteHelpCenterCategory::class);
|
||||
}
|
||||
|
||||
public function replies(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteHelpCenterTicketReply::class, 'ticket_id');
|
||||
}
|
||||
|
||||
public function canDeleteTicket()
|
||||
{
|
||||
return $this->user_id === Auth::id() || hasPermission('delete_website_tickets');
|
||||
}
|
||||
|
||||
public function canManageTicket()
|
||||
{
|
||||
return $this->user_id === Auth::id() || hasPermission('manage_website_tickets');
|
||||
}
|
||||
|
||||
public function canCloseTicket()
|
||||
{
|
||||
return $this->user_id === Auth::id() || hasPermission('manage_website_tickets');
|
||||
}
|
||||
|
||||
public function isOpen()
|
||||
{
|
||||
return $this->open || hasPermission('manage_website_tickets');
|
||||
}
|
||||
|
||||
protected function content(): \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
{
|
||||
return \Illuminate\Database\Eloquent\Casts\Attribute::make(get: fn($value) => Purify::clean($value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHelpCenterTicketCategories extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Stevebauman\Purify\Facades\Purify;
|
||||
|
||||
class WebsiteHelpCenterTicketReply extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function ticket(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteHelpCenterTicket::class, 'ticket_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function canDeleteReply()
|
||||
{
|
||||
return $this->user_id === Auth::id() || hasPermission('delete_website_ticket_replies');
|
||||
}
|
||||
|
||||
protected function content(): \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
{
|
||||
return \Illuminate\Database\Eloquent\Casts\Attribute::make(get: fn($value) => Purify::clean($value));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHelpCenterTicketStatus extends Model
|
||||
{
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteRule extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteRuleCategory::class, 'category_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteRuleCategory extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function rules(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteRule::class, 'category_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\User\UserItem;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class ItemDefinition extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $table = 'items_base';
|
||||
|
||||
public function userItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserItem::class, 'item_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\Room;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class CameraWeb extends Model
|
||||
{
|
||||
protected $table = 'camera_web';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Illuminate\Database\Eloquent\Attributes\Scope]
|
||||
protected function period(Builder $query, $period): void
|
||||
{
|
||||
if ($period == 'today') {
|
||||
$query->where('timestamp', '>=', \Illuminate\Support\Facades\Date::today()->timestamp);
|
||||
}
|
||||
|
||||
if ($period == 'last_week') {
|
||||
$query->whereBetween('timestamp', [now()->subWeek()->timestamp, now()->timestamp]);
|
||||
}
|
||||
|
||||
if ($period == 'last_month') {
|
||||
$query->whereBetween('timestamp', [now()->subMonth()->timestamp, now()->timestamp]);
|
||||
}
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function room(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Room::class);
|
||||
}
|
||||
|
||||
public function likes(): HasMany
|
||||
{
|
||||
return $this->hasMany(CameraLike::class);
|
||||
}
|
||||
|
||||
public function views(): HasMany
|
||||
{
|
||||
return $this->hasMany(CameraView::class);
|
||||
}
|
||||
|
||||
protected function formattedDate(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn () => \Illuminate\Support\Facades\Date::parse($this->timestamp)->format('Y-m-d H:i'),
|
||||
);
|
||||
}
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'timestamp' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteBetaCode extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteInstallation extends Model
|
||||
{
|
||||
protected $table = 'website_installation';
|
||||
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteIpBlacklist extends Model
|
||||
{
|
||||
protected $table = 'website_ip_blacklist';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteIpWhitelist extends Model
|
||||
{
|
||||
protected $table = 'website_ip_whitelist';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteLanguage extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteMaintenanceTask extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsitePermission extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteSetting extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteWordfilter extends Model
|
||||
{
|
||||
protected $table = 'website_wordfilter';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PasswordResetToken extends Model
|
||||
{
|
||||
protected $primaryKey = 'token';
|
||||
|
||||
protected $fillable = ['email', 'token', 'created_at'];
|
||||
|
||||
// timestamps = true, but we don't have "UPDATED_AT". To prevent an error, we set the default value to `null`.
|
||||
public const UPDATED_AT = null;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'email', 'mail');
|
||||
}
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'created_at' => 'date',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\User\UserItem;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Room extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner_id');
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserItem::class);
|
||||
}
|
||||
|
||||
public function replicateForUser(User $user): self
|
||||
{
|
||||
$replicatedRoom = $this->replicate();
|
||||
|
||||
$replicatedRoom->owner_id = $user->id;
|
||||
$replicatedRoom->owner_name = $user->username;
|
||||
$replicatedRoom->score = 0;
|
||||
$replicatedRoom->guild_id = 0;
|
||||
$replicatedRoom->is_public = '0';
|
||||
$replicatedRoom->is_staff_picked = '0';
|
||||
|
||||
$replicatedRoom->save();
|
||||
|
||||
$items = [];
|
||||
|
||||
foreach ($this->items as $item) {
|
||||
$replicatedItem = $item->replicate();
|
||||
|
||||
$replicatedItem->user_id = $user->id;
|
||||
$replicatedItem->room_id = $replicatedRoom->id;
|
||||
|
||||
$items[] = $replicatedItem;
|
||||
}
|
||||
|
||||
$replicatedRoom->items()->saveMany($items);
|
||||
|
||||
return $replicatedRoom;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Session extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $incrementing = false;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsitePaypalTransaction extends Model
|
||||
{
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use App\Models\Game\Furniture\ItemBase;
|
||||
use App\Models\Game\Permission;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
class WebsiteShopArticle extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function furniItems(): Collection
|
||||
{
|
||||
if (! $this->furniture) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$furniture = json_decode($this->furniture, true);
|
||||
$furnitureIds = array_column($furniture, 'item_id');
|
||||
|
||||
return ItemBase::whereIn('id', $furnitureIds)->get();
|
||||
}
|
||||
|
||||
public function rank(): HasOne
|
||||
{
|
||||
return $this->hasOne(Permission::class, 'id', 'give_rank');
|
||||
}
|
||||
|
||||
public function features(): HasMany
|
||||
{
|
||||
return $this->HasMany(WebsiteShopArticleFeature::class, 'article_id', 'id');
|
||||
}
|
||||
|
||||
public function price(): float|int
|
||||
{
|
||||
if ($this->costs < 100) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return $this->costs / 100;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteShopArticleFeature extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteShopArticle::class, 'article_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteShopCategory extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteShopArticle::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteShopVoucher extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteUsedShopVoucher extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function used(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteUsedShopVoucher::class, 'voucher_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,300 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Articles\WebsiteArticle;
|
||||
use App\Models\Articles\WebsiteArticleComment;
|
||||
use App\Models\Community\Staff\WebsiteStaffApplications;
|
||||
use App\Models\Community\Staff\WebsiteTeam;
|
||||
use App\Models\Game\Furniture\Item;
|
||||
use App\Models\Game\Permission;
|
||||
use App\Models\Game\Player\MessengerFriendship;
|
||||
use App\Models\Game\Player\UserBadge;
|
||||
use App\Models\Game\Player\UserCurrency;
|
||||
use App\Models\Game\Player\UserSetting;
|
||||
use App\Models\Game\Player\UserSubscription;
|
||||
use App\Models\Game\Room;
|
||||
use App\Models\Help\WebsiteHelpCenterTicket;
|
||||
use App\Models\Miscellaneous\CameraWeb;
|
||||
use App\Models\Miscellaneous\WebsiteBetaCode;
|
||||
use App\Models\Shop\WebsitePaypalTransaction;
|
||||
use App\Models\Shop\WebsiteUsedShopVoucher;
|
||||
use App\Models\User\Ban;
|
||||
use App\Models\User\ClaimedReferralLog;
|
||||
use App\Models\User\Referral;
|
||||
use App\Models\User\UserReferral;
|
||||
use App\Models\User\WebsiteUserGuestbook;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Models\Contracts\HasName;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use Laravel\Fortify\TwoFactorAuthenticatable;
|
||||
use Laravel\Fortify\TwoFactorAuthenticationProvider;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
class User extends Authenticatable implements FilamentUser, HasName
|
||||
{
|
||||
use HasApiTokens, HasFactory, LogsActivity, Notifiable, TwoFactorAuthenticatable;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected $hidden = ['id', 'password', 'remember_token'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'hidden_staff' => 'boolean',
|
||||
'online' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function currencies(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserCurrency::class, 'user_id');
|
||||
}
|
||||
|
||||
public function sessions()
|
||||
{
|
||||
return $this->hasMany(Session::class);
|
||||
}
|
||||
|
||||
public function currency(string $currency)
|
||||
{
|
||||
if (! $this->relationLoaded('currencies')) {
|
||||
$this->load('currencies');
|
||||
}
|
||||
|
||||
$type = match ($currency) {
|
||||
'duckets' => 0,
|
||||
'diamonds' => 5,
|
||||
'points' => 101,
|
||||
};
|
||||
|
||||
return $this->currencies->where('type', $type)->first()->amount ?? 0;
|
||||
}
|
||||
|
||||
public function permission(): HasOne
|
||||
{
|
||||
return $this->hasOne(Permission::class, 'id', 'rank');
|
||||
}
|
||||
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteArticle::class);
|
||||
}
|
||||
|
||||
public function referrals(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserReferral::class);
|
||||
}
|
||||
|
||||
public function userReferrals(): HasMany
|
||||
{
|
||||
return $this->hasMany(Referral::class);
|
||||
}
|
||||
|
||||
public function claimedReferralLog(): HasMany
|
||||
{
|
||||
return $this->hasMany(ClaimedReferralLog::class);
|
||||
}
|
||||
|
||||
public function badges(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserBadge::class);
|
||||
}
|
||||
|
||||
public function rooms(): HasMany
|
||||
{
|
||||
return $this->hasMany(Room::class, 'owner_id');
|
||||
}
|
||||
|
||||
public function friends(): HasMany
|
||||
{
|
||||
return $this->hasMany(MessengerFriendship::class, 'user_one_id');
|
||||
}
|
||||
|
||||
public function referralsNeeded()
|
||||
{
|
||||
$referrals = 0;
|
||||
|
||||
if (! is_null($this->referrals)) {
|
||||
$referrals = $this->referrals->referrals_total;
|
||||
}
|
||||
|
||||
return setting('referrals_needed') - $referrals;
|
||||
}
|
||||
|
||||
public function ban(): HasOne
|
||||
{
|
||||
return $this->hasOne(Ban::class, 'user_id')->where('ban_expire', '>', time())->whereIn('type', ['account', 'super']);
|
||||
}
|
||||
|
||||
public function settings(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserSetting::class);
|
||||
}
|
||||
|
||||
public function ssoTicket(): string
|
||||
{
|
||||
$sso = sprintf('%s-%s', Str::replace(' ', '', setting('hotel_name')), Str::uuid());
|
||||
|
||||
if (User::where('auth_ticket', $sso)->exists()) {
|
||||
return $this->ssoTicket();
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'auth_ticket' => $sso,
|
||||
]);
|
||||
|
||||
return $sso;
|
||||
}
|
||||
|
||||
public function betaCode(): HasOne
|
||||
{
|
||||
return $this->hasOne(WebsiteBetaCode::class);
|
||||
}
|
||||
|
||||
public function team(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteTeam::class, 'team_id');
|
||||
}
|
||||
|
||||
public function applications(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteStaffApplications::class, 'user_id');
|
||||
}
|
||||
|
||||
public function hcSubscription(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserSubscription::class);
|
||||
}
|
||||
|
||||
public function articleComments(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteArticleComment::class);
|
||||
}
|
||||
|
||||
public function transactions(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsitePaypalTransaction::class);
|
||||
}
|
||||
|
||||
public function usedShopVouchers(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteUsedShopVoucher::class);
|
||||
}
|
||||
|
||||
public function items(): HasMany
|
||||
{
|
||||
return $this->hasMany(Item::class, 'user_id');
|
||||
}
|
||||
|
||||
public function tickets(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteHelpCenterTicket::class);
|
||||
}
|
||||
|
||||
public function photos(): HasMany
|
||||
{
|
||||
return $this->hasMany(CameraWeb::class);
|
||||
}
|
||||
|
||||
public function profileGuestbook(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteUserGuestbook::class, 'profile_id');
|
||||
}
|
||||
|
||||
public function guestbook(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteUserGuestbook::class, 'user_id');
|
||||
}
|
||||
|
||||
public function chatLogs()
|
||||
{
|
||||
return $this->hasMany(ChatlogRoom::class, 'user_from_id');
|
||||
}
|
||||
|
||||
public function chatLogsPrivate()
|
||||
{
|
||||
return $this->hasMany(ChatlogPrivate::class, 'user_from_id');
|
||||
}
|
||||
|
||||
public function getOnlineFriends(int $total = 10)
|
||||
{
|
||||
return $this->friends()
|
||||
->select(['user_two_id', 'users.id', 'users.username', 'users.look', 'users.motto', 'users.last_online'])
|
||||
->join('users', 'users.id', '=', 'user_two_id')
|
||||
->where('users.online', '1')
|
||||
->inRandomOrder()
|
||||
->limit($total)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function confirmTwoFactorAuthentication($code)
|
||||
{
|
||||
$codeIsValid = app(TwoFactorAuthenticationProvider::class)
|
||||
->verify(decrypt($this->two_factor_secret), $code);
|
||||
|
||||
if (! $codeIsValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'two_factor_confirmed' => true,
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasAppliedForPosition(int $rankId)
|
||||
{
|
||||
return $this->applications()->where('rank_id', '=', $rankId)->exists();
|
||||
}
|
||||
|
||||
public function changePassword(string $newPassword)
|
||||
{
|
||||
$this->password = Hash::make($newPassword);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getFilamentName(): string
|
||||
{
|
||||
return $this->username ?? 'Guest';
|
||||
}
|
||||
|
||||
public function canAccessPanel(Panel $panel): bool
|
||||
{
|
||||
return hasHousekeepingPermission('can_access_housekeeping');
|
||||
}
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logOnly(['id', 'username', 'motto', 'rank', 'credits'])
|
||||
->logOnlyDirty()
|
||||
->dontSubmitEmptyLogs();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public function save(array $options = [])
|
||||
{
|
||||
if (! $this->isDirty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::save($options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
class Ban extends Model
|
||||
{
|
||||
use LogsActivity;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function staff(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_staff_id');
|
||||
}
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logOnly(['user_id', 'ip', 'ban_expire', 'ban_reason', 'type']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ClaimedReferralLog extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Referral extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserReferral extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteUserGuestbook extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function profile(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'profile_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\SettingsService;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class WebsiteAd extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'image',
|
||||
];
|
||||
|
||||
protected function imageUrl(): \Illuminate\Database\Eloquent\Casts\Attribute
|
||||
{
|
||||
return \Illuminate\Database\Eloquent\Casts\Attribute::make(get: function () {
|
||||
$settingsService = app(SettingsService::class);
|
||||
$adsPicturePath = Cache::remember('ads_picture_path', 3600, fn () => $settingsService->getOrDefault('ads_picture_path'));
|
||||
if (! str_starts_with((string) $adsPicturePath, 'http')) {
|
||||
$adsPicturePath = rtrim((string) config('app.url'), '/') . '/' . ltrim((string) $adsPicturePath, '/');
|
||||
}
|
||||
return rtrim((string) $adsPicturePath, '/') . '/' . $this->image;
|
||||
});
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected static function booted()
|
||||
{
|
||||
static::deleting(function ($websiteAd): void {
|
||||
try {
|
||||
$websiteAd->configureAdsDisk();
|
||||
|
||||
logger()->info('Attempting to delete image file:', ['file' => $websiteAd->image]);
|
||||
|
||||
if ($websiteAd->image && Storage::disk('ads')->exists($websiteAd->image)) {
|
||||
Storage::disk('ads')->delete($websiteAd->image);
|
||||
logger()->info('Image file deleted:', ['file' => $websiteAd->image]);
|
||||
} else {
|
||||
logger()->warning('Image file not found:', ['file' => $websiteAd->image]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
logger()->error('Failed to delete image file:', [
|
||||
'file' => $websiteAd->image,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected function configureAdsDisk(): void
|
||||
{
|
||||
$settingsService = app(SettingsService::class);
|
||||
|
||||
$adsPath = Cache::remember('ads_path_filesystem', 3600, fn () => $settingsService->getOrDefault('ads_path_filesystem'));
|
||||
|
||||
config(['filesystems.disks.ads' => [
|
||||
'driver' => 'local',
|
||||
'root' => $adsPath,
|
||||
]]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteBadge extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'badge_key',
|
||||
'badge_name',
|
||||
'badge_description',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteDrawBadge extends Model
|
||||
{
|
||||
protected $table = 'website_drawbadges';
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHousekeepingPermission extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
class Wordfilter extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
use LogsActivity;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $table = 'wordfilter';
|
||||
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()->logAll();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user