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;
 }
Example #2
0
 public function addStage(Stage $newStage)
 {
     foreach ($this->stages as $stage) {
         if ($stage->getId() == $newStage->getId()) {
             return;
         }
     }
     $this->stages[] = $newStage;
 }
 /**
  * @Route("/{id}/update-db", name="update-db")
  */
 public function updateDb(Stage $stage)
 {
     $em = $this->getDoctrine()->getManager();
     $query = $em->createQuery('SELECT m FROM AppBundle:Match m WHERE m.status = 2 AND m.stage = :stage')->setParameter('stage', $stage->getId());
     $results = $query->getResult();
     foreach ($results as $match) {
         $sm = new SubscriptionManager($this->get('app.whoscored'), $this->get('doctrine.orm.entity_manager'));
         $sm->getMatchData($match);
     }
     $this->addFlash('notice', 'Flushed match data for stage ' . $stage->getName() . '. ' . count($results) . ' matches flushed.');
     return $this->redirectToRoute('homepage');
 }