Files
fotospiel-app/app/Http/Controllers/Api/Tenant/EventAnalyticsController.php
Codex Agent fa33e7cbcf Fix Event & EventType resource issues and apply formatting
- Fix EventType deletion error handling (constraint violations)
- Fix Event update error (package_id column missing)
- Fix Event Type dropdown options (JSON display issue)
- Fix EventPackagesRelationManager query error
- Add missing translations for deletion errors
- Apply Pint formatting
2026-01-21 10:34:06 +01:00

46 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Tenant;
use App\Http\Controllers\Controller;
use App\Models\Event;
use App\Services\Analytics\EventAnalyticsService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class EventAnalyticsController extends Controller
{
public function __construct(
private readonly EventAnalyticsService $analyticsService
) {}
public function show(Request $request, Event $event): JsonResponse
{
// Check if package has advanced_analytics feature
$packageFeatures = $event->eventPackage?->package?->features ?? [];
// Handle array or JSON string features
if (is_string($packageFeatures)) {
$packageFeatures = json_decode($packageFeatures, true) ?? [];
}
$hasAccess = in_array('advanced_analytics', $packageFeatures, true);
if (! $hasAccess) {
return response()->json([
'message' => 'This feature is only available in the Premium package.',
'code' => 'feature_locked',
], 403);
}
$timeline = $this->analyticsService->getTimeline($event);
$contributors = $this->analyticsService->getTopContributors($event);
$tasks = $this->analyticsService->getTaskStats($event);
return response()->json([
'timeline' => $timeline,
'contributors' => $contributors,
'tasks' => $tasks,
]);
}
}