Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 40 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| OnboardingController | |
0.00% |
0 / 40 |
|
0.00% |
0 / 9 |
506 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
6 | |||
| platform | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| feed | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| channel | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| complete | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
30 | |||
| needsOnboarding | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
12 | |||
| hasPlatformAccount | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasFeed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| hasChannel | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\Feed; |
| 6 | use App\Models\PlatformAccount; |
| 7 | use App\Models\PlatformChannel; |
| 8 | use App\Models\PlatformInstance; |
| 9 | use App\Services\SystemStatusService; |
| 10 | use App\Services\DashboardStatsService; |
| 11 | use Illuminate\Http\Request; |
| 12 | use Illuminate\View\View; |
| 13 | use Illuminate\Http\RedirectResponse; |
| 14 | |
| 15 | class OnboardingController extends Controller |
| 16 | { |
| 17 | public function index(Request $request): View|RedirectResponse |
| 18 | { |
| 19 | // Check if user needs onboarding |
| 20 | if (!$this->needsOnboarding()) { |
| 21 | $systemStatus = resolve(SystemStatusService::class)->getSystemStatus(); |
| 22 | $statsService = resolve(DashboardStatsService::class); |
| 23 | |
| 24 | $period = $request->get('period', 'today'); |
| 25 | $stats = $statsService->getStats($period); |
| 26 | $systemStats = $statsService->getSystemStats(); |
| 27 | $availablePeriods = $statsService->getAvailablePeriods(); |
| 28 | |
| 29 | return view('pages.dashboard', compact( |
| 30 | 'systemStatus', |
| 31 | 'stats', |
| 32 | 'systemStats', |
| 33 | 'availablePeriods', |
| 34 | 'period' |
| 35 | )); |
| 36 | } |
| 37 | |
| 38 | return view('onboarding.welcome'); |
| 39 | } |
| 40 | |
| 41 | public function platform(): View|RedirectResponse |
| 42 | { |
| 43 | if (!$this->needsOnboarding()) { |
| 44 | return redirect()->route('feeds.index'); |
| 45 | } |
| 46 | |
| 47 | return view('onboarding.platform'); |
| 48 | } |
| 49 | |
| 50 | public function feed(): View|RedirectResponse |
| 51 | { |
| 52 | if (!$this->needsOnboarding()) { |
| 53 | return redirect()->route('feeds.index'); |
| 54 | } |
| 55 | |
| 56 | if (!$this->hasPlatformAccount()) { |
| 57 | return redirect()->route('onboarding.platform'); |
| 58 | } |
| 59 | |
| 60 | return view('onboarding.feed'); |
| 61 | } |
| 62 | |
| 63 | public function channel(): View|RedirectResponse |
| 64 | { |
| 65 | if (!$this->needsOnboarding()) { |
| 66 | return redirect()->route('feeds.index'); |
| 67 | } |
| 68 | |
| 69 | if (!$this->hasPlatformAccount()) { |
| 70 | return redirect()->route('onboarding.platform'); |
| 71 | } |
| 72 | |
| 73 | if (!$this->hasFeed()) { |
| 74 | return redirect()->route('onboarding.feed'); |
| 75 | } |
| 76 | |
| 77 | return view('onboarding.channel'); |
| 78 | } |
| 79 | |
| 80 | public function complete(): View|RedirectResponse |
| 81 | { |
| 82 | if (!$this->needsOnboarding()) { |
| 83 | return redirect()->route('feeds.index'); |
| 84 | } |
| 85 | |
| 86 | if (!$this->hasPlatformAccount() || !$this->hasFeed() || !$this->hasChannel()) { |
| 87 | return redirect()->route('onboarding.index'); |
| 88 | } |
| 89 | |
| 90 | $systemStatus = resolve(SystemStatusService::class)->getSystemStatus(); |
| 91 | |
| 92 | return view('onboarding.complete', compact('systemStatus')); |
| 93 | } |
| 94 | |
| 95 | private function needsOnboarding(): bool |
| 96 | { |
| 97 | return !$this->hasPlatformAccount() || !$this->hasFeed() || !$this->hasChannel(); |
| 98 | } |
| 99 | |
| 100 | private function hasPlatformAccount(): bool |
| 101 | { |
| 102 | return PlatformAccount::where('is_active', true)->exists(); |
| 103 | } |
| 104 | |
| 105 | private function hasFeed(): bool |
| 106 | { |
| 107 | return Feed::where('is_active', true)->exists(); |
| 108 | } |
| 109 | |
| 110 | private function hasChannel(): bool |
| 111 | { |
| 112 | return PlatformChannel::where('is_active', true)->exists(); |
| 113 | } |
| 114 | } |