CI Feature / test (push) Successful in 5m29s
- Eine veroeffentlichte CMS-Seite mit dem Pfad /shop bestimmt den Aufbau von /shop, sonst gilt die Standardseite - Widget shop_products mit Filter (Saeule, Materialart), Reihenfolge, Anzahl und Suchfeld; leer, solange der Shop nicht sichtbar ist - ShopCatalog mit Filter, Sortierung und Limit; Suchbegriff auf 100 Zeichen gekuerzt - Sitemap ohne /shop, solange nicht gekauft werden kann - Mitgliederseite Angebote zeigt die neuesten Produkte als Kacheln - ADR-55, Widget-Register Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
99 lines
3.5 KiB
PHP
99 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Domain\Catalog\Pillar;
|
|
use App\Domain\Cms\Page;
|
|
use App\Domain\Cms\PageRevision;
|
|
use App\Domain\Cms\PageTemplates;
|
|
use App\Domain\Cms\Sections\SectionRenderer;
|
|
use App\Domain\Cms\Widgets\RenderContext;
|
|
use App\Domain\Commerce\Shop;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Response;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
class PageController extends Controller
|
|
{
|
|
public function home(): View
|
|
{
|
|
return $this->render(Page::query()->where('path', '/')->firstOrFail(), preview: false);
|
|
}
|
|
|
|
public function show(string $path): View
|
|
{
|
|
return $this->render(Page::query()->where('path', '/'.$path)->firstOrFail(), preview: false);
|
|
}
|
|
|
|
/**
|
|
* Die frühere Angebotsseite der Website ist der Shop. Solange er nicht sichtbar ist, bleibt eine noch vorhandene
|
|
* CMS-Seite unter dieser Adresse erreichbar (sonst 404).
|
|
*/
|
|
public function offers(): View|RedirectResponse
|
|
{
|
|
return Shop::visible() ? redirect()->route('shop') : $this->show('angebote');
|
|
}
|
|
|
|
/** Eine veröffentlichte CMS-Seite unter einer festen App-Adresse (der Shop unter /shop). */
|
|
public function showPage(Page $page): View
|
|
{
|
|
return $this->render($page, preview: false);
|
|
}
|
|
|
|
public function preview(PageRevision $revision): View
|
|
{
|
|
$page = $revision->page;
|
|
Gate::forUser(auth('staff')->user())->authorize('view', $page);
|
|
|
|
return $this->render($page, preview: true, revision: $revision);
|
|
}
|
|
|
|
/**
|
|
* Rahmen für die Vorschau einer Revision in den Breiten Smartphone, Tablet und Desktop.
|
|
*/
|
|
public function devices(PageRevision $revision): View
|
|
{
|
|
$page = $revision->page;
|
|
Gate::forUser(auth('staff')->user())->authorize('view', $page);
|
|
|
|
return view('public.preview-devices', [
|
|
'page' => $page,
|
|
'revision' => $revision,
|
|
'isLive' => $page->published_revision_id === $revision->id,
|
|
]);
|
|
}
|
|
|
|
public function sitemap(): Response
|
|
{
|
|
// Der Shop gehört nicht in die Sitemap, solange man dort nicht kaufen kann (die Seiten sind dann noindex).
|
|
$pages = Page::query()->whereNotNull('published_revision_id')->orderBy('path')->get()
|
|
->reject(fn (Page $page): bool => $page->path === '/shop' && ! Shop::checkoutOpen());
|
|
$themes = Pillar::query()->published()->get();
|
|
|
|
return response()
|
|
->view('public.sitemap', ['pages' => $pages, 'themes' => $themes])
|
|
->header('Content-Type', 'application/xml');
|
|
}
|
|
|
|
private function render(Page $page, bool $preview, ?PageRevision $revision = null): View
|
|
{
|
|
$revision ??= $page->publishedRevision;
|
|
abort_if($revision === null, 404);
|
|
|
|
$context = $preview ? RenderContext::preview() : RenderContext::publicPage();
|
|
|
|
return view('public.page', [
|
|
'page' => $page,
|
|
'revision' => $revision,
|
|
'preview' => $preview,
|
|
'template' => app(PageTemplates::class)->viewFor($page),
|
|
'content' => app(SectionRenderer::class)->renderAll($revision->sections(), $context),
|
|
'documentTitle' => $revision->seo_title ?: ($revision->contentTitle() ?? config('app.name')),
|
|
'documentDescription' => $revision->seo_description,
|
|
'themes' => $page->path === '/' ? Pillar::query()->published()->get() : collect(),
|
|
'activePath' => $page->path,
|
|
]);
|
|
}
|
|
}
|