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; }