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.
84 lines
2.7 KiB
PHP
84 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Song;
|
|
use App\Models\SongArrangement;
|
|
use Barryvdh\DomPDF\Facade\Pdf;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Response;
|
|
|
|
class SongPdfController extends Controller
|
|
{
|
|
public function preview(Song $song, SongArrangement $arrangement): JsonResponse
|
|
{
|
|
abort_unless($arrangement->song_id === $song->id, 404);
|
|
|
|
$groupsInOrder = $this->buildGroupsInOrder($arrangement);
|
|
|
|
return response()->json([
|
|
'song' => [
|
|
'id' => $song->id,
|
|
'title' => $song->title,
|
|
'copyright_text' => $song->copyright_text,
|
|
'ccli_id' => $song->ccli_id,
|
|
],
|
|
'arrangement' => [
|
|
'id' => $arrangement->id,
|
|
'name' => $arrangement->name,
|
|
],
|
|
'groups' => $groupsInOrder,
|
|
]);
|
|
}
|
|
|
|
public function download(Song $song, SongArrangement $arrangement): Response|JsonResponse
|
|
{
|
|
abort_unless($arrangement->song_id === $song->id, 404);
|
|
|
|
try {
|
|
$groupsInOrder = $this->buildGroupsInOrder($arrangement);
|
|
|
|
$pdf = Pdf::loadView('pdf.song', [
|
|
'song' => $song,
|
|
'arrangement' => $arrangement,
|
|
'groupsInOrder' => $groupsInOrder,
|
|
])->setPaper('a4', 'portrait');
|
|
|
|
$filename = str($song->title)->slug().'-'.str($arrangement->name)->slug().'.pdf';
|
|
|
|
return $pdf->download($filename);
|
|
} catch (\Throwable $e) {
|
|
return response()->json([
|
|
'message' => 'PDF-Erzeugung fehlgeschlagen: '.$e->getMessage(),
|
|
], 500);
|
|
}
|
|
}
|
|
|
|
private function buildGroupsInOrder(SongArrangement $arrangement): array
|
|
{
|
|
$arrangement->load([
|
|
'arrangementSections' => fn ($query) => $query->orderBy('order'),
|
|
'arrangementSections.section.slides' => fn ($query) => $query->orderBy('order'),
|
|
'arrangementSections.section.label',
|
|
]);
|
|
|
|
return $arrangement->arrangementSections->map(function ($arrangementSection) {
|
|
$section = $arrangementSection->section;
|
|
$label = $section?->label;
|
|
|
|
if ($section === null || $label === null) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'name' => $label->name,
|
|
'color' => $label->color ?? '#6b7280',
|
|
'slides' => $section->slides->map(fn ($slide) => [
|
|
'text_content' => $slide->text_content,
|
|
'text_content_translated' => $slide->text_content_translated,
|
|
])->values()->all(),
|
|
];
|
|
})->filter()->values()->all();
|
|
}
|
|
}
|