示例#1
0
 /**
  * Hydrate $object with the provided $data.
  *
  * @param array $data
  * @param \Application\Model\Entity\Match $match
  *
  * @return \Application\Model\Entity\Match
  */
 public function hydrate(array $data, $match)
 {
     $match->setGames($data['games']);
     if ($match instanceof DoubleMatch) {
         $match->setTeamOne($this->repository->find($data['teamOneAttack']), $this->repository->find($data['teamOneDefence']));
         $match->setTeamTwo($this->repository->find($data['teamTwoAttack']), $this->repository->find($data['teamTwoDefence']));
     }
     return $match;
 }
示例#2
0
 /**
  * @param \Application\Model\Entity\Match $match
  *
  * @return string
  */
 public function __invoke($match)
 {
     $gameResults = array();
     $games = $match->getGames();
     foreach ($games as $game) {
         $goalsOne = $game->getGoalsTeamOne();
         $goalsTwo = $game->getGoalsTeamTwo();
         $gameResults[] = $goalsOne . ":" . $goalsTwo;
     }
     return implode(", ", $gameResults);
 }
示例#3
0
文件: MatchTest.php 项目: 0ida/fussi
 /**
  * @param int $goalsTeamOne
  * @param int $goalsTeamTwo
  */
 protected function addGameToMatch($goalsTeamOne, $goalsTeamTwo)
 {
     $game = new Game();
     $game->setGoalsTeamOne($goalsTeamOne);
     $game->setGoalsTeamTwo($goalsTeamTwo);
     $this->match->addGame($game);
 }
示例#4
0
文件: Elo.php 项目: 0ida/fussi
 /**
  * @param Match $match
  *
  * @return bool
  */
 protected function matchHasNewPlayer(Match $match)
 {
     foreach ($match->getPlayer() as $player) {
         if ($player->getMatchCount() < 30) {
             return true;
         }
     }
     return false;
 }
示例#5
0
 /**
  * @param Match        $match
  * @param PlannedMatch $plannedMatch
  *
  * @return ViewModel
  */
 protected function handleForm($match, $plannedMatch = null)
 {
     $tournament = $match->getTournament();
     $factory = new \Application\Form\Factory($this->playerRepository);
     $form = $factory->getMatchForm($tournament, $plannedMatch);
     $form->bind($match);
     if ($this->request->isPost()) {
         $form->setData($this->request->getPost());
         if ($form->isValid()) {
             if ($match->isResultValid()) {
                 $tournament->matchPlayed($match, $plannedMatch);
                 $this->matchRepository->persist($match);
                 if ($plannedMatch != null) {
                     $this->plannedMatchRepository->persist($plannedMatch);
                 }
                 $ranking = new Elo();
                 $log = $ranking->calculateMatch($match);
                 $this->pointLogRepository->persist($log);
                 foreach ($match->getPlayer() as $player) {
                     $this->playerRepository->persist($player);
                 }
                 return $this->redirect()->toRoute('tournament/show', array('id' => $tournament->getId()));
             } else {
                 $form->setMessages(array('submit' => array('You need to play more matches')));
             }
         }
     }
     if ($match->getId() != null) {
         $url = $this->url()->fromRoute('match/edit/', array('mid' => $match->getId()));
         $form->setAttribute('action', $url);
     }
     $view = new ViewModel(array('form' => $form, 'tournament' => $tournament));
     $view->setTemplate('application/match/edit');
     if ($this->getRequest()->isXmlHttpRequest()) {
         $view->setTerminal(true);
     }
     return $view;
 }