Optimierung 4.3/4.4 (Veroeffentlichen): Page-Data-Service + Invokable Controller
Veroeffentlichen-Closure in VeroeffentlichenPageData + Web\VeroeffentlichenController verschoben. Verhalten unveraendert, 92 Web-Tests gruen. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
01f3f7f8c7
commit
debcf81adf
3 changed files with 108 additions and 71 deletions
16
app/Http/Controllers/Web/VeroeffentlichenController.php
Normal file
16
app/Http/Controllers/Web/VeroeffentlichenController.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\Web\VeroeffentlichenPageData;
|
||||
use App\Support\WebPortalContext;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
class VeroeffentlichenController extends Controller
|
||||
{
|
||||
public function __invoke(VeroeffentlichenPageData $pageData): View
|
||||
{
|
||||
return view('web.veroeffentlichen', $pageData->build(WebPortalContext::fromRequest()));
|
||||
}
|
||||
}
|
||||
89
app/Services/Web/VeroeffentlichenPageData.php
Normal file
89
app/Services/Web/VeroeffentlichenPageData.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services\Web;
|
||||
|
||||
use App\Enums\PressReleaseStatus;
|
||||
use App\Models\Company;
|
||||
use App\Models\PressRelease;
|
||||
use App\Scopes\PortalScope;
|
||||
use App\Support\EditorialClock;
|
||||
use App\Support\WebPortalContext;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Datenaufbereitung der Veröffentlichen-Marketingseite (Einreichung läuft im
|
||||
* Publisher-Hub): Archiv-Kennzahlen, Beispiel-Meldung und aktive Newsrooms.
|
||||
*/
|
||||
class VeroeffentlichenPageData
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function build(WebPortalContext $context): array
|
||||
{
|
||||
$portalValues = $context->portalValues;
|
||||
$language = $context->language;
|
||||
$referenceNow = EditorialClock::reference($portalValues, $language);
|
||||
$recentSince = $referenceNow->copy()->subDays(30);
|
||||
|
||||
$publishedBase = static fn (): Builder => PressRelease::query()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->forPortalValues($portalValues)
|
||||
->forLanguage($language)
|
||||
->visibleInArchive();
|
||||
|
||||
$archiveTotal = $publishedBase()->count();
|
||||
$publishedToday = $publishedBase()->whereDate('published_at', $referenceNow->toDateString())->count();
|
||||
$oldest = $publishedBase()->min('published_at');
|
||||
$oldestYear = $oldest ? (int) Carbon::parse($oldest)->format('Y') : null;
|
||||
|
||||
$inReview = PressRelease::query()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->whereIn('portal', $portalValues)
|
||||
->where('status', PressReleaseStatus::Review)
|
||||
->where('language', $language)
|
||||
->count();
|
||||
|
||||
$exampleRelease = $publishedBase()
|
||||
->with([
|
||||
'company',
|
||||
'category.translations' => fn ($query) => $query->where('locale', $language),
|
||||
])
|
||||
->orderByDesc('published_at')
|
||||
->first();
|
||||
|
||||
$newsroomFilter = static function (Builder $query) use ($portalValues, $language, $recentSince): void {
|
||||
$query
|
||||
->forPortalValues($portalValues)
|
||||
->forLanguage($language)
|
||||
->published()
|
||||
->where('published_at', '>=', $recentSince);
|
||||
};
|
||||
|
||||
$newsroomQuery = Company::query()
|
||||
->withoutGlobalScope(PortalScope::class)
|
||||
->whereIn('portal', $portalValues)
|
||||
->where('is_active', true)
|
||||
->whereHas('pressReleases', fn (Builder $query) => $newsroomFilter($query));
|
||||
|
||||
$activeNewsroomsTotal = (clone $newsroomQuery)->count();
|
||||
$activeNewsroomNames = (clone $newsroomQuery)
|
||||
->withCount(['pressReleases as recent_count' => fn (Builder $query) => $newsroomFilter($query)])
|
||||
->orderByDesc('recent_count')
|
||||
->limit(10)
|
||||
->pluck('name')
|
||||
->all();
|
||||
|
||||
return [
|
||||
'referenceNow' => $referenceNow,
|
||||
'archiveTotal' => $archiveTotal,
|
||||
'publishedToday' => $publishedToday,
|
||||
'inReview' => $inReview,
|
||||
'oldestYear' => $oldestYear,
|
||||
'exampleRelease' => $exampleRelease,
|
||||
'activeNewsroomNames' => $activeNewsroomNames,
|
||||
'activeNewsroomsTotal' => $activeNewsroomsTotal,
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue