82 lines
1.7 KiB
PHP
82 lines
1.7 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 MusicNumber extends Model
|
|
{
|
|
use HasFactory;
|
|
use HasUlids;
|
|
|
|
protected $fillable = [
|
|
'title',
|
|
'artist',
|
|
'genre',
|
|
'duration_seconds',
|
|
'key',
|
|
'tempo_bpm',
|
|
'time_signature',
|
|
'lyrics',
|
|
'notes',
|
|
'tags',
|
|
'play_count',
|
|
'is_active',
|
|
'created_by',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'duration_seconds' => 'integer',
|
|
'tempo_bpm' => 'integer',
|
|
'tags' => 'array',
|
|
'play_count' => 'integer',
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
// Relationships
|
|
|
|
public function creator(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'created_by');
|
|
}
|
|
|
|
public function attachments(): HasMany
|
|
{
|
|
return $this->hasMany(MusicAttachment::class);
|
|
}
|
|
|
|
public function setlistItems(): HasMany
|
|
{
|
|
return $this->hasMany(SetlistItem::class);
|
|
}
|
|
|
|
// Helper methods
|
|
|
|
public function formattedDuration(): string
|
|
{
|
|
if (!$this->duration_seconds) {
|
|
return '0:00';
|
|
}
|
|
|
|
$minutes = floor($this->duration_seconds / 60);
|
|
$seconds = $this->duration_seconds % 60;
|
|
|
|
return sprintf('%d:%02d', $minutes, $seconds);
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->is_active;
|
|
}
|
|
}
|
|
|