Esempio n. 1
0
 public function writeResult($team, $point1, $point2)
 {
     $result = new ResultGame();
     $point = $this->checkGoals($point1, $point2);
     $data = $this->getDoctrine()->getRepository('AppBundle:ResultGame')->findOneBy(array('team' => $team));
     if ($data) {
         $count = $data->getCountGame();
         $win = $data->getWinGame();
         $draw = $data->getDrawGame();
         $defeat = $data->getDefeatGame();
     } else {
         $count = 0;
         $win = 0;
         $draw = 0;
         $defeat = 0;
     }
     switch ($point) {
         case 0:
             $defeat += 1;
             $count += 1;
             break;
         case 1:
             $draw += 1;
             $count += 1;
             break;
         case 3:
             $win += 1;
             $count += 1;
             break;
     }
     $points = $draw + 3 * $win;
     $em = $this->getDoctrine()->getManager();
     $result->setCountGame($count);
     $result->setWinGame($win);
     $result->setDrawGame($draw);
     $result->setDefeatGame($defeat);
     $result->setPoints($points);
     $result->setTeam($team);
     $em->persist($result);
     $em->flush();
     return;
 }
 /**
  * @Route("/admin/insert/result/{id}", name="result_insert_admin", requirements={"id" : "\d+"})
  */
 public function generateResultGameAction($id)
 {
     $teams = $this->getDoctrine()->getRepository('AppBundle:Team')->find($id);
     if (!$teams) {
         throw $this->createNotFoundException('Not found');
     }
     $em = $this->getDoctrine()->getManager();
     $result = new ResultGame();
     $result->setTeam($teams);
     $result->setCountGame(rand(0, 20));
     $result->setWinGame(rand(0, 15));
     $result->setDrawGame(rand(0, 15));
     $result->setDefeatGame(rand(0, 15));
     $result->setPoints(rand(0, 30));
     $em->persist($result);
     $em->flush();
     $this->addFlash('notice', 'Add results!');
     return $this->forward('AppBundle:Admin:show');
 }