Wird in der nächsten Version drin sein.
Beiträge von Yannici
Ich habe einen Blog Artikel verfasst - Wie benutze ich die Suche richtig - Bitte diesen beachten und auch umsetzen bevor Ihr ein Neues Thema eröffnet!
-
-
kaikiste Karlnapp75 Es gibt aber wie Horst richtig geschrieben hat keine Zuordnung von Teams zu Ligen. Die Teams werden einer Saison innerhalb einer Liga zugeordnet, und diese Zuordnung ist im xdata korrekt.
-
Ich habe hierzu schon ein funktionierendes Image + Docker Compose.
Aktuell aber noch nicht zu veröffentlichen, weil ich auch noch eine CI/CD-Pipeline dazu bauen möchte und diverse Codeänderungen an XTipp, sofern es innerhalb eines Docker Containers läuft --> u.a. eben das Updaten innerhalb der Konfiguration und das Installationsscript muss angepasst werden.
Für die Lösung habe ich ein eigenes Image auf Basis von serversideup/php:8.3-fpm-nginx gebaut.
Zusätzlich eine Docker Compose Datei erstellt, in der einerseits XTipp hochgefahren wird, andererseits eine MariaDB.Beim Start des Containers wird Laravel "hochgefahren" und einige Umgebungsvariablen gesetzt, die die Verbindung zur Datenbank konfiguriert.
Dann läuft das Script problemlos
Nachteil im Moment ist, dass ich innerhalb des Images auch die ganzen node_modules habe, weil ich auch die css/js files kompiliere.
Ggf. ändere ich es letztendlich auch darauf um, dass das fertig kompilierte Script ins Image gezogen wird (ggf. Download des fertig gezippten Scripts ins Image).
Vorteil wäre ein nicht so großes Image!
Habe mich allerdings bisher nicht drum gekümmert wie man es umsetzt mit SSL - da kann ggf. auch jemand unterstützen
-
Naja, die Lizenz wird wohl auf https://xtipp.trainersessel.de/ laufen und nicht auf https://trainersessel.de oder?
Neue Lizenz beantragen für die neue Domain wurde ich sagen.
-
Ist ein Fehler in XTipp und ist in der nächsten Version gefixt. Sorry!
-
Schriftfarbe und Schrifthintergrund ist in der kommenden Version dabei.
-
Es ist der CKEditor 5. Farbauswahl kann ich noch ergänzen.
-
In der nächsten Version ist der Editor aktualisiert und Bilder können hochgeladen werden.
-
Ja aufgrund der current timestamp Einstellung sind nach dem Update ca. 5min alle User online.
-
Nachrichten können in der kommenden Version gelöscht werden. Admins können alle löschen, die User können ihre eigenen Nachrichten löschen.
-
Habs grade mal gemacht. Komischerweise verhält sich die Suche da tatsächlich komisch. Wenn ich "Span" eingegeben habe, finde ich "Spanien". Wenn ich aber "Spanien" eingebe, finde ich es nicht.
Dasselbe auch bei Frankreich... Müssen wir mal schauen.
-
Könnt ihr prüfen ob es nun stimmt? Bei jedem Sync (und das kommt relativ häufig vor) wird das Ranking berechnet. Vermutlich ruft ihr die Seite dann während der Berechnung auf.
Das sollte natürlich verhindert werden - ich habe dazu was in XTipp implementiert, das wird in der nächsten Version enthalten sein. Damit werden keine Zwischenstände während der Berechnung der Rangliste mehr angezeigt.
-
Funktion "Letzte Aktivtät" ist in der kommenden Version implementiert. Aus Datenschutz erstmal nur sichtbar innerhalb des Admin-Bereichs. Wird aber für die Funktion "Wer ist online?" genutzt.
-
Funktion "Letzte Aktivtät" ist in der kommenden Version implementiert. Aus Datenschutz erstmal nur sichtbar innerhalb des Admin-Bereichs. Wird aber für die Funktion "Wer ist online?" genutzt.
-
Die Elfmeter aus dem Elfmeterschießen waren als "Elfmeter" gepflegt. Das zählt in die Statistik. Der Typ "Elfmeterschießen" muss in diesem Fall ausgewählt werden.
Wurde nun angepasst und nun stimmts.
-
Es steht dann 0:0 da, im XTipp könnte es aber richtig dargestellt werden. Das müsste ich mal testen.
Dann würde auch die Statistik wieder stimmen, denn ein "Elfmeter" geht als Tor eines Spielers in dessen Statistik ein.
-
Der Richtige "Typ" wäre nicht "Elfmeter" im XDataService gewesen, sondern "Elfmeterschießen". Dann hätte es vermutlich auch gestimmt.
Wobei ich gesehen habe, dass dann das Ergebnis nicht korrekt dargestellt wird.
-
Habe ich so im XDataService angepasst.
-
Grundsätzlich ist es angedacht, dass auf der linken Seite nur ein Spiel dargestellt wird. Die Übersicht hat man ja auf der rechten Seite.
-
Hier eine neue Version, die sollte nun funktionieren (MatchcenterController.php):
Code- <?php
- namespace App\Http\Controllers;
- use App\Helper\GameEventType;
- use App\Helpers\Tactics;
- use App\Models\Game\Game;
- use App\Models\Game\GameEvent;
- use App\Models\Game\GameLineUp;
- use App\Models\Player;
- use App\Models\Ranking\Ranking;
- use App\Models\Round\Round;
- use App\Models\Round\RoundTeams;
- use App\Models\Season\Season;
- use App\Models\Season\SeasonTable;
- use App\Models\Team;
- use App\Models\Tip\Tip;
- use App\Models\User;
- use Auth;
- use Carbon\Carbon;
- use DB;
- use Illuminate\Contracts\Foundation\Application;
- use Illuminate\Contracts\View\Factory;
- use Illuminate\Contracts\View\View;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Log;
- /**
- * MatchcenterController
- */
- class MatchcenterController extends Controller {
- /**
- * Show the index view
- *
- * @return Application|Factory|View
- */
- public function index(): Application|Factory|View {
- // Get current user league and season
- $league = Auth::user()->currentLeague;
- $season = $league->currentSeason();
- // Get all seasons of league
- $leagueSeasons = $league->seasons()->orderBy('name', 'DESC')->get();
- // Check if season given
- $lastEventLogGame = null;
- $lastEventLogEvent = null;
- if (!is_null($season)) {
- // Get last event log
- $lastEventLogGame = Game::select(DB::raw('MAX(updated_at) AS `max_updated_at`, MAX(created_at) AS `max_created_at`, MAX(deleted_at) AS `max_deleted_at`'))
- ->withTrashed()->whereHas('Round', function($query) use ($season) {
- $query->where('season_id', $season->id);
- })->limit(1)->first();
- // Get last event log
- $lastEventLogEvent = GameEvent::select(DB::raw('MAX(updated_at) AS `max_updated_at`, MAX(created_at) AS `max_created_at`, MAX(deleted_at) AS `max_deleted_at`'))
- ->whereHas('Game', function ($query) use ($season) {
- $query->whereHas('Round', function ($query2) use ($season) {
- $query2->where('season_id', $season->id);
- });
- })->withTrashed()->limit(1)->first();
- }
- // Check both event logs
- if (!is_null($lastEventLogGame) && !is_null($lastEventLogEvent)) {
- $stampLastEvent = Carbon::parse(max([$lastEventLogGame->max_updated_at, $lastEventLogGame->max_created_at, $lastEventLogGame->max_deleted_at,
- $lastEventLogEvent->max_updated_at, $lastEventLogEvent->max_created_at, $lastEventLogEvent->max_deleted_at]))->toDateTimeString();
- } else {
- $stampLastEvent = Carbon::now()->toDateTimeString();
- }
- return view('matchcenter.index', [
- 'league' => $league,
- 'season' => $season,
- 'leagueSeasons' => $leagueSeasons,
- 'stampLastEvent' => $stampLastEvent
- ]);
- }
- /**
- * Function to check for update
- *
- * @param Request $request
- *
- * @return array
- */
- public function hasUpdate(Request $request): array {
- // Define some variables
- $seasonId = intval($request->input('seasonID'));
- $updateStamp = Carbon::parse($request->input('updateStamp'));
- $hasUpdate = false;
- // Check season id and update stamp
- if ($seasonId === 0 || !$updateStamp) {
- return ['update' => false, 'error' => 'Wrong data'];
- }
- // Get season
- $season = Season::find($seasonId);
- if (!$season) {
- return ['update' => false, 'error' => 'No season'];
- }
- // Get last event log
- $lastEventLogGame = Game::select(DB::raw('MAX(updated_at) AS `max_updated_at`, MAX(created_at) AS `max_created_at`, MAX(deleted_at) AS `max_deleted_at`'))
- ->withTrashed()->where(function ($whereQuery) use ($season) {
- $whereQuery->whereHas('Round', function($query) use ($season) {
- $query->where('season_id', $season->id);
- });
- })->where(function ($whereQuery) use ($updateStamp) {
- $whereQuery->where('updated_at', '>', $updateStamp)->orWhere('created_at', '>', $updateStamp)->orWhere('deleted_at', '>', $updateStamp);
- })->limit(1)->first();
- // Get last event
- $lastEventLogEvent = GameEvent::select(DB::raw('MAX(updated_at) AS `max_updated_at`, MAX(created_at) AS `max_created_at`, MAX(deleted_at) AS `max_deleted_at`'))
- ->withTrashed()->where(function($whereQuery) use ($season) {
- $whereQuery->whereHas('Game', function ($query) use ($season) {
- $query->whereHas('Round', function ($query2) use ($season) {
- $query2->where('season_id', $season->id);
- });
- });
- })->where(function($whereQuery) use ($updateStamp) {
- $whereQuery->where('updated_at', '>', $updateStamp)->orWhere('created_at', '>', $updateStamp)->orWhere('deleted_at', '>', $updateStamp);
- })->limit(1)->first();
- // Get maximum value
- $max = max([$lastEventLogGame->max_updated_at, $lastEventLogGame->max_created_at, $lastEventLogGame->max_deleted_at,
- $lastEventLogEvent->max_updated_at, $lastEventLogEvent->max_created_at, $lastEventLogEvent->max_deleted_at]);
- // Check for maximum value
- if (!$max) {
- $stamp = $request->input('updateStamp');
- } else {
- $hasUpdate = true;
- $stamp = Carbon::parse($max)->toDateTimeString();
- }
- return [
- 'update' => $hasUpdate,
- 'stamp' => $stamp
- ];
- }
- /**
- * Get table
- *
- * @param Request $request
- *
- * @return Application|Factory|View
- */
- public function getLiveTable(Request $request): Application|Factory|View {
- // Define variables for return
- $table = null;
- $tableDefinition = null;
- // Define arguments
- $season = Season::find($request->input('seasonID'));
- $tableRoundArgument = $request->has('tableRound') ? (int) $request->input('tableRound') : 0;
- $matchDayArgument = (string) $request->input('matchDay');
- $matchDayParts = explode('_', $matchDayArgument);
- $matchDay = (int) $matchDayParts[1];
- // Check season
- if (!$season) {
- Log::error('getLiveTable - Season not found');
- abort(500, 'Season not found.');
- }
- // Check if match day is zero
- if ($matchDay === 0) {
- $matchDay = $season->getCurrentOrLastGame()->game_match_day_id;
- }
- // Get games
- $games = Game::whereHas('Round', function($query) use ($season) {
- $query->where('season_id', $season->id);
- })->where('game_match_day_id', '<=', $matchDay)->where('status', '1')->orderBy('start', 'ASC')->get();
- // Define round
- $round = null;
- if ($tableRoundArgument > 0) {
- $round = Round::find($tableRoundArgument);
- } else {
- $round = $season->getRoundByMatchday($matchDay);
- }
- // If a round found, get current table
- if ($round !== null) {
- $currentTable = SeasonTable::ranking($round->id, $matchDay);
- foreach ($games as $game) {
- $teamHome = $currentTable->first(function ($value) use ($game) {
- return $value->team_id === $game->home_team_id;
- });
- $teamGuest = $currentTable->first(function ($value) use ($game) {
- return $value->team_id === $game->guest_team_id;
- });
- // If no home or guest team found
- if (!$teamHome || !$teamGuest) {
- continue;
- }
- // Set live flag
- $teamHome->isLive = true;
- $teamGuest->isLive = true;
- }
- // If games found, define table
- if ($games->count() > 0) {
- $table = collect($this->calculateMatchdayRanks($round, $currentTable));
- } else {
- $table = $currentTable;
- }
- // Add trends to table
- SeasonTable::addTrendsToTable($table, $round->season, $matchDay);
- // Define variable with table definitions
- $tableDefinition = $round->tableDefinitions;
- }
- return view('table.table', [
- 'table' => $table,
- 'compact' => true,
- 'definitions' => $tableDefinition,
- ]);
- }
- /**
- * Get ranking
- *
- * @return string
- */
- public function getLiveRanking(): string {
- // Get season and define match day
- $season = Season::find(Request::input('seasonID'));
- $matchDay = intval(Request::input('matchday'));
- // Check season
- if (!$season) {
- Log::error('getLiveRanking - Season not found');
- abort(500, 'Season not found.');
- }
- // Load config
- $extraNumberOfTips = (int) config('xtipp.extra-number-of-tips');
- $extraNumberOfPoints = (int) config('xtipp.extra-number-of-points');
- $pointsCalculationPlaytime = (int) config('xtipp.points-calculation-playtime', 0);
- // Check match day
- if ($matchDay === 0) {
- $matchDay = $season->getCurrentOrLastGame()->game_match_day_id;
- }
- // Get all games
- $games = Game::whereHas('Round', function($query) use ($season) {
- $query->where('season_id', $season->id);
- })->where('game_match_day_id', '<=', $matchDay)->orderBy('start', 'ASC')->get();
- // Get current ranking
- $rankingList = [];
- $i = 0;
- $currentRanking = Ranking::ranking($season->id, ['from' => 1, 'to' => $matchDay]);
- foreach ($currentRanking as $row) {
- $rankingList[$i]['place'] = $i + 1;
- $rankingList[$i]['user'] = User::where('id', $row->user_id)->first();
- $rankingList[$i]['tips'] = $row->tips;
- $rankingList[$i]['result'] = $row->result;
- $rankingList[$i]['difference'] = $row->difference;
- $rankingList[$i]['tendency'] = $row->tendency;
- $rankingList[$i]['points'] = $row->points;
- $rankingList[$i]['extra'] = $row->extra;
- $rankingList[$i]['actualMDPoints'] = 0;
- $i++;
- }
- // Check current round match day
- $actualRoundMatchDay = $season->getRoundByMatchday($matchDay);
- foreach ($rankingList as $rank) {
- $actualPoints = Ranking::leftJoin('ranking_metas', 'ranking_metas.id', '=', 'rankings.ranking_meta_id')->where('season_id', Request::input('seasonID'))->where('user_id', $rank['user']->id)->where('round_id', $actualRoundMatchDay->id)->where('matchDay', $matchDay)->value('points');
- if ($actualPoints) {
- $rank['actualMDPoints'] = $actualPoints;
- }
- // Go through all games
- $extraCounter = 0;
- foreach ($games as $game) {
- // Done a tip?
- $tip = Tip::where('game_id', $game->id)->where('user_id', $rank['user']->id)->first();
- if (!$tip) {
- continue;
- }
- $pointsBefore = $rank['points'];
- $rank = Ranking::allocateData(
- $rank,
- $tip,
- $game->homeTeamGoals($pointsCalculationPlaytime),
- $game->guestTeamGoals($pointsCalculationPlaytime)
- );
- if ($rank['extra']) {
- $extraCounter++;
- }
- // Check for extra points
- if ($extraNumberOfTips > 0 && $rank['extra'] > 0) {
- // Increase counter
- $extraCounter++;
- // Check if counter is equal or greater than needed tips
- if ($extraCounter >= $extraNumberOfTips) {
- $rank['extra'] = $extraNumberOfPoints;
- } else {
- $rank['extra'] = 0;
- }
- }
- // Add current points
- $rank['actualMDPoints'] += $rank['points'] - $pointsBefore - $rank['extra'];
- }
- }
- // Resort ranking
- Ranking::resort($rankingList);
- // Set new correct places
- $i = 0;
- foreach ($rankingList as $rank) {
- $rank['place'] = ++$i;
- }
- return view('ranking.list', compact('rankingList'))->render();
- }
- /**
- * Get actual matchday
- */
- public function getActualMatchday($roundIDs)
- {
- $actualGame = Game::select('game_match_day_id')
- ->whereIn('round_id', $roundIDs)
- ->where('status', '1')
- ->orderBy('start', 'asc')
- ->first();
- if (!$actualGame) {
- $lastGame = Game::select('game_match_day_id')
- ->whereIn('round_id', $roundIDs)
- ->where(function ($query) {
- $query->where('status', '2')
- ->orWhere('status', '3')
- ->orWhere('status', '4');
- })
- ->orderBy('start', 'desc')
- ->first();
- if (!$lastGame) {
- return 0;
- } else {
- return $lastGame->game_match_day_id;
- }
- } else {
- return $actualGame->game_match_day_id;
- }
- }
- /**
- * Get all game event logs
- *
- * @return array
- */
- public function getAllGameEventLogs($game): array {
- $homeEventLogs = $game->homeTeamEvents()->where('change_info', '!=', 'out')->orderBy('minute', 'asc')->orderBy('extra_minute', 'asc')->get();
- $guestEventLogs = $game->guestTeamEvents()->where('change_info', '!=', 'out')->orderBy('minute', 'asc')->orderBy('extra_minute', 'asc')->get();
- return [
- 'gameEvents' => $game->logs,
- 'homeEvents' => $homeEventLogs,
- 'guestEvents' => $guestEventLogs
- ];
- }
- /**
- * Get all matches from given match day
- *
- * @param Request $request
- *
- * @return string
- */
- public function getAllMatchesFromMatchDay(Request $request): string {
- // Find given season
- $seasonId = Season::find($request->input('seasonID'));
- if (!$seasonId) {
- Log::error('getAllMatchesFromMatchDay - Season not found');
- abort(500, 'Season not found.');
- }
- // Define match day information
- $matchDayArgument = (string) $request->input('matchDay');
- $matchDayParts = explode('_', $matchDayArgument);
- $matchDayType = $matchDayParts[0];
- $matchDay = (int) $matchDayParts[1];
- // Check type
- if ($matchDayType === 'round') {
- $games = Game::where('round_id', $matchDay)->orderBy('start', 'ASC')->get();
- } else {
- // Get all games
- $games = Game::whereHas('Round', function($query) use ($seasonId) {
- $query->where('season_id', $seasonId->id);
- })->where('game_match_day_id', $matchDay)->orderBy('start', 'ASC');
- // Check for possible table round
- $tableRoundArgument = $request->has('tableRound') ? (int) $request->input('tableRound') : 0;
- if ($tableRoundArgument > 0) {
- $round = Round::find($tableRoundArgument);
- if ($round !== null) {
- $games = $games->where('round_id', $round->id);
- }
- }
- $games = $games->get();
- }
- // Go through each game
- $oldStart = null;
- $outputMatches = [];
- $matchToSelectWithLive = false;
- $matchToSelectWithNotStarted = false;
- $matchToSelect = 0;
- foreach ($games as $gameKey => $game) {
- // Set first game for select
- if ($gameKey === 0) {
- $matchToSelect = $game->id;
- }
- // Mark game to select if the game is live
- if ($game->status === 1 && !$matchToSelectWithLive) {
- $matchToSelect = $game->id;
- $matchToSelectWithLive = true;
- }
- // Mark game to select if the game is not start
- if (in_array($game->status, [-1, 0]) && !$matchToSelectWithNotStarted && !$matchToSelectWithLive) {
- $matchToSelect = $game->id;
- $matchToSelectWithNotStarted = true;
- }
- // Get start information
- $matchStart = '';
- if ($game->start->format('Y-m-d H:i:s') !== '-0001-11-30 00:00:00' && $oldStart !== strtotime($game->start)) {
- $matchStart = Carbon::createFromTimestamp(strtotime($game->start))->timezone('Europe/Berlin')->format('d.m.Y - H:i').' Uhr';
- }
- // Define output array
- $outputMatches[$gameKey]['gameID'] = $game->id;
- $outputMatches[$gameKey]['start'] = $matchStart;
- $outputMatches[$gameKey]['homeTeamID'] = $game->home_team_id;
- $outputMatches[$gameKey]['homeTeamName'] = $game->homeTeam !== null ? $game->homeTeam->short_name : $game->home_team_placeholder;
- $outputMatches[$gameKey]['homeTeamShortName'] = $game->homeTeam !== null ? $game->homeTeam->short_cut_name : $game->home_team_placeholder;
- $outputMatches[$gameKey]['homeTeamImageName'] = $game->homeTeam !== null ? $game->homeTeam->getImageName() : 'dummy.png';
- $outputMatches[$gameKey]['guestTeamID'] = $game->guest_team_id;
- $outputMatches[$gameKey]['guestTeamName'] = $game->guestTeam !== null ? $game->guestTeam->short_name : $game->guest_team_placeholder;
- $outputMatches[$gameKey]['guestTeamShortName'] = $game->guestTeam !== null ? $game->guestTeam->short_cut_name : $game->guest_team_placeholder;
- $outputMatches[$gameKey]['guestTeamImageName'] = $game->guestTeam !== null ? $game->guestTeam->getImageName() : 'dummy.png';
- $outputMatches[$gameKey]['result'] = $game->getResultString();
- $outputMatches[$gameKey]['status'] = $game->status;
- $outputMatches[$gameKey]['visitors'] = $game->visitors;
- $outputMatches[$gameKey]['tacticHome'] = $game->tactic_home;
- $outputMatches[$gameKey]['tacticGuest'] = $game->tactic_guest;
- $oldStart = strtotime($game->start);
- }
- return view('matchcenter.content.matches', [
- 'outputMatches' => $outputMatches,
- 'matchToSelect' => $matchToSelect,
- ])->render();
- }
- /**
- * Get all rounds from a season
- */
- public function getAllSeasonRounds(int $seasonId) {
- return Round::where('season_id', $seasonId)->get();
- }
- /**
- * Get all goal game event logs
- */
- public function getGameEventLogs($gameID, $teamID) {
- $gameEventLogs = GameEvent::select('game_events.player_id', 'players.firstname', 'players.familyname', 'game_events.minute',
- 'game_events.extra_minute', 'game_events.change_info', 'game_events.game_event_type_id')
- ->leftJoin('players', 'players.id', '=', 'game_events.player_id')
- ->where('game_id', $gameID)
- ->where(function ($query) use ($teamID) {
- $query->where(function ($query) use ($teamID) {
- $query->where('team_id', $teamID)
- ->where('game_events.game_event_type_id', '!=', GameEventType::OwnGoal)
- ->where(function ($query) {
- $query->where('game_events.game_event_type_id', '=', GameEventType::Goal)
- ->orWhere('game_events.game_event_type_id', '=', GameEventType::Penalty);
- });
- });
- $query->orWhere(function ($query) use ($teamID) {
- $query->where('team_id', '!=', $teamID)
- ->where('game_events.game_event_type_id', GameEventType::OwnGoal);
- });
- })
- ->orderBy('minute', 'asc')
- ->orderBy('extra_minute', 'asc')
- ->get();
- $i = 0;
- $output = [];
- foreach ($gameEventLogs as $eventLog) {
- $output[$i]['logName'] = $eventLog->name;
- $output[$i]['player']['id'] = $eventLog->player_id;
- $output[$i]['player']['familyname'] = $eventLog->familyname;
- $output[$i]['player']['firstname'] = $eventLog->firstname;
- $output[$i]['minute'] = $eventLog->minute;
- $output[$i]['extraMinute'] = $eventLog->extra_minute;
- $output[$i]['changeInfo'] = $eventLog->change_info;
- $output[$i]['eventType'] = $eventLog->game_event_type_id;
- $i++;
- }
- return $output;
- }
- /**
- * Get the game result
- *
- * @param int $gameID
- *
- * @return array
- */
- public static function getGameResult(int $gameID): array {
- // Define variables
- $game = Game::find($gameID);
- $goals = [];
- // Check for status
- if ($game->status > 0) {
- // Get total information
- $goals['totalHome'] = $game->homeTeamGoals();
- $goals['totalGuest'] = $game->guestTeamGoals();
- // Get half goals
- $goals['halfHome'] = $game->logs()->where(function($query) use ($game) {
- $query->where(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::Goal);
- $hasQuery->orWhere('game_event_type_id', GameEventType::Penalty);
- })->where('team_id', $game->homeTeam->id);
- })->orWhere(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::OwnGoal);
- })->where('team_id', $game->guestTeam->id);
- });
- })->where('minute', '<=', 45)->count();
- $goals['halfGuest'] = $game->logs()->where(function($query) use ($game) {
- $query->where(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::Goal);
- $hasQuery->orWhere('game_event_type_id', GameEventType::Penalty);
- })->where('team_id', $game->guestTeam->id);
- })->orWhere(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::OwnGoal);
- })->where('team_id', $game->homeTeam->id);
- });
- })->where('minute', '<=', 45)->count();
- // Get addition goals
- $goals['additionHome'] = $game->logs()->where(function($query) use ($game) {
- $query->where(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::Goal);
- $hasQuery->orWhere('game_event_type_id', GameEventType::Penalty);
- })->where('team_id', $game->homeTeam->id);
- })->orWhere(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::OwnGoal);
- })->where('team_id', $game->guestTeam->id);
- });
- })->whereBetween('minute', [91, 120])->count();
- $goals['additionGuest'] = $game->logs()->where(function($query) use ($game) {
- $query->where(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::Goal);
- $hasQuery->orWhere('game_event_type_id', GameEventType::Penalty);
- })->where('team_id', $game->guestTeam->id);
- })->orWhere(function($whereQuery) use ($game) {
- $whereQuery->where(function($hasQuery) {
- $hasQuery->where('game_event_type_id', GameEventType::OwnGoal);
- })->where('team_id', $game->homeTeam->id);
- });
- })->whereBetween('minute', [91, 120])->count();
- // Get penalty goals
- $goals['penaltyHome'] = $game->logs()->where(function($query) use ($game) {
- $query->where('game_event_type_id', GameEventType::PenaltyShootout);
- $query->where('team_id', $game->homeTeam->id);
- })->where('minute', '>', 120)->count();
- $goals['penaltyGuest'] = $game->logs()->where(function($query) use ($game) {
- $query->where('game_event_type_id', GameEventType::PenaltyShootout);
- $query->where('team_id', $game->guestTeam->id);
- })->where('minute', '>', 120)->count();
- // Make some checks
- $goals['additionString'] = '';
- if ($goals['penaltyHome'] > 0 && $goals['penaltyGuest'] > 0) {
- $goals['additionString'] = 'n.E.';
- } elseif ($goals['additionHome'] > 0 && $goals['additionGuest'] > 0) {
- $goals['additionString'] = 'n.V.';
- }
- } else {
- $goals = [
- 'totalHome' => '-',
- 'totalGuest' => '-',
- 'halfHome' => '-',
- 'halfGuest' => '-',
- 'additionString' => '',
- 'additionHome' => '-',
- 'additionGuest' => '-',
- 'penaltyHome' => '-',
- 'penaltyGuest' => '-',
- ];
- }
- return $goals;
- }
- /**
- * Get all match days of season
- *
- * @param Request $request
- *
- * @return array
- */
- public function getLeagueSeasonMatchDays(Request $request): array {
- // Check if request has a season id
- if ($request->has('seasonID')) {
- // Get and check season
- $season = Season::find($request->input('seasonID'));
- if ($season !== null) {
- return $season->preparedMatchDayRounds(true);
- }
- }
- return [];
- }
- /**
- * Get a single match
- *
- * @param Request $request
- *
- * @return string
- */
- public function getSingleMatch(Request $request): string {
- // Check for a game id
- if ((int) $request->input('gameID') !== 0) {
- $currentGame = Game::find($request->input('gameID'));
- } else {
- // Get season
- $season = Season::find($request->input('seasonID'));
- if (!$season) {
- Log::error('getSingleMatch - Season not found');
- abort(500, 'Season not found.');
- }
- // Define match day information
- $matchDayArgument = (string) $request->input('matchDay');
- $matchDayParts = explode('_', $matchDayArgument);
- $matchDayType = $matchDayParts[0];
- $matchDay = (int) $matchDayParts[1];
- // Check for given match day and current game
- $currentGame = $season->getCurrentGameByMatchday($matchDay, $matchDayType);
- if (!$currentGame) {
- // Get first game of given match day
- $currentGame = $season->getFirstGameByMatchday($matchDay, $matchDayType);
- if (!$currentGame) {
- Log::error('getSingleMatch - No game found');
- abort(500, 'No game found.');
- }
- }
- }
- // Define output information
- $outputMatch = [];
- if ($currentGame) {
- $outputMatch['gameID'] = $currentGame->id;
- $outputMatch['start'] = $currentGame->start;
- $outputMatch['visitors'] = number_format($currentGame->visitors, 0, ',', '.');
- $outputMatch['homeTeamID'] = $currentGame->home_team_id;
- $outputMatch['homeTeamName'] = $currentGame->homeTeam !== null ? $currentGame->homeTeam->short_name : $currentGame->home_team_placeholder;
- $outputMatch['homeTeamImageName'] = $currentGame->homeTeam !== null ? $currentGame->homeTeam->getImageName() : 'dummy.png';
- $outputMatch['guestTeamID'] = $currentGame->guest_team_id;
- $outputMatch['guestTeamName'] = $currentGame->guestTeam !== null ? $currentGame->guestTeam->short_name : $currentGame->guest_team_placeholder;
- $outputMatch['guestTeamImageName'] = $currentGame->guestTeam !== null ? $currentGame->guestTeam->getImageName() : 'dummy.png';
- $outputMatch['result'] = self::getGameResult($currentGame->id);
- $outputMatch['homeGoalEventLog'] = self::getGameEventLogs($currentGame->id, $currentGame->home_team_id);
- $outputMatch['guestGoalEventLog'] = self::getGameEventLogs($currentGame->id, $currentGame->guest_team_id);
- $outputMatch['status'] = $currentGame->status;
- $outputMatch['tactichome'] = $currentGame->tactic_home;
- $outputMatch['tacticguest'] = $currentGame->tactic_guest;
- }
- return view('matchcenter.content.live_top_display_field', compact('outputMatch'))->render();
- }
- /**
- * Get a single match complete data
- *
- * @param Request $request
- *
- * @return string
- */
- public function getSingleMatchCompleteData(Request $request): string {
- // Check for possible game id
- if ((int) $request->input('gameID') !== 0) {
- $currentGame = Game::find($request->input('gameID'));
- } else {
- // Find season
- $season = Season::find($request->input('seasonID'));
- if (!$season) {
- Log::error('getSingleMatchCompleteData - Season not found');
- abort(500, 'Season not found.');
- }
- // Define match day information
- $matchDayArgument = (string) $request->input('matchday');
- $matchDayParts = explode('_', $matchDayArgument);
- $matchDayType = $matchDayParts[0];
- $matchDay = (int) $matchDayParts[1];
- // Find match day and current game
- $currentGame = $season->getCurrentGameByMatchday($matchDay, $matchDayType);
- if (!$currentGame) {
- // Get first game of match day
- $currentGame = $season->getFirstGameByMatchday($matchDay, $matchDayType);
- if (!$currentGame) {
- Log::error('getSingleMatchCompleteData - No game found');
- abort(500, 'No game found.');
- }
- }
- }
- // Get all events of game
- $gameEvents = $this->getAllGameEventLogs($currentGame);
- $gameEvents['game'] = $currentGame;
- $gameEvents['player'] = [];
- // Get line up
- $gameHomeTeamLineUpQuery = GameLineUp::where('game_id', $currentGame->id)->where('team_id', $currentGame->home_team_id)->first();
- $gameGuestTeamLineUpQuery = GameLineUp::where('game_id', $currentGame->id)->where('team_id', $currentGame->guest_team_id)->first();
- // Go through home line up
- $gameHomeTeamLineUp = [];
- if (!is_null($gameHomeTeamLineUpQuery)) {
- // Define tactic and positions
- $gameHomeTeamLineUp['tactic'] = $gameHomeTeamLineUpQuery->tactic;
- $gameHomeTeamLineUp['positions'] = Tactics::$TACTIC_HOME[$gameHomeTeamLineUpQuery->tactic];
- for ($i = 1; $i <= 11; $i++) {
- // Define players
- if ($gameHomeTeamLineUpQuery->{'player' . $i} !== 0) {
- $gameHomeTeamLineUp['player' . $i] = [
- 'playerObject' => Player::find($gameHomeTeamLineUpQuery->{'player' . $i}),
- 'position' => Tactics::$TACTIC_POSITIONS[$gameHomeTeamLineUp['positions'][$i - 1]],
- ];
- $gameEvents['player'][$gameHomeTeamLineUpQuery->{'player' . $i}] = $this->getAllGameEventLogsFromPlayer($currentGame->id, $gameHomeTeamLineUpQuery->{'player' . $i});
- } else {
- $gameHomeTeamLineUp['player' . $i] = 0;
- }
- }
- }
- // Go through guest line up
- $gameGuestTeamLineUp = [];
- if (!is_null($gameGuestTeamLineUpQuery)) {
- // Define tactic and positions
- $gameGuestTeamLineUp['tactic'] = $gameGuestTeamLineUpQuery->tactic;
- $gameGuestTeamLineUp['positions'] = Tactics::$TACTIC_GUEST[$gameGuestTeamLineUpQuery->tactic];
- for ($i = 1; $i <= 11; $i++) {
- // Define players
- if ($gameGuestTeamLineUpQuery->{'player' . $i} !== 0) {
- $gameGuestTeamLineUp['player' . $i] = [
- 'playerObject' => Player::find($gameGuestTeamLineUpQuery->{'player' . $i}),
- 'position' => Tactics::$TACTIC_POSITIONS[$gameGuestTeamLineUp['positions'][$i - 1]],
- ];
- $gameEvents['player'][$gameGuestTeamLineUpQuery->{'player' . $i}] = $this->getAllGameEventLogsFromPlayer($currentGame->id, $gameGuestTeamLineUpQuery->{'player' . $i});
- } else {
- $gameGuestTeamLineUp['player' . $i] = 0;
- }
- }
- }
- return view('matchcenter.content.live_match_details', compact('gameEvents', 'gameHomeTeamLineUp', 'gameGuestTeamLineUp'))->render();
- }
- /**
- * Get schedule overview
- *
- * @param Request $request
- *
- * @return string
- */
- public function getScheduleOverview(Request $request): string {
- // Get and check season
- $season = Season::find($request->input('seasonID'));
- if (!$season) {
- Log::error('getScheduleOverview - Season not found');
- abort(500, 'Season not found.');
- }
- // Get data by schedule type
- if ($request->input('teamID') !== '0') {
- $games = Game::whereHas('Round', function($query) use ($season) {
- $query->where('season_id', $season->id);
- })->where(function($query) use ($request) {
- $query->where('home_team_id', $request->input('teamID'))
- ->orWhere('guest_team_id', $request->input('teamID'));
- })->orderBy('game_match_day_id', 'ASC')->get();
- } else {
- // Define match day information
- $matchDayArgument = (string) $request->input('matchDay');
- if ($matchDayArgument !== '') {
- $matchDayParts = explode('_', $matchDayArgument);
- $matchDayType = $matchDayParts[0];
- $matchDay = (int) $matchDayParts[1] ?? 0;
- // Check type
- if ($matchDayType === 'round') {
- $games = Game::where('round_id', $matchDay)->orderBy('start', 'ASC')->get();
- } else {
- // Get all games
- $games = Game::whereHas('Round', function($query) use ($season) {
- $query->where('season_id', $season->id);
- })->where('game_match_day_id', $matchDay)->orderBy('start', 'ASC')->get();
- }
- } else {
- Log::error('getScheduleOverview - Round not found');
- abort(500, 'Round not found.');
- }
- }
- // Define data of matches
- $dataMatches = [];
- foreach ($games as $game) {
- $dataMatches[$game->id] = [
- 'gameID' => $game->id,
- 'start' => $game->start->format('Y-m-d H:i:s') !== '-0001-11-30 00:00:00' ? Carbon::createFromTimestamp(strtotime($game->start))->timezone('Europe/Berlin')->format('d.m.Y - H:i') . ' Uhr' : '-',
- 'homeTeamID' => $game->home_team_id,
- 'homeTeamName' => $game->homeTeam !== null ? $game->homeTeam->short_name : $game->home_team_placeholder,
- 'homeTeamImageName' => $game->homeTeam !== null ? $game->homeTeam->getImageName() : 'dummy.png',
- 'guestTeamID' => $game->guest_team_id,
- 'guestTeamName' => $game->guestTeam !== null ? $game->guestTeam->short_name : $game->guest_team_placeholder,
- 'guestTeamImageName' => $game->guestTeam !== null ? $game->guestTeam->getImageName() : 'dummy.png',
- 'result' => self::getGameResult($game->id),
- 'status' => $game->status,
- ];
- }
- return view(
- 'matchcenter.content.schedule_matches',
- compact('dataMatches')
- )->render();
- }
- /**
- * Get all game event logs for given player
- *
- * @param $gameID
- * @param $playerID
- *
- * @return mixed
- */
- public function getAllGameEventLogsFromPlayer($gameID, $playerID) {
- return Game::find($gameID)->logs()->where('player_id', $playerID)->orderBy('minute', 'asc')->orderBy('extra_minute', 'asc')->get();
- }
- /**
- * Get schedule
- *
- * @param Request $request
- *
- * @return string
- */
- public function getSchedule(Request $request): string {
- // Find given season
- $season = Season::find($request->input('seasonID'));
- if (!$season) {
- Log::error('getSchedule - Season not found');
- abort(500, 'Season not found.');
- }
- // Get teams
- $teams = collect();
- foreach ($season->rounds as $round) {
- // Get and go through all round teams
- $roundTeams = RoundTeams::where('round_id', $round->id)->get();
- foreach ($roundTeams as $roundTeam) {
- $team = $roundTeam->team;
- // If given team not in the array
- if (!is_null($team) && !$teams->has($team->id)) {
- $teams->put($team->id, $team);
- }
- }
- }
- // Sort teams for short name
- $sortedTeams = $teams->sortBy([
- fn (Team $a, Team $b) => $a->short_name <=> $b->short_name,
- ]);
- // Get prepared rounds and match days for season
- $preparedSeasonRounds = $season->preparedMatchDayRounds();
- return view('matchcenter.content.schedule', [
- 'actualMatchDay' => $preparedSeasonRounds['lastMatchDayRound'],
- 'matchDays' => $preparedSeasonRounds['matchDaysRounds'],
- 'seasonTeams' => $sortedTeams,
- ])->render();
- }
- /**
- * Get statistics
- *
- * @param Request $request
- *
- * @return string
- */
- public function getStatistics(Request $request): string {
- // Find given season
- $season = Season::find($request->input('seasonID'));
- if (!$season) {
- Log::error('getStatistics - Season not found');
- abort(500, 'Season not found.');
- }
- // Calculate statistics
- $teams = collect();
- $playerGoals = [];
- $goals = [];
- $playerCards = [];
- $cards = [];
- foreach ($season->rounds as $round) {
- // Go through each round team
- $roundTeams = RoundTeams::where('round_id', $round->id)->get();
- foreach ($roundTeams as $roundTeam) {
- // Define team
- $team = $roundTeam->team;
- // Check if given team is not in array
- if (!is_null($team) && !$teams->has($team->id)) {
- $teams->put($team->id, $team);
- // Check each player
- foreach ($team->squad()->with('player')->get() as $squadPlayer) {
- $player = $squadPlayer->player;
- $pGoals = 0;
- $pCards = null;
- if (!is_null($player)) {
- $pGoals = $player->logs()->whereIn('game_event_type_id', [GameEventType::Goal, GameEventType::OwnGoal, GameEventType::Penalty])->whereHas('Game', function($query) use ($season) {
- $query->whereHas('Round', function($query2) use ($season) {
- $query2->where('season_id', $season->id);
- });
- })->count();
- $pCards = $player->logs()->whereIn('game_event_type_id', [GameEventType::YellowCard, GameEventType::YellowRedCard, GameEventType::RedCard])->whereHas('Game', function($query) use ($season) {
- $query->whereHas('Round', function($query2) use ($season) {
- $query2->where('season_id', $season->id);
- });
- })->get();
- }
- // If goals given
- if ($pGoals > 0) {
- $playerGoals[] = [
- 'player' => $player,
- 'teamname' => $team->short_name,
- 'teamImageName' => $team->getImageName(),
- 'goals' => $pGoals
- ];
- }
- if (!is_null($pCards) && $pCards->count() > 0) {
- $playerCards[] = [
- 'player' => $player,
- 'teamImage' => $season->league->team_type == 2 ? $player->currentNationTeam()->getImageName() : $player->currentClubTeam()->getImageName(),
- 'teamName' => $season->league->team_type == 2 ? $player->currentNationTeam()->short_name : $player->currentClubTeam()->short_name,
- 'yellow' => $pCards->filter(function($item) { return $item->game_event_type_id == GameEventType::YellowCard; })->count(),
- 'yellowred' => $pCards->filter(function($item) { return $item->game_event_type_id == GameEventType::YellowRedCard; })->count(),
- 'red' => $pCards->filter(function($item) { return $item->game_event_type_id == GameEventType::RedCard; })->count()
- ];
- }
- }
- // Calculate team goals once by games
- if (!isset($goals[$team->id])) {
- $goals[$team->id] = [
- 'team' => $team,
- 'goals' => $this->getTeamGoals($round, $team),
- ];
- }
- // Get team cards
- $teamCards = $this->getCards($round, $team);
- // Check if some data found
- if ($teamCards['yellow'] > 0 || $teamCards['yellowred'] > 0 || $teamCards['red'] > 0) {
- $cards[] = $teamCards;
- }
- }
- }
- }
- // Sort all arrays
- usort($cards, [$this, 'cardCompare']);
- usort($playerCards, [$this, 'cardCompare']);
- usort($playerGoals, [$this, 'goalsCompare']);
- usort($goals, [$this, 'goalsCompare']);
- return view('matchcenter.content.statistic', [
- 'playerGoals' => array_slice($playerGoals, 0, 20),
- 'playerCards' => array_slice($playerCards, 0, 20),
- 'cards' => $cards,
- 'goals' => $goals,
- ])->render();
- }
- /**
- * Check rank data
- *
- * @param $homeRank
- * @param $guestRank
- * @param $game
- * @param $scoringRule
- *
- * @return void
- */
- private function allocateRankData($homeRank, $guestRank, $game, $scoringRule): void {
- // Check game status
- if ($game->isDraw()) {
- $homeRank->draws += 1;
- $homeRank->points += $scoringRule->points_for_draw;
- $guestRank->draws += 1;
- $guestRank->points += $scoringRule->points_for_draw;
- } elseif ($game->getWinnerTeam()->id == $homeRank->id) {
- $homeRank->wins += 1;
- $homeRank->points += $scoringRule->points_for_win;
- $guestRank->loss += 1;
- $guestRank->points += $scoringRule->points_for_defeat;
- } elseif ($game->getWinnerTeam()->id == $guestRank->id) {
- $guestRank->wins += 1;
- $guestRank->points += $scoringRule->points_for_win;
- $homeRank->loss += 1;
- $homeRank->points += $scoringRule->points_for_defeat;
- }
- // Define general data
- $homeRank->games += 1;
- $homeRank->goals_shot += $game->homeTeamGoals();
- $homeRank->goals_against += $game->guestTeamGoals();
- $guestRank->games += 1;
- $guestRank->goals_shot += $game->guestTeamGoals();
- $guestRank->goals_against += $game->homeTeamGoals();
- }
- /**
- * Calculate match day ranks
- *
- * @param $round
- * @param $teams
- *
- * @return array
- */
- private function calculateMatchdayRanks($round, $teams): array {
- // Get order rules
- $orderRules = $round->orderRules;
- // Define table variable
- $table = [];
- foreach ($teams as $rank) {
- $table[] = $rank;
- }
- // Sort table
- usort($table, function($homeRank, $guestRank) use ($orderRules) {
- $result = 0;
- foreach ($orderRules as $rule) {
- $result = $rule->executeSort($homeRank, $guestRank);
- if ($result != 0) {
- break;
- }
- }
- return $result;
- });
- // Update ranks
- $i = 1;
- foreach ($table as $rank) {
- $rank->Rank = $i++;
- }
- return $table;
- }
- /**
- * Functionality to get cards
- *
- * @param $round
- * @param $team
- *
- * @return array
- */
- private function getCards($round, $team): array {
- // Get all logs for cards
- $logs = $team->logs()->whereHas('Game', function($query) use ($round) {
- $query->whereHas('Round', function($query) use ($round) {
- $query->where('season_id', $round->season_id);
- });
- })->whereIn('game_event_type_id', [GameEventType::YellowCard, GameEventType::YellowRedCard, GameEventType::RedCard])->get();
- return [
- 'team' => $team,
- 'yellow' => $logs->filter(function($item) { return $item->game_event_type_id == GameEventType::YellowCard; })->count(),
- 'yellowred' => $logs->filter(function($item) { return $item->game_event_type_id == GameEventType::YellowRedCard; })->count(),
- 'red' => $logs->filter(function($item) { return $item->game_event_type_id == GameEventType::RedCard; })->count()
- ];
- }
- /**
- * Functionality to get goals
- *
- * @param $round
- * @param $team
- *
- * @return array
- */
- private function getTeamGoals($round, $team): int {
- // Get all logs for cards
- $gameIds = Game::whereHas('Round', function($query) use ($round) {
- $query->where('season_id', $round->season_id);
- })
- ->where(function($query) use ($team) {
- return $query->where('home_team_id', $team->id)
- ->orWhere('guest_team_id', $team->id);
- })->pluck('id')->toArray();
- // Get game logs
- $logs = GameEvent::where(function($query) use ($gameIds) {
- return $query->whereIn('game_id', $gameIds)
- ->whereIn('game_event_type_id', [GameEventType::Goal, GameEventType::OwnGoal, GameEventType::Penalty])
- ->where('player_id', '!=', 0);
- })->get();
- // Count logs of team
- $teamGoals = 0;
- foreach ( $logs as $log ) {
- if (($log->team_id == $team->id && $log->game_event_type_id != GameEventType::OwnGoal) ||
- ($log->team_id != $team->id && $log->game_event_type_id == GameEventType::OwnGoal)) {
- $teamGoals++;
- }
- }
- return $teamGoals;
- }
- /**
- * Function to compare goals
- *
- * @param array $player1
- * @param array $player2
- *
- * @return int
- */
- private function goalsCompare(array $player1, array $player2): int {
- if ($player1['goals'] > $player2['goals']) {
- return -1;
- } elseif ($player2['goals'] > $player1['goals']) {
- return 1;
- }
- return 0;
- }
- /**
- * Function to compary cards
- *
- * @param array $obj1
- * @param array $obj2
- *
- * @return int
- */
- private function cardCompare(array $obj1, array $obj2): int {
- $obj1Points = ($obj1['yellow']) + ($obj1['yellowred'] * 3) + ($obj1['red'] * 5);
- $obj2Points = ($obj2['yellow']) + ($obj2['yellowred'] * 3) + ($obj2['red'] * 5);
- if ($obj1Points > $obj2Points) {
- return -1;
- } elseif ($obj2Points > $obj1Points) {
- return 1;
- }
- return 0;
- }
- }