user(); $context = app(CustomerCompanyContext::class); // Ohne Firma kein PM-Formular: statt eines leeren Editors, in dem // weder Firma wählbar noch Speichern möglich ist, erscheint eine // Meldung mit dem direkten Weg zur Firmen-Anlage. $this->hasCompanies = $context->companyCountFor($user) > 0; if (! $this->hasCompanies) { return; } $firstCompany = $context->selectedCompany($user) ?? $context->latestCompaniesFor($user, 1)->first(); if ($firstCompany) { $this->companyId = $firstCompany->id; $this->portal = $firstCompany->portal?->value ?? Portal::Presseecho->value; $this->contactId = $this->defaultContactIdFor((int) $firstCompany->id); } $this->placeholderVariant = PressReleasePlaceholder::default()->value; } #[On('placeholder-selected')] public function setPlaceholderVariant(string $variant): void { $this->placeholderVariant = PressReleasePlaceholder::fromValueOrDefault($variant)->value; } public function updatedCompanyId(): void { $company = $this->selectedCompany(); if ($company?->portal) { $this->portal = $company->portal->value; } $this->contactId = $company ? $this->defaultContactIdFor((int) $company->id) : null; unset($this->tags, $this->presubmitChecks); } public function updatedCompanySearch(): void { $this->resetErrorBag('companyId'); } /** * Single Source of Truth für die Validierungsregeln. * * @return array> */ protected function formRules(): array { return [ ...$this->baseFormRules(), 'companyId' => ['required', 'integer'], ]; } // Tag-Verwaltung (addTag/removeTag/tagsArray) liegt im Trait // App\Livewire\Concerns\InteractsWithPressReleaseTags. /** * Lazy Auto-Draft: legt sofort einen Entwurf an, damit Titelbild und * Einstellungen schon vor dem finalen Speichern gepflegt werden * können. Erfordert nur Firma und Kategorie (category_id ist NOT NULL), * alle übrigen Felder werden – soweit erfasst – übernommen. Anschließend * wird in den vollwertigen Editor (Edit-Seite) weitergeleitet, wo der * Bild-Manager direkt zur Verfügung steht. */ public function ensureDraft(): void { try { $this->validate([ 'companyId' => ['required', 'integer'], 'categoryId' => ['required', 'integer', Rule::exists('categories', 'id')], ], [ 'companyId.required' => __('Bitte zuerst eine Firma wählen, bevor du ein Titelbild hochlädst.'), 'categoryId.required' => __('Bitte zuerst eine Kategorie wählen, bevor du ein Titelbild hochlädst.'), ]); } catch (\Illuminate\Validation\ValidationException $e) { $this->notifyValidationError($e); throw $e; } $user = auth()->user(); $company = $this->selectedCompany(); if (! $company) { $this->addError('companyId', __('Die gewählte Firma ist nicht Ihrem Account zugeordnet.')); $this->notifyValidationError(); return; } $this->portal = $company->portal?->value ?? Portal::Presseecho->value; $slug = (new PressRelease)->generateUniqueSlug($this->title ?: __('Entwurf'), [ 'portal' => $this->portal, 'language' => $this->language, ]); $pr = new PressRelease([ 'uuid' => (string) Str::uuid(), 'user_id' => $user->id, 'status' => PressReleaseStatus::Draft->value, ...$this->pressReleaseAttributes($slug), ]); $pr->saveWithUniqueSlugRetry($this->title ?: __('Entwurf'), [ 'portal' => $this->portal, 'language' => $this->language, ]); if ($this->contactId) { $contact = $this->companyContact((int) $this->contactId, (int) $company->id); if ($contact) { $pr->contacts()->sync([$contact->id]); } } Flux::toast( heading: __('Entwurf gesichert'), text: __('Du kannst jetzt ein Titelbild hochladen und alle Einstellungen vornehmen. Der Entwurf liegt unter „Meine PMs".'), variant: 'success', ); $this->redirect(route('me.press-releases.edit', $pr->id), navigate: true); } /** * Validiert das Formular und legt die Pressemitteilung als Entwurf an. * Gibt den persistierten Entwurf zurück oder null, wenn Firma/Kontakt nicht * auflösbar sind (Validierungsfehler wirft ValidationException). * * Wichtig: Dies ist der einzige Persistenz-Pfad. Jede Aktion (Speichern, * Einreichen, „Buchung auswählen") MUSS zuerst hierüber speichern, bevor * navigiert wird — sonst geht der erfasste Inhalt verloren. */ private function persistDraft(): ?PressRelease { $this->syncScheduledAt(); $this->useEmbargo = false; $this->embargoAt = null; try { $this->validate($this->formRules()); } catch (\Illuminate\Validation\ValidationException $e) { $this->notifyValidationError($e); throw $e; } $user = auth()->user(); $company = $this->selectedCompany(); if (! $company) { $this->addError('companyId', __('Die gewählte Firma ist nicht Ihrem Account zugeordnet.')); $this->notifyValidationError(); return null; } $contact = null; if ($this->contactId) { $contact = $this->companyContact((int) $this->contactId, (int) $company->id); if (! $contact) { $this->addError('contactId', __('Der gewählte Pressekontakt gehört nicht zu dieser Firma.')); $this->notifyValidationError(); return null; } } $this->portal = $company->portal?->value ?? Portal::Presseecho->value; $slug = (new PressRelease)->generateUniqueSlug($this->title, [ 'portal' => $this->portal, 'language' => $this->language, ]); // Immer als Entwurf anlegen — der Weg nach "review" führt ausschließlich // über submitForReview() (Blacklist, Gate, Quota, Status-Log, KI). $pr = new PressRelease([ 'uuid' => (string) Str::uuid(), 'user_id' => $user->id, 'status' => PressReleaseStatus::Draft->value, ...$this->pressReleaseAttributes($slug), ]); $pr->saveWithUniqueSlugRetry($this->title, [ 'portal' => $this->portal, 'language' => $this->language, ]); if ($contact) { $pr->contacts()->sync([$contact->id]); } return $pr; } /** * Speichert den Entwurf und leitet anschließend zur Buchungsseite — wird * vom Submit-Modal genutzt, wenn keine Buchung vorliegt. So bleibt der * erfasste Inhalt erhalten (kein Sprung ohne Speichern). */ public function saveDraftAndChooseBooking(): void { $pr = $this->persistDraft(); if (! $pr) { return; } Flux::toast( heading: __('Entwurf gespeichert'), text: __('Ihr Entwurf ist gesichert. Wählen Sie eine Buchung, um ihn anschließend einzureichen.'), variant: 'success', ); $this->redirect(route('me.bookings.index'), navigate: true); } public function save(string $submitStatus = 'draft'): void { // KI-Kennzeichnung (Art. 50 KI-VO): Pflicht nur beim Einreichen — // zuerst prüfen, damit die Fehler direkt im Submit-Modal erscheinen. if ($submitStatus === 'review') { $this->validateAiDeclaration(); $this->persistLegalAcceptances(); } $pr = $this->persistDraft(); if (! $pr) { return; } if ($submitStatus === 'review') { $this->authorize('submitForReview', $pr); try { app(PressReleaseService::class)->submitForReview($pr); } catch (BlacklistViolationException $e) { Flux::toast( heading: __('Automatisch abgelehnt'), text: __('Unzulässiges Wort gefunden: ":word". Bitte überarbeiten.', ['word' => $e->word]), variant: 'danger', duration: 8000, ); $this->redirect(route('me.press-releases.show', $pr->id), navigate: true); return; } catch (BookingRequiredException|QuotaExceededException $e) { Flux::toast( heading: __('Als Entwurf gespeichert'), text: $e->getMessage(), variant: 'warning', duration: 8000, ); $this->redirect(route('me.press-releases.show', $pr->id), navigate: true); return; } Flux::toast( heading: __('Eingereicht'), text: __('Die automatische Inhaltsprüfung ist in der Regel innerhalb weniger Minuten abgeschlossen.'), variant: 'success', ); } else { Flux::toast( heading: __('Entwurf gespeichert'), text: __('Deine Änderungen sind gesichert. Du kannst die PM jederzeit weiter bearbeiten.'), variant: 'success', ); } $this->redirect(route('me.press-releases.show', $pr->id), navigate: true); } /** * Gemeinsame Spaltenwerte für Create- und Auto-Draft-Anlage. * * @return array */ private function pressReleaseAttributes(string $slug): array { return [ 'portal' => $this->portal, 'language' => $this->language, 'company_id' => (int) $this->companyId, 'category_id' => (int) $this->categoryId, 'title' => trim($this->title) !== '' ? $this->title : __('Unbenannter Entwurf'), 'subtitle' => trim($this->subtitle) ?: null, 'slug' => $slug, 'text' => app(PressReleaseHtmlSanitizer::class)->clean($this->text), 'boilerplate_override' => $this->useBoilerplateOverride && trim($this->boilerplateOverride) !== '' ? trim($this->boilerplateOverride) : null, 'placeholder_variant' => $this->placeholderVariant ?: PressReleasePlaceholder::default()->value, 'keywords' => $this->keywords ?: null, 'backlink_url' => $this->backlinkUrl ?: null, 'scheduled_at' => $this->publishMode === 'scheduled' ? $this->resolveScheduledAt() : null, 'embargo_at' => null, ...$this->aiDeclarationAttributes(), ]; } public function with(): array { $user = auth()->user(); $context = app(CustomerCompanyContext::class); $selectedCompany = $this->selectedCompany(); $companyOptions = $context->searchCompaniesFor( $user, $this->companySearch, $this->companyId ? (int) $this->companyId : null, 10, ); $categories = Category::query() ->with('translations') ->where('is_active', true) ->orderBy('id') ->get(); return [ 'companyOptions' => $companyOptions, 'categories' => $categories, 'selectedCompany' => $selectedCompany, 'selectedCompanyContacts' => $selectedCompany ? $this->companyContacts((int) $selectedCompany->id) : Contact::query()->whereRaw('0 = 1')->get(), 'selectedPortalLabel' => $selectedCompany?->portal?->label() ?? __('Wird aus der Firma übernommen'), 'tagSuggestions' => $this->tagSuggestionsFor($selectedCompany), 'quotaTotal' => $user->pressReleaseQuotaTotal(), 'quotaRemaining' => $user->pressReleaseQuotaRemaining(), ]; } #[Computed] public function tags(): array { return $this->tagsArray(); } private function selectedCompany(): ?Company { if (! $this->companyId) { return null; } return app(CustomerCompanyContext::class) ->findFor(auth()->user(), (int) $this->companyId); } }; ?>
{{-- ============== PAGE HEADER ============== --}} @if (! $hasCompanies) {{-- ============== KEINE FIRMA: MELDUNG STATT FORMULAR ============== --}}

{{ __('Ohne Firma kann keine Pressemitteilung angelegt werden.') }}

{{ __('Jede Pressemitteilung erscheint im Namen einer Firma. Bitte legen Sie zuerst eine Firma an — danach können Sie hier direkt loslegen.') }}

{{ __('Firma anlegen') }} {{ __('Zur PM-Übersicht') }}
@else {{-- ============== 2-COLUMN GRID ============== --}}
{{-- =================== LINKS: SCHREIBFLÄCHE =================== --}}
{{-- 1) FIRMA-SELEKTOR --}}
{{ __('Für Firma') }} @foreach ($companyOptions as $company) {{ $company->name }}{{ $company->portal ? ' ('.$company->portal->abbreviation().')' : '' }} @endforeach @if (blank(trim($companySearch))) {{ __('Keine Firma verfügbar.') }} @else {{ __('Keine Firma gefunden.') }} @endif
{{ __('Boilerplate und Pressekontakt werden vorbefüllt.') }} @if ($selectedCompany) {{ __('Firmenprofil') }} @endif
{{-- 2) KATEGORIE (Pflichtfeld — bewusst prominent vor der Headline) --}}
{{ __('Kategorie') }} *
@foreach ($categories as $cat) @endforeach
{{ __('Pflichtfeld — steuert, in welcher Rubrik die PM erscheint.') }}
{{-- 3) TITEL --}}
{{ __('Titel / Headline') }} *
@php $titleLen = mb_strlen($title); $titleClass = $titleLen >= 40 && $titleLen <= 90 ? 'good' : ($titleLen > 0 ? 'warn' : ''); $titleBar = min(100, max(0, ($titleLen / 100) * 100)); @endphp {{ $titleLen }} / 100 {{ __('KI-Titel · bald') }}

{{ __('40–90 Zeichen empfohlen. Konkret, ohne Marketing-Floskeln.') }}

{{-- 4) SUBTITLE --}}
{{ __('Untertitel') }} — {{ __('optional') }} @php $subLen = mb_strlen($subtitle); $subBar = min(100, max(0, ($subLen / 200) * 100)); @endphp {{ $subLen }} / 200
{{-- 5) FLIESSTEXT --}}
{{ __('Fließtext') }} *
@php $textLen = app(\App\Services\PressRelease\PressReleaseHtmlSanitizer::class)->plainTextLength($text); $textClass = $textLen >= 600 ? 'good' : ($textLen >= 50 ? 'warn' : ''); $textBar = min(100, max(0, ($textLen / 3500) * 100)); @endphp {{ number_format($textLen, 0, ',', '.') }} / 3.500 Z. {{ __('KI-Lektorat · bald') }}

{{ __('Links im Text sind ausdrücklich erwünscht. Externe Links werden bei Veröffentlichung automatisch als sponsored/nofollow ausgezeichnet (Google-Vorgabe für Pressemitteilungen) — Links auf Ihr Unternehmensprofil im Portal bleiben follow.') }}

{{ __('KI-Lektorat') }} {{ __('liest Korrektur, schlägt Kürzungen vor und prüft auf werbliche Sprache. Erscheint hier inline — bald verfügbar.') }}
{{-- 6) TITELBILD --}}
{{ __('Titelbild') }} {{ __('KI-Bildgenerierung · bald') }}
{{-- Titelbild-Platzhalter (bis ein eigenes Bild hochgeladen ist) --}}
{{ __('Titelbild-Platzhalter') }} {{ __('Platzhalter wählen') }}
{{-- Anzeige analog Detailansicht: max. 1280×580, zentriert begrenzt --}}

{{ __('Dieser Platzhalter wird angezeigt, bis ein eigenes Titelbild hochgeladen ist.') }}

{{ __('Lade ein eigenes Titelbild hoch. Dafür wird automatisch ein Entwurf gesichert — danach kannst du alles weiter bearbeiten.') }}

{{ __('Titelbild hochladen & Entwurf sichern') }}

{{ __('Erfordert nur Firma + Kategorie. Du landest danach im Editor mit Bild-Upload.') }}

{{-- Titelbild-Platzhalter-Auswahl --}} {{-- 7) ANHÄNGE — TEMPORÄR DEAKTIVIERT Datei-Uploads erfordern eine vollständige Sicherheitsprüfung (Virus-/Malware-Scan, MIME-Validierung, Storage-Quoten). Wird in einer späteren Phase aktiviert.
{{ __('Anhänge / Downloads') }} — {{ __('optional, nach Speichern verfügbar') }}
{{ __('PDF, Pressemappen und andere Dokumente kannst du nach dem ersten Speichern hinzufügen.') }}
--}} {{-- 8) BOILERPLATE --}}
{{ __('Über das Unternehmen') }} — {{ __('Boilerplate aus Firma') }}
@if ($selectedCompany?->boilerplate)

{!! nl2br(e($selectedCompany->boilerplate)) !!}

@if ($selectedCompany->website)

Web: {{ $selectedCompany->website }}

@endif
@else
{{ __('Für diese Firma ist noch kein Boilerplate-Text hinterlegt. Du kannst entweder einen Override-Text für diese PM setzen oder das Firmenprofil ergänzen.') }}
@endif @if ($useBoilerplateOverride)
@endif

{{ __('Wird automatisch unter jeder Pressemitteilung dieser Firma angefügt. Pro PM editierbar.') }}

{{-- /Schreibfläche --}} {{-- =================== RECHTS: SETTINGS-SIDEBAR =================== --}}
{{-- Einreichungs-Modal (öffnet über „Zur Prüfung freigeben") --}} {{-- Im Erstellen-Formular gibt es noch keinen Bild-Upload (der folgt im Editor nach dem Entwurf-Sichern), daher entfällt die Bildrechte-Frage. --}} @endif