Files
fotospiel-app/app/Models/Photo.php
Codex Agent 117250879b
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
tests / ui (push) Has been cancelled
Add superadmin moderation queues
2026-01-01 18:52:32 +01:00

114 lines
2.7 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Schema;
use Znck\Eloquent\Relations\BelongsToThrough as BelongsToThroughRelation;
use Znck\Eloquent\Traits\BelongsToThrough;
class Photo extends Model
{
use BelongsToThrough;
use HasFactory;
public const SOURCE_GUEST_PWA = 'guest_pwa';
public const SOURCE_TENANT_ADMIN = 'tenant_admin';
public const SOURCE_PHOTOBOOTH = 'photobooth';
public const SOURCE_SPARKBOOTH = 'sparkbooth';
public const SOURCE_UNKNOWN = 'unknown';
protected static ?array $columnCache = null;
protected $table = 'photos';
protected $guarded = [];
protected $casts = [
'is_featured' => 'boolean',
'metadata' => 'array',
'security_meta' => 'array',
'security_scanned_at' => 'datetime',
'moderated_at' => 'datetime',
];
protected $attributes = [
'security_scan_status' => 'pending',
'ingest_source' => self::SOURCE_GUEST_PWA,
];
public function mediaAsset(): BelongsTo
{
return $this->belongsTo(EventMediaAsset::class, 'media_asset_id');
}
public function getImagePathAttribute(): ?string
{
return $this->file_path;
}
public function setImagePathAttribute(string $value): void
{
$this->attributes['file_path'] = $value;
}
public function event(): BelongsTo
{
return $this->belongsTo(Event::class);
}
public function emotion(): BelongsTo
{
return $this->belongsTo(Emotion::class);
}
public function task(): BelongsTo
{
return $this->belongsTo(Task::class);
}
public function moderator(): BelongsTo
{
return $this->belongsTo(User::class, 'moderated_by');
}
public function likes(): HasMany
{
return $this->hasMany(PhotoLike::class);
}
public function shareLinks(): HasMany
{
return $this->hasMany(PhotoShareLink::class);
}
public static function supportsFilenameColumn(): bool
{
return static::hasColumn('filename');
}
public static function hasColumn(string $column): bool
{
if (static::$columnCache === null) {
static::$columnCache = Schema::getColumnListing((new self)->getTable());
}
return in_array($column, static::$columnCache, true);
}
public function tenant(): BelongsToThroughRelation
{
return $this->belongsToThrough(
Tenant::class,
Event::class
);
}
}