From cbc66d7e2784b8e9294b47813f13bbc86e38d8c3 Mon Sep 17 00:00:00 2001 From: salam Date: Tue, 29 Sep 2026 18:02:14 +0200 Subject: [PATCH] fix select country --- app/Actions/LoadSofaScoreCategory.php | 22 ++--- app/Traits/Sofascore/GrapSofascore.php | 16 ++-- app/Traits/Sofascore/GrappingToExcel.php | 103 +++++++++++------------ 3 files changed, 68 insertions(+), 73 deletions(-) diff --git a/app/Actions/LoadSofaScoreCategory.php b/app/Actions/LoadSofaScoreCategory.php index 061c9f33..90456304 100644 --- a/app/Actions/LoadSofaScoreCategory.php +++ b/app/Actions/LoadSofaScoreCategory.php @@ -14,22 +14,12 @@ class LoadSofaScoreCategory ->groupBy('league_id') ->pluck('league_id')->toArray(); - /* - 0 => 24 - 1 => 25 - 2 => 54 - 3 => 131 - 4 => 192 - 5 => 242 - 6 => 406 - 7 => 11539 - 8 => 11621 - */ + $res = SofaScoreTournament::with('sofascore_category')->whereIn('tournament_id', $league_ids)->get(); - $sofa_score_category_id = SofaScoreTournament::whereIn('tournament_id', $league_ids)->pluck('sofa_score_category_id')->toArray(); - - $sofa_score_category_id = array_unique($sofa_score_category_id); - - return SofaScoreCategory::where('in_soccer', 1)->whereIn('id', $sofa_score_category_id)->orderBy('name')->pluck('name', 'id'); + $arr = []; + foreach ($res as $value) { + $arr[$value->sofa_score_category_id] = $value->sofascore_category->name; + } + return $arr; } } diff --git a/app/Traits/Sofascore/GrapSofascore.php b/app/Traits/Sofascore/GrapSofascore.php index 83c18333..68df9ed0 100644 --- a/app/Traits/Sofascore/GrapSofascore.php +++ b/app/Traits/Sofascore/GrapSofascore.php @@ -117,10 +117,11 @@ trait GrapSofascore $this->load_tournaments_requested($folder); + $this->clear_folder($folder, 'all'); + /** * day 1 */ - $this->clear_folder($folder, 'all'); $day = Carbon::now()->subDay()->format('Y-m-d'); @@ -130,12 +131,9 @@ trait GrapSofascore $this->get_event($day, $tournament); } - $this->import_to_excel($folder, $day); - /** * day 5 */ - $this->clear_folder($folder, 'data'); $day = Carbon::now()->subDays(5)->format('Y-m-d'); @@ -145,7 +143,15 @@ trait GrapSofascore $this->get_event($day, $tournament); } - $this->import_to_excel($folder, $day); + /** + * to excel day by day + */ + + $this->import_to_excel($folder); + + /** + * mail it + */ $this->send($folder); } diff --git a/app/Traits/Sofascore/GrappingToExcel.php b/app/Traits/Sofascore/GrappingToExcel.php index 86df2530..a5c2ebea 100644 --- a/app/Traits/Sofascore/GrappingToExcel.php +++ b/app/Traits/Sofascore/GrappingToExcel.php @@ -6,6 +6,7 @@ use App\Models\SofaScoreTask; use App\Utilities\Notice; use PhpOffice\PhpSpreadsheet\IOFactory; use PhpOffice\PhpSpreadsheet\Spreadsheet; +use Illuminate\Support\Facades\File; trait GrappingToExcel { @@ -13,73 +14,71 @@ trait GrappingToExcel protected string $titel = ''; - public function import_to_excel(string $folder, $day = '') + public function import_to_excel(string $folder) { ini_set('memory_limit', -1); if ($this->debug) { - Notice::note("import $folder to excel", 'g'); + Notice::note("Import to Excel", 'bb'); } - switch ($this->task_id) { - case 1: - $this->titel = ucfirst($folder) . '_' . $day; + $directories = File::directories($this->data_dir . '/' . $folder); - $files = $this->get_tree($this->data_dir . '/' . $day); + foreach ($directories as $directory) { - break; - case 3: - $task = SofaScoreTask::with('sport')->where('id', $this->task_id)->first(); - $this->titel = ucfirst($folder) . '-' . $this->clean_string($task->name); - $files = $this->get_tree($this->data_dir); - break; - } + $day = substr(strrchr($directory, "/"), 1); - $files = array_chunk($this->filter($files), $this->max); + $this->titel = ucfirst($folder) . '-' . $day; - foreach ($files as $key => $value) { + $files = $this->get_tree($directory); - $has = count($value); - if (! $key && $has < $this->max) { - $count_from = 1; - $count_to = $has; - } elseif (! $key) { - $count_from = 1; - $key++; - $count_to = $key * $this->max; - } elseif ($has == $this->max) { - $count_from = $key * $this->max + 1; - $key++; - $count_to = $key * $this->max; - } else { - $count_from = $key * $this->max + 1; - $count_to = $key * $this->max + $has; - } + // only json max 2000 + $files = array_chunk($this->filter($files), $this->max); - $spreadsheet = new Spreadsheet; - $spreadsheet->getProperties()->setTitle($this->titel . '-' . $count_from . '-' . $count_to); - $activeWorksheet = $spreadsheet->getActiveSheet(); + foreach ($files as $key => $value) { - $column = 1; - foreach ($value as $file) { - $data = file_get_contents($file); - $data = json_decode($data, true); - $json_string = json_encode($data, JSON_PRETTY_PRINT); - - $arr = explode(PHP_EOL, $json_string); - $row = 0; - foreach ($arr as $string) { - $row++; - $replacedString = preg_replace('/\\\\u([0-9abcdef]{4})/', '&#x$1;', $string); - $utf8string = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES'); - $activeWorksheet->setCellValue([$column, $row], $utf8string); + $has = count($value); + if (! $key && $has < $this->max) { + $count_from = 1; + $count_to = $has; + } elseif (! $key) { + $count_from = 1; + $key++; + $count_to = $key * $this->max; + } elseif ($has == $this->max) { + $count_from = $key * $this->max + 1; + $key++; + $count_to = $key * $this->max; + } else { + $count_from = $key * $this->max + 1; + $count_to = $key * $this->max + $has; } - $column++; - } - $spreadsheet->setActiveSheetIndex(0); - $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); - $writer->save("$this->data_dir/$this->titel-$count_from-$count_to.xlsx"); + $spreadsheet = new Spreadsheet; + $spreadsheet->getProperties()->setTitle($this->titel . '-' . $count_from . '-' . $count_to); + $activeWorksheet = $spreadsheet->getActiveSheet(); + + $column = 1; + foreach ($value as $file) { + $data = file_get_contents($file); + $data = json_decode($data, true); + $json_string = json_encode($data, JSON_PRETTY_PRINT); + + $arr = explode(PHP_EOL, $json_string); + $row = 0; + foreach ($arr as $string) { + $row++; + $replacedString = preg_replace('/\\\\u([0-9abcdef]{4})/', '&#x$1;', $string); + $utf8string = mb_convert_encoding($replacedString, 'UTF-8', 'HTML-ENTITIES'); + $activeWorksheet->setCellValue([$column, $row], $utf8string); + } + $column++; + } + + $spreadsheet->setActiveSheetIndex(0); + $writer = IOFactory::createWriter($spreadsheet, 'Xlsx'); + $writer->save("$this->data_dir/$this->titel-$count_from-$count_to.xlsx"); + } } }