101 lines
2.4 KiB
PHP
101 lines
2.4 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_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',
|
|
];
|
|
|
|
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 likes(): HasMany
|
|
{
|
|
return $this->hasMany(PhotoLike::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
|
|
);
|
|
}
|
|
}
|