195 lines
9.0 KiB
PHP
195 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers\Filament;
|
|
|
|
use App\Exports\OddsExporter;
|
|
use App\Filament\Exports\BetfairExporter;
|
|
use App\Filament\Pages\PlayerProps;
|
|
use App\Filament\Pages\Statistic;
|
|
use App\Http\Middleware\RecordUserActivity;
|
|
use App\Models\Event;
|
|
use Awcodes\LightSwitch\Enums\Alignment;
|
|
use Awcodes\LightSwitch\LightSwitchPlugin;
|
|
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\ExportAction;
|
|
use Filament\Actions\Exports\Models\Export;
|
|
use Filament\Auth\MultiFactor\App\AppAuthentication;
|
|
use Filament\Auth\MultiFactor\Email\EmailAuthentication;
|
|
use Filament\Auth\Pages\PasswordReset\RequestPasswordReset;
|
|
use Filament\Http\Middleware\Authenticate;
|
|
use Filament\Http\Middleware\AuthenticateSession;
|
|
use Filament\Http\Middleware\DisableBladeIconComponents;
|
|
use Filament\Http\Middleware\DispatchServingFilamentEvent;
|
|
use Filament\Panel;
|
|
use Filament\PanelProvider;
|
|
use Filament\Support\Enums\Width;
|
|
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
|
|
use Illuminate\Cookie\Middleware\EncryptCookies;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
|
|
use Illuminate\Routing\Middleware\SubstituteBindings;
|
|
use Illuminate\Session\Middleware\StartSession;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\View\Middleware\ShareErrorsFromSession;
|
|
use Joaopaulolndev\FilamentEditProfile\FilamentEditProfilePlugin;
|
|
use Joaopaulolndev\FilamentEditProfile\Pages\EditProfilePage;
|
|
use Maatwebsite\Excel\Facades\Excel;
|
|
use Swis\Filament\Backgrounds\FilamentBackgroundsPlugin;
|
|
use Swis\Filament\Backgrounds\ImageProviders\MyImages;
|
|
|
|
class AdminPanelProvider extends PanelProvider
|
|
{
|
|
public function panel(Panel $panel): Panel
|
|
{
|
|
return $panel
|
|
->spa()
|
|
->id('admin')
|
|
->breadcrumbs(false)
|
|
->middleware([
|
|
RecordUserActivity::class,
|
|
])
|
|
->userMenuItems([
|
|
ExportAction::make('download_betfair')
|
|
->columnMapping(false)
|
|
->exporter(BetfairExporter::class)
|
|
->label('Betfair Odds')
|
|
->visible(fn (): bool => Auth::user()->hasRole('download_betfair'))
|
|
->fileName(fn (Export $export): string => 'betfair-odds-'.date('d.m.Y-H.i')."-{$export->getKey()}")
|
|
->modifyQueryUsing(fn (Builder $query) => $query->whereHas('odds_3ways_bf')
|
|
->whereHas('odds_totals_bf')
|
|
->where('sport_id', 1))
|
|
->icon('phosphor-download'),
|
|
'export' => Action::make('bookmaker_odds_download')
|
|
->label('Bookmakers Odds')
|
|
->visible(fn (): bool => Auth::user()->hasRole('download_betfair'))
|
|
->icon('phosphor-download')
|
|
->color('success')
|
|
->action(function () {
|
|
$rows = [];
|
|
|
|
$events = Event::with(['odds_3ways', 'odds_totals', 'competition_group'])->where('starttime', '>', Carbon::now())->where('starttime', '<', Carbon::now()->addDays(15))->orderBy('starttime', 'ASC')->get();
|
|
|
|
foreach ($events as $event) {
|
|
|
|
$event->loadMissing(['odds_3ways', 'odds_totals']);
|
|
|
|
$totals = [];
|
|
foreach ($event->odds_totals as $item) {
|
|
$bkmid = $item->bookmaker_id;
|
|
$totals[$bkmid]['bookid'] = $item->bookmaker_id;
|
|
$totals[$bkmid]['book'] = $item->bookmaker->name;
|
|
$totals[$bkmid]['over'] = $item->over;
|
|
$totals[$bkmid]['under'] = $item->under;
|
|
$totals[$bkmid]['total'] = $item->total;
|
|
}
|
|
foreach ($event->odds_3ways as $item) {
|
|
$bkmid = $item->bookmaker_id;
|
|
$tmp = [];
|
|
$tmp['Match Id'] = $event->id;
|
|
$tmp['BetsApi Id'] = $event->betsapi_id;
|
|
$tmp['Betradar Id'] = $event->betradar_id;
|
|
$tmp['Bet365 Id'] = $event->bet365_id;
|
|
$tmp['Starttime'] = $event->starttime;
|
|
$tmp['Sport Id'] = $event->sport_id;
|
|
$tmp['Group Id'] = $event->competition_group_id;
|
|
$tmp['Group'] = $event->competition_group->name;
|
|
$tmp['Home Id'] = $event->home_id;
|
|
$tmp['Home'] = $event->home->name;
|
|
$tmp['Away Id'] = $event->away_id;
|
|
$tmp['Away'] = $event->away->name;
|
|
$tmp['Book Id'] = $item->bookmaker->name;
|
|
$tmp['Book'] = $bkmid;
|
|
$tmp['One'] = $item->h3w;
|
|
$tmp['X'] = $item->d3w;
|
|
$tmp['Two'] = $item->a3w;
|
|
|
|
if (isset($totals[$bkmid])) {
|
|
$tmp['Book Id To'] = $bkmid;
|
|
$tmp['Book To'] = $totals[$bkmid]['book'];
|
|
$tmp['Over'] = $totals[$bkmid]['over'];
|
|
$tmp['Under'] = $totals[$bkmid]['under'];
|
|
$tmp['Total'] = $totals[$bkmid]['total'];
|
|
}
|
|
$rows[] = $tmp;
|
|
}
|
|
}
|
|
|
|
// Triggert den direkten Browser-Download der fertigen Excel-Datei
|
|
return Excel::download(
|
|
new OddsExporter($rows),
|
|
'major-markets-'.now()->format('Y-m-d-H-i').'.xlsx'
|
|
);
|
|
}),
|
|
])
|
|
->path('')
|
|
->login()
|
|
->passwordReset(RequestPasswordReset::class)
|
|
->emailVerification()
|
|
->emailChangeVerification()
|
|
->databaseNotifications()
|
|
->databaseNotificationsPolling('30s') // default is 30
|
|
->profile(isSimple: false)
|
|
->default()
|
|
->globalSearch(false)
|
|
->globalSearchKeyBindings(['command+k', 'ctrl+k'])
|
|
->brandLogo(asset('logo/statistiko.svg'))
|
|
->darkModeBrandLogo(asset('logo/statistiko-d.svg'))
|
|
->favicon(asset('favicon/favicon.ico'))
|
|
->brandName('')
|
|
->brandLogoHeight('2rem')
|
|
->unsavedChangesAlerts()
|
|
->topNavigation()
|
|
->multiFactorAuthentication([
|
|
EmailAuthentication::make(),
|
|
AppAuthentication::make()
|
|
->recoverable(),
|
|
])
|
|
// ], isRequired: true)
|
|
->viteTheme('resources/css/filament/admin/theme.css')
|
|
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
|
|
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
|
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
|
|
->discoverClusters(in: app_path('Filament/Clusters'), for: 'App\\Filament\\Clusters')
|
|
->maxContentWidth(Width::ScreenTwoExtraLarge)
|
|
->breadcrumbs(false)
|
|
->sidebarCollapsibleOnDesktop(false)
|
|
->userMenuItems([
|
|
'profile' => Action::make('profile')
|
|
->label(fn () => Auth::user()->name)
|
|
->url(fn (): string => EditProfilePage::getUrl())
|
|
->icon('phosphor-user-circle-fill'),
|
|
])
|
|
->pages([
|
|
Statistic::class,
|
|
PlayerProps::class,
|
|
])
|
|
->widgets([])
|
|
->middleware([
|
|
EncryptCookies::class,
|
|
AddQueuedCookiesToResponse::class,
|
|
StartSession::class,
|
|
AuthenticateSession::class,
|
|
ShareErrorsFromSession::class,
|
|
VerifyCsrfToken::class,
|
|
SubstituteBindings::class,
|
|
DisableBladeIconComponents::class,
|
|
DispatchServingFilamentEvent::class,
|
|
])
|
|
->authMiddleware([
|
|
Authenticate::class,
|
|
])->plugins([
|
|
FilamentShieldPlugin::make()
|
|
->navigationGroup('User')
|
|
->navigationSort(10)
|
|
->navigationBadge(5),
|
|
// HooksHelperPlugin::make(),
|
|
FilamentEditProfilePlugin::make()->shouldRegisterNavigation(false),
|
|
LightSwitchPlugin::make()->position(Alignment::BottomCenter),
|
|
FilamentBackgroundsPlugin::make()
|
|
->imageProvider(MyImages::make()->directory('images/backgrounds')),
|
|
]);
|
|
}
|
|
}
|