Kunden koennen eigene veroeffentlichte PMs kostenpflichtig aus der oeffentlichen Ansicht nehmen: Panel auf der PM-Detailseite (inkl. T1neu-Unternehmer-Checkbox und Doppelausweis netto/brutto), Stripe- Ad-hoc-Checkout wie Credit-Topups, Erfuellung im Webhook — die PM wechselt auf archived + depublished_at, die oeffentliche URL zeigt dauerhaft einen Tombstone (410 Gone, ohne Inhalte, mit ehrlichem Drittarchive-Hinweis). Doppelbuchungs-Bremse pro PM; Status-Log mit Quelle "depublication". Gate: ohne BILLING_DEPUBLICATION_PRICE_CENTS bleibt der Weg deaktiviert und /melden zeigt die neutrale Preisformulierung [EXTERN: Preis festlegen, O6]. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
103 lines
3.6 KiB
PHP
103 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Web;
|
|
|
|
use App\Models\PressRelease;
|
|
use App\Scopes\PortalScope;
|
|
use App\Support\WebPortalContext;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
/**
|
|
* Datenaufbereitung der Detailseite einer Pressemitteilung je Ausgabe inkl.
|
|
* Hit-Zähler und verwandten Meldungen (Firma, Kategorie). Unbekannter oder nicht
|
|
* öffentlich sichtbarer Slug → 404.
|
|
*/
|
|
class ReleaseDetailPageData
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function build(WebPortalContext $context, string $slug): array
|
|
{
|
|
$portalValues = $context->portalValues;
|
|
$language = $context->language;
|
|
|
|
$publishedScope = static fn (Builder $query): Builder => $query
|
|
->forPortalValues($portalValues)
|
|
->forLanguage($language)
|
|
->visibleInArchive();
|
|
|
|
$release = PressRelease::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->tap($publishedScope)
|
|
->where('slug', $slug)
|
|
->with([
|
|
'company',
|
|
'category.translations' => fn ($query) => $query->where('locale', $language),
|
|
'category.parent.translations' => fn ($query) => $query->where('locale', $language),
|
|
'images' => fn ($query) => $query->orderByDesc('is_preview')->orderBy('sort_order'),
|
|
'contacts',
|
|
])
|
|
->first();
|
|
|
|
if (! $release) {
|
|
// T12-Tombstone: depublizierte PMs (kostenpflichtige Entfernung
|
|
// auf Wunsch des Absenders) melden 410 statt 404 — die URL gab
|
|
// es, der Inhalt wurde bewusst entfernt.
|
|
$depublished = PressRelease::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->forPortalValues($portalValues)
|
|
->forLanguage($language)
|
|
->whereNotNull('depublished_at')
|
|
->where('slug', $slug)
|
|
->exists();
|
|
|
|
if ($depublished) {
|
|
return ['tombstone' => true];
|
|
}
|
|
|
|
abort(404);
|
|
}
|
|
|
|
PressRelease::withoutGlobalScope(PortalScope::class)
|
|
->whereKey($release->getKey())
|
|
->update(['hits' => ($release->hits ?? 0) + 1]);
|
|
|
|
$with = [
|
|
'company',
|
|
'category.translations' => fn ($query) => $query->where('locale', $language),
|
|
'images' => fn ($query) => $query->orderByDesc('is_preview')->orderBy('sort_order')->limit(1),
|
|
];
|
|
|
|
$companyReleases = $release->company_id
|
|
? PressRelease::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->tap($publishedScope)
|
|
->where('company_id', $release->company_id)
|
|
->whereKeyNot($release->getKey())
|
|
->with($with)
|
|
->orderByDesc('published_at')
|
|
->limit(3)
|
|
->get()
|
|
: collect();
|
|
|
|
$relatedReleases = $release->category_id
|
|
? PressRelease::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->tap($publishedScope)
|
|
->where('category_id', $release->category_id)
|
|
->whereKeyNot($release->getKey())
|
|
->when($companyReleases->isNotEmpty(), fn (Builder $query) => $query->whereNotIn('id', $companyReleases->modelKeys()))
|
|
->with($with)
|
|
->orderByDesc('published_at')
|
|
->limit(3)
|
|
->get()
|
|
: collect();
|
|
|
|
return [
|
|
'release' => $release,
|
|
'companyReleases' => $companyReleases,
|
|
'relatedReleases' => $relatedReleases,
|
|
];
|
|
}
|
|
}
|