set('pdfUrl', $this->resolvePdfUrl($model)); $template->set('showNavigation', '1' === (string) ($model->flipbookShowNavigation ?? '1')); $template->set('playTurnSound', '1' === (string) ($model->flipbookPlaySound ?? '1')); $template->set('splitSpreads', '1' === (string) ($model->flipbookSplitSpreads ?? '0')); $template->set('initialRenderPages', $this->normalizeInitialRenderPages((string) ($model->flipbookInitialPages ?? '4'))); $template->set('startMode', $this->normalizeStartMode((string) ($model->flipbookStartMode ?? 'center'))); return $template->getResponse(); } private function resolvePdfUrl(ContentModel $model): string { $uuid = (string) ($model->flipbookPdfSrc ?? ''); if ('' === $uuid) { return ''; } $fileModel = FilesModel::findByUuid($uuid); if (null === $fileModel) { return ''; } $path = trim((string) $fileModel->path, '/'); if ('' === $path || !str_ends_with(strtolower($path), '.pdf')) { return ''; } return '/'.implode('/', array_map('rawurlencode', explode('/', $path))); } private function normalizeInitialRenderPages(string $value): int { $count = (int) $value; if ($count < 2) { return 2; } if ($count > 4) { return 4; } return $count; } private function normalizeStartMode(string $value): string { if ('spread' === $value || 'cover' === $value) { return 'spread'; } return 'center'; } }