87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class GroupAsset extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
public const CATEGORY_LOGO = 'logo';
|
|
public const CATEGORY_BRAND = 'brand';
|
|
public const CATEGORY_PALETTE = 'palette';
|
|
public const CATEGORY_WATERMARK = 'watermark';
|
|
public const CATEGORY_TEMPLATE = 'template';
|
|
public const CATEGORY_REFERENCE = 'reference';
|
|
public const CATEGORY_SOURCE_PACK = 'source_pack';
|
|
public const CATEGORY_PROMO = 'promo';
|
|
public const CATEGORY_MISC = 'misc';
|
|
|
|
public const VISIBILITY_INTERNAL = 'internal';
|
|
public const VISIBILITY_MEMBERS_ONLY = 'members_only';
|
|
public const VISIBILITY_PUBLIC_DOWNLOAD = 'public_download';
|
|
|
|
public const STATUS_ACTIVE = 'active';
|
|
public const STATUS_ARCHIVED = 'archived';
|
|
|
|
protected $fillable = [
|
|
'group_id',
|
|
'title',
|
|
'description',
|
|
'category',
|
|
'file_path',
|
|
'preview_path',
|
|
'visibility',
|
|
'status',
|
|
'linked_project_id',
|
|
'uploaded_by_user_id',
|
|
'approved_by_user_id',
|
|
'is_featured',
|
|
'file_meta_json',
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_featured' => 'boolean',
|
|
'file_meta_json' => 'array',
|
|
];
|
|
|
|
public function group(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Group::class);
|
|
}
|
|
|
|
public function linkedProject(): BelongsTo
|
|
{
|
|
return $this->belongsTo(GroupProject::class, 'linked_project_id');
|
|
}
|
|
|
|
public function uploader(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'uploaded_by_user_id');
|
|
}
|
|
|
|
public function approver(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'approved_by_user_id');
|
|
}
|
|
|
|
public function canBeViewedBy(?User $viewer): bool
|
|
{
|
|
if ($this->status !== self::STATUS_ACTIVE) {
|
|
return false;
|
|
}
|
|
|
|
return match ($this->visibility) {
|
|
self::VISIBILITY_PUBLIC_DOWNLOAD => $this->group->canBeViewedBy($viewer),
|
|
self::VISIBILITY_MEMBERS_ONLY => $viewer !== null && $this->group->hasActiveMember($viewer),
|
|
default => $viewer !== null && $this->group->canViewInternalAssets($viewer),
|
|
};
|
|
}
|
|
} |