Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 53 |
|
0.00% |
0 / 8 |
CRAP | |
0.00% |
0 / 1 |
| PlatformChannelsController | |
0.00% |
0 / 53 |
|
0.00% |
0 / 8 |
110 | |
0.00% |
0 / 1 |
| index | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| store | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
6 | |||
| show | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| edit | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| destroy | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| toggle | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers; |
| 4 | |
| 5 | use App\Models\PlatformChannel; |
| 6 | use App\Models\PlatformInstance; |
| 7 | use Illuminate\Http\Request; |
| 8 | use Illuminate\Contracts\View\View; |
| 9 | use Illuminate\Http\RedirectResponse; |
| 10 | use Illuminate\Support\Facades\View as ViewFacade; |
| 11 | |
| 12 | class PlatformChannelsController extends Controller |
| 13 | { |
| 14 | public function index(): View |
| 15 | { |
| 16 | $channels = PlatformChannel::with('platformInstance') |
| 17 | ->orderBy('platform_instance_id') |
| 18 | ->orderBy('name') |
| 19 | ->get(); |
| 20 | |
| 21 | return ViewFacade::make('pages.channels.index', compact('channels')); |
| 22 | } |
| 23 | |
| 24 | public function create(): View |
| 25 | { |
| 26 | $instances = PlatformInstance::where('is_active', true) |
| 27 | ->orderBy('name') |
| 28 | ->get(); |
| 29 | |
| 30 | return ViewFacade::make('pages.channels.create', compact('instances')); |
| 31 | } |
| 32 | |
| 33 | public function store(Request $request): RedirectResponse |
| 34 | { |
| 35 | $validated = $request->validate([ |
| 36 | 'platform_instance_id' => 'required|exists:platform_instances,id', |
| 37 | 'name' => 'required|string|max:255', |
| 38 | 'display_name' => 'nullable|string|max:255', |
| 39 | 'channel_id' => 'nullable|string|max:255', |
| 40 | 'description' => 'nullable|string', |
| 41 | 'language_id' => 'required|exists:languages,id', |
| 42 | 'is_active' => 'boolean', |
| 43 | ]); |
| 44 | |
| 45 | // Default is_active to true if not provided |
| 46 | $validated['is_active'] = $validated['is_active'] ?? true; |
| 47 | |
| 48 | // Set display_name to name if not provided |
| 49 | $validated['display_name'] = $validated['display_name'] ?? $validated['name']; |
| 50 | |
| 51 | PlatformChannel::create($validated); |
| 52 | |
| 53 | // Check if there's a redirect_to parameter for onboarding flow |
| 54 | $redirectTo = $request->input('redirect_to'); |
| 55 | if ($redirectTo) { |
| 56 | return redirect($redirectTo) |
| 57 | ->with('success', 'Channel created successfully!'); |
| 58 | } |
| 59 | |
| 60 | return redirect()->route('channels.index') |
| 61 | ->with('success', 'Channel created successfully!'); |
| 62 | } |
| 63 | |
| 64 | public function show(PlatformChannel $channel): View |
| 65 | { |
| 66 | $channel->load(['platformInstance', 'feeds']); |
| 67 | |
| 68 | return ViewFacade::make('pages.channels.show', compact('channel')); |
| 69 | } |
| 70 | |
| 71 | public function edit(PlatformChannel $channel): View |
| 72 | { |
| 73 | $instances = PlatformInstance::where('is_active', true) |
| 74 | ->orderBy('name') |
| 75 | ->get(); |
| 76 | |
| 77 | return ViewFacade::make('pages.channels.edit', compact('channel', 'instances')); |
| 78 | } |
| 79 | |
| 80 | public function update(Request $request, PlatformChannel $channel): RedirectResponse |
| 81 | { |
| 82 | $validated = $request->validate([ |
| 83 | 'platform_instance_id' => 'required|exists:platform_instances,id', |
| 84 | 'name' => 'required|string|max:255', |
| 85 | 'display_name' => 'nullable|string|max:255', |
| 86 | 'channel_id' => 'nullable|string|max:255', |
| 87 | 'description' => 'nullable|string', |
| 88 | 'language_id' => 'required|exists:languages,id', |
| 89 | 'is_active' => 'boolean', |
| 90 | ]); |
| 91 | |
| 92 | $channel->update($validated); |
| 93 | |
| 94 | return redirect()->route('channels.index') |
| 95 | ->with('success', 'Channel updated successfully!'); |
| 96 | } |
| 97 | |
| 98 | public function destroy(PlatformChannel $channel): RedirectResponse |
| 99 | { |
| 100 | $channel->delete(); |
| 101 | |
| 102 | return redirect()->route('channels.index') |
| 103 | ->with('success', 'Channel deleted successfully!'); |
| 104 | } |
| 105 | |
| 106 | public function toggle(PlatformChannel $channel): RedirectResponse |
| 107 | { |
| 108 | $newStatus = !$channel->is_active; |
| 109 | $channel->update(['is_active' => $newStatus]); |
| 110 | |
| 111 | $status = $newStatus ? 'activated' : 'deactivated'; |
| 112 | |
| 113 | return redirect()->route('channels.index') |
| 114 | ->with('success', "Channel {$status} successfully!"); |
| 115 | } |
| 116 | } |