You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Compositions\HasBadge;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property int $level
|
||||
*/
|
||||
class Achievement extends Model implements HasBadge
|
||||
{
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'name', 'level'];
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Tag extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public function websiteArticles()
|
||||
{
|
||||
return $this->morphedByMany(WebsiteArticle::class, 'taggable');
|
||||
}
|
||||
}
|
||||
Executable
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Database\Factories\Articles\WebsiteArticleFactory;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Spatie\Sluggable\HasSlug;
|
||||
use Spatie\Sluggable\SlugOptions;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $title
|
||||
* @property string $slug
|
||||
* @property string $short_story
|
||||
* @property string $full_story
|
||||
* @property string $image
|
||||
* @property int $user_id
|
||||
* @property Carbon|null $deleted_at
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read User|null $user
|
||||
* @property-read Collection<int, WebsiteArticleReaction> $reactions
|
||||
* @property-read Collection<int, WebsiteArticleComment> $comments
|
||||
* @property-read Collection<int, Tag> $tags
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle whereNot($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle whereHas($relation, \Closure $callback = null, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle latest($column = 'created_at')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle take(int $value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle with($relations)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticle has($relation, \Closure $callback = null, $operator = '>=', $count = 1)
|
||||
*/
|
||||
class WebsiteArticle extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
use HasSlug, \Illuminate\Database\Eloquent\Factories\HasFactory, SoftDeletes;
|
||||
|
||||
/** @var array<int, string> */
|
||||
#[\Override]
|
||||
protected $with = ['user'];
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return WebsiteArticleFactory::new();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'slug', 'visible', 'fixed'];
|
||||
|
||||
public function getSlugOptions(): SlugOptions
|
||||
{
|
||||
return SlugOptions::create()
|
||||
->generateSlugsFrom('title')
|
||||
->saveSlugsTo('slug')
|
||||
->usingSeparator('-')->allowDuplicateSlugs();
|
||||
}
|
||||
|
||||
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) {
|
||||
if (empty($model->image)) {
|
||||
$model->image = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function tags()
|
||||
{
|
||||
return $this->morphToMany(Tag::class, 'taggable');
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $article_id
|
||||
* @property int $user_id
|
||||
* @property string $comment
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read WebsiteArticle|null $article
|
||||
* @property-read User|null $user
|
||||
*/
|
||||
class WebsiteArticleComment extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteArticle::class, 'article_id');
|
||||
}
|
||||
|
||||
public function canBeDeleted(): bool
|
||||
{
|
||||
return $this->user_id === Auth::id() || hasPermission('delete_article_comments');
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Articles;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticleReaction where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteArticleReaction first($columns = ['*'])
|
||||
*/
|
||||
class WebsiteArticleReaction extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'user_id', 'article_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $hidden = [
|
||||
'user_id',
|
||||
'article_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return static|null
|
||||
*/
|
||||
public static function getReaction(int $articleId, int $userId, string $reaction): ?self
|
||||
{
|
||||
/** @var static|null $reaction */
|
||||
$reaction = self::where('user_id', $userId)
|
||||
->where('article_id', $articleId)
|
||||
->where('reaction', $reaction)
|
||||
->first();
|
||||
|
||||
return $reaction;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($model) {
|
||||
$model->user_id = auth()->id();
|
||||
});
|
||||
}
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteArticle::class, 'article_id');
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read User|null $user
|
||||
*/
|
||||
class AuthorNotification extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'type'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = true;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'author_notifications';
|
||||
}
|
||||
Executable
+31
@@ -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 ChatlogPrivate extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'chatlogs_private';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['timestamp', 'user_from_id', 'user_to_id'];
|
||||
|
||||
#[\Override]
|
||||
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');
|
||||
}
|
||||
}
|
||||
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'chatlogs_room';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['timestamp', 'user_from_id', 'user_to_id', 'room_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
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');
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class CommandLog extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'commandlogs';
|
||||
|
||||
#[\Override]
|
||||
protected $primaryKey = 'timestamp';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['timestamp', 'user_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'timestamp' => 'datetime',
|
||||
];
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\RareValue;
|
||||
|
||||
use App\Models\Game\Furniture\CatalogItem;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $item_name
|
||||
* @property int $category_id
|
||||
* @property int $item_id
|
||||
* @property int $currency_type
|
||||
* @property int $cost
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read WebsiteRareValueCategory|null $category
|
||||
* @property-read CatalogItem|null $item
|
||||
*/
|
||||
class WebsiteRareValue extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
#[\Override]
|
||||
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,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\RareValue;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $badge
|
||||
* @property int $priority
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Collection<int, WebsiteRareValue> $furniture
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory orderBy($column, $direction = 'asc')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory has($relation, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory whereId($id)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory whereHas($relation, \Closure $callback = null, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteRareValueCategory withCount($relations)
|
||||
*/
|
||||
class WebsiteRareValueCategory extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
#[\Override]
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'priority' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function furniture(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteRareValue::class, 'category_id');
|
||||
}
|
||||
|
||||
public function getTotalValue(): int
|
||||
{
|
||||
return $this->furniture->sum(fn ($rare) => $rare->credit_value ?? 0);
|
||||
}
|
||||
|
||||
public function getAverageValue(): float
|
||||
{
|
||||
if ($this->furniture->isEmpty()) {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return $this->furniture->avg(fn ($rare) => $rare->credit_value ?? 0);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\Community\Teams\WebsiteTeam;
|
||||
use App\Models\Game\Permission;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteOpenPosition canApply()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteOpenPosition get($columns = ['*'])
|
||||
*/
|
||||
class WebsiteOpenPosition extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'website_open_positions';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'rank_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'apply_from' => 'datetime',
|
||||
'apply_to' => 'datetime',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function ($openPosition) {
|
||||
if ($openPosition->position_kind === 'rank' && $openPosition->permission_id) {
|
||||
WebsiteStaffApplications::where('rank_id', $openPosition->permission_id)->delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function permission()
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'permission_id', 'id');
|
||||
}
|
||||
|
||||
public function team()
|
||||
{
|
||||
return $this->belongsTo(WebsiteTeam::class, 'team_id', 'id');
|
||||
}
|
||||
|
||||
public function applications()
|
||||
{
|
||||
return $this->hasMany(WebsiteStaffApplications::class, 'rank_id', 'permission_id');
|
||||
}
|
||||
|
||||
public function scopeCanApply($query)
|
||||
{
|
||||
return $query->where('apply_from', '<=', now())->where('apply_to', '>', now());
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\Community\Teams\WebsiteTeam;
|
||||
use App\Models\Game\Permission;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteStaffApplications where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteStaffApplications create($attributes = [])
|
||||
*/
|
||||
class WebsiteStaffApplications extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_staff_applications';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'rank_id', 'status'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'approved_at' => 'datetime',
|
||||
'rejected_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function approver(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'approved_by');
|
||||
}
|
||||
|
||||
public function rejector(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function rank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'rank_id');
|
||||
}
|
||||
|
||||
public function team(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteTeam::class, 'team_id');
|
||||
}
|
||||
}
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Staff;
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string|null $badge
|
||||
* @property string $color
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Collection<int, User> $users
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteTeam where($column, $operator = null, $value = null)
|
||||
*/
|
||||
class WebsiteTeam extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
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 ?: '';
|
||||
}
|
||||
}
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Community\Teams;
|
||||
|
||||
use App\Models\Community\Staff\WebsiteOpenPosition;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteTeam select($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteTeam where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteTeam orderByDesc($column)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteTeam get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteTeam with($relations)
|
||||
*/
|
||||
class WebsiteTeam extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_teams';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'name', 'badge', 'color'];
|
||||
|
||||
public function users(): HasMany
|
||||
{
|
||||
return $this->hasMany(User::class, 'team_id', 'id');
|
||||
}
|
||||
|
||||
public function openPositions(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteOpenPosition::class, 'team_id', 'id');
|
||||
}
|
||||
|
||||
public function scopeVisible($query)
|
||||
{
|
||||
return $query->where('hidden_rank', false);
|
||||
}
|
||||
}
|
||||
Executable
+12
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Compositions;
|
||||
|
||||
interface HasBadge
|
||||
{
|
||||
public function getBadgePath(): string;
|
||||
|
||||
public function getBadgeName(): string;
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Compositions;
|
||||
|
||||
trait HasNotificationUrl
|
||||
{
|
||||
public function getNotificationUrl(): string
|
||||
{
|
||||
return route('articles.show', [$this->id, $this->slug]);
|
||||
}
|
||||
}
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
trait BelongsToUser
|
||||
{
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
}
|
||||
Executable
+64
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait HasCommonScopes
|
||||
{
|
||||
/**
|
||||
* Scope to get active records.
|
||||
*/
|
||||
public function scopeActive(Builder $query): Builder
|
||||
{
|
||||
return $query->where('active', true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get pending records.
|
||||
*/
|
||||
public function scopePending(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', 'pending');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get ordered records.
|
||||
*/
|
||||
public function scopeOrdered(Builder $query, $column = 'order', $direction = 'asc'): Builder
|
||||
{
|
||||
return $query->orderBy($column, $direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get latest records.
|
||||
*/
|
||||
public function scopeLatest(Builder $query, $column = 'created_at'): Builder
|
||||
{
|
||||
return $query->orderBy($column, 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get records created today.
|
||||
*/
|
||||
public function scopeToday(Builder $query, $column = 'created_at'): Builder
|
||||
{
|
||||
return $query->whereDate($column, today());
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to get records from the last days.
|
||||
*/
|
||||
public function scopeLastDays(Builder $query, $days, $column = 'created_at'): Builder
|
||||
{
|
||||
return $query->where($column, '>=', now()->subDays($days));
|
||||
}
|
||||
|
||||
/**
|
||||
* Default behavior scope (can be overridden).
|
||||
*/
|
||||
public function scopeDefaultBehavior(Builder $query): Builder
|
||||
{
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class DailyChallenge extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $fillable = [
|
||||
'name', 'description', 'game', 'type', 'target', 'reward_currency', 'reward_amount', 'date',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected $casts = ['target' => 'integer', 'reward_amount' => 'integer', 'date' => 'date'];
|
||||
|
||||
public function progress(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserChallengeProgress::class, 'challenge_id');
|
||||
}
|
||||
}
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EmailTemplate extends Model
|
||||
{
|
||||
protected $table = 'email_templates';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'subject',
|
||||
'body',
|
||||
'variables',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public static function getTemplate(string $name): ?self
|
||||
{
|
||||
return static::where('name', $name)
|
||||
->where('is_active', true)
|
||||
->first();
|
||||
}
|
||||
|
||||
public static function render(string $name, array $variables): ?array
|
||||
{
|
||||
$template = static::getTemplate($name);
|
||||
|
||||
if (! $template) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$subject = $template->subject;
|
||||
$body = $template->body;
|
||||
|
||||
foreach ($variables as $key => $value) {
|
||||
$subject = str_replace('{{' . $key . '}}', $value, $subject);
|
||||
$body = str_replace('{{' . $key . '}}', $value, $body);
|
||||
}
|
||||
|
||||
return [
|
||||
'subject' => $subject,
|
||||
'body' => $body,
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EmulatorSetting extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['key'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
#[\Override]
|
||||
public $incrementing = false;
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class EmulatorText extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['key'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $primaryKey = 'key';
|
||||
|
||||
#[\Override]
|
||||
public $incrementing = false;
|
||||
}
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $item_ids
|
||||
* @property int $page_id
|
||||
* @property string $catalog_name
|
||||
* @property int $cost_credits
|
||||
* @property int $cost_pixels
|
||||
* @property int $cost_diamonds
|
||||
* @property int $amount
|
||||
* @property int $limited_stack
|
||||
* @property int $limited_sells
|
||||
* @property int $order_number
|
||||
* @property string $badge
|
||||
* @property-read ItemBase|null $itemBase
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CatalogItem whereKey($id)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CatalogItem where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CatalogItem whereIn($column, $values, $boolean = 'and', $not = false)
|
||||
*/
|
||||
class CatalogItem extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'page_id', 'item_ids', 'cost_credits', 'cost_duckets', 'cost_diamonds'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function itemBase(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ItemBase::class, 'item_ids', 'id');
|
||||
}
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CatalogPage find($id, $columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CatalogPage pluck($column, $key = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CatalogPage whereKey($id)
|
||||
*/
|
||||
class CatalogPage extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'parent_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function catalogItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(CatalogItem::class, 'page_id');
|
||||
}
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'item_id', 'room_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
Executable
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Furniture;
|
||||
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $item_name
|
||||
* @property string $public_name
|
||||
* @property int $width
|
||||
* @property int $length
|
||||
* @property float $stack_height
|
||||
* @property bool $allow_stack
|
||||
* @property bool $allow_sit
|
||||
* @property bool $allow_lay
|
||||
* @property bool $allow_walk
|
||||
* @property string $sprite_id
|
||||
* @property bool $allow_recycle
|
||||
* @property bool $allow_trade
|
||||
* @property bool $allow_marketplace_sell
|
||||
* @property bool $allow_gift
|
||||
* @property bool $allow_inventory_stack
|
||||
* @property string $interaction_type
|
||||
* @property int $vending_ids
|
||||
* @property int $is_ambience
|
||||
* @property bool $no_effect
|
||||
* @property int $effect_id
|
||||
* @property-read Collection<int, CatalogItem> $catalogItems
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ItemBase whereIn($column, $values, $boolean = 'and', $not = false)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ItemBase get($columns = ['*'])
|
||||
*/
|
||||
class ItemBase extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'items_base';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'sprite_id', 'public_name'];
|
||||
|
||||
#[\Override]
|
||||
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');
|
||||
}
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Guild;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Guild extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'owner_id', 'name', 'badge'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function members(): HasMany
|
||||
{
|
||||
return $this->hasMany(GuildMember::class);
|
||||
}
|
||||
}
|
||||
Executable
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Guild;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class GuildMember extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'guilds_members';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'guild_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function guild(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Guild::class, 'guild_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game;
|
||||
|
||||
use App\Models\Compositions\HasBadge;
|
||||
use App\Models\StaffApplication;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $rank_name
|
||||
* @property string $badge
|
||||
* @property-read Collection<int, User> $users
|
||||
* @property-read Collection<int, PermissionRole> $roles
|
||||
* @property-read Collection<int, StaffApplication> $staffApplications
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Permission where($column, $operator = null, $value = null)
|
||||
*/
|
||||
class Permission extends Model implements HasBadge
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'permissions';
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
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;
|
||||
}
|
||||
}
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class PermissionRole extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'role', 'permission'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'permission_roles';
|
||||
|
||||
public function permissions(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Permission::class, 'role_permissions');
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MessengerFriendship select($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MessengerFriendship where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MessengerFriendship whereHas($relation, \Closure $callback = null, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|MessengerFriendship inRandomOrder($seed = '')
|
||||
*/
|
||||
class MessengerFriendship extends Model
|
||||
{
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_two_id', 'id');
|
||||
}
|
||||
|
||||
public function friend(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_one_id', 'id');
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?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
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'users_badges';
|
||||
|
||||
#[\Override]
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['user_id', 'badge_slot'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'id');
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserCurrency insert($values)
|
||||
*/
|
||||
class UserCurrency extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['user_id', 'type'];
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'users_currency';
|
||||
|
||||
#[\Override]
|
||||
protected $primaryKey = 'user_id';
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserSetting select($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserSetting whereNotIn($column, $values, $boolean = 'and')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserSetting orderByDesc($column)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserSetting with($relations)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserSetting get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserSetting take(int $value)
|
||||
*/
|
||||
class UserSetting extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'users_settings';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Game\Player;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class UserSubscription extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'users_subscriptions';
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
<?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
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'owner_id', 'name', 'state'];
|
||||
|
||||
public function guild(): HasOne
|
||||
{
|
||||
return $this->hasOne(Guild::class, 'room_id');
|
||||
}
|
||||
|
||||
public function owner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'owner_id', 'id');
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterCategory orderBy($column, $direction = 'asc')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterCategory get($columns = ['*'])
|
||||
*/
|
||||
class WebsiteHelpCenterCategory extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'name', 'icon'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHelpCenterQuestion extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'help_questions';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'category_id', 'created_at', 'updated_at'];
|
||||
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(WebsiteHelpCenterCategory::class, 'category_id');
|
||||
}
|
||||
}
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $category_id
|
||||
* @property string $subject
|
||||
* @property string $content
|
||||
* @property int $severity
|
||||
* @property bool $open
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read string $content
|
||||
* @property-read User|null $user
|
||||
* @property-read WebsiteHelpCenterCategory|null $category
|
||||
* @property-read Collection<int, WebsiteHelpCenterTicketReply> $replies
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket orderBy($column, $direction = 'asc')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteHelpCenterTicket paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
|
||||
*/
|
||||
class WebsiteHelpCenterTicket extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'status', 'subject', 'category_id'];
|
||||
|
||||
/** @var array<int, string> */
|
||||
#[\Override]
|
||||
protected $with = ['user', 'category'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteHelpCenterCategory::class);
|
||||
}
|
||||
|
||||
public function replies(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteHelpCenterTicketReply::class, 'ticket_id')->latest();
|
||||
}
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public function getContentAttribute($value)
|
||||
{
|
||||
return Purify::clean($value);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHelpCenterTicketCategories extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Stevebauman\Purify\Facades\Purify;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $ticket_id
|
||||
* @property int $user_id
|
||||
* @property string $content
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read string $content
|
||||
* @property-read WebsiteHelpCenterTicket|null $ticket
|
||||
* @property-read User|null $user
|
||||
*/
|
||||
class WebsiteHelpCenterTicketReply extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'ticket_id', 'content'];
|
||||
|
||||
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');
|
||||
}
|
||||
|
||||
public function getContentAttribute($value)
|
||||
{
|
||||
return Purify::clean($value);
|
||||
}
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHelpCenterTicketStatus extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteRule extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'category_id', 'created_at', 'updated_at'];
|
||||
|
||||
public function category(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteRuleCategory::class, 'category_id');
|
||||
}
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Help;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteRuleCategory extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
public function rules(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteRule::class, 'category_id');
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?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;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|ItemDefinition count($columns = '*')
|
||||
*/
|
||||
class ItemDefinition extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id'];
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'items_base';
|
||||
|
||||
public function userItems(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserItem::class, 'item_id');
|
||||
}
|
||||
}
|
||||
Executable
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AlertLog extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $fillable = [
|
||||
'type',
|
||||
'severity',
|
||||
'message',
|
||||
'context',
|
||||
'sent_via_email',
|
||||
'sent_via_discord',
|
||||
'is_read',
|
||||
'read_at',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'context' => 'array',
|
||||
'sent_via_email' => 'boolean',
|
||||
'sent_via_discord' => 'boolean',
|
||||
'is_read' => 'boolean',
|
||||
'read_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function markAsRead(): void
|
||||
{
|
||||
$this->update([
|
||||
'is_read' => true,
|
||||
'read_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function scopeUnread($query)
|
||||
{
|
||||
return $query->where('is_read', false);
|
||||
}
|
||||
|
||||
public function scopeByType($query, string $type)
|
||||
{
|
||||
return $query->where('type', $type);
|
||||
}
|
||||
|
||||
public function scopeBySeverity($query, string $severity)
|
||||
{
|
||||
return $query->where('severity', $severity);
|
||||
}
|
||||
|
||||
public function scopeCritical($query)
|
||||
{
|
||||
return $query->where('severity', 'critical');
|
||||
}
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CameraLike extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'photo_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'camera_likes';
|
||||
|
||||
public function cameraWeb(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CameraWeb::class, 'camera_id');
|
||||
}
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class CameraView extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'photo_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'camera_views';
|
||||
|
||||
public function cameraWeb(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(CameraWeb::class, 'camera_id');
|
||||
}
|
||||
}
|
||||
Executable
+93
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
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\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int|null $room_id
|
||||
* @property string $url
|
||||
* @property string $caption
|
||||
* @property int $timestamp
|
||||
* @property int $likes
|
||||
* @property int $views
|
||||
* @property-read Carbon $timestamp
|
||||
* @property-read string $formattedDate
|
||||
* @property-read User|null $user
|
||||
* @property-read Room|null $room
|
||||
* @property-read Collection<int, CameraLike> $likesRelation
|
||||
* @property-read Collection<int, CameraView> $views
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CameraWeb where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CameraWeb latest($column = 'created_at')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CameraWeb count($columns = '*')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CameraWeb take(int $value)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|CameraWeb with($relations)
|
||||
*/
|
||||
class CameraWeb extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'camera_web';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'image', 'caption'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'timestamp' => 'datetime',
|
||||
];
|
||||
|
||||
public function scopePeriod(Builder $query, $period): void
|
||||
{
|
||||
if ($period == 'today') {
|
||||
$query->where('timestamp', '>=', Carbon::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 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);
|
||||
}
|
||||
|
||||
public function formattedDate(): Attribute
|
||||
{
|
||||
return new Attribute(
|
||||
get: fn () => Carbon::parse($this->timestamp)->format('Y-m-d H:i'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteBetaCode where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteBetaCode whereCode($code)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteBetaCode whereNull($columns, $boolean = 'and', $not = false)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteBetaCode doesntExist()
|
||||
*/
|
||||
class WebsiteBetaCode extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'code', 'user_id'];
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteBlockedCountry extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_blocked_countries';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'country_code'];
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteInstallation first($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteInstallation latest($column = 'created_at')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteInstallation create($attributes = [])
|
||||
* @method static mixed toArray()
|
||||
*/
|
||||
class WebsiteInstallation extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_installation';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteIpBlacklist where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteIpBlacklist create($attributes = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteIpBlacklist exists()
|
||||
*/
|
||||
class WebsiteIpBlacklist extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_ip_blacklist';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'ip_address', 'reason'];
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteIpWhitelist where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteIpWhitelist exists()
|
||||
*/
|
||||
class WebsiteIpWhitelist extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_ip_whitelist';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'ip_address'];
|
||||
}
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteLanguage where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteLanguage exists()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteLanguage doesntExist()
|
||||
*/
|
||||
class WebsiteLanguage extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'code', 'name'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteMaintenanceTask extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'user_id', 'created_at', 'updated_at'];
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class WebsitePermission extends Model
|
||||
{
|
||||
/**
|
||||
* Zorgt ervoor dat alle velden behalve ID gevuld mogen worden.
|
||||
*/
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'permission', 'rank_id'];
|
||||
|
||||
/**
|
||||
* Automatische cache-opschoning bij wijzigingen.
|
||||
*/
|
||||
#[\Override]
|
||||
protected static function booted(): void
|
||||
{
|
||||
$clearCache = fn () => Cache::forget('website_permissions');
|
||||
|
||||
static::saved($clearCache);
|
||||
static::deleted($clearCache);
|
||||
}
|
||||
}
|
||||
Executable
+129
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use App\Services\CacheService;
|
||||
use App\Services\SettingsService;
|
||||
use Database\Factories\Miscellaneous\WebsiteSettingFactory;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting whereIn(string $column, array $values)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting whereNotIn(string $column, array $values)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting orWhere($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting count($columns = '*')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting first()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting updateOrCreate(array $attributes, array $values = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting pluck($column, $key = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteSetting exists()
|
||||
*
|
||||
* @property string $key
|
||||
* @property string|null $value
|
||||
*/
|
||||
class WebsiteSetting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return WebsiteSettingFactory::new();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id'];
|
||||
|
||||
public static function updateOrCreate(array $attributes, array $values = []): Builder|Model
|
||||
{
|
||||
$instance = static::firstOrNew($attributes);
|
||||
|
||||
if (! $instance->getKey()) {
|
||||
$instance->forceFill(array_merge($attributes, $values))->save();
|
||||
} else {
|
||||
$instance->fill($values)->save();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public static function firstOrCreate(array $attributes, array $values = []): Model|static
|
||||
{
|
||||
$instance = static::firstOrNew($attributes);
|
||||
|
||||
if (! $instance->getKey()) {
|
||||
$instance->forceFill(array_merge($attributes, $values))->save();
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::saved(function (WebsiteSetting $setting) {
|
||||
SettingsService::clearCache();
|
||||
self::clearRelatedCache($setting->key);
|
||||
});
|
||||
static::deleted(function (WebsiteSetting $setting) {
|
||||
SettingsService::clearCache();
|
||||
self::clearRelatedCache($setting->key);
|
||||
});
|
||||
}
|
||||
|
||||
private static function clearRelatedCache(?string $key): void
|
||||
{
|
||||
if ($key === null) {
|
||||
CacheService::clearAllAppCache();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'points_')) {
|
||||
CacheService::clearPointsSettings();
|
||||
CacheService::clearLeaderboards();
|
||||
CacheService::clearApiCache();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'ai_filter_') || str_starts_with($key, 'filter_word_')) {
|
||||
CacheService::clearContentModeration();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'radio_')) {
|
||||
CacheService::clearRadioSettings();
|
||||
CacheService::clearLeaderboards();
|
||||
CacheService::clearApiCache();
|
||||
CacheService::clearLeaderboard();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'rare_value_')) {
|
||||
CacheService::clearRareValueCategories();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'staff_')) {
|
||||
CacheService::clearStaff();
|
||||
CacheService::clearLeaderboard();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (str_starts_with($key, 'help_center') || str_starts_with($key, 'website_rules')) {
|
||||
CacheService::clearHelpCenter();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Miscellaneous;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteWordfilter get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteWordfilter pluck($column, $key = null)
|
||||
* @method static mixed toArray()
|
||||
*/
|
||||
class WebsiteWordfilter extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_wordfilter';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'word', 'replacement'];
|
||||
}
|
||||
Executable
+35
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|PasswordResetToken create($attributes = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|PasswordResetToken select($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|PasswordResetToken where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|PasswordResetToken first()
|
||||
*/
|
||||
class PasswordResetToken extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $primaryKey = 'token';
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = ['email', 'token', 'created_at'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'created_at' => 'date',
|
||||
];
|
||||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioApplication where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioApplication create($attributes = [])
|
||||
*/
|
||||
class RadioApplication extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_applications';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'position_id', 'status'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'approved_at' => 'datetime',
|
||||
'rejected_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function rank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RadioRank::class, 'rank_id');
|
||||
}
|
||||
|
||||
public function approver(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'approved_by');
|
||||
}
|
||||
|
||||
public function rejector(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'rejected_by');
|
||||
}
|
||||
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('status', 'pending');
|
||||
}
|
||||
|
||||
public function scopeApproved($query)
|
||||
{
|
||||
return $query->where('status', 'approved');
|
||||
}
|
||||
|
||||
public function scopeRejected($query)
|
||||
{
|
||||
return $query->where('status', 'rejected');
|
||||
}
|
||||
}
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioBanner where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioBanner create($attributes = [])
|
||||
*/
|
||||
class RadioBanner extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_banners';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'image', 'url'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function scopeOrdered($query)
|
||||
{
|
||||
return $query->orderBy('sort_order');
|
||||
}
|
||||
|
||||
public function getImageUrlAttribute(): string
|
||||
{
|
||||
return Storage::url($this->image_path);
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected static function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
static::deleting(function ($banner) {
|
||||
if ($banner->image_path && Storage::exists($banner->image_path)) {
|
||||
Storage::delete($banner->image_path);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Executable
+50
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class RadioContest extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_contests';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'prize'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
'is_ended' => 'boolean',
|
||||
'winners_announced' => 'boolean',
|
||||
];
|
||||
|
||||
public function entries(): HasMany
|
||||
{
|
||||
return $this->hasMany(RadioContestEntry::class);
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->is_active &&
|
||||
now()->gte($this->starts_at) &&
|
||||
now()->lte($this->ends_at) &&
|
||||
! $this->is_ended;
|
||||
}
|
||||
|
||||
public function entryCount(): int
|
||||
{
|
||||
return $this->entries()->count();
|
||||
}
|
||||
|
||||
public function uniqueParticipants(): int
|
||||
{
|
||||
return $this->entries()->distinct('user_id')->count('user_id');
|
||||
}
|
||||
}
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class RadioContestEntry extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'radio_contest_entries';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'contest_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'submitted_at' => 'datetime',
|
||||
'is_winner' => 'boolean',
|
||||
];
|
||||
|
||||
public function contest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RadioContest::class);
|
||||
}
|
||||
|
||||
public function markAsWinner(): void
|
||||
{
|
||||
$this->update(['is_winner' => true]);
|
||||
}
|
||||
}
|
||||
Executable
+66
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class RadioGiveaway extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_giveaways';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'prize'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'starts_at' => 'datetime',
|
||||
'ends_at' => 'datetime',
|
||||
'is_active' => 'boolean',
|
||||
'is_ended' => 'boolean',
|
||||
'winner_announced' => 'boolean',
|
||||
'prize_value' => 'decimal:2',
|
||||
];
|
||||
|
||||
public function winner(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'winner_id');
|
||||
}
|
||||
|
||||
public function participants(): HasMany
|
||||
{
|
||||
return $this->hasMany(RadioGiveawayParticipant::class);
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->is_active &&
|
||||
now()->gte($this->starts_at) &&
|
||||
now()->lte($this->ends_at) &&
|
||||
! $this->is_ended;
|
||||
}
|
||||
|
||||
public function hasEnded(): bool
|
||||
{
|
||||
return now()->isAfter($this->ends_at) || $this->is_ended;
|
||||
}
|
||||
|
||||
public function announceWinner(User $user): void
|
||||
{
|
||||
$this->update([
|
||||
'winner_id' => $user->id,
|
||||
'winner_announced' => true,
|
||||
'is_ended' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public function participantCount(): int
|
||||
{
|
||||
return $this->participants()->count();
|
||||
}
|
||||
}
|
||||
Executable
+38
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class RadioGiveawayParticipant extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'radio_giveaway_participants';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'giveaway_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'joined_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function giveaway(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RadioGiveaway::class);
|
||||
}
|
||||
|
||||
public function hasJoined(User $user): bool
|
||||
{
|
||||
return $this->where('giveaway_id', $this->giveaway_id)
|
||||
->where('user_id', $user->id)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioHistory where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioHistory create($attributes = [])
|
||||
*/
|
||||
class RadioHistory extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_history';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'dj_id', 'song'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'started_at' => 'datetime',
|
||||
'ended_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function scopeRecent($query)
|
||||
{
|
||||
return $query->orderBy('started_at', 'desc');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->whereNull('ended_at');
|
||||
}
|
||||
|
||||
public function getDurationAttribute(): ?string
|
||||
{
|
||||
if (! $this->ended_at) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$diff = $this->started_at->diff($this->ended_at);
|
||||
|
||||
if ($diff->h > 0) {
|
||||
return $diff->h . ' uur ' . $diff->i . ' min';
|
||||
}
|
||||
|
||||
return $diff->i . ' minuten';
|
||||
}
|
||||
|
||||
public function endSession(): void
|
||||
{
|
||||
$this->update([
|
||||
'ended_at' => now(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Executable
+69
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RadioListenerPoint extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'radio_listener_points';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'points'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'points' => 'integer',
|
||||
'earned_at' => 'datetime',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected $attributes = [
|
||||
'points' => 0,
|
||||
];
|
||||
|
||||
public static function awardPoints(User $user, int $points, string $reason): self
|
||||
{
|
||||
$pointRecord = self::create([
|
||||
'user_id' => $user->id,
|
||||
'points' => $points,
|
||||
'reason' => $reason,
|
||||
'earned_at' => now(),
|
||||
]);
|
||||
|
||||
$user->increment('radio_points', $points);
|
||||
|
||||
return $pointRecord;
|
||||
}
|
||||
|
||||
public static function deductPoints(User $user, int $points, string $reason): self
|
||||
{
|
||||
$pointRecord = self::create([
|
||||
'user_id' => $user->id,
|
||||
'points' => -$points,
|
||||
'reason' => $reason,
|
||||
'earned_at' => now(),
|
||||
]);
|
||||
|
||||
$user->decrement('radio_points', $points);
|
||||
|
||||
return $pointRecord;
|
||||
}
|
||||
|
||||
public function scopeRecent($query, int $days = 30)
|
||||
{
|
||||
return $query->where('earned_at', '>=', now()->subDays($days));
|
||||
}
|
||||
|
||||
public function scopeByUser($query, User $user)
|
||||
{
|
||||
return $query->where('user_id', $user->id);
|
||||
}
|
||||
}
|
||||
Executable
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Database\Factories\RadioRankFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RadioRank extends Model
|
||||
{
|
||||
/** @use HasFactory<RadioRankFactory> */
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'badge_code',
|
||||
'accepts_applications',
|
||||
'application_rank',
|
||||
];
|
||||
|
||||
#[\Override]
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'accepts_applications' => 'boolean',
|
||||
];
|
||||
}
|
||||
}
|
||||
Executable
+80
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioSchedule where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|RadioSchedule create($attributes = [])
|
||||
*/
|
||||
class RadioSchedule extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'radio_schedules';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'start_time' => 'datetime:H:i',
|
||||
'end_time' => 'datetime:H:i',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function scopeActive($query)
|
||||
{
|
||||
return $query->where('is_active', true);
|
||||
}
|
||||
|
||||
public function scopeToday($query)
|
||||
{
|
||||
$days = [
|
||||
'Sunday' => 'sunday',
|
||||
'Monday' => 'monday',
|
||||
'Tuesday' => 'tuesday',
|
||||
'Wednesday' => 'wednesday',
|
||||
'Thursday' => 'thursday',
|
||||
'Friday' => 'friday',
|
||||
'Saturday' => 'saturday',
|
||||
];
|
||||
|
||||
return $query->where('day', $days[now()->format('l')]);
|
||||
}
|
||||
|
||||
public function scopeOrdered($query)
|
||||
{
|
||||
$days = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'];
|
||||
|
||||
return $query->orderByRaw("FIELD(day, '" . implode("','", $days) . "')")
|
||||
->orderBy('start_time');
|
||||
}
|
||||
|
||||
public function getDayNameAttribute(): string
|
||||
{
|
||||
$days = [
|
||||
'monday' => 'Maandag',
|
||||
'tuesday' => 'Dinsdag',
|
||||
'wednesday' => 'Woensdag',
|
||||
'thursday' => 'Donderdag',
|
||||
'friday' => 'Vrijdag',
|
||||
'saturday' => 'Zaterdag',
|
||||
'sunday' => 'Zondag',
|
||||
];
|
||||
|
||||
return $days[$this->day] ?? $this->day;
|
||||
}
|
||||
|
||||
public function getTimeRangeAttribute(): string
|
||||
{
|
||||
return $this->start_time->format('H:i') . ' - ' . $this->end_time->format('H:i');
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RadioShout extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
use HasFactory;
|
||||
|
||||
/** @var array<int, string> */
|
||||
#[\Override]
|
||||
protected $with = ['user'];
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'message',
|
||||
'reported',
|
||||
'reported_by',
|
||||
];
|
||||
}
|
||||
Executable
+113
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class RadioSongRequest extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'radio_song_requests';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'submitted_at' => 'datetime',
|
||||
'played_at' => 'datetime',
|
||||
'is_played' => 'boolean',
|
||||
'is_approved' => 'boolean',
|
||||
'votes' => 'integer',
|
||||
];
|
||||
|
||||
public function votes(): HasMany
|
||||
{
|
||||
return $this->hasMany(RadioSongVote::class);
|
||||
}
|
||||
|
||||
public function isPending(): bool
|
||||
{
|
||||
return ! $this->is_played && ! $this->played_at;
|
||||
}
|
||||
|
||||
public function isQueued(): bool
|
||||
{
|
||||
return $this->is_approved && ! $this->is_played;
|
||||
}
|
||||
|
||||
public function isPlayed(): bool
|
||||
{
|
||||
return $this->is_played || $this->played_at !== null;
|
||||
}
|
||||
|
||||
public function approve(): void
|
||||
{
|
||||
$this->update(['is_approved' => true]);
|
||||
}
|
||||
|
||||
public function markAsPlayed(): void
|
||||
{
|
||||
$this->update([
|
||||
'is_played' => true,
|
||||
'played_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function voteCount(): int
|
||||
{
|
||||
return $this->votes()->count();
|
||||
}
|
||||
|
||||
public function hasUserVoted(User $user): bool
|
||||
{
|
||||
return $this->votes()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
public function addVote(User $user): bool
|
||||
{
|
||||
if ($this->hasUserVoted($user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
RadioSongVote::create([
|
||||
'song_request_id' => $this->id,
|
||||
'user_id' => $user->id,
|
||||
]);
|
||||
|
||||
$this->increment('votes');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getQueuePosition(): int
|
||||
{
|
||||
return self::where('is_approved', true)
|
||||
->where('is_played', false)
|
||||
->orderBy('votes', 'desc')
|
||||
->orderBy('submitted_at', 'asc')
|
||||
->pluck('id')
|
||||
->search($this->id) + 1;
|
||||
}
|
||||
|
||||
public function scopeQueued($query)
|
||||
{
|
||||
return $query->where('is_approved', true)
|
||||
->where('is_played', false)
|
||||
->orderBy('votes', 'desc')
|
||||
->orderBy('submitted_at', 'asc');
|
||||
}
|
||||
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('is_approved', false)
|
||||
->orderBy('submitted_at', 'desc');
|
||||
}
|
||||
}
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class RadioSongVote extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'radio_song_votes';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'song_id'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'voted_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function songRequest(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(RadioSongRequest::class);
|
||||
}
|
||||
}
|
||||
Executable
+74
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\User\UserItem;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int|null $owner_id
|
||||
* @property string|null $owner_name
|
||||
* @property int $score
|
||||
* @property int $guild_id
|
||||
* @property string $is_public
|
||||
* @property string $is_staff_picked
|
||||
* @property-read User|null $user
|
||||
* @property-read Collection<int, UserItem> $items
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Room count($columns = '*')
|
||||
*/
|
||||
class Room extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'owner_id', 'owner_name', 'score', 'guild_id'];
|
||||
|
||||
#[\Override]
|
||||
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();
|
||||
|
||||
/** @var UserItem $replicatedItem */
|
||||
$replicatedItem->user_id = $user->id;
|
||||
$replicatedItem->room_id = $replicatedRoom->id;
|
||||
|
||||
$items[] = $replicatedItem;
|
||||
}
|
||||
|
||||
$replicatedRoom->items()->saveMany($items);
|
||||
|
||||
return $replicatedRoom;
|
||||
}
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Session extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'ip_address', 'user_agent', 'payload'];
|
||||
|
||||
#[\Override]
|
||||
public $incrementing = false;
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsitePaypalTransaction extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
}
|
||||
Executable
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use App\Models\Game\Furniture\ItemBase;
|
||||
use App\Models\Game\Permission;
|
||||
use Carbon\Carbon;
|
||||
use Database\Factories\WebsiteShopArticleFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $description
|
||||
* @property string $furniture
|
||||
* @property int $give_rank
|
||||
* @property int $costs
|
||||
* @property int $sort_order
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read Collection<int, ItemBase> $furniItems
|
||||
* @property-read Permission|null $rank
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection<int, WebsiteShopArticleFeature> $features
|
||||
* @property-read float|int $price
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopArticle orderBy($column, $direction = 'asc')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopArticle get($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopArticle with($relations)
|
||||
*/
|
||||
class WebsiteShopArticle extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return WebsiteShopArticleFactory::new();
|
||||
}
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'price', 'credits', 'duckets', 'diamonds', 'give_rank', 'badges', 'furniture', 'is_giftable'];
|
||||
|
||||
public function furniItems(): Collection
|
||||
{
|
||||
if (! $this->furniture) {
|
||||
return collect();
|
||||
}
|
||||
|
||||
$furniture = json_decode($this->furniture, true);
|
||||
$furnitureIds = array_column($furniture, 'item_id');
|
||||
|
||||
return ItemBase::query()->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;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteShopArticleFeature extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'article_id', 'feature'];
|
||||
|
||||
public function article(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteShopArticle::class, 'article_id', 'id');
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Database\Factories\Shop\WebsiteShopCategoryFactory;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopCategory whereHas($relation, \Closure $callback = null, $operator = '>=', $count = 1)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopCategory get($columns = ['*'])
|
||||
*/
|
||||
class WebsiteShopCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at'];
|
||||
|
||||
protected static function newFactory()
|
||||
{
|
||||
return WebsiteShopCategoryFactory::new();
|
||||
}
|
||||
|
||||
public function articles(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteShopArticle::class);
|
||||
}
|
||||
}
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopVoucher where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteShopVoucher first()
|
||||
*/
|
||||
class WebsiteShopVoucher extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'code', 'amount', 'max_uses', 'expires_at'];
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'expires_at' => 'datetime',
|
||||
];
|
||||
}
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Shop;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteUsedShopVoucher extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'voucher_id'];
|
||||
|
||||
public function used(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteUsedShopVoucher::class, 'voucher_id');
|
||||
}
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class SocialAccount extends Model
|
||||
{
|
||||
protected $table = 'social_accounts';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'provider',
|
||||
'provider_id',
|
||||
'avatar',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public static function findByProvider(string $provider, string $providerId): ?self
|
||||
{
|
||||
return static::where('provider', $provider)
|
||||
->where('provider_id', $providerId)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
Executable
+86
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class StaffActivity extends Model
|
||||
{
|
||||
protected $table = 'staff_activities';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'action',
|
||||
'target_type',
|
||||
'target_id',
|
||||
'description',
|
||||
'ip_address',
|
||||
'metadata',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'metadata' => 'array',
|
||||
'created_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
public static function log(int $userId, string $action, string $description, ?string $targetType = null, ?int $targetId = null, array $metadata = []): self
|
||||
{
|
||||
return static::create([
|
||||
'user_id' => $userId,
|
||||
'action' => $action,
|
||||
'target_type' => $targetType,
|
||||
'target_id' => $targetId,
|
||||
'description' => $description,
|
||||
'ip_address' => request()->ip() ?? 'unknown',
|
||||
'metadata' => $metadata,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function logLogin(int $userId): self
|
||||
{
|
||||
return self::log($userId, 'login', 'Staff logged into housekeeping', null, null, [
|
||||
'browser' => request()->userAgent() ?? 'unknown',
|
||||
]);
|
||||
}
|
||||
|
||||
public static function logAction(int $userId, string $action, string $targetType, int $targetId, string $description): self
|
||||
{
|
||||
return self::log($userId, $action, $description, $targetType, $targetId);
|
||||
}
|
||||
|
||||
public static function getActionIcon(string $action): string
|
||||
{
|
||||
return match ($action) {
|
||||
'login' => '🔓',
|
||||
'logout' => '🔒',
|
||||
'user_ban' => '🚫',
|
||||
'user_unban' => '✅',
|
||||
'user_edit' => '✏️',
|
||||
'user_delete' => '🗑️',
|
||||
'rank_change' => '⬆️',
|
||||
'settings_update' => '⚙️',
|
||||
'content_delete' => '🗑️',
|
||||
'content_create' => '➕',
|
||||
'content_edit' => '✏️',
|
||||
default => '📝',
|
||||
};
|
||||
}
|
||||
|
||||
public static function getActionColor(string $action): string
|
||||
{
|
||||
return match ($action) {
|
||||
'login', 'logout' => '#22c55e',
|
||||
'user_ban', 'content_delete' => '#ef4444',
|
||||
'user_unban', 'content_create' => '#22c55e',
|
||||
'user_edit', 'content_edit', 'rank_change' => '#f59e0b',
|
||||
'settings_update' => '#3b82f6',
|
||||
default => '#9ca3af',
|
||||
};
|
||||
}
|
||||
}
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\Game\Permission;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class StaffApplication extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'rank_id', 'status'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = true;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'staff_applications';
|
||||
|
||||
public function rank(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Permission::class, 'rank_id');
|
||||
}
|
||||
}
|
||||
Executable
+423
@@ -0,0 +1,423 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
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\Guild\GuildMember;
|
||||
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\Collection;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User query()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User orWhere($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User find($id, $columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User first($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User create(array $attributes)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User updateOrCreate(array $attributes, array $values = [])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User select($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User count($columns = '*')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder|User get($columns = ['*'])
|
||||
*
|
||||
* @property int $id
|
||||
* @property string $username
|
||||
* @property string $mail
|
||||
* @property string $password
|
||||
* @property string $account_created
|
||||
* @property string|null $last_login
|
||||
* @property string|null $last_online
|
||||
* @property string|null $motto
|
||||
* @property string $look
|
||||
* @property int $credits
|
||||
* @property int $rank
|
||||
* @property bool $online
|
||||
* @property string $auth_ticket
|
||||
* @property string $ip_register
|
||||
* @property string $ip_current
|
||||
* @property int $home_room
|
||||
* @property string|null $referral_code
|
||||
* @property string|null $two_factor_secret
|
||||
* @property string|null $two_factor_recovery_codes
|
||||
* @property string|null $two_factor_confirmed_at
|
||||
* @property bool|null $hidden_staff
|
||||
* @property int|null $team_id
|
||||
* @property int|null $website_balance
|
||||
* @property int $radio_points
|
||||
* @property array|null $preferences
|
||||
* @property-read UserSetting|null $settings
|
||||
* @property-read Collection<int, UserCurrency> $currencies
|
||||
* @property-read Ban|null $ban
|
||||
* @property-read Permission $permission
|
||||
* @property-read UserReferral|null $referrals
|
||||
* @property-read Collection<int, Referral> $userReferrals
|
||||
* @property-read Collection<int, ClaimedReferralLog> $claimedReferralLog
|
||||
* @property-read Collection<int, UserBadge> $badges
|
||||
* @property-read Collection<int, Room> $rooms
|
||||
* @property-read Collection<int, MessengerFriendship> $friends
|
||||
* @property-read Ban|null $banRelation
|
||||
* @property-read WebsiteBetaCode|null $betaCode
|
||||
* @property-read WebsiteTeam|null $team
|
||||
* @property-read Collection<int, WebsiteStaffApplications> $applications
|
||||
* @property-read UserSubscription|null $hcSubscription
|
||||
* @property-read Collection<int, WebsiteArticleComment> $articleComments
|
||||
* @property-read Collection<int, WebsitePaypalTransaction> $transactions
|
||||
* @property-read Collection<int, WebsiteUsedShopVoucher> $usedShopVouchers
|
||||
* @property-read Collection<int, Item> $items
|
||||
* @property-read Collection<int, WebsiteHelpCenterTicket> $tickets
|
||||
* @property-read Collection<int, CameraWeb> $photos
|
||||
* @property-read Collection<int, WebsiteUserGuestbook> $profileGuestbook
|
||||
* @property-read Collection<int, WebsiteUserGuestbook> $guestbook
|
||||
* @property-read Collection<int, ChatlogRoom> $chatLogs
|
||||
* @property-read Collection<int, ChatlogPrivate> $chatLogsPrivate
|
||||
* @property-read Collection<int, WebsiteArticle> $articles
|
||||
* @property-read Collection<int, Session> $sessions
|
||||
*
|
||||
* @extends Factory<User>
|
||||
*/
|
||||
class User extends Authenticatable implements FilamentUser, HasName
|
||||
{
|
||||
use HasApiTokens;
|
||||
use HasFactory;
|
||||
use LogsActivity;
|
||||
use Notifiable;
|
||||
use TwoFactorAuthenticatable;
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = ['username', 'mail', 'password', 'account_created', 'last_login', 'motto', 'look', 'credits', 'auth_ticket', 'home_room', 'ip_register', 'ip_current', 'referral_code', 'preferences', 'team_id', 'avatar_background', 'home_background', 'pincode', 'secret_key', 'extra_rank', 'is_hidden', 'background_id', 'background_stand_id', 'background_overlay_id', 'radio_points', 'pixels', 'points', 'online', 'gender', 'rank', 'mail_verified', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at'];
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
#[\Override]
|
||||
protected $hidden = ['id', 'password', 'remember_token'];
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
#[\Override]
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'hidden_staff' => 'boolean',
|
||||
'online' => 'boolean',
|
||||
'preferences' => 'array',
|
||||
];
|
||||
}
|
||||
|
||||
public function currencies(): HasMany
|
||||
{
|
||||
return $this->hasMany(UserCurrency::class, 'user_id');
|
||||
}
|
||||
|
||||
public function sessions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Session::class);
|
||||
}
|
||||
|
||||
public function currency(string $currency): int
|
||||
{
|
||||
if (! $this->relationLoaded('currencies')) {
|
||||
$this->load('currencies');
|
||||
}
|
||||
|
||||
$type = match ($currency) {
|
||||
'duckets' => 0,
|
||||
'diamonds' => 5,
|
||||
'points' => 101,
|
||||
default => 0,
|
||||
};
|
||||
|
||||
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(): int
|
||||
{
|
||||
$referrals = $this->referrals?->referrals_total ?? 0;
|
||||
|
||||
return (int) setting('referrals_needed') - (int) $referrals;
|
||||
}
|
||||
|
||||
public function ban(): HasOne
|
||||
{
|
||||
return $this->hasOne(Ban::class, 'user_id')
|
||||
->where('ban_expire', '>', time())
|
||||
->whereIn('type', ['account', 'super'])
|
||||
->withoutGlobalScopes();
|
||||
}
|
||||
|
||||
public function settings(): HasOne
|
||||
{
|
||||
return $this->hasOne(UserSetting::class);
|
||||
}
|
||||
|
||||
public function ssoTicket(): string
|
||||
{
|
||||
$hotelName = Str::replace(' ', '', (string) setting('hotel_name'));
|
||||
$sso = sprintf('%s-%s', $hotelName, Str::uuid()->toString());
|
||||
|
||||
$this->update([
|
||||
'auth_ticket' => $sso,
|
||||
'ip_current' => request()->ip(),
|
||||
]);
|
||||
|
||||
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 guilds(): HasMany
|
||||
{
|
||||
return $this->hasMany(GuildMember::class, 'user_id');
|
||||
}
|
||||
|
||||
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(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChatlogRoom::class, 'user_from_id');
|
||||
}
|
||||
|
||||
public function chatLogsPrivate(): HasMany
|
||||
{
|
||||
return $this->hasMany(ChatlogPrivate::class, 'user_from_id');
|
||||
}
|
||||
|
||||
public function socialAccounts(): HasMany
|
||||
{
|
||||
return $this->hasMany(SocialAccount::class);
|
||||
}
|
||||
|
||||
public function hasSocialAccount(string $provider): bool
|
||||
{
|
||||
return $this->socialAccounts()->where('provider', $provider)->exists();
|
||||
}
|
||||
|
||||
public function getOnlineFriends(int $total = 10): Collection
|
||||
{
|
||||
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()
|
||||
->map(fn ($item) => (new User)->forceFill([
|
||||
'id' => $item->id,
|
||||
'username' => $item->username,
|
||||
'look' => $item->look,
|
||||
'motto' => $item->motto,
|
||||
'last_online' => $item->last_online,
|
||||
]));
|
||||
}
|
||||
|
||||
public function confirmTwoFactorAuthentication(string $code): bool
|
||||
{
|
||||
$secret = $this->two_factor_secret;
|
||||
if ($secret === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$codeIsValid = app(TwoFactorAuthenticationProvider::class)
|
||||
->verify(decrypt((string) $secret), $code);
|
||||
|
||||
if (! $codeIsValid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->update(['two_factor_confirmed' => true]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasAppliedForPosition(int $rankId): bool
|
||||
{
|
||||
return $this->applications()->where('rank_id', $rankId)->exists();
|
||||
}
|
||||
|
||||
public function changePassword(string $newPassword): void
|
||||
{
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $options
|
||||
*/
|
||||
#[\Override]
|
||||
public function save(array $options = []): bool
|
||||
{
|
||||
if (! $this->isDirty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return parent::save($options);
|
||||
}
|
||||
|
||||
public function hasAppliedForTeam(int $teamId): bool
|
||||
{
|
||||
if ($teamId === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->applications()
|
||||
->where('team_id', $teamId)
|
||||
->exists();
|
||||
}
|
||||
}
|
||||
Executable
+40
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Spatie\Activitylog\LogOptions;
|
||||
use Spatie\Activitylog\Traits\LogsActivity;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Ban where($column, $operator = null, $value = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Ban orderByDesc($column)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Ban whereIn($column, $values, $boolean = 'and', $not = false)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Ban first($columns = ['*'])
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|Ban exists()
|
||||
*/
|
||||
class Ban extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
use LogsActivity;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'ban_expire', 'type', 'reason'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
Executable
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class ClaimedReferralLog extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'referral_id'];
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Referral extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'referrer_id'];
|
||||
}
|
||||
Executable
+37
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\ItemDefinition;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $item_id
|
||||
* @property int $room_id
|
||||
* @property string $extra_data
|
||||
* @property-read User|null $user
|
||||
* @property-read ItemDefinition|null $itemDefinition
|
||||
*/
|
||||
class UserItem extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'item_id'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
#[\Override]
|
||||
protected $table = 'user_items';
|
||||
|
||||
public function itemDefinition(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ItemDefinition::class, 'item_id');
|
||||
}
|
||||
}
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserNotification create($attributes = [])
|
||||
*/
|
||||
class UserNotification extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'type'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = true;
|
||||
|
||||
/** @var array<string, string> */
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'read' => 'boolean',
|
||||
];
|
||||
|
||||
public static function insert(array $data): void
|
||||
{
|
||||
self::create($data);
|
||||
}
|
||||
}
|
||||
Executable
+49
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserOrder latest($column = 'created_at')
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserOrder pending()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserOrder cancelled()
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserOrder completed()
|
||||
*/
|
||||
class UserOrder extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'status', 'amount'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = true;
|
||||
|
||||
public const STATUS_PENDING = 'pending';
|
||||
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
|
||||
public const STATUS_CANCELLED = 'cancelled';
|
||||
|
||||
public function scopePending($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_PENDING);
|
||||
}
|
||||
|
||||
public function scopeCompleted($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_COMPLETED);
|
||||
}
|
||||
|
||||
public function scopeCancelled($query)
|
||||
{
|
||||
return $query->where('status', self::STATUS_CANCELLED);
|
||||
}
|
||||
|
||||
public function scopeLatest($query)
|
||||
{
|
||||
return $query->orderBy('created_at', 'desc');
|
||||
}
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\Concerns\BelongsToUser;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property int $referrals_total
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read User|null $user
|
||||
*/
|
||||
class UserReferral extends Model
|
||||
{
|
||||
use BelongsToUser;
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'referral_code'];
|
||||
}
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\User;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class WebsiteUserGuestbook extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'user_id', 'profile_id'];
|
||||
|
||||
public function profile(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'profile_id');
|
||||
}
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
Executable
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class UserChallengeProgress extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'user_challenge_progress';
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = ['user_id', 'challenge_id', 'progress', 'completed', 'claimed', 'completed_at'];
|
||||
|
||||
#[\Override]
|
||||
protected $casts = [
|
||||
'progress' => 'integer',
|
||||
'completed' => 'boolean',
|
||||
'claimed' => 'boolean',
|
||||
'completed_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
public function challenge(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DailyChallenge::class, 'challenge_id');
|
||||
}
|
||||
|
||||
public function addProgress(int $amount): bool
|
||||
{
|
||||
if ($this->completed) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->increment('progress', $amount);
|
||||
$this->refresh();
|
||||
|
||||
if ($this->progress >= $this->challenge->target && ! $this->completed) {
|
||||
$this->update([
|
||||
'completed' => true,
|
||||
'completed_at' => now(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Executable
+82
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Services\SettingsService;
|
||||
use Carbon\Carbon;
|
||||
use Exception;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $image
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property-read string $imageUrl
|
||||
*
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteAd pluck($column, $key = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteAd insert($values)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteAd truncate()
|
||||
* @method static mixed toArray()
|
||||
*/
|
||||
class WebsiteAd extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = [
|
||||
'image',
|
||||
];
|
||||
|
||||
public function getImageUrlAttribute(): string
|
||||
{
|
||||
$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) {
|
||||
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,
|
||||
]]);
|
||||
}
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteBadge upsert($values, $uniqueBy, $update = null)
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteBadge count($columns = '*')
|
||||
*/
|
||||
class WebsiteBadge extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
#[\Override]
|
||||
protected $fillable = [
|
||||
'badge_key',
|
||||
'badge_name',
|
||||
'badge_description',
|
||||
];
|
||||
}
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static \Illuminate\Database\Eloquent\Builder<static>|WebsiteDrawBadge create($attributes = [])
|
||||
*/
|
||||
class WebsiteDrawBadge extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $table = 'website_drawbadges';
|
||||
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'cost', 'credits'];
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
}
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebsiteHousekeepingPermission extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'permission', 'rank_id'];
|
||||
}
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class WebsiteNavigation extends Model
|
||||
{
|
||||
#[\Override]
|
||||
protected $guarded = ['id', 'created_at', 'updated_at', 'order', 'visible'];
|
||||
|
||||
#[\Override]
|
||||
public $timestamps = false;
|
||||
|
||||
public function children(): HasMany
|
||||
{
|
||||
return $this->hasMany(WebsiteNavigation::class, 'parent_id');
|
||||
}
|
||||
|
||||
public function parent(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(WebsiteNavigation::class, 'parent_id');
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user