- Post-login (OAuth + dev-login) now redirects to the next upcoming service's edit page instead of /dashboard, mirroring the GET / route. - NameTagResolver now reads the real ChurchTools `responsible` shape (persons[].person.title) and resolves moderator/preacher/worship-leader by responsible ROLE ([Moderation]/[Predigt]/[Lobpreis]). This fixes missing name slides and makes the worship-leader arrangement trigger (e.g. service 12 → "Benedikt Hardt" / "Jennifer Schneider"). - NameTagSlideBuilder no longer silently drops the name slide when the configured macro id points to a missing macro; it emits the slide without a macro instead. - Song export: the "first slide" / "last slide" macro now applies only to the song's very first/last slide (global slide index across all sections), not the first slide of every section. - Export "headlines" for content-less agenda items are now emitted as proper ProPresenter playlist HEADER items instead of text presentations. - Prefix/postfix export files now also accept .probundle (unzipped: inner .pro + media embedded) in addition to .pro, both for upload validation and export injection. Full suite green (587 passed).
193 lines
6.1 KiB
PHP
193 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Service;
|
|
use App\Models\Song;
|
|
use ProPresenter\Parser\ProFileGenerator;
|
|
|
|
class ProExportService
|
|
{
|
|
public function __construct(
|
|
private readonly MacroResolutionService $macroResolutionService,
|
|
private readonly ServiceImageResolver $imageResolver,
|
|
) {}
|
|
|
|
public function generateProFile(Song $song, ?Service $service = null): string
|
|
{
|
|
$tempPath = sys_get_temp_dir().'/'.uniqid('pro-export-').'.pro';
|
|
|
|
ProFileGenerator::generateAndWrite(
|
|
$tempPath,
|
|
$song->title,
|
|
$this->buildGroups($song, $service),
|
|
$this->buildArrangements($song),
|
|
$this->buildCcliMetadata($song),
|
|
);
|
|
|
|
return $tempPath;
|
|
}
|
|
|
|
public function generateParserSong(Song $song, ?Service $service = null): \ProPresenter\Parser\Song
|
|
{
|
|
$song->loadMissing(['arrangements.arrangementSections.section.slides', 'arrangements.arrangementSections.section.label']);
|
|
|
|
return ProFileGenerator::generate(
|
|
$song->title,
|
|
$this->buildGroups($song, $service),
|
|
$this->buildArrangements($song),
|
|
$this->buildCcliMetadata($song),
|
|
);
|
|
}
|
|
|
|
private function buildGroups(Song $song, ?Service $service = null): array
|
|
{
|
|
$defaultArr = $song->arrangements->firstWhere('is_default', true) ?? $song->arrangements->first();
|
|
|
|
if ($defaultArr === null) {
|
|
return [];
|
|
}
|
|
|
|
$defaultArr->loadMissing('arrangementSections.section.slides', 'arrangementSections.section.label');
|
|
|
|
$groups = [];
|
|
$seenSectionIds = [];
|
|
$background = $this->backgroundData($service);
|
|
|
|
// Pre-compute the total slide count across the whole song (same filtering as the loop below)
|
|
// so that 'first_slide' and 'last_slide' macro positions refer to the song's very first/last slide.
|
|
$totalSlidesInSong = 0;
|
|
$seenForCount = [];
|
|
foreach ($defaultArr->arrangementSections->sortBy('order') as $arrangementSection) {
|
|
$section = $arrangementSection->section;
|
|
if ($section === null || $section->label === null) {
|
|
continue;
|
|
}
|
|
if (in_array($section->id, $seenForCount, true)) {
|
|
continue;
|
|
}
|
|
$seenForCount[] = $section->id;
|
|
$totalSlidesInSong += $section->slides->count();
|
|
}
|
|
|
|
$globalSlideIndex = 0;
|
|
|
|
foreach ($defaultArr->arrangementSections->sortBy('order') as $arrangementSection) {
|
|
$section = $arrangementSection->section;
|
|
$label = $section?->label;
|
|
|
|
if ($section === null || $label === null) {
|
|
continue;
|
|
}
|
|
|
|
if (in_array($section->id, $seenSectionIds, true)) {
|
|
continue;
|
|
}
|
|
$seenSectionIds[] = $section->id;
|
|
|
|
$slides = [];
|
|
$sectionSlides = $section->slides->sortBy('order')->values();
|
|
|
|
foreach ($sectionSlides as $slide) {
|
|
$slideData = ['text' => $slide->text_content ?? ''];
|
|
|
|
if ($slide->text_content_translated) {
|
|
$slideData['translation'] = $slide->text_content_translated;
|
|
}
|
|
|
|
if ($background !== null && ! $this->isFullCoverImageSlide($slide, $slideData)) {
|
|
$slideData['background'] = $background;
|
|
}
|
|
|
|
if ($service !== null) {
|
|
$macros = $this->macroResolutionService->macrosForSlide(
|
|
$service,
|
|
'song',
|
|
['index' => $globalSlideIndex, 'total' => $totalSlidesInSong, 'label_id' => $label->id],
|
|
);
|
|
|
|
if (! empty($macros)) {
|
|
// ProPresenter parser currently supports one `macro` entry per slide; keep the first resolved macro until stacked macros are supported.
|
|
$slideData['macro'] = $macros[0];
|
|
}
|
|
}
|
|
|
|
$slides[] = $slideData;
|
|
$globalSlideIndex++;
|
|
}
|
|
|
|
$groups[] = [
|
|
'name' => $label->name,
|
|
'color' => ProImportService::hexToRgba($label->color ?? '#808080'),
|
|
'slides' => $slides,
|
|
];
|
|
}
|
|
|
|
return $groups;
|
|
}
|
|
|
|
private function backgroundData(?Service $service): ?array
|
|
{
|
|
if ($service === null) {
|
|
return null;
|
|
}
|
|
|
|
$background = $this->imageResolver->backgroundFor($service);
|
|
|
|
if ($background === null) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'path' => ServiceImageResolver::BACKGROUND_EXPORT_NAME,
|
|
'format' => 'JPG',
|
|
'width' => 1920,
|
|
'height' => 1080,
|
|
'bundleRelative' => true,
|
|
];
|
|
}
|
|
|
|
private function isFullCoverImageSlide(object $slide, array $slideData): bool
|
|
{
|
|
if (! isset($slideData['media'])) {
|
|
return false;
|
|
}
|
|
|
|
return ($slide->cover_mode ?? null) === true;
|
|
}
|
|
|
|
private function buildArrangements(Song $song): array
|
|
{
|
|
$arrangements = [];
|
|
|
|
foreach ($song->arrangements as $arrangement) {
|
|
$arrangement->loadMissing('arrangementSections.section.label');
|
|
|
|
$groupNames = $arrangement->arrangementSections
|
|
->sortBy('order')
|
|
->map(fn ($arrangementSection) => $arrangementSection->section?->label?->name)
|
|
->filter()
|
|
->values()
|
|
->toArray();
|
|
|
|
$arrangements[] = [
|
|
'name' => $arrangement->name,
|
|
'groupNames' => $groupNames,
|
|
];
|
|
}
|
|
|
|
return $arrangements;
|
|
}
|
|
|
|
private function buildCcliMetadata(Song $song): array
|
|
{
|
|
return array_filter([
|
|
'author' => $song->author,
|
|
'song_title' => $song->title,
|
|
'copyright_year' => $song->copyright_year,
|
|
'publisher' => $song->publisher,
|
|
'song_number' => $song->ccli_id ? (int) $song->ccli_id : null,
|
|
]);
|
|
}
|
|
}
|