Gebuendelt, da ueber gemeinsame lang-/Service-Dateien verschraenkt: - Kontakt-Nachrichten: contact_messages-Tabelle + Model/Enums/Factory, Admin-Queue (livewire/admin/contact-messages), ContactController persistiert das Anliegen zusaetzlich zur Brand-Mail - Page-Data-Cache (Services/Web/*PageData) + web-archive-Indizes auf press_releases - Validierungs-Feedback + Company-Portal-Restriction (Feature-Tests) - i18n-Auslagerung lang/de|en (auth, passwords, validation, static) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
131 lines
4.7 KiB
PHP
131 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Web;
|
|
|
|
use App\Models\Category;
|
|
use App\Models\Company;
|
|
use App\Models\PressRelease;
|
|
use App\Scopes\PortalScope;
|
|
use App\Support\WebPortalContext;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* Datenaufbereitung der Newsroom-Markenseite eines Unternehmens je Ausgabe:
|
|
* alle veröffentlichten Meldungen der Firma plus Kennzahlen. Ohne aktives
|
|
* Unternehmen oder ohne veröffentlichte Meldung gibt es keine öffentliche Seite
|
|
* (404).
|
|
*/
|
|
class NewsroomDetailPageData
|
|
{
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function build(WebPortalContext $context, string $slug): array
|
|
{
|
|
$portalValues = $context->portalValues;
|
|
$language = $context->language;
|
|
|
|
$company = Company::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->whereIn('portal', $portalValues)
|
|
->where('is_active', true)
|
|
->where('slug', $slug)
|
|
->with(['contacts'])
|
|
->first();
|
|
|
|
if (! $company) {
|
|
abort(404);
|
|
}
|
|
|
|
$base = static fn (): Builder => PressRelease::query()
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->where('company_id', $company->id)
|
|
->forPortalValues($portalValues)
|
|
->forLanguage($language)
|
|
->visibleInArchive();
|
|
|
|
// Keine öffentliche Newsroom-Seite ohne veröffentlichte Meldung.
|
|
if (! $base()->exists()) {
|
|
abort(404);
|
|
}
|
|
|
|
$latest = $base()->max('published_at');
|
|
$referenceNow = $latest ? Carbon::parse($latest) : now();
|
|
if ($referenceNow->gt(now())) {
|
|
$referenceNow = now();
|
|
}
|
|
$recentSince = $referenceNow->copy()->subDays(30);
|
|
$oldest = $base()->min('published_at');
|
|
|
|
$with = [
|
|
'company',
|
|
'category.translations' => fn ($query) => $query->where('locale', $language),
|
|
'images' => fn ($query) => $query->orderByDesc('is_preview')->orderBy('sort_order')->limit(1),
|
|
];
|
|
|
|
$leadRelease = $base()->with($with)->orderByDesc('published_at')->first();
|
|
|
|
$releases = $base()
|
|
->with($with)
|
|
->when($leadRelease, fn (Builder $query) => $query->whereKeyNot($leadRelease->getKey()))
|
|
->orderByDesc('published_at')
|
|
->paginate(10)
|
|
->withQueryString();
|
|
|
|
$mostReadReleases = $base()
|
|
->orderByDesc('hits')
|
|
->orderByDesc('published_at')
|
|
->limit(5)
|
|
->get(['id', 'slug', 'title', 'hits', 'portal', 'language']);
|
|
|
|
$companyFilter = static function (Builder $query) use ($company, $portalValues, $language): void {
|
|
$query
|
|
->withoutGlobalScope(PortalScope::class)
|
|
->where('company_id', $company->id)
|
|
->forPortalValues($portalValues)
|
|
->forLanguage($language)
|
|
->published();
|
|
};
|
|
|
|
$categories = Category::query()
|
|
->whereIn('portal', $portalValues)
|
|
->whereHas('pressReleases', fn (Builder $query) => $companyFilter($query))
|
|
->with(['translations' => fn ($query) => $query->where('locale', $language)])
|
|
->withCount(['pressReleases as releases_count' => fn (Builder $query) => $companyFilter($query)])
|
|
->orderByDesc('releases_count')
|
|
->limit(8)
|
|
->get()
|
|
->map(function (Category $category): ?array {
|
|
$translation = $category->translations->first();
|
|
|
|
if (! $translation) {
|
|
return null;
|
|
}
|
|
|
|
return [
|
|
'name' => $translation->name,
|
|
'href' => $translation->slug ? route('kategorie', ['slug' => $translation->slug]) : route('web.home'),
|
|
'count' => (int) ($category->releases_count ?? 0),
|
|
];
|
|
})
|
|
->filter()
|
|
->values();
|
|
|
|
return [
|
|
'company' => $company,
|
|
'referenceNow' => $referenceNow,
|
|
'leadRelease' => $leadRelease,
|
|
'releases' => $releases,
|
|
'mostReadReleases' => $mostReadReleases,
|
|
'categories' => $categories,
|
|
'newsroomStats' => [
|
|
'total' => $base()->count(),
|
|
'recent' => $base()->where('published_at', '>=', $recentSince)->count(),
|
|
'today' => $base()->whereBetween('published_at', [$referenceNow->copy()->startOfDay(), $referenceNow->copy()->endOfDay()])->count(),
|
|
'totalHits' => (int) $base()->sum('hits'),
|
|
'sinceYear' => $oldest ? (int) Carbon::parse($oldest)->format('Y') : null,
|
|
],
|
|
];
|
|
}
|
|
}
|