Limit-Status im Upload-Flow anzeigen (Warnbanner + Sperrzustände).
Upload-Fehlercodes auswerten und freundliche Dialoge zeigen.
This commit is contained in:
@@ -113,6 +113,36 @@ class PackageLimitEvaluator
|
||||
return $eventPackage;
|
||||
}
|
||||
|
||||
public function summarizeEventPackage(EventPackage $eventPackage): array
|
||||
{
|
||||
$package = $eventPackage->package;
|
||||
|
||||
$photoSummary = $this->buildUsageSummary(
|
||||
(int) $eventPackage->used_photos,
|
||||
$package?->max_photos,
|
||||
config('package-limits.photo_thresholds', [])
|
||||
);
|
||||
|
||||
$guestSummary = $this->buildUsageSummary(
|
||||
(int) $eventPackage->used_guests,
|
||||
$package?->max_guests,
|
||||
config('package-limits.guest_thresholds', [])
|
||||
);
|
||||
|
||||
$gallerySummary = $this->buildGallerySummary(
|
||||
$eventPackage,
|
||||
config('package-limits.gallery_warning_days', [])
|
||||
);
|
||||
|
||||
return [
|
||||
'photos' => $photoSummary,
|
||||
'guests' => $guestSummary,
|
||||
'gallery' => $gallerySummary,
|
||||
'can_upload_photos' => $photoSummary['state'] !== 'limit_reached' && $gallerySummary['state'] !== 'expired',
|
||||
'can_add_guests' => $guestSummary['state'] !== 'limit_reached',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: ?Event, 1: ?\App\Models\EventPackage}
|
||||
*/
|
||||
@@ -148,4 +178,120 @@ class PackageLimitEvaluator
|
||||
|
||||
return [$event, $eventPackage];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|float|string> $rawThresholds
|
||||
*/
|
||||
private function buildUsageSummary(int $used, ?int $limit, array $rawThresholds): array
|
||||
{
|
||||
$thresholds = collect($rawThresholds)
|
||||
->filter(fn ($value) => is_numeric($value) && $value > 0 && $value < 1)
|
||||
->map(fn ($value) => round((float) $value, 4))
|
||||
->unique()
|
||||
->sort()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if ($limit === null || $limit <= 0) {
|
||||
return [
|
||||
'limit' => null,
|
||||
'used' => $used,
|
||||
'remaining' => null,
|
||||
'percentage' => null,
|
||||
'state' => 'unlimited',
|
||||
'threshold_reached' => null,
|
||||
'next_threshold' => $thresholds[0] ?? null,
|
||||
'thresholds' => $thresholds,
|
||||
];
|
||||
}
|
||||
|
||||
$clampedLimit = max(1, (int) $limit);
|
||||
$ratio = $used / $clampedLimit;
|
||||
$percentage = round(min(1, $ratio), 4);
|
||||
$remaining = max(0, $clampedLimit - $used);
|
||||
$state = 'ok';
|
||||
$thresholdReached = null;
|
||||
$nextThreshold = null;
|
||||
|
||||
foreach ($thresholds as $threshold) {
|
||||
if ($percentage >= $threshold) {
|
||||
$thresholdReached = $threshold;
|
||||
if ($state !== 'limit_reached') {
|
||||
$state = 'warning';
|
||||
}
|
||||
} elseif ($nextThreshold === null) {
|
||||
$nextThreshold = $threshold;
|
||||
}
|
||||
}
|
||||
|
||||
if ($used >= $clampedLimit) {
|
||||
$state = 'limit_reached';
|
||||
$thresholdReached = 1.0;
|
||||
$nextThreshold = null;
|
||||
}
|
||||
|
||||
return [
|
||||
'limit' => $clampedLimit,
|
||||
'used' => $used,
|
||||
'remaining' => $remaining,
|
||||
'percentage' => $percentage,
|
||||
'state' => $state,
|
||||
'threshold_reached' => $thresholdReached,
|
||||
'next_threshold' => $nextThreshold,
|
||||
'thresholds' => $thresholds,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int|string> $warningDays
|
||||
*/
|
||||
private function buildGallerySummary(EventPackage $eventPackage, array $warningDays): array
|
||||
{
|
||||
$expiresAt = $eventPackage->gallery_expires_at;
|
||||
$warningValues = collect($warningDays)
|
||||
->filter(fn ($value) => is_numeric($value) && $value >= 0)
|
||||
->map(fn ($value) => (int) $value)
|
||||
->unique()
|
||||
->sort()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
if (! $expiresAt) {
|
||||
return [
|
||||
'state' => 'unlimited',
|
||||
'expires_at' => null,
|
||||
'days_remaining' => null,
|
||||
'warning_thresholds' => $warningValues,
|
||||
'warning_triggered' => null,
|
||||
'warning_sent_at' => null,
|
||||
'expired_notified_at' => null,
|
||||
];
|
||||
}
|
||||
|
||||
$daysRemaining = now()->diffInDays($expiresAt, false);
|
||||
$state = 'ok';
|
||||
$warningTriggered = null;
|
||||
|
||||
foreach ($warningValues as $threshold) {
|
||||
if ($daysRemaining <= $threshold && $daysRemaining >= 0) {
|
||||
$warningTriggered = $threshold;
|
||||
$state = 'warning';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($daysRemaining < 0) {
|
||||
$state = 'expired';
|
||||
}
|
||||
|
||||
return [
|
||||
'state' => $state,
|
||||
'expires_at' => $expiresAt->toIso8601String(),
|
||||
'days_remaining' => $daysRemaining,
|
||||
'warning_thresholds' => $warningValues,
|
||||
'warning_triggered' => $warningTriggered,
|
||||
'warning_sent_at' => $eventPackage->gallery_warning_sent_at?->toIso8601String(),
|
||||
'expired_notified_at' => $eventPackage->gallery_expired_notified_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user