Refactor lyric storage so each song owns its sections instead of sharing global labels. Adds song_sections (per song+label) owning song_slides; labels stay global ProPresenter group tags (name/color/macro). Arrangements now reference sections, so editing/importing one song no longer corrupts others that share a label name. - New: song_sections table + migration with safe backfill; SongSection, SongArrangementSection models; SongSectionController (edit/add/delete sections, immediate persistence) wired into SongEditModal. - Refactor writers/readers: CcliImport, ProImport, SongService, ArrangementController, SongController, ProExport, PDF, Translation (translation reset now section-scoped), CCLI pairing. - CCLI import fixes: parse SongSelect copy-icon format (German "Vers" abbrev + trailing author), fill empty CTS-synced songs instead of blocking as duplicate, distinct label colors per section kind, import&edit/existing-song open the edit modal (no 404/405), teleport paste dialog above assign dialog, preview shows section content, correct SongSelect search URL, copy-icon instructions. - Bookmarklet clicks #generalCopyLyricsButton and captures clipboard; serves correct host from request. - Export: embed key-visual/background under fixed bundle-relative names. - Tests updated for the section model; new section + isolation coverage.
74 lines
1.8 KiB
PHP
74 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Song extends Model
|
|
{
|
|
use HasFactory;
|
|
use SoftDeletes;
|
|
|
|
protected $fillable = [
|
|
'ccli_id',
|
|
'cts_song_id',
|
|
'imported_from_ccli_at',
|
|
'ccli_source_url',
|
|
'title',
|
|
'author',
|
|
'copyright_text',
|
|
'copyright_year',
|
|
'publisher',
|
|
'has_translation',
|
|
'last_used_at',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'has_translation' => 'boolean',
|
|
'last_used_at' => 'datetime',
|
|
'imported_from_ccli_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function arrangements(): HasMany
|
|
{
|
|
return $this->hasMany(SongArrangement::class);
|
|
}
|
|
|
|
public function sections(): HasMany
|
|
{
|
|
return $this->hasMany(SongSection::class)->orderBy('order');
|
|
}
|
|
|
|
public function serviceSongs(): HasMany
|
|
{
|
|
return $this->hasMany(ServiceSong::class);
|
|
}
|
|
|
|
/**
|
|
* Letztes Service-Datum, in dem dieser Song verwendet wurde.
|
|
* Berechnet über die service_songs -> services Verknüpfung.
|
|
*/
|
|
public function lastUsedInService(): Attribute
|
|
{
|
|
return Attribute::get(function () {
|
|
$latestDate = $this->serviceSongs()
|
|
->join('services', 'services.id', '=', 'service_songs.service_id')
|
|
->max('services.date');
|
|
|
|
if ($latestDate === null) {
|
|
return null;
|
|
}
|
|
|
|
// SQLite gibt date-Spalten als 'YYYY-MM-DD 00:00:00' zurück
|
|
return substr((string) $latestDate, 0, 10);
|
|
});
|
|
}
|
|
}
|