Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 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;
 }
 /**
  * @Route("user/challenge/accept/{slug}", name="challenge_accept")
  */
 public function challengeAcceptAction(Request $request, $slug)
 {
     $em = $this->getDoctrine()->getManager();
     $challenge = $em->getRepository('AppBundle:Challenge')->find($slug);
     $match = new Match();
     $match->setPlayer1($challenge->getPlayer1());
     $match->setPlayer2($challenge->getPlayer2());
     $match->setClub($challenge->getClub());
     $match->setDate($challenge->getDate());
     $match->setTime($challenge->getTime());
     if (!$challenge) {
         throw $this->createNotFoundException("No challenge found for id" . $slug);
     }
     $challenge->setStatus("Accepted");
     $em->persist($match);
     $em->flush();
     $userId = $this->getUser()->getId();
     $challenges = $this->getDoctrine()->getRepository('AppBundle:Challenge')->findUserChallenges($userId);
     return $this->render('challenge/challenge_list.html.twig', array('data' => $request, 'userId' => $userId, 'challenges' => $challenges));
 }