78 lines
1.6 KiB
PHP
78 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Concerns\HasUlids;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
final class Setlist extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'description',
|
|
'total_duration_seconds',
|
|
'is_template',
|
|
'is_archived',
|
|
'created_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'total_duration_seconds' => 'integer',
|
|
'is_template' => 'boolean',
|
|
'is_archived' => 'boolean',
|
|
];
|
|
}
|
|
|
|
// Relationships
|
|
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function items(): HasMany
|
|
{
|
|
return $this->hasMany(SetlistItem::class)->orderBy('position');
|
|
}
|
|
|
|
public function events(): HasMany
|
|
{
|
|
return $this->hasMany(Event::class);
|
|
}
|
|
|
|
// Helper methods
|
|
|
|
public function isTemplate(): bool
|
|
{
|
|
return $this->is_template;
|
|
}
|
|
|
|
public function isArchived(): bool
|
|
{
|
|
return $this->is_archived;
|
|
}
|
|
|
|
public function formattedDuration(): string
|
|
{
|
|
if (!$this->total_duration_seconds) {
|
|
return '0:00';
|
|
}
|
|
|
|
$minutes = floor($this->total_duration_seconds / 60);
|
|
$seconds = $this->total_duration_seconds % 60;
|
|
|
|
return sprintf('%d:%02d', $minutes, $seconds);
|
|
}
|
|
}
|
|
|