slides() ->where('type', $blockType) ->orderBy('sort_order') ->get(); $groupName = ucfirst($blockType); return $this->buildBundleFromSlides($slides, $groupName); } public function generateAgendaItemBundle(ServiceAgendaItem $agendaItem): string { $agendaItem->loadMissing([ 'slides', 'serviceSong.song.groups.slides', 'serviceSong.song.arrangements.arrangementGroups.group', ]); $title = $agendaItem->title ?: 'Ablauf-Element'; if ($agendaItem->serviceSong?->song_id && $agendaItem->serviceSong->song) { $song = $agendaItem->serviceSong->song; if ($song->groups()->count() === 0) { throw new RuntimeException('Song "'.$song->title.'" hat keine Gruppen.'); } $parserSong = (new ProExportService)->generateParserSong($song); $proFilename = self::safeFilename($song->title).'.pro'; $bundle = new PresentationBundle($parserSong, $proFilename); $bundlePath = sys_get_temp_dir().'/'.uniqid('agenda-song-').'.probundle'; ProBundleWriter::write($bundle, $bundlePath); return $bundlePath; } $slides = $agendaItem->slides() ->whereNull('deleted_at') ->orderBy('sort_order') ->get(); return $this->buildBundleFromSlides($slides, $title); } /** @param \Illuminate\Database\Eloquent\Collection $slides */ private function buildBundleFromSlides($slides, string $groupName): string { $slideData = []; $mediaFiles = []; foreach ($slides as $slide) { $sourcePath = Storage::disk('public')->path($slide->stored_filename); if (! file_exists($sourcePath)) { continue; } $imageFilename = basename($slide->stored_filename); $imageContent = file_get_contents($sourcePath); if ($imageContent === false) { continue; } $mediaFiles[$imageFilename] = $imageContent; $slideData[] = [ 'media' => $imageFilename, 'format' => 'JPG', 'label' => $slide->original_filename, ]; } $groups = [ [ 'name' => $groupName, 'color' => [0, 0, 0, 1], 'slides' => $slideData, ], ]; $arrangements = [ [ 'name' => 'normal', 'groupNames' => [$groupName], ], ]; $song = ProFileGenerator::generate($groupName, $groups, $arrangements); $proFilename = self::safeFilename($groupName).'.pro'; $bundle = new PresentationBundle($song, $proFilename, $mediaFiles); $bundlePath = sys_get_temp_dir().'/'.uniqid('bundle-').'.probundle'; ProBundleWriter::write($bundle, $bundlePath); return $bundlePath; } private static function safeFilename(string $name): string { return preg_replace('/[^a-zA-Z0-9äöüÄÖÜß\-_ ]/', '', $name) ?: 'presentation'; } }