diff --git a/app/config/config.yml b/app/config/config.yml index 9694d6a..fcc20a2 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -10,7 +10,7 @@ parameters: locale: en # application parameters football_api.name: football_data_org - football_api.base_uri: http://api.football-data.org/v1 + football_api.base_uri: http://api.football-data.org/v2 framework: #esi: ~ @@ -175,4 +175,4 @@ fos_oauth_server: options: access_token_lifetime: 7776000 # 90 days in seconds -nelmio_api_doc: ~ \ No newline at end of file +nelmio_api_doc: ~ diff --git a/src/Devlabs/SportifyBundle/Services/DataUpdates/Fetchers/FootballDataOrg.php b/src/Devlabs/SportifyBundle/Services/DataUpdates/Fetchers/FootballDataOrg.php index cb30ce0..9ed0e56 100644 --- a/src/Devlabs/SportifyBundle/Services/DataUpdates/Fetchers/FootballDataOrg.php +++ b/src/Devlabs/SportifyBundle/Services/DataUpdates/Fetchers/FootballDataOrg.php @@ -81,9 +81,9 @@ public function processResponse(Response $response, $bodyProperty = null) */ public function fetchFixturesByTournamentAndMatchDay($apiTournamentId, $matchDay) { - $uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/fixtures/?matchday='.$matchDay; + $uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/matches/?matchday='.$matchDay; - return $this->processResponse($this->getResponse($uri), 'fixtures'); + return $this->processResponse($this->getResponse($uri), 'matches'); } /** @@ -96,9 +96,9 @@ public function fetchFixturesByTournamentAndMatchDay($apiTournamentId, $matchDay */ public function fetchFixturesByTournamentAndTimeRange($apiTournamentId, $dateFrom, $dateTo) { - $uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/fixtures/?timeFrameStart='.$dateFrom.'&timeFrameEnd='.$dateTo; + $uri = $this->baseUri.'/competitions/'.$apiTournamentId.'/matches/?dateFrom='.$dateFrom.'&dateTo='.$dateTo; - return $this->processResponse($this->getResponse($uri), 'fixtures'); + return $this->processResponse($this->getResponse($uri), 'matches'); } /** @@ -122,7 +122,6 @@ public function fetchTeamsByTournament($apiTournamentId) public function fetchAllTournaments() { $uri = $this->baseUri.'/competitions'; - - return $this->processResponse($this->getResponse($uri)); + return $this->processResponse($this->getResponse($uri), 'competitions'); } } diff --git a/src/Devlabs/SportifyBundle/Services/DataUpdates/Parsers/FootballDataOrg.php b/src/Devlabs/SportifyBundle/Services/DataUpdates/Parsers/FootballDataOrg.php index b3e6134..706f938 100644 --- a/src/Devlabs/SportifyBundle/Services/DataUpdates/Parsers/FootballDataOrg.php +++ b/src/Devlabs/SportifyBundle/Services/DataUpdates/Parsers/FootballDataOrg.php @@ -19,7 +19,7 @@ public function parseTeams(array $teams) foreach ($teams as &$team) { $parsedTeam = array(); - $parsedTeam['team_id'] = $this->getNumberAtEndOfString($team->_links->self->href); + $parsedTeam['team_id'] = $team->id; $parsedTeam['name'] = $team->name; $parsedTeam['team_logo'] = $team->crestUrl; @@ -40,22 +40,30 @@ public function parseFixtures(array $fixtures) foreach ($fixtures as &$fixture) { $parsedFixture = array(); - $parsedFixture['match_id'] = $this->getNumberAtEndOfString($fixture->_links->self->href); - $parsedFixture['tournament_id'] = $this->getNumberAtEndOfString($fixture->_links->competition->href); - $parsedFixture['home_team_id'] = $this->getNumberAtEndOfString($fixture->_links->homeTeam->href); - $parsedFixture['away_team_id'] = $this->getNumberAtEndOfString($fixture->_links->awayTeam->href); - $parsedFixture['match_local_time'] = date('Y-m-d H:i:s', strtotime($fixture->date)); + $parsedFixture['match_id'] = $fixture->id; + $parsedFixture['tournament_id'] = $fixture->season->id; + $parsedFixture['home_team_id'] = $fixture->homeTeam->id; + $parsedFixture['away_team_id'] = $fixture->awayTeam->id; + + // NOTE: team id 757 is just a placeholder used in this API, + // when match is scheduled, but teams are still not clear. + // This occurs in scheduled knock-out round matches. + if ($parsedFixture['home_team_id'] == 757 || $parsedFixture['away_team_id'] == 757) { + continue; + } + + $parsedFixture['match_local_time'] = date('Y-m-d H:i:s', strtotime($fixture->utcDate)); $parsedFixture['status'] = $fixture->status; if ($fixture->status === 'FINISHED') { - $parsedFixture['home_team_goals'] = $fixture->result->goalsHomeTeam; - $parsedFixture['away_team_goals'] = $fixture->result->goalsAwayTeam; + $parsedFixture['home_team_goals'] = $fixture->score->fullTime->homeTeam; + $parsedFixture['away_team_goals'] = $fixture->score->fullTime->awayTeam; } else { $parsedFixture['home_team_goals'] = null; $parsedFixture['away_team_goals'] = null; } - if ($fixture->odds && ($fixture->odds !== 'null')) { +/* if ($fixture->odds && ($fixture->odds !== 'null')) { $parsedFixture['odds_home_win'] = $fixture->odds->homeWin; $parsedFixture['odds_draw'] = $fixture->odds->draw; $parsedFixture['odds_away_win'] = $fixture->odds->awayWin; @@ -64,7 +72,7 @@ public function parseFixtures(array $fixtures) $parsedFixture['odds_draw'] = null; $parsedFixture['odds_away_win'] = null; } - +*/ $fixture = $parsedFixture; } @@ -83,8 +91,7 @@ public function parseTournaments(array $tournaments) $parsedTournament = array(); $parsedTournament['id'] = $tournament->id; - $parsedTournament['name'] = $tournament->caption; - + $parsedTournament['name'] = $tournament->name; $tournament = $parsedTournament; }