69 lines
1.4 KiB
PHP
69 lines
1.4 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;
|
|
|
|
final class SetlistItem extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $fillable = [
|
|
'setlist_id',
|
|
'music_number_id',
|
|
'position',
|
|
'set_number',
|
|
'is_break',
|
|
'break_duration_seconds',
|
|
'notes',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'position' => 'integer',
|
|
'set_number' => 'integer',
|
|
'is_break' => 'boolean',
|
|
'break_duration_seconds' => 'integer',
|
|
];
|
|
}
|
|
|
|
// Relationships
|
|
|
|
public function setlist(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Setlist::class);
|
|
}
|
|
|
|
public function musicNumber(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MusicNumber::class);
|
|
}
|
|
|
|
// Helper methods
|
|
|
|
public function isBreak(): bool
|
|
{
|
|
return $this->is_break;
|
|
}
|
|
|
|
public function formattedBreakDuration(): string
|
|
{
|
|
if (!$this->is_break || !$this->break_duration_seconds) {
|
|
return '';
|
|
}
|
|
|
|
$minutes = floor($this->break_duration_seconds / 60);
|
|
$seconds = $this->break_duration_seconds % 60;
|
|
|
|
return sprintf('%d:%02d', $minutes, $seconds);
|
|
}
|
|
}
|
|
|