public function getFixtures(Stage $stage, $week) { try { $fixtures = $this->whoscored->loadStatistics('stagefixtures', array('stageId' => $stage->getWsId(), 'd' => $week, 'isAggregate' => false)); } catch (\Exception $e) { throw $e; } $rows_affected = 0; foreach ($fixtures as $fixture) { $matchId = $fixture[0]; $count = $this->em->createQuery('SELECT COUNT(m) FROM AppBundle:Match m WHERE m.wsId = :id')->setParameter(':id', $matchId)->getSingleScalarResult(); if ($count == 1) { continue; } $homeTeam = $this->getTeam($fixture[4]); $awayTeam = $this->getTeam($fixture[7]); $match = new Match(); $match->setStage($stage); $match->setWsId($matchId); $time = DateTime::createFromFormat('D, M j Y H:i', $fixture[2] . ' ' . $fixture[3], new DateTimeZone('UTC'))->getTimestamp(); $match->setTime($time); $match->setHomeTeam($homeTeam); $match->setAwayTeam($awayTeam); $match->setStatus(0); $this->em->persist($match); $rows_affected++; } $this->em->flush(); return $rows_affected; }
public function getFixtures(Stage $stage, $dates) { try { $fixtures = $this->downloader->schedule('fixtures', ['stage' => $stage, 'dates' => $dates, 'isAggregate' => false]); } catch (\Exception $e) { throw $e; } foreach ($fixtures as $fixture) { $match = $this->em->getRepository('AppBundle:Match')->findOneBy(['wsId' => $fixture->id]); if (null !== $match) { if (1 !== $match->getStatus()) { if ($fixture->elapsed === 'Abd' || 'Can' === $fixture->elapsed || 'Post' === $fixture->elapsed || 'Susp' === $fixture->elapsed) { $status = 3; } else { if ('FT' === $fixture->elapsed) { $status = 2; } else { $status = 0; } } $match->setStatus($status); $time = DateTime::createFromFormat('D, M j Y H:i', $fixture->start_date . ' ' . $fixture->start_time, new DateTimeZone('UTC'))->getTimestamp(); $match->setTime($time); } } else { try { $homeTeam = $this->getTeam($fixture->home_team_id); } catch (\Exception $e) { $homeTeam = new Team(); $homeTeam->setName($fixture->home_team_name); $homeTeam->setWsId($fixture->home_team_id); $this->em->persist($homeTeam); } try { $awayTeam = $this->getTeam($fixture->home_team_id); } catch (\Exception $e) { $awayTeam = new Team(); $awayTeam->setName($fixture->home_team_name); $awayTeam->setWsId($fixture->home_team_id); $this->em->persist($awayTeam); } $match = new Match(); $match->setStage($stage); $match->setWsId($fixture->id); $time = DateTime::createFromFormat('D, M j Y H:i', $fixture->start_date . ' ' . $fixture->start_time, new DateTimeZone('UTC'))->getTimestamp(); $match->setTime($time); $match->setHomeTeam($homeTeam); $match->setAwayTeam($awayTeam); $match->setIsOpta($fixture->is_opta); if ($fixture->elapsed === 'Abd' || 'Can' === $fixture->elapsed || 'Post' === $fixture->elapsed || 'Susp' === $fixture->elapsed) { $status = 3; } else { if ('FT' === $fixture->elapsed) { $status = 2; } else { $status = 0; } } $match->setStatus($status); $this->em->persist($match); } } $this->em->flush(); return true; }