/** * @Route("/new/{ranking_id}") * @Template() */ public function newAction($ranking_id) { if (false === $this->get('security.context')->isGranted('ROLE_USER')) { throw new AccessDeniedException(); } $em = $this->getDoctrine()->getManager(); $ranking = $em->find('ClubRankingBundle:Ranking', $ranking_id); $res = array(); $res['user0'] = $this->getUser(); $form = $this->get('club_match.match')->getMatchForm($res, $ranking->getGameSet()); if ($this->getRequest()->getMethod() == 'POST') { $form->bind($this->getRequest()); if ($form->isValid()) { $this->get('club_match.match')->bindMatch($form->getData()); $this->get('club_ranking.ranking')->validateMatch($ranking, $this->get('club_match.match')); if ($this->get('club_match.match')->isValid()) { $rm = new \Club\RankingBundle\Entity\Match(); $rm->setRanking($ranking); $rm->setMatch($this->get('club_match.match')->getMatch()); $ranking->addMatch($rm); $this->get('club_match.match')->save(); $this->get('session')->getFlashBag()->add('notice', $this->get('translator')->trans('Your changes are saved.')); return $this->redirect($this->generateUrl('club_ranking_ranking_show', array('id' => $ranking->getId()))); } else { $this->get('session')->getFlashBag()->add('error', $this->get('club_match.match')->getError()); } } } return array('form' => $form->createView(), 'ranking' => $ranking, 'sets' => $ranking->getGameSet()); }
public function onVersionMigrate(\Club\InstallerBundle\Event\FilterVersionEvent $event) { if ($event->getVersion()->getVersion() != '20121016161300') { // fit to this version only return; } $rules = $this->em->getRepository('ClubMatchBundle:Rule')->findAll(); foreach ($rules as $r) { $r2 = new \Club\RankingBundle\Entity\Rule(); $r2->setName($r->getName()); $r2->setPointWon($r->getPointWon()); $r2->setPointLost($r->getPointLost()); $r2->setSamePlayer($r->getSamePlayer()); $this->em->persist($r2); } $this->em->flush(); $leagues = $this->em->getRepository('ClubMatchBundle:League')->findAll(); foreach ($leagues as $l) { $r = new \Club\RankingBundle\Entity\Ranking(); $r->setName($l->getName()); $r->setGendeR($l->getGender()); $r->setInviteOnly($l->getInviteOnly()); $r->setGameSet($l->getGameSet()); $r->setType($l->getType()); $r->setStartDate($l->getStartDate()); $r->setEndDate($l->getEndDate()); $rule = $this->em->getRepository('ClubRankingBundle:Rule')->findOneBy(array('name' => $l->getRule()->getName())); $r->setRule($rule); foreach ($r->getUsers() as $u) { $r->addUser($u); } foreach ($l->getMatches() as $m) { $match = new \Club\RankingBundle\Entity\Match(); $match->setMatch($m); $match->setRanking($r); $match->setProcessed(true); $this->em->persist($match); $r->addMatch($match); } $tables = $this->em->getRepository('ClubMatchBundle:LeagueTable')->findBy(array('league' => $l->getId())); foreach ($tables as $t) { $e = new \Club\RankingBundle\Entity\RankingEntry(); $e->setRanking($r); $e->setPlayed($t->getPlayed()); $e->setWon($t->getWon()); $e->setLost($t->getLost()); $e->setPoint($t->getPoint()); $e->setTeam($t->getTeam()); $this->em->persist($e); } $this->em->persist($r); } }