コード例 #1
0
ファイル: Match.php プロジェクト: 0ida/fussi
 /**
  * @param LeaguePeriod  $period
  * @param League    $tournament
  * @param SingleMatch[] $matches
  * @param Player        $player1
  * @param Player        $player2
  *
  * @return string
  */
 public function __invoke(LeaguePeriod $period, League $tournament, array $matches, Player $player1, Player $player2)
 {
     $allow = $period->inCurrentMonth();
     $out = '';
     if ($player1 != $player2) {
         $ok = false;
         foreach ($matches as $match) {
             $url = $this->getView()->url('match/edit', array('mid' => $match->getId()));
             if ($match->isPlayedBy($player1, $player2)) {
                 $title = $player1->getName() . " vs. " . $player2->getName();
                 $results = array();
                 $counter = 1;
                 foreach ($match->getGames() as $game) {
                     $results[] = "Game " . $counter . ": " . $game->getGoalsTeamOne() . ' / ' . $game->getGoalsTeamTwo();
                     $counter++;
                 }
                 $content = implode("<br>", $results);
                 if ($allow) {
                     $content .= "<br><br><a href='" . $url . "' class='btn btn-small'>Edit</a>";
                 }
                 $out .= '<span title="' . $title . '" data-content="' . $content . '" class="match btn result">';
                 $out .= $match->getScore();
                 $out .= '</span>';
                 $ok = true;
             }
         }
         if (!$ok && $allow) {
             $url = $this->getView()->url('match/new', array('tid' => $tournament->getId(), 'player1' => $player1->getId(), 'player2' => $player2->getId()));
             $out .= '<a href="' . $url . '" class="btn btn-small">Edit</a>';
         }
     }
     return $out;
 }
コード例 #2
0
ファイル: TournamentController.php プロジェクト: 0ida/fussi
 /**
  * @param League $tournament
  *
  * @return array
  */
 protected function handleLeague(League $tournament)
 {
     $year = $this->params()->fromRoute('year');
     $month = $this->params()->fromRoute('month');
     $leaguePeriod = new LeaguePeriod($tournament->getStart(), $year, $month);
     if ($leaguePeriod->isOutOfBounds()) {
         $this->getResponse()->setStatusCode(404);
         return;
     }
     $matches = $this->matchRepository->findForPeriod($tournament, $leaguePeriod);
     $players = $tournament->getPlayers();
     $activePlayers = $this->matchRepository->getActivePlayers($tournament, $leaguePeriod);
     if (!$leaguePeriod->inCurrentMonth()) {
         $players = $activePlayers;
     }
     $ranking = new Ranking($matches);
     $infoMaxPoints = (count($players) - 1) * 2;
     $infoMaxMatches = count($players) - 1;
     $tournamentPotential = $ranking->getPotential(count($players) - 1);
     $infoMaxPoints = $infoMaxPoints >= 0 ? $infoMaxPoints : 0;
     $infoMaxMatches = $infoMaxMatches >= 0 ? $infoMaxMatches : 0;
     $viewData = array('period' => $leaguePeriod, 'players' => $players, 'activePlayers' => $activePlayers, 'matches' => $matches, 'ranking' => $ranking, 'tournament' => $tournament, 'infoMaxPoints' => $infoMaxPoints, 'infoMaxMatches' => $infoMaxMatches, 'tournamentPotential' => $tournamentPotential);
     $viewModel = new ViewModel($viewData);
     $viewModel->setTemplate('application/tournament/show-league');
     return $viewModel;
 }
コード例 #3
0
 /**
  * @return array|\Zend\Http\Response
  */
 public function addLeagueAction()
 {
     $form = new LeagueForm();
     $tournament = new League();
     $tournament->setStart(new \DateTime());
     $form->bind($tournament);
     $form->setInputFilter(new \Application\Form\InputFilter\League($this->tournamentRepository));
     if ($this->request->isPost()) {
         $form->setData($this->request->getPost());
         if ($form->isValid()) {
             $this->tournamentRepository->persist($tournament);
             return $this->redirect()->toRoute('tournaments');
         }
     }
     return array('form' => $form);
 }
コード例 #4
0
ファイル: LeagueTest.php プロジェクト: 0ida/fussi
 public function testIsInactive()
 {
     $this->tournament->setEnd(new \DateTime("2013-01-31"));
     $this->assertFalse($this->tournament->isActive());
 }
コード例 #5
0
ファイル: LeaguePaginator.php プロジェクト: 0ida/fussi
 /**
  * @param League $tournament
  * @param DateTime   $date
  *
  * @return string
  */
 protected function getUrl(League $tournament, DateTime $date)
 {
     return $this->view->url('tournament/show', array('id' => $tournament->getId(), 'year' => $date->format('Y'), 'month' => $date->format('m')));
 }