Files
nuhodds_fi4/app/Console/Commands/Grapper/Sofascore.php
T
2026-06-24 15:56:43 +02:00

94 lines
2.6 KiB
PHP

<?php
namespace App\Console\Commands\Grapper;
use App\Console\Commands\Grapper\Sofascore\Events;
use App\Console\Commands\Grapper\Sofascore\EventsDatabase;
use App\Console\Commands\Grapper\Sofascore\Special;
use App\Console\Commands\Grapper\Sofascore\Tournament;
use App\Console\Commands\Nuh;
use App\Models\SofaScoreCategorie;
use App\Models\SofaScoreDay;
use App\Models\SofaScoreDayTournament;
use App\Models\SofaScoreTournament;
use App\Utilities\Notice;
use DateTime;
use Illuminate\Support\Carbon;
class Sofascore
{
public static $auth_header = [];
public static $base_url = '';
public static $_days = [];
public static $sport = [1];
public static function switch()
{
$debug = Nuh::$options['d'] ?? 0;
if (Nuh::$options['truncate']) {
SofaScoreDayTournament::truncate();
SofaScoreTournament::truncate();
SofaScoreDay::truncate();
SofaScoreCategorie::truncate();
Notice::note('Table SofaScoreDay, SofaScoreDayTournament, SofaScoreTournament, SofaScoreCategorie truncated!', 'b', 1);
}
if (Nuh::$options['t']) {
self::$_days[] = Carbon::now()->format('Y-m-d');
} elseif (Nuh::$options['day']) {
$day = self::validateDate(Nuh::$options['day']);
if ($day) {
self::$_days[] = $day;
} else {
Notice::note('date not valid '.Nuh::$options['day'], 'r', 1);
}
} elseif (Nuh::$options['days']) {
$to = Carbon::now()->subDays(Nuh::$options['days']);
$from = Carbon::now()->subDay();
while ($from >= $to) {
self::$_days[] = $from->format('Y-m-d');
$from->subDay();
}
}
if ($debug) {
Notice::note(Nuh::$options['sport'].' '.Nuh::$options['name'], 'bb');
}
switch (Nuh::$options['name']) {
case 'TOURNAMENTS':
Tournament::load();
break;
case 'EVENTS':
Events::load();
break;
case 'EVENTSDB':
EventsDatabase::load();
break;
case 'SPECIAL':
Special::load();
break;
default:
// code...
break;
}
}
public static function validateDate($date, $format = 'Y-m-d')
{
if (is_numeric($date)) {
$date = date('Y').'-'.date('m').'-'.$date;
}
$d = DateTime::createFromFormat($format, $date);
if ($d && $d->format($format) == $date) {
return $d->format($format);
}
}
}