%PDF- %PDF-
Direktori : /www/loslex/demo/app/Http/Controllers/ |
Current File : //www/loslex/demo/app/Http/Controllers/CupResultsController.php |
<?php namespace App\Http\Controllers; use App\Models\Contest; use App\Workers\Cup\LosCupProcessor; use Illuminate\Support\Carbon; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; if (!defined('RESULTS_CACHE_TTL')) define('RESULTS_CACHE_TTL', 7 * 24 * 3600); class CupResultsController extends Controller { public $cacheKey; public $dateStart; public $dateEnd; public $cupName; public $dateDecision; private function presetCup($id) { switch ($id) { case 1: $this->cacheKey = 'cup/handgun/2024'; $this->dateStart = Date::createFromDate(2023, 9, 01); $this->dateEnd = Date::createFromDate(2024, 8, 31); $this->cupName = 'Pohár LOS 2024'; $this->dateDecision = Carbon::parse("2024-06-30"); break; case 2: default: $this->cacheKey = 'cup/handgun/2025'; $this->dateStart = Date::createFromDate(2024, 9, 01); $this->dateEnd = Date::createFromDate(2025, 8, 31); $this->cupName = 'Pohár LOS 2025'; $this->dateDecision = Carbon::parse("2025-06-30"); break; } } public function results($id = 1) { $this->presetCup($id); $data = Cache::remember($this->cacheKey, RESULTS_CACHE_TTL, function () { Log::info("Cache MISS", ['key' => $this->cacheKey]); $processor = new LosCupProcessor($this->cupName, $this->dateDecision); $contests = Contest::whereBetween('date', [$this->dateStart, $this->dateEnd]) ->where('contest_category_id', 1) ->where('contest_level_id', 2) ->where('published', 1) ->getModels(); return $processor->ProcessCupResults($contests); }); return view("cup.los", ['cup' => $data]); } public function clear($id) { $this->presetCup($id); if (Auth::user() && Auth::user()->is_admin) { Log::info("Cache clear - manual", ['key' => $this->cacheKey]); Cache::forget($this->cacheKey); } return redirect(route('cup.results', $id)); } }